summaryrefslogtreecommitdiff
path: root/pp_hot.c
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2009-12-14 12:19:35 +0100
committerRafael Garcia-Suarez <rgs@consttype.org>2009-12-14 12:19:35 +0100
commit69dc4b30f4725ad5f212d45d3c856ac1caaacf17 (patch)
treedf18d52a4e4de66a3e51752d969e266ad1bd40f6 /pp_hot.c
parentd275fa5ec19c41bfadd2caecf9152a6e9b995717 (diff)
downloadperl-69dc4b30f4725ad5f212d45d3c856ac1caaacf17.tar.gz
[perl #70764] $' fails to initialized for pre-compiled regular expression matches
The match vars are associated with the regexp that last matched successfully. In the case of $str =~ $qr or /$qr/, since the $qr could be used in multiple scopes that need their own sets of match vars, the $qr is cloned by Perl_reg_temp_copy as of change 30677/28d8d7f. This happens in pp_regcomp before pp_match has stringified the LHS, hence the bug. In short, /$gror/ is not equivalent to ($which = !$which) ? /$gror/ : /$gror/, which is weird. Attached is a patch, which admittedly is a hack, but fixes this particular side effect of what is probably a bad design, by stringifying the LHS in pp_regcomp, and having pp_match skip get-magic in such cases. A real fix far exceeds my capabalities, and would also be very intrusive according to <http://www.nntp.perl.org/group/perl.perl5.porters/2007/03/msg122415.html>.
Diffstat (limited to 'pp_hot.c')
-rw-r--r--pp_hot.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/pp_hot.c b/pp_hot.c
index 2c2edcd648..a8aa4ba2db 100644
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -1261,7 +1261,11 @@ PP(pp_match)
}
PUTBACK; /* EVAL blocks need stack_sp. */
- s = SvPV_const(TARG, len);
+ /* Skip get-magic if this is a qr// clone, because regcomp has
+ already done it. */
+ s = ((struct regexp *)SvANY(rx))->mother_re
+ ? SvPV_nomg_const(TARG, len)
+ : SvPV_const(TARG, len);
if (!s)
DIE(aTHX_ "panic: pp_match");
strend = s + len;