develooper Front page | perl.perl5.porters | Postings from April 2006

[perl #37407] /(??{ "(PAT)" })/ doesn't set $1.

From:
Steve Peters via RT
Date:
April 12, 2006 17:39
Subject:
[perl #37407] /(??{ "(PAT)" })/ doesn't set $1.
Message ID:
rt-3.0.11-37407-132225.15.1974917590451@perl.org
> [shouldbedomo@mac.com - Mon Apr 03 12:54:19 2006]:
> 
> 
> On 2006–04–03, at 20:32, Abigail wrote:
> > On Mon, Apr 03, 2006 at 04:54:27AM -0700, Hugo van der Sanden via  
> > RT wrote:
> >> I may be wrong - I didn't check the code or docs before writing  
> >> that - but
> >> as far as I know this is NOTABUG: the parent expression has no  
> >> captures,
> >> so no captures are set by the time the parent successfully completes.
> >
> >
> > The documentation (of 5.8.8) says:
> >
> >       This is a "postponed" regular subexpression. The "code" is
> >       evaluated at run time, at the moment this subexpression may  
> > match.
> >       The result of evaluation is considered as a regular expression
> >       and matched as if it were inserted instead of this construct.
> 
> Well, the easiest thing to do would be to fix the documentation to  
> match the implementation. However, if the subexpression has its own  
> context to which the results of any capture are confined, is there  
> any way of getting at those captures in order to export them to some  
> surrounding context? If so, the docs should show it as a work-around.  
> (Or, if not, say it can't be done.)
> 
> Hugo's perlmonks wizardry referenced earlier in the thread does not  
> seem quite to fill the bill -- the capture surrounds the postponed  
> subexpression, rather than being a part of it -- so I've tried a lot  
> of variations on
> 
> $ ./perl -Ilib -Mre=debug -lwe '$r = qr/(?{print $1})/; @m = "abc"  
> =~ /(.)(??{"(.)$r"})(.)/; print @m'
> Use of uninitialized value.     <-- seems to be an artefact of re=debug
> Compiling REx "(?{print $1})"
> size 3 Got 28 bytes for offset annotations.
> first at 1
>     1: EVAL(3)
>     3: END(0)
> minlen 0 with eval
> Offsets: [3]
>          1[13] 0[0] 14[0]
> Compiling REx "(.)(??{"(.)$r"})(.)"
> size 14 Got 116 bytes for offset annotations.
> first at 3
>     1: OPEN1(3)
>     3:   REG_ANY(4)
>     4: CLOSE1(6)
>     6: LOGICAL[2](7)
>     7: EVAL(9)
>     9: OPEN2(11)
>    11:   REG_ANY(12)
>    12: CLOSE2(14)
>    14: END(0)
> minlen 2 with eval
> Offsets: [14]
>          1[1] 0[0] 2[1] 3[1] 0[0] 16[0] 16[0] 0[0] 17[1] 0[0] 18[1] 19 
> [1] 0[0] 20[0]
> Omitting $` $& $' support.
> 
> EXECUTING...
> 
> Matching REx "(.)(??{"(.)$r"})(.)" against "abc"
>    Setting an EVAL scope, savestack=15
>     0 <> <abc>             |  1:  OPEN1
>     0 <> <abc>             |  3:  REG_ANY
>     1 <a> <bc>             |  4:  CLOSE1
>     1 <a> <bc>             |  6:  LOGICAL[2]
>     1 <a> <bc>             |  7:  EVAL
>    re_eval 0x1317440
> Compiling REx "(.)(?-xism:(?{print $1}))"
> size 8 Got 68 bytes for offset annotations.
> first at 3
>     1: OPEN1(3)
>     3:   REG_ANY(4)
>     4: CLOSE1(6)
>     6: EVAL(8)
>     8: END(0)
> minlen 1 with eval
> Offsets: [8]
>          1[1] 0[0] 2[1] 3[1] 0[0] 12[13] 0[0] 26[0]
> Entering embedded "(.)(?-xism:(?{print $1}))"
>    Setting an EVAL scope, savestack=25
>     1 <a> <bc>             |  1:    OPEN1
>     1 <a> <bc>             |  3:    REG_ANY
>     2 <ab> <c>             |  4:    CLOSE1
>     2 <ab> <c>             |  6:    EVAL
>    re_eval 0x1317770
> Bus error
> 
> Program received signal EXC_BAD_ACCESS, Could not access memory.
> Reason: KERN_PROTECTION_FAILURE at address: 0x00000004
> 0x00085790 in Perl_pp_gvsv (my_perl=0x1800400) at pp_hot.c:64
> 64              PUSHs(GvSVn(cGVOP_gv));
> 
> without success. Backtrace here is
> 
> #0  0x00085790 in Perl_pp_gvsv (my_perl=0x1800400) at pp_hot.c:64
> #1  0x0023d1f4 in Perl_runops_debug (my_perl=0x1800400) at dump.c:1698
> #2  0x00569f58 in S_regmatch (my_perl=0x1800400, prog=0x1105e44) at  
> re_exec.c:3281
> #3  0x0056a938 in S_regmatch (my_perl=0x1800400, prog=0x1116f94) at  
> re_exec.c:3366
> #4  0x00563e34 in S_regtry (my_perl=0x1800400, prog=0x1116f50,  
> startpos=0x1106640 "abc") at re_exec.c:2202
> #5  0x005627e0 in my_regexec (my_perl=0x1800400, prog=0x1116f50,  
> stringarg=0x1106640 "abc", strend=0x1106642 "c", strbeg=0x1106640  
> "abc", minend=0, sv=0x1802150, data=0x0, flags=3) at re_exec.c:2011
> #6  0x00090184 in Perl_pp_match (my_perl=0x1800400) at pp_hot.c:1373
> #7  0x0023d1f4 in Perl_runops_debug (my_perl=0x1800400) at dump.c:1698
> #8  0x00043a34 in S_run_body (my_perl=0x1800400, oldscope=1) at  
> perl.c:2374
> #9  0x00042d38 in perl_run (my_perl=0x1800400) at perl.c:2294
> #10 0x00002f50 in main (argc=5, argv=0xbffff8f4, env=0xbffff90c) at  
> perlmain.c:103
> 
> and it's always the same -- apart from where one ends up in pp_hot.c  
> -- whatever the code in the (?{...})
> 
> The ones that don't crash invariably end up like
> 
> $ ./perl -Ilib -Mre=eval -lwe '$r = q/(?{print $1})/; @m = "abc" =~ / 
> (.)(??{"(.)$r"})(.)/; print @m'
> Eval-group not allowed at runtime, use re 'eval' in regex m/(.)(? 
> {print $1})/ at -e line 1.
> 
> (Which is probably a manifestation of  bug #23569 -- compiler hints  
> not being propagated to eval-strings.)
> 
> 

This appears to have been fixed with the more recent recursion removals.

steve@kirk:~/perl-current$ perl -lwe '$r = qr/(?{print $1})/; @m = "abc"
=~ /(.)(??{"(.)$r"})(.)/; print @m'
Segmentation fault
steve@kirk:~/perl-current$ ./perl -Ilib -lwe '$r = qr/(?{print $1})/; @m
= "abc" =~ /(.)(??{"(.)$r"})(.)/; print @m'
b
ac




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About