[Pcre-svn] [735] code/trunk: Extend auto-anchoring to ignore…

Inizio della pagina
Delete this message
Autore: Subversion repository
Data:  
To: pcre-svn
Oggetto: [Pcre-svn] [735] code/trunk: Extend auto-anchoring to ignore "never-obeyed" groups at the start.
Revision: 735
          http://www.exim.org/viewvc/pcre2?view=rev&revision=735
Author:   ph10
Date:     2017-04-07 09:46:29 +0100 (Fri, 07 Apr 2017)
Log Message:
-----------
Extend auto-anchoring to ignore "never-obeyed" groups at the start.


Modified Paths:
--------------
    code/trunk/ChangeLog
    code/trunk/src/pcre2_compile.c
    code/trunk/testdata/testinput2
    code/trunk/testdata/testoutput2


Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog    2017-04-06 18:02:40 UTC (rev 734)
+++ code/trunk/ChangeLog    2017-04-07 08:46:29 UTC (rev 735)
@@ -116,7 +116,12 @@
 20. Applied Jason Hood's patches (slightly modified) to pcre2grep, to implement 
 the --output=text (-O) option and the inbuilt callout echo.


+21. Extend auto-anchoring etc. to ignore groups with a zero qualifier and
+single-branch conditions with a false condition (e.g. DEFINE) at the start of a
+branch. For example, /(?(DEFINE)...)^A/ and /(...){0}^B/ are now flagged as
+anchored.

+
Version 10.23 14-February-2017
------------------------------


Modified: code/trunk/src/pcre2_compile.c
===================================================================
--- code/trunk/src/pcre2_compile.c    2017-04-06 18:02:40 UTC (rev 734)
+++ code/trunk/src/pcre2_compile.c    2017-04-07 08:46:29 UTC (rev 735)
@@ -4164,6 +4164,18 @@
     case OP_CALLOUT_STR:
     code += GET(code, 1 + 2*LINK_SIZE);
     break;
+    
+    case OP_SKIPZERO:
+    code += 2 + GET(code, 2) + LINK_SIZE;
+    break;   
+    
+    case OP_COND:
+    case OP_SCOND:
+    if (code[1+LINK_SIZE] != OP_FALSE ||   /* Not DEFINE */
+        code[GET(code, 1)] != OP_KET)      /* More than one branch */
+      return code;
+    code += GET(code, 1) + 1 + LINK_SIZE;
+    break;    


     default:
     return code;


Modified: code/trunk/testdata/testinput2
===================================================================
--- code/trunk/testdata/testinput2    2017-04-06 18:02:40 UTC (rev 734)
+++ code/trunk/testdata/testinput2    2017-04-07 08:46:29 UTC (rev 735)
@@ -5040,4 +5040,20 @@


#subject -no_jit

+# Check auto-anchoring when there is a group that is never obeyed at
+# the start of a branch.
+
+/(?(DEFINE)(a))^bc/I
+
+/(a){0}.*bc/sI
+
+# This should be anchored, as the condition is always false and there is
+# no alternative branch.
+
+/(?(VERSION>=999)yes)^bc/I
+
+# This should not be anchored.
+
+/(?(VERSION>=999)yes|no)^bc/I
+
# End of testinput2

Modified: code/trunk/testdata/testoutput2
===================================================================
--- code/trunk/testdata/testoutput2    2017-04-06 18:02:40 UTC (rev 734)
+++ code/trunk/testdata/testoutput2    2017-04-07 08:46:29 UTC (rev 735)
@@ -15576,6 +15576,38 @@


#subject -no_jit

+# Check auto-anchoring when there is a group that is never obeyed at
+# the start of a branch.
+
+/(?(DEFINE)(a))^bc/I
+Capturing subpattern count = 1
+Compile options: <none>
+Overall options: anchored
+Subject length lower bound = 2
+
+/(a){0}.*bc/sI
+Capturing subpattern count = 1
+Compile options: dotall
+Overall options: anchored dotall
+Last code unit = 'c'
+Subject length lower bound = 2
+
+# This should be anchored, as the condition is always false and there is
+# no alternative branch.
+
+/(?(VERSION>=999)yes)^bc/I
+Capturing subpattern count = 0
+Compile options: <none>
+Overall options: anchored
+Subject length lower bound = 2
+
+# This should not be anchored.
+
+/(?(VERSION>=999)yes|no)^bc/I
+Capturing subpattern count = 0
+Last code unit = 'c'
+Subject length lower bound = 4
+
# End of testinput2
Error -63: PCRE2_ERROR_BADDATA (unknown error number)
Error -62: bad serialized data