[Pcre-svn] [1035] code/trunk: Make pcregrep use PCRE_STUDY_E…

Góra strony
Delete this message
Autor: Subversion repository
Data:  
Dla: pcre-svn
Temat: [Pcre-svn] [1035] code/trunk: Make pcregrep use PCRE_STUDY_EXTRA_NEEDED.
Revision: 1035
          http://vcs.pcre.org/viewvc?view=rev&revision=1035
Author:   ph10
Date:     2012-09-10 17:23:12 +0100 (Mon, 10 Sep 2012)


Log Message:
-----------
Make pcregrep use PCRE_STUDY_EXTRA_NEEDED.

Modified Paths:
--------------
    code/trunk/ChangeLog
    code/trunk/pcregrep.c


Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog    2012-09-10 11:14:25 UTC (rev 1034)
+++ code/trunk/ChangeLog    2012-09-10 16:23:12 UTC (rev 1035)
@@ -70,6 +70,9 @@
     general tidy up of EBCDIC-related issues, and the documentation was also 
     not quite right. There is now a test that can be run on ASCII systems to 
     check some of the EBCDIC-related things (but is it not a full test). 
+    
+16. The new PCRE_STUDY_EXTRA_NEEDED option is now used by pcregrep, resulting 
+    in a small tidy to the code.





Modified: code/trunk/pcregrep.c
===================================================================
--- code/trunk/pcregrep.c    2012-09-10 11:14:25 UTC (rev 1034)
+++ code/trunk/pcregrep.c    2012-09-10 16:23:12 UTC (rev 1035)
@@ -2880,9 +2880,15 @@
     goto EXIT2;
   }


-/* Study the regular expressions, as we will be running them many times. Unless
-JIT has been explicitly disabled, arrange a stack for it to use. */
+/* Study the regular expressions, as we will be running them many times. If an
+extra block is needed for a limit, set PCRE_STUDY_EXTRA_NEEDED so that one is
+returned, even if studying produces no data. */

+if (match_limit > 0 || match_limit_recursion > 0)
+ study_options |= PCRE_STUDY_EXTRA_NEEDED;
+
+/* Unless JIT has been explicitly disabled, arrange a stack for it to use. */
+
#ifdef SUPPORT_PCREGREP_JIT
if ((study_options & PCRE_STUDY_JIT_COMPILE) != 0)
jit_stack = pcre_jit_stack_alloc(32*1024, 1024*1024);
@@ -2905,32 +2911,22 @@
}

/* If --match-limit or --recursion-limit was set, put the value(s) into the
-pcre_extra block for each pattern. */
+pcre_extra block for each pattern. There will always be an extra block because
+of the use of PCRE_STUDY_EXTRA_NEEDED above. */

-if (match_limit > 0 || match_limit_recursion > 0)
+for (cp = patterns; cp != NULL; cp = cp->next)
   {
-  for (cp = patterns; cp != NULL; cp = cp->next)
+  if (match_limit > 0)
     {
-    if (cp->hint == NULL)
-      {
-      cp->hint = (pcre_extra *)malloc(sizeof(pcre_extra));
-      if (cp->hint == NULL)
-        {
-        fprintf(stderr, "pcregrep: malloc failed\n");
-        pcregrep_exit(2);
-        }
-      }
-    if (match_limit > 0)
-      {
-      cp->hint->flags |= PCRE_EXTRA_MATCH_LIMIT;
-      cp->hint->match_limit = match_limit;
-      }
-    if (match_limit_recursion > 0)
-      {
-      cp->hint->flags |= PCRE_EXTRA_MATCH_LIMIT_RECURSION;
-      cp->hint->match_limit_recursion = match_limit_recursion;
-      }
+    cp->hint->flags |= PCRE_EXTRA_MATCH_LIMIT;
+    cp->hint->match_limit = match_limit;
     }
+     
+  if (match_limit_recursion > 0)
+    {
+    cp->hint->flags |= PCRE_EXTRA_MATCH_LIMIT_RECURSION;
+    cp->hint->match_limit_recursion = match_limit_recursion;
+    }
   }


/* If there are include or exclude patterns read from the command line, compile