New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(?{...}) not executed in many regexes that do subpattern recursion #13550
Comments
From smls75@gmail.comI've been experimenting with using embedded (?{...}) blocks in regexes that also make use of the (?&NAME) "Recurse to a named subpattern" feature, and found that for many such regexes, the embedded code blocks fail to take effect when they should. Here's a simple test case that demonstrates the bug: use Data::Dumper; Output: Expected output: 42 instead of undef Curiously, the above test case suddenly *does* work when a superfluous {1,1} is added to the regex like so: "abcd" =~ /(?&Char){1,1} (?{ 42 }) The output is now: This is just one example of how fragile & unpredictable the combination of these two regexp features seems to be; Many cases don't work, although some do. PS: I'm using Perl 5.18.2 on Arch Linux, installed using the official distro-provided packages. Output of "perlbug -d" is attached. |
From smls75@gmail.comFlags: Site configuration information for perl 5.18.2: Configured by nobody at Sun Jan 12 12:54:37 CET 2014. Summary of my perl5 (revision 5 version 18 subversion 2) configuration: Locally applied patches: @INC for perl 5.18.2: Environment for perl 5.18.2: |
From @AbigailOn Thu, Jan 23, 2014 at 01:28:00PM -0800, Sam S. wrote:
The bug doesn't seem that (?{ }) isn't executed, but that the result isn't use Data::Dumper; gives as output: 42 showing that (?{ }) *is* executed, but it's the assignment to $^R that fails. Abigail |
The RT System itself - Status changed from 'new' to 'open' |
From @demerphqOn 24 January 2014 10:50, Abigail <abigail@abigail.be> wrote:
Thanks for the analysis. I will try to find time to poke into this. Yves -- |
From @LeontOn Fri, Jan 24, 2014 at 10:50 AM, Abigail <abigail@abigail.be> wrote:
Not quite: "abcd" =~ /(?&Char) (?{ 42 }) (?{ say $^R }) (?(DEFINE) (?<Char> . ))/x; Does print 42. It is assigned to, but it's apparently not available outside Leon |
From @demerphqOn 23 January 2014 22:28, Sam S. <perlbug-followup@perl.org> wrote:
This is fixed in 4b22688 If you wanted to create tests for the various bugs you are finding it Yves |
From @cpansproutOn Sat Jan 25 08:15:29 2014, demerphq wrote:
Unfortunately, that causes this to crash: $ ./miniperl -Ilib -e '"" =~ /(??{undef *^R;""})(?{42})/; ' What happens is that the undef frees the scalar pointed to by oreplsv in I do not understand why it only started crashing at 4b22688. In any case this diff seems to fix it (part of a local commit that also Inline Patchdiff --git a/regexec.c b/regexec.c
index 0109370..8e0bdd2 100644
--- a/regexec.c
+++ b/regexec.c
@@ -3666,6 +3666,7 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, r
U32 lastopen = 0; /* last open we saw */
bool has_cutgroup = RX_HAS_CUTGROUP(rex) ? 1 : 0;
SV* const oreplsv = GvSVn(PL_replgv);
+ SAVEFREESV(SvREFCNT_inc_simple_NN(oreplsv));
/* these three flags are set by various ops to signal information to
* the very next op. They have a useful lifetime of exactly one loop
* iteration, and are not preserved or restored by state pushes/pops
-- Father Chrysostomos |
From @demerphqOn 28 January 2014 13:43, Father Chrysostomos via RT
Umm, what cauldron of evil did you find that in? :-)
Yeah, ugly.
Hrm. Well I think somewhere along the line something changed in the
It looks fine to me. The only thought I have is maybe this is wrong solution overall. I fixed bugs related to this in the past, if you look at the comments I think that we dont handle (?{ }) properly in general. We use the Consider this pattern: "abc" =~ /(?{41}) (?:(??{print "$^R\n"; ""})a (?{ 42 })(??{print We expect that to print 41 Notice how we restore the value of '41'. This behaviour on backtrack The fact that you might undef *^R at any time during matching So I think there is a reasonable argument to say that we should handle Instead of using local like this, we could store the return of (?{ }) This would eliminate a lot of local calls, and IMO make the behavior Just Work. But until someone has the time to do this, assuming it can be done, I
-- |
From smls75@gmail.comOn Sat Jan 25 08:15:29 2014, demerphq wrote:
Was that directed at me? |
From @demerphqOn 29 January 2014 00:34, Sam S. via RT <perlbug-followup@perl.org> wrote:
Yes. :-)
Er good question. A patch to the relevent test file (in this case You can see the patch I did to add a test for this here: http://perl5.git.perl.org/perl.git/commitdiff/4b22688e5c51dea3e913d630e965389c5c029765 Cheers, -- |
From perl5-porters@perl.orgYves Orton wrote:
Recently I fixed various bugs relating to the use of GvSV with no null (I still find the sv_setsv(GvSV(PL_replgv)...) suspicious, but I have
I tried disabling it and a test failed in t/re/pat.t, which comes down "" =~ /(?{42})/;
Thank you. I have applied it as 7e68f15. |
From @demerphqOn 29 January 2014 09:59, Father Chrysostomos <sprout@cpan.org> wrote:
Ah. Makes sense.
Understood. Do you think its worth me digging a bit? (Note this stuff
Thanks, I had been meaning to do that myself when I got a bit more time.
And thank you for catching the bug. :-) Cheers, |
From perl5-porters@perl.orgYves Orton wrote:
It would be nice to know that the code is safe. I think I have fig- Is there any way that 'case EVAL_AB:' can be reached without $^R |
Migrated from rt.perl.org#121070 (status was 'open')
Searchable as RT121070$
The text was updated successfully, but these errors were encountered: