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 $!” erroneously restores empty value #15404

Open
p5pRT opened this issue Jun 22, 2016 · 7 comments
Open

“local $!” erroneously restores empty value #15404

p5pRT opened this issue Jun 22, 2016 · 7 comments

Comments

@p5pRT
Copy link

p5pRT commented Jun 22, 2016

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

Searchable as RT128460$

@p5pRT
Copy link
Author

p5pRT commented Jun 22, 2016

From @FGasper

Created by @FGasper

--------------------
our $foo = 'bar';

unlink('/i/do/not/exist');
{
  local $foo = 'qux';
  local $! = $!;
}
print "err​: [$!]; foo​: [$foo]\n";
--------------------

Run the above, and note that $! doesn�t get restored after the
block with the local()s, even though $foo does get restored.

If you remove the �local $!� line, $! has the expected value.

Perl Info

Flags:
    category=core
    severity=low

Site configuration information for perl 5.22.2:

Configured by buildbot at Sat May  7 02:51:01 PDT 2016.

Summary of my perl5 (revision 5 version 22 subversion 2) configuration:
   
  Platform:
    osname=darwin, osvers=15.4.0, archname=darwin-thread-multi-2level
    uname='darwin teneleven-slave.macports.org 15.4.0 darwin kernel version 15.4.0: fri feb 26 22:08:05 pst 2016; root:xnu-3248.40.184~3release_x86_64 x86_64 '
    config_args='-des -Dprefix=/opt/local -Dscriptdir=/opt/local/bin -Dcppflags=-I/opt/local/include -Dccflags=-pipe -Os  -Dldflags=-L/opt/local/lib -Wl,-headerpad_max_install_names  -Dvendorprefix=/opt/local -Dusemultiplicity=y -Dusethreads -Duseshrplib -Dcc=/usr/bin/clang -Dld=env MACOSX_DEPLOYMENT_TARGET=10.11 /usr/bin/clang -Dman1ext=1pm -Dman3ext=3pm -Dman1dir=/opt/local/share/man/man1p -Dman3dir=/opt/local/share/man/man3p -Dsitebin=/opt/local/libexec/perl5.22/sitebin -Dsiteman1dir=/opt/local/share/perl5.22/siteman/man1 -Dsiteman3dir=/opt/local/share/perl5.22/siteman/man3 -Dvendorbin=/opt/local/libexec/perl5.22 -Dvendorman1dir=/opt/local/share/perl5.22/man/man1 -Dvendorman3dir=/opt/local/share/perl5.22/man/man3 -Dpager=/usr/bin/less -sR -Dperlpath=/opt/local/bin/perl5.22 -Dstartperl=#!/opt/local/bin/perl5.22'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='/usr/bin/clang', ccflags ='-pipe -Os  -fno-common -DPERL_DARWIN -I/opt/local/include -fno-strict-aliasing -fstack-protector-strong -I/opt/local/include -DPERL_USE_SAFE_PUTENV',
    optimize='-O3',
    cppflags='-I/opt/local/include -pipe -Os  -fno-common -DPERL_DARWIN -I/opt/local/include -fno-strict-aliasing -fstack-protector-strong -I/opt/local/include'
    ccversion='', gccversion='4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678, doublekind=3
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16, longdblkind=3
    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.11 /usr/bin/clang', ldflags ='-L/opt/local/lib -Wl,-headerpad_max_install_names  -fstack-protector-strong'
    libpth=/opt/local/lib /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.0.2/lib /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib /usr/lib
    libs=-lpthread -lgdbm -ldbm -ldl -lm -lutil -lc
    perllibs=-lpthread -ldl -lm -lutil -lc
    libc=, so=dylib, useshrplib=true, libperl=libperl.dylib
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags='-L/opt/local/lib -Wl,-headerpad_max_install_names  -bundle -undefined dynamic_lookup -fstack-protector-strong'



@INC for perl 5.22.2:
    /opt/local/lib/perl5/site_perl/5.22/darwin-thread-multi-2level
    /opt/local/lib/perl5/site_perl/5.22
    /opt/local/lib/perl5/vendor_perl/5.22/darwin-thread-multi-2level
    /opt/local/lib/perl5/vendor_perl/5.22
    /opt/local/lib/perl5/5.22/darwin-thread-multi-2level
    /opt/local/lib/perl5/5.22
    .


Environment for perl 5.22.2:
    DYLD_LIBRARY_PATH (unset)
    HOME=/Users/Felipe
    LANG=en_US.UTF-8
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/Users/Felipe/.opt/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/Users/Felipe/.opt/bin
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Jun 22, 2016

From zefram@fysh.org

I think this is a duplicate of [perl #119683].

-zefram

@p5pRT
Copy link
Author

p5pRT commented Jun 22, 2016

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

@p5pRT
Copy link
Author

p5pRT commented Jun 22, 2016

From @FGasper

Hm. The other case involves use of ref; this shows more general breakage?

On June 22, 2016 11​:20​:51 AM CDT, Zefram via RT <perlbug-followup@​perl.org> wrote​:

I think this is a duplicate of [perl #119683].

-zefram

--
Sent from my Android device with K-9 Mail. Please excuse my brevity.

@p5pRT
Copy link
Author

p5pRT commented Jun 22, 2016

From zefram@fysh.org

Felipe Gasper wrote​:

Hm. The other case involves use of ref; this shows more general breakage?

ref turned out not to be critical to it. That ticket moved on to more
general trouble with localisation of $!, due to its magic.

-zefram

@FGasper
Copy link
Contributor

FGasper commented Jan 31, 2020

Improved demonstration of the bug:

our $foo = 'bar';

unlink('/i/do/not/exist');
my $val = $!;
print "err: $!\n";
$! = $val;
{
  local $foo = 'qux';
  local $! = $!;
}
print "err: [$!]; foo: [$foo]\n";

@Leont
Copy link
Contributor

Leont commented Jan 31, 2020

This is indeed a duplicate of #13244. Compare:

perl -le '$!=42; {local $! = $!} print 0+$!'

with:

perl -le '$!=42; {local $! = 0+$!} print 0+$!'

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

4 participants