Skip Menu |
 
Report information
Id: 16235
Status: open
Priority: 0/
Queue: perl5

Owner: stmpeters <steve [at] fisharerojo.org>
Requestors: jima [at] simplex.com
mauke- <l.mai [at] web.de>
Cc:
AdminCc:

Operating System: generic
PatchStatus: (no value)
Severity: medium
Type:
  • core
  • lexical/scope/closure
Perl Version:
  • 5.6.0
  • 5.6.1
  • 5.8.0
Fixed In: (no value)



Date: Thu, 15 Aug 2002 16:45:16 -0700 (PDT)
From: Jim Avera <jima [...] simplex.com>
To: perlbug [...] perl.org
Subject: local($^W) does not work correctly
Cc: jima [...] simplex.com
Download (untitled) / with headers
text/plain 3.4k
This is a bug report for perl from jima@simplex.com, generated with the help of perlbug 1.33 running under perl v5.6.1. ----------------------------------------------------------------- [Please enter your report here] # local() doesn't seem to work correctly with $^W in Perl 5.6.1 # Run this program to see. # -Jim Avera jima@simplex.com 8/15/2002 use strict; #------ this works ------ use vars '$XX'; $XX = 1; die "BUG: XX is off" unless $XX; { local($XX) = $XX; die "BUG: XX is off" unless $XX; } die "BUG: XX is off" unless $XX; #------ this doesn't work ------ $^W = 1; die "BUG: warn is off" unless $^W; { local($^W) = $^W; die "BUG: warn is off" unless $^W; # dies here in Win32 Perl 5.6.1 } die "BUG: warn is off" unless $^W; # dies here in Solaris Perl 5.6.1 print "Test passed.\n"; [Please do not change anything below this line] ----------------------------------------------------------------- --- Flags: category=core severity=medium --- Site configuration information for perl v5.6.1: Configured by carl at Tue Dec 11 12:21:24 PST 2001. Summary of my perl5 (revision 5.0 version 6 subversion 1) configuration: Platform: osname=solaris, osvers=2.7, archname=sun4-solaris uname='sunos bermuda 5.7 generic_106541-17 sun4u sparc sunw,ultra-5_10 ' config_args='' hint=recommended, useposix=true, d_sigaction=define usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef useperlio=undef d_sfio=undef uselargefiles=define usesocks=undef use64bitint=undef use64bitall=undef uselongdouble=undef Compiler: cc='/users/egcs/bin/gcc', ccflags ='-fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64', optimize='-O', cppflags='-fno-strict-aliasing -I/usr/local/include' ccversion='', gccversion='2.95.2 19991024 (release)', gccosandvers='solaris2.6' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8 alignbytes=8, usemymalloc=y, prototype=define Linker and Libraries: ld='/users/egcs/bin/gcc', ldflags =' -L/usr/local/lib ' libpth=/usr/local/lib /usr/lib /usr/ccs/lib libs=-lsocket -lnsl -ldl -lm -lc perllibs=-lsocket -lnsl -ldl -lm -lc libc=, so=so, useshrplib=false, libperl=libperl.a Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' ' cccdlflags='-fPIC', lddlflags='-G -L/usr/local/lib' Locally applied patches: --- @INC for perl v5.6.1: /usr/local/lib/perl5/5.6.1/sun4-solaris /usr/local/lib/perl5/5.6.1 /usr/local/lib/perl5/site_perl/5.6.1/sun4-solaris /usr/local/lib/perl5/site_perl/5.6.1 /usr/local/lib/perl5/site_perl . --- Environment for perl v5.6.1: HOME=/hcusers/jima LANG (unset) LANGUAGE (unset) LD_LIBRARY_PATH (unset) LOGDIR (unset) PATH=/usr/local/bin:/usr/local/gcc/3.1/bin:/usr/local/gcc/gdb-5.2/bin:/usr/bin:bin/sun5:libdft/src:../../bin/sun5:../../libdft/src:/hcusers/jima/work/output/sun5/bin:/hcusers/jima/work/libdft/src:/hcusers/jima/work.mess/output/sun5/bin:/hcusers/jima/work.mess/libdft/src:/hcusers/jima/bin/sun5:/hcusers/jima/bin:/hcusers/jima/jima_tools/bin:/bin:/opt/SUNWspro/bin:/users/egcs/2.95.3/bin:/users/egcs/bin:/users/gnu/bin:/usr/5bin:/usr/X/bin:/usr/ccs/bin:/usr/openwin/bin:/usr/sbin:/usr/ucb:/usr/xpg4/bin:. PERL_BADLANG (unset) SHELL=/usr/bin/bash
Confirmed in 5.8.0 and 5.8.1 RC2.
RT-Send-CC: perl5-porters [...] perl.org
Download (untitled) / with headers
text/plain 342b
On Tue Jul 15 23:16:04 2003, schwern wrote: Show quoted text
> Confirmed in 5.8.0 and 5.8.1 RC2.
This is still present in 5.14.2 and blead, but a small update: The original bug report says that Solaris behaved differently, failing on the final die. Now it's the same same place as Linux/Windows, on { local($^W) = $^W; die "BUG: warn is off5" unless $^W; }
RT-Send-CC: perl5-porters [...] perl.org
Download (untitled) / with headers
text/plain 1.1k
On Sat Apr 28 02:11:01 2012, Hugmeir wrote: Show quoted text
> On Tue Jul 15 23:16:04 2003, schwern wrote:
> > Confirmed in 5.8.0 and 5.8.1 RC2.
> > This is still present in 5.14.2 and blead, but a small update: The > original bug report says that Solaris behaved differently,
Knowing how this is implemented, I think it was misdiagnosed. Show quoted text
> failing on > the final die. Now it's the same same place as Linux/Windows, on > > { local($^W) = $^W; > die "BUG: warn is off5" unless $^W; > }
Usually, local($foo) creates a new $foo in *foo{SCALAR}, copies the magic to it, and then calls set-magic on it. This allows a plain local($^W); to work. local($foo) = $foo works because the $foo on the RHS (which is executed first) is the original $foo; i.e., a completely different scalar. For magical variables things gang agley, because the local($^W) on the LHS is a separate operator from assignment and sets $^W to undef befor the assignment happens. Since both $^W’s have magic that writes to the same underlying structures, the assignment has no affect. This is similar to bug #104118, but a little different; but I think it’s the same code that would need adjustment. -- Father Chrysostomos
RT-Send-CC: perl5-porters [...] perl.org
Download (untitled) / with headers
text/plain 1.3k
On Sat Apr 28 13:56:58 2012, sprout wrote: Show quoted text
> On Sat Apr 28 02:11:01 2012, Hugmeir wrote:
> > On Tue Jul 15 23:16:04 2003, schwern wrote:
> > > Confirmed in 5.8.0 and 5.8.1 RC2.
> > > > This is still present in 5.14.2 and blead, but a small update: The > > original bug report says that Solaris behaved differently,
> > Knowing how this is implemented, I think it was misdiagnosed. >
> > failing on > > the final die. Now it's the same same place as Linux/Windows, on > > > > { local($^W) = $^W; > > die "BUG: warn is off5" unless $^W; > > }
> > Usually, local($foo) creates a new $foo in *foo{SCALAR}, copies the > magic to it, and then calls set-magic on it. This allows a plain > local($^W); to work. > > local($foo) = $foo works because the $foo on the RHS (which is executed > first) is the original $foo; i.e., a completely different scalar. > > For magical variables things gang agley, because the local($^W) on the > LHS is a separate operator from assignment and sets $^W to undef befor > the assignment happens. Since both $^W’s have magic that writes to the > same underlying structures, the assignment has no affect.
I forgot to mention that local($hash{elem}) in lvalue context is special-cased to work, for the sake of %SIG. There are various /* XXX - FIXME - see #60360 */ comments sprinkled here and there. -- Father Chrysostomos
Subject: self-assignment 'local $? = $?' resets $?
Date: Thu, 21 Feb 2013 03:10:47 +0100
To: perlbug [...] perl.org
From: l.mai [...] web.de
Download (untitled) / with headers
text/plain 4.1k
This is a bug report for perl from l.mai@web.de, generated with the help of perlbug 1.39 running under perl 5.16.0. ----------------------------------------------------------------- [Please describe your issue here] % perl -wle '$? = 123; print "before: $?"; local $? = $?; print "after: $?"' before: 123 after: 0 % perl -wle '$? = 123; print "before: $?"; local $? = $? + 0; print "after: $?"' before: 123 after: 123 I would have expected the first version to output "after: 123" instead of resetting $? to 0. Oh wait, it's actually worse than I thought: % perl -wle '$? = 123; print "before: $?"; { local $? = $?; print "after: $?"; } print "finally: $?"' before: 123 after: 0 finally: 0 i.e. the reset isn't even localized; it straight up clobbers $?. This bug interacts badly with END blocks: % perl -e 'exit 123; END { local $? = $?; }'; echo $? 0 instead of the expected: % perl -e 'exit 123; END { local $? = $? + 0; }'; echo $? 123 [Please do not change anything below this line] ----------------------------------------------------------------- --- Flags: category=core severity=low --- This perlbug was built using Perl 5.12.1 - Thu Jun 3 20:09:15 CEST 2010 It is being executed now by Perl 5.16.0 - Mon May 21 12:24:16 CEST 2012. Site configuration information for perl 5.16.0: Configured by mauke at Mon May 21 12:24:16 CEST 2012. Summary of my perl5 (revision 5 version 16 subversion 0) configuration: Platform: osname=linux, osvers=2.6.38-gentoo-r6, archname=i686-linux uname='linux nora 2.6.38-gentoo-r6 #1 preempt sat aug 6 03:05:34 cest 2011 i686 amd athlon(tm) 64 processor 3200+ authenticamd gnulinux ' config_args='-Dcc=cgcc -Dprefix=/home/mauke/usr/local -Dman1dir=none -Dman3dir=none -Dinc_version_list=none -Doptimize=-O2 -flto' hint=recommended, useposix=true, d_sigaction=define useithreads=undef, usemultiplicity=undef useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef use64bitint=undef, use64bitall=undef, uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='cgcc', ccflags ='-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64', optimize='-O2 -flto', cppflags='-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include' ccversion='', gccversion='4.6.3', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8 alignbytes=4, prototype=define Linker and Libraries: ld='cgcc', ldflags ='-fstack-protector -L/usr/local/lib -O2 -flto' libpth=/usr/local/lib /lib/../lib /usr/lib/../lib /lib /usr/lib libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc -lgdbm_compat perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc libc=/lib/libc-2.14.1.so, so=so, useshrplib=false, libperl=libperl.a gnulibc_version='2.14.1' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E' cccdlflags='-fPIC', lddlflags='-shared -O2 -flto -L/usr/local/lib -fstack-protector' Locally applied patches: SAVEARGV0 - disable magic open in <ARGV> --- @INC for perl 5.16.0: /home/mauke/usr/local/lib/perl5/site_perl/5.16.0/i686-linux /home/mauke/usr/local/lib/perl5/site_perl/5.16.0 /home/mauke/usr/local/lib/perl5/5.16.0/i686-linux /home/mauke/usr/local/lib/perl5/5.16.0 . --- Environment for perl 5.16.0: HOME=/home/mauke LANG=en_US.UTF-8 LANGUAGE (unset) LC_COLLATE=POSIX LD_LIBRARY_PATH=/home/mauke/usr/local/lib LOGDIR (unset) PATH=/home/mauke/usr/perlbrew/bin:/home/mauke/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/4.6.3:/opt/sun-jdk-1.4.2.13/bin:/opt/sun-jdk-1.4.2.13/jre/bin:/opt/sun-jdk-1.4.2.13/jre/javaws:/opt/dmd/bin:/usr/games/bin PERLBREW_BASHRC_VERSION=0.43 PERLBREW_HOME=/home/mauke/.perlbrew PERLBREW_PATH=/home/mauke/usr/perlbrew/bin PERLBREW_ROOT=/home/mauke/usr/perlbrew PERLBREW_VERSION=0.27 PERL_BADLANG (unset) PERL_UNICODE=SAL SHELL=/bin/bash
RT-Send-CC: perl5-porters [...] perl.org
Also affects Windows and cygwin, so it's not OS specific.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org