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

[perl #133517] $! cannot be localized by doing a copy

Thread Next
From:
Atoomic
Date:
September 14, 2018 17:21
Subject:
[perl #133517] $! cannot be localized by doing a copy
Message ID:
rt-4.0.24-6866-1536945667-1216.133517-75-0@perl.org
# New Ticket Created by  Atoomic 
# Please include the string:  [perl #133517]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=133517 >


This is a bug report for perl from atoomic@cpan.org,
generated with the help of perlbug 1.40 running under perl 5.26.1.


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


We recently discovered this issue while updating Test::Trap to 0.3.3
which by trying to localize $!, in fact corrupted it using a simple

    local ($!, $^E) = ($!, $^E);

view https://rt.cpan.org/Public/Bug/Display.html?id=127112 for more details

So I performed some basic tests using multiple perl versions from 5.10 to
5.28
and looks like they all behave in the same way (which is good).

But I think it's weird that $! cannot be localized performing a copy

perl -e'$! = 4; do { local $! = $!; 1; }; print 0 + $!'
0

Another variable would work fine and preserve its original value
perl  -e'our $x= 4; do { local $x = $x; }; print 0 + $x'
4

of course a workaround could be
perl -e'$! = 4; do { local $! = $! . q//; 1; }; print 0 + $!'
4

or a less convoluted by doing a manual copy

perl -e'$! = 4; do { my $copy = $!; local $! = $copy; 1; }; print 0 + $!'
4

At this point I'm not sure we can call it a bug... (maybe it's a feature)
but I still want to know your opinion on this
and you think it is worth fixing.


[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=core
    severity=low
---
Site configuration information for perl 5.26.1:

Configured by nicolas at Wed Nov 29 10:26:27 MST 2017.

Summary of my perl5 (revision 5 version 26 subversion 1) configuration:

  Platform:
    osname=darwin
    osvers=15.6.0
    archname=darwin-2level
    uname='darwin nicolas-r.local 15.6.0 darwin kernel version 15.6.0: mon
oct 2 22:20:08 pdt 2017; root:xnu-3248.71.4~1release_x86_64 x86_64 '
    config_args='-de -Dprefix=/usr/local/perl/perls/perl-5.26.1
-Aeval:scriptdir=/usr/local/perl/perls/perl-5.26.1/bin'
    hint=recommended
    useposix=true
    d_sigaction=define
    useithreads=undef
    usemultiplicity=undef
    use64bitint=define
    use64bitall=define
    uselongdouble=undef
    usemymalloc=n
    default_inc_excludes_dot=define
    bincompat5005=undef
  Compiler:
    cc='cc'
    ccflags ='-fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe
-fstack-protector-strong -I/usr/local/include'
    optimize='-O3'
    cppflags='-fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe
-fstack-protector-strong -I/usr/local/include'
    ccversion=''
    gccversion='4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)'
    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.3 cc'
    ldflags =' -fstack-protector-strong -L/usr/local/lib'
    libpth=/usr/local/lib
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.0.0/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=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/usr/local/lib
-fstack-protector-strong'


---
@INC for perl 5.26.1:
    /Users/nicolas/.dotfiles/perl-must-have/lib
    /Users/nicolas/perl5/lib/perl5/
    /usr/local/perl/perls/perl-5.26.1/lib/site_perl/5.26.1/darwin-2level
    /usr/local/perl/perls/perl-5.26.1/lib/site_perl/5.26.1
    /usr/local/perl/perls/perl-5.26.1/lib/5.26.1/darwin-2level
    /usr/local/perl/perls/perl-5.26.1/lib/5.26.1

---
Environment for perl 5.26.1:
    DYLD_LIBRARY_PATH (unset)
    HOME=/Users/nicolas
    LANG=en_US.UTF-8
    LANGUAGE (unset)
    LC_CTYPE=en_US.UTF-8
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)

PATH=/usr/local/perl/bin:/usr/local/perl/perls/perl-5.26.1/bin:/usr/local/opt/ccache/libexec:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/git/bin:/usr/local/MacGPG2/bin:/Users/nicolas/.dotfiles/bin:/Users/nicolas/perl5/bin
    PERL5DB=use Devel::NYTProf

PERL5LIB=/Users/nicolas/.dotfiles/perl-must-have/lib:/Users/nicolas/perl5/lib/perl5/
    PERLBREW_BASHRC_VERSION=0.80
    PERLBREW_HOME=/Users/nicolas/.perlbrew
    PERLBREW_MANPATH=/usr/local/perl/perls/perl-5.26.1/man
    PERLBREW_PATH=/usr/local/perl/bin:/usr/local/perl/perls/perl-5.26.1/bin
    PERLBREW_PERL=perl-5.26.1
    PERLBREW_ROOT=/usr/local/perl
    PERLBREW_VERSION=0.80
    PERL_BADLANG (unset)
    PERL_CPANM_OPT=--quiet
    SHELL=/usr/local/bin/zsh


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