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

local($^W) does not work correctly #5835

Open
p5pRT opened this issue Aug 15, 2002 · 10 comments
Open

local($^W) does not work correctly #5835

p5pRT opened this issue Aug 15, 2002 · 10 comments

Comments

@p5pRT
Copy link

p5pRT commented Aug 15, 2002

Migrated from rt.perl.org#16235 (status was 'open')

Searchable as RT16235$

@p5pRT
Copy link
Author

p5pRT commented Aug 15, 2002

From jima@simplex.com

Created by jima@simplex.com

# 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";
Perl Info

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

@p5pRT
Copy link
Author

p5pRT commented Jul 16, 2003

From @schwern

Confirmed in 5.8.0 and 5.8.1 RC2.

@p5pRT
Copy link
Author

p5pRT commented Jul 16, 2003

@schwern - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Apr 28, 2012

From @Hugmeir

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, 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;
}

@p5pRT
Copy link
Author

p5pRT commented Apr 28, 2012

From @cpansprout

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.

This is similar to bug #104118, but a little different; but I think it’s
the same code that would need adjustment.

--

Father Chrysostomos

@p5pRT
Copy link
Author

p5pRT commented Apr 28, 2012

From @cpansprout

On Sat Apr 28 13​:56​:58 2012, sprout wrote​:

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

@p5pRT
Copy link
Author

p5pRT commented Feb 21, 2013

From @mauke

Created by @mauke

% 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
Perl Info

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

@p5pRT
Copy link
Author

p5pRT commented Feb 21, 2013

From @ikegami

Also affects Windows and cygwin, so it's not OS specific.

@p5pRT
Copy link
Author

p5pRT commented Feb 21, 2013

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

@p5pRT
Copy link
Author

p5pRT commented Feb 21, 2013

@ikegami - Status changed from 'open' to 'new'

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

3 participants