develooper Front page | perl.perl5.porters | Postings from September 2009

[perl #69134] re "(?{ code })" sets $^R on ab|c, fails to set on $^R on ab|a, executes code for both

Thread Next
From:
Chris Pirazzi
Date:
September 15, 2009 03:25
Subject:
[perl #69134] re "(?{ code })" sets $^R on ab|c, fails to set on $^R on ab|a, executes code for both
Message ID:
rt-3.6.HEAD-21832-1252958610-759.69134-75-0@perl.org
# New Ticket Created by  Chris Pirazzi 
# Please include the string:  [perl #69134]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=69134 >


This is a bug report for perl from perlbug@lurkertech.com,
generated with the help of perlbug 1.36 running under perl 5.10.0.


-----------------------------------------------------------------

I have found a bug with the "(?{ code })" perl regular expression feature of
5.10.0

The following script shows a case where $^R ($LAST_REGEXP_CODE_RESULT) does
not get set, even though its corresponding "(?{ code })" does get executed.

I only see this behavior with certain patterns, in particular patterns where
two branches of an "|" have common prefixes, so it is likely related to re
optimizations.  But it does not fall under the WARNING case in perlre,
because the code executed does not have side effects other than setting ^$R:
there's no issue of order of execution of different "(?{ code })" chunks in
the same re.  There is also no issue of lexical variables or confusion with
"(?(condition)yes-pattern|no-pattern)" as explained in perlre.

use strict;

# the first regexp is basically /ab|c/
$^R = 54321;
die if ('abfoo' !~ m/ ^( (?:ab(?{'5'}))  |  (?:c(?{'6'}))  )/x);
print "it is [$1][$^R]\n";
# GOOD: prints "it is [ab][5]"

# the second regexp is basically /ab|a/ - same otherwise!
$^R = 12345;
die if ('abfoo' !~ m/ ^( (?:ab(?{'5'}))  |  (?:a(?{'6'}))  )/x);
print "it is [$1][$^R]\n";
# BAD: prints "it is [ab][12345]": ^R HAS NOT BEEN SET!

# this shows that the '5' code IS being executed:
$^R = 12345;
'abfoo' =~ m/ ^( (?:ab(?{print "yes\n"; '5'}))  |  (?:a(?{'6'}))  )/x;
print "it is [$1][$^R]\n";
# BAD: prints "yes" and "it is [ab][12345]": ^R HAS NOT BEEN SET!

-----------------------------------------------------------------
---
Flags:
    category=core
    severity=medium
---
Site configuration information for perl 5.10.0:

Configured by SYSTEM at Tue May 13 16:52:25 2008.

Summary of my perl5 (revision 5 version 10 subversion 0) configuration:
  Platform:
    osname=MSWin32, osvers=5.00, archname=MSWin32-x86-multi-thread
    uname=''
    config_args='undef'
    hint=recommended, useposix=true, d_sigaction=undef
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=undef, use64bitall=undef, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cl', ccflags ='-nologo -GF -W3 -MD -Zi -DNDEBUG -O1 -DWIN32
-D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT -DUSE_SITECUSTOMIZE
-DPRIVLIB_LAST_IN_INC -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS
-DUSE_PERLIO -DPERL_MSVCRT_READFIX',
    optimize='-MD -Zi -DNDEBUG -O1',
    cppflags='-DWIN32'
    ccversion='15.0.30729', gccversion='', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='__int64',
lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='link', ldflags ='-nologo -nodefaultlib -debug -opt:ref,icf
-libpath:"C:\perl\lib\CORE"  -machine:x86'
    libpth=\lib
    libs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib  netapi32.lib
uuid.lib ws2_32.lib mpr.lib winmm.lib  version.lib odbc32.lib odbccp32.lib
msvcrt.lib
    perllibs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib  netapi32.lib
uuid.lib ws2_32.lib mpr.lib winmm.lib  version.lib odbc32.lib odbccp32.lib
msvcrt.lib
    libc=msvcrt.lib, so=dll, useshrplib=true, libperl=perl510.lib
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -debug
-opt:ref,icf  -libpath:"C:\perl\lib\CORE"  -machine:x86'

Locally applied patches:
    ACTIVEPERL_LOCAL_PATCHES_ENTRY
    33741 avoids segfaults invoking S_raise_signal() (on Linux)
    33763 Win32 process ids can have more than 16 bits
    32809 Load 'loadable object' with non-default file extension
    32728 64-bit fix for Time::Local

---
@INC for perl 5.10.0:
    c:/perl/site/lib
    c:/perl/lib
    .

---
Environment for perl 5.10.0:
    HOME=c:\
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)

PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\s\Common7\IDE;C:\s\VC\BIN;C:\s\Common7\Tools;C:\WINDOWS\Microsoft.NET\Framework\v3.5;C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727;C:\s\VC\VCPackages;C:\Program
Files\Microsoft SDKs\Windows\v6.0A\bin;c:\Program Files\Common Files\Roxio
Shared\DLLShared\;c:\Program Files\Common Files\Roxio
Shared\DLLShared\;c:\Program Files\Common Files\Roxio
Shared\9.0\DLLShared\;C:\Program
Files\Hewlett-Packard\IAM\bin;c:\perl\bin;c:\tcl\bin;C:\mysql\bin;c:\bin;c:\magick;c:\cygwin\bin;c:\stlport\STLport-5.2.1\bin;c:\icu\icu-3.4.1\bin;C:\Program
Files\QuickTime\QTSystem\
    PERL_BADLANG (unset)
    SHELL (unset)

Thread Next


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