From 4b22688e5c51dea3e913d630e965389c5c029765 Mon Sep 17 00:00:00 2001 From: Yves Orton Date: Sat, 25 Jan 2014 16:48:56 +0100 Subject: [PATCH] resolve bug 121070 - preserve $^R after successful match We call LEAVE after successful eval matches, which clears $^R. This changes a test that was added as part of handling bug 56194. --- regexec.c | 13 ++++++++++++- t/re/pat_re_eval.t | 13 ++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/regexec.c b/regexec.c index 624ee4c..4b586be 100644 --- a/regexec.c +++ b/regexec.c @@ -5253,7 +5253,14 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog) SET_reg_curpm(rex_sv); rex = ReANY(rex_sv); rexi = RXi_GET(rex); - regcpblow(ST.cp); + { + /* preserve $^R across LEAVE's. See Bug 121070. */ + SV *save_sv= GvSV(PL_replgv); + SvREFCNT_inc(save_sv); + regcpblow(ST.cp); /* LEAVE in disguise */ + sv_setsv(GvSV(PL_replgv), save_sv); + SvREFCNT_dec(save_sv); + } cur_eval = ST.prev_eval; cur_curlyx = ST.prev_curlyx; @@ -6702,6 +6709,10 @@ yes: * When popping the save stack, all these locals would be undone; * bypass this by setting the outermost saved $^R to the latest * value */ + /* I dont know if this is needed or works properly now. + * see code related to PL_replgv elsewhere in this file. + * Yves + */ if (oreplsv != GvSV(PL_replgv)) sv_setsv(oreplsv, GvSV(PL_replgv)); } diff --git a/t/re/pat_re_eval.t b/t/re/pat_re_eval.t index 551788b..d64cb28 100644 --- a/t/re/pat_re_eval.t +++ b/t/re/pat_re_eval.t @@ -22,7 +22,7 @@ BEGIN { } -plan tests => 525; # Update this when adding/deleting tests. +plan tests => 527; # Update this when adding/deleting tests. run_tests() unless caller; @@ -340,8 +340,15 @@ sub run_tests { is("@ctl_n", "1 2 undef", 'Bug 56194'); is("@plus", "1 2 undef", 'Bug 56194'); is($str, - "\$1 = undef, \$2 = undef, \$3 = undef, \$4 = undef, \$5 = undef, \$^R = undef", - 'Bug 56194'); + "\$1 = undef, \$2 = undef, \$3 = undef, \$4 = undef, \$5 = undef, \$^R = 3", + 'Bug 56194 ($^R tweaked by 121070)'); + } + { + undef $^R; + "abcd"=~/(?.)(?&Char)(?{ 42 })/; + is("$^R", 42, 'Bug 121070 - use of (?&Char) should not clobber $^R'); + "abcd"=~/(?.)(?&Char)(?{ 42 })(?{ 43 })/; + is("$^R", 43, 'related to 121070 - use of (?&Char) should not clobber $^R'); } } -- 2.7.4