summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2018-11-14 09:09:38 -0700
committerKarl Williamson <khw@cpan.org>2018-11-16 10:29:26 -0700
commit950da19151ab0eeaf8415e508fb51c36f2b5d70c (patch)
treea5b09b1c01219063aab4d6a5b7784d959d9071eb
parent48975adaf1ddd57fb4b698978ba40f3ef0271f74 (diff)
downloadperl-950da19151ab0eeaf8415e508fb51c36f2b5d70c.tar.gz
regcomp.c: Fix up RE_TRACK_PATTERN_OFFSETS
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.
-rw-r--r--ext/re/t/regop.t4
-rw-r--r--regcomp.c37
2 files changed, 20 insertions, 21 deletions
diff --git a/ext/re/t/regop.t b/ext/re/t/regop.t
index 54a197b3a1..cf35d71fb0 100644
--- a/ext/re/t/regop.t
+++ b/ext/re/t/regop.t
@@ -241,7 +241,7 @@ floating ""$ at 3..4 (checking floating)
#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)
@@ -254,7 +254,7 @@ floating ""$ at 3..4 (checking floating)
#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%
diff --git a/regcomp.c b/regcomp.c
index 24aca3f6f8..871f4e63ac 100644
--- 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. */
- SetProgLen(RExC_rxi,RExC_size);
-
/* 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",
- (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(
@@ -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);
});
-#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);
@@ -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);
}
- RExC_offsets[0] = 2*RExC_size+1;
+ RExC_offsets[0] = RExC_size;
#endif
}