This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regcomp.c: Fix up RE_TRACK_PATTERN_OFFSETS
authorKarl Williamson <khw@cpan.org>
Wed, 14 Nov 2018 16:09:38 +0000 (09:09 -0700)
committerKarl Williamson <khw@cpan.org>
Fri, 16 Nov 2018 17:29:26 +0000 (10:29 -0700)
These need to be changed around as a result of removing the sizing pass
from pattern compilation.

The first element in the array is the number of offsets.  This had
become wrong.  And it is used instead of the program length when it is
available.

ext/re/t/regop.t
regcomp.c

index 54a197b..cf35d71 100644 (file)
@@ -241,7 +241,7 @@ floating ""$ at 3..4 (checking floating)
 #Matching stclass EXACTF <.> against ".exe"
 ---
 #Compiling REx "[q]"
 #Matching stclass EXACTF <.> against ".exe"
 ---
 #Compiling REx "[q]"
-#size 3 nodes Got 28 bytes for offset annotations.
+#size 3 nodes Got 7 bytes for offset annotations.
 #first at 1
 #Final program:
 #   1: EXACT <q>(3)
 #first at 1
 #Final program:
 #   1: EXACT <q>(3)
@@ -254,7 +254,7 @@ floating ""$ at 3..4 (checking floating)
 #Guessed: match at offset 0
 #%MATCHED%
 #Freeing REx: "[q]"
 #Guessed: match at offset 0
 #%MATCHED%
 #Freeing REx: "[q]"
-Got 28 bytes for offset annotations.
+Got 7 bytes for offset annotations.
 Offsets: [3]
 1:1[3] 3:4[0]
 %MATCHED%        
 Offsets: [3]
 1:1[3] 3:4[0]
 %MATCHED%        
index 24aca3f..871f4e6 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -7540,8 +7540,6 @@ Perl_re_op_compile(pTHX_ SV ** const patternp, int pat_count,
      * for the regex engine.  We are ready to finish things up and look for
      * optimizations. */
 
      * for the regex engine.  We are ready to finish things up and look for
      * optimizations. */
 
-    SetProgLen(RExC_rxi,RExC_size);
-
     /* Update the string to compile, with correct modifiers, etc */
     set_regex_pv(pRExC_state, Rx);
 
     /* Update the string to compile, with correct modifiers, etc */
     set_regex_pv(pRExC_state, Rx);
 
@@ -7562,7 +7560,23 @@ Perl_re_op_compile(pTHX_ SV ** const patternp, int pat_count,
     DEBUG_OFFSETS_r(Perl_re_printf( aTHX_
                           "%s %" UVuf " bytes for offset annotations.\n",
                           RExC_offsets ? "Got" : "Couldn't get",
     DEBUG_OFFSETS_r(Perl_re_printf( aTHX_
                           "%s %" UVuf " bytes for offset annotations.\n",
                           RExC_offsets ? "Got" : "Couldn't get",
-                          (UV)((2*RExC_size+1) * sizeof(U32))));
+                          (UV)((RExC_offsets[0] * 2 + 1))));
+    DEBUG_OFFSETS_r(if (RExC_offsets) {
+        const STRLEN len = RExC_offsets[0];
+        STRLEN i;
+        GET_RE_DEBUG_FLAGS_DECL;
+        Perl_re_printf( aTHX_
+                      "Offsets: [%" UVuf "]\n\t", (UV)RExC_offsets[0]);
+        for (i = 1; i <= len; i++) {
+            if (RExC_offsets[i*2-1] || RExC_offsets[i*2])
+                Perl_re_printf( aTHX_  "%" UVuf ":%" UVuf "[%" UVuf "] ",
+                (UV)i, (UV)RExC_offsets[i*2-1], (UV)RExC_offsets[i*2]);
+        }
+        Perl_re_printf( aTHX_  "\n");
+    });
+
+#else
+    SetProgLen(RExC_rxi,RExC_size);
 #endif
 
     DEBUG_OPTIMISE_r(
 #endif
 
     DEBUG_OPTIMISE_r(
@@ -8078,21 +8092,6 @@ Perl_re_op_compile(pTHX_ SV ** const patternp, int pat_count,
         Perl_re_printf( aTHX_ "Final program:\n");
         regdump(RExC_rx);
     });
         Perl_re_printf( aTHX_ "Final program:\n");
         regdump(RExC_rx);
     });
-#ifdef RE_TRACK_PATTERN_OFFSETS
-    DEBUG_OFFSETS_r(if (RExC_offsets) {
-        const STRLEN len = RExC_offsets[0];
-        STRLEN i;
-        GET_RE_DEBUG_FLAGS_DECL;
-        Perl_re_printf( aTHX_
-                      "Offsets: [%" UVuf "]\n\t", (UV)RExC_offsets[0]);
-        for (i = 1; i <= len; i++) {
-            if (RExC_offsets[i*2-1] || RExC_offsets[i*2])
-                Perl_re_printf( aTHX_  "%" UVuf ":%" UVuf "[%" UVuf "] ",
-                (UV)i, (UV)RExC_offsets[i*2-1], (UV)RExC_offsets[i*2]);
-            }
-        Perl_re_printf( aTHX_  "\n");
-    });
-#endif
 
     if (RExC_open_parens) {
         Safefree(RExC_open_parens);
 
     if (RExC_open_parens) {
         Safefree(RExC_open_parens);
@@ -19200,7 +19199,7 @@ S_change_engine_size(pTHX_ RExC_state_t *pRExC_state, const Ptrdiff_t size)
     if (size > 0) {
         Zero(RExC_offsets + 2*(RExC_size - size) + 1, 2 * size, U32);
     }
     if (size > 0) {
         Zero(RExC_offsets + 2*(RExC_size - size) + 1, 2 * size, U32);
     }
-    RExC_offsets[0] = 2*RExC_size+1;
+    RExC_offsets[0] = RExC_size;
 #endif
 }
 
 #endif
 }