Skip to content
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

re.pm clobbers $_ #12202

Closed
p5pRT opened this issue Jun 19, 2012 · 9 comments
Closed

re.pm clobbers $_ #12202

p5pRT opened this issue Jun 19, 2012 · 9 comments

Comments

@p5pRT
Copy link

p5pRT commented Jun 19, 2012

Migrated from rt.perl.org#113750 (status was 'resolved')

Searchable as RT113750$

@p5pRT
Copy link
Author

p5pRT commented Jun 19, 2012

From gr@univie.ac.at

Created by gr@univie.ac.at

re.pm line 145 clobbers $_. This line is​:

  $_ = $1;

when, I believe, it should be​:

  local $_ = $1;

The line as it is causes problems if $_ is used in a loop higher up
somewhere. I don't quite understand where in my project's code I'm
doing this, but from time to time I get this error​:

  Modification of a read-only value attempted at .../perl-5.16.0/lib/5.16.0/darwin-2level/re.pm line 145.

Regardless of where exactly the cause is, I think re.pm shouldn't make
an assumption about whether or not $_ is used somewhere higher up.

Perl Info

Flags:
    category=library
    severity=low
    module=re

Site configuration information for perl 5.16.0:

Configured by marcel at Mon Jun 11 16:19:31 CEST 2012.

Summary of my perl5 (revision 5 version 16 subversion 0) configuration:
   
  Platform:
    osname=darwin, osvers=10.8.0, archname=darwin-2level
    uname='darwin macfh.cc.univie.ac.at 10.8.0 darwin kernel version 10.8.0: tue jun 7 16:33:36 pdt 2011; root:xnu-1504.15.3~1release_i386 i386 '
    config_args='-de -Dprefix=/Users/marcel/perl5/perlbrew/perls/perl-5.16.0'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=undef, usemultiplicity=undef
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe -fstack-protector -I/opt/local/include',
    optimize='-O3',
    cppflags='-fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe -fstack-protector -I/opt/local/include'
    ccversion='', gccversion='4.2.1 (Apple Inc. build 5664)', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='env MACOSX_DEPLOYMENT_TARGET=10.3 cc', ldflags =' -fstack-protector -L/opt/local/lib'
    libpth=/opt/local/lib /usr/lib
    libs=-ldbm -ldl -lm -lutil -lc
    perllibs=-ldl -lm -lutil -lc
    libc=, so=dylib, useshrplib=false, libperl=libperl.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags=' -bundle -undefined dynamic_lookup -L/opt/local/lib -fstack-protector'

Locally applied patches:
    


@INC for perl 5.16.0:
    /Users/marcel/code/github/Waya/lib
    /Users/marcel/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/darwin-2level
    /Users/marcel/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0
    /Users/marcel/perl5/perlbrew/perls/perl-5.16.0/lib/5.16.0/darwin-2level
    /Users/marcel/perl5/perlbrew/perls/perl-5.16.0/lib/5.16.0
    .


Environment for perl 5.16.0:
    DYLD_LIBRARY_PATH (unset)
    HOME=/Users/marcel
    LANG (unset)
    LANGUAGE (unset)
    LC_CTYPE=UTF-8
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/usr/local/Cellar/coreutils/8.17/libexec/gnubin:/usr/local/texlive/2010/bin/x86_64-darwin:/usr/local/mysql/bin:/opt/vim/bin:/Users/marcel/code/dev/bin/bin:/Users/marcel/code/github/Waya/bin:/Users/marcel/bin:/usr/local/bin:/usr/local/sbin:/Users/marcel/perl5/perlbrew/bin:/Users/marcel/perl5/perlbrew/perls/perl-5.16.0/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/X11/bin
    PERL5LIB=/Users/marcel/code/github/Waya/lib
    PERLBREW_BASHRC_VERSION=0.43
    PERLBREW_HOME=/Users/marcel/.perlbrew
    PERLBREW_MANPATH=/Users/marcel/perl5/perlbrew/perls/perl-5.16.0/man
    PERLBREW_PATH=/Users/marcel/perl5/perlbrew/bin:/Users/marcel/perl5/perlbrew/perls/perl-5.16.0/bin
    PERLBREW_PERL=perl-5.16.0
    PERLBREW_ROOT=/Users/marcel/perl5/perlbrew
    PERLBREW_VERSION=0.43
    PERL_AUTOINSTALL_PREFER_CPAN=1
    PERL_BADLANG (unset)
    PERL_EXTUTILS_AUTOINSTALL=--default-deps
    PERL_MM_USE_DEFAULT=1
    SHELL=/bin/bash


@p5pRT
Copy link
Author

p5pRT commented Jun 19, 2012

From @cpansprout

On Tue Jun 19 08​:23​:36 2012, gr@​univie.ac.at wrote​:

This is a bug report for perl from gr@​univie.ac.at,
generated with the help of perlbug 1.39 running under perl 5.16.0.

-----------------------------------------------------------------
[Please describe your issue here]

re.pm line 145 clobbers $_. This line is​:

$\_ = $1;

when, I believe, it should be​:

local $\_ = $1;

Yes, you’re right. Ouch! This goes back to 5.13.10​:

commit b4ab316
Author​: Karl Williamson <public@​khwilliamson.com>
Date​: Fri Feb 11 10​:22​:53 2011 -0700

  re.pm​: Add /aa support

--

Father Chrysostomos

@p5pRT
Copy link
Author

p5pRT commented Jun 19, 2012

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Jun 20, 2012

From @khwilliamson

On 06/19/2012 09​:26 AM, Father Chrysostomos via RT wrote​:

On Tue Jun 19 08​:23​:36 2012, gr@​univie.ac.at wrote​:

This is a bug report for perl from gr@​univie.ac.at,
generated with the help of perlbug 1.39 running under perl 5.16.0.

-----------------------------------------------------------------
[Please describe your issue here]

re.pm line 145 clobbers $_. This line is​:

 $\_ = $1;

when, I believe, it should be​:

 local $\_ = $1;

Yes, you’re right. Ouch! This goes back to 5.13.10​:

commit b4ab316
Author​: Karl Williamson <public@​khwilliamson.com>
Date​: Fri Feb 11 10​:22​:53 2011 -0700

 re\.pm&#8203;: Add /aa support

The reason this hasn't shown up before is because it clobbers $_ at
compile time, where its value is rarely needed. I am having trouble
writing a test for this. Ideas welcome

@p5pRT
Copy link
Author

p5pRT commented Jun 20, 2012

From @doy

On Tue, Jun 19, 2012 at 10​:16​:57PM -0600, Karl Williamson wrote​:

On 06/19/2012 09​:26 AM, Father Chrysostomos via RT wrote​:

On Tue Jun 19 08​:23​:36 2012, gr@​univie.ac.at wrote​:

This is a bug report for perl from gr@​univie.ac.at,
generated with the help of perlbug 1.39 running under perl 5.16.0.

-----------------------------------------------------------------
[Please describe your issue here]

re.pm line 145 clobbers $_. This line is​:

$\_ = $1;

when, I believe, it should be​:

local $\_ = $1;

Yes, you’re right. Ouch! This goes back to 5.13.10​:

commit b4ab316
Author​: Karl Williamson <public@​khwilliamson.com>
Date​: Fri Feb 11 10​:22​:53 2011 -0700

re\.pm&#8203;: Add /aa support

The reason this hasn't shown up before is because it clobbers $_ at
compile time, where its value is rarely needed. I am having trouble
writing a test for this. Ideas welcome

This triggers it​:

$ perl -E'require re; re->import("/aa") for 1'

but it's a bit artificial (although this may be good enough for the
test). Would be useful though if the original reporter could figure out
what their code was doing to cause $_ to be read only at compile time.

-doy

@p5pRT
Copy link
Author

p5pRT commented Jun 20, 2012

From @cpansprout

On Tue Jun 19 21​:29​:01 2012, doy@​tozt.net wrote​:

On Tue, Jun 19, 2012 at 10​:16​:57PM -0600, Karl Williamson wrote​:

On 06/19/2012 09​:26 AM, Father Chrysostomos via RT wrote​:

On Tue Jun 19 08​:23​:36 2012, gr@​univie.ac.at wrote​:

This is a bug report for perl from gr@​univie.ac.at,
generated with the help of perlbug 1.39 running under perl 5.16.0.

-----------------------------------------------------------------
[Please describe your issue here]

re.pm line 145 clobbers $_. This line is​:

$\_ = $1;

when, I believe, it should be​:

local $\_ = $1;

Yes, you’re right. Ouch! This goes back to 5.13.10​:

commit b4ab316
Author​: Karl Williamson <public@​khwilliamson.com>
Date​: Fri Feb 11 10​:22​:53 2011 -0700

re\.pm&#8203;: Add /aa support

The reason this hasn't shown up before is because it clobbers $_ at
compile time, where its value is rarely needed. I am having trouble
writing a test for this. Ideas welcome

This triggers it​:

$ perl -E'require re; re->import("/aa") for 1'

but it's a bit artificial (although this may be good enough for the
test). Would be useful though if the original reporter could figure out
what their code was doing to cause $_ to be read only at compile time.

I think a better test case could be derived from this​:

$ ./perl -Ilib -MTest​::More=tests,1 -e '$_ = 42; require re;
re->import("/aa"); is $_, 42'
1..1
not ok 1
# Failed test at -e line 1.
# got​: 'aa'
# expected​: '42'
# Looks like you failed 1 test of 1.

--

Father Chrysostomos

@p5pRT
Copy link
Author

p5pRT commented Jun 20, 2012

From @khwilliamson

Fixed by commit 48895a0
--
Karl Williamson

@p5pRT
Copy link
Author

p5pRT commented Jun 20, 2012

@khwilliamson - Status changed from 'open' to 'resolved'

@p5pRT p5pRT closed this as completed Jun 20, 2012
@p5pRT
Copy link
Author

p5pRT commented Jun 20, 2012

From gr@univie.ac.at

On Jun 20, 2012, at 6​:28 AM, Jesse Luehrs wrote​:

Would be useful though if the original reporter could figure out
what their code was doing to cause $_ to be read only at compile time.

I've figured it out; basically various modules that "use re" are
loaded at runtime in a loop that uses $_.

That's the concise explanation; the whole thing happens in tests for
our project-specific server during Test​::Class runs for app-specific
handler classes (that are loaded when needed at run-time) in response
to various kinds of requests.

Thanks to all involved for the concise test and the fix.

Marcel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant