Skip Menu |
Report information
Id: 133538
Status: resolved
Priority: 0/
Queue: perl5

Owner: Nobody
Requestors: kes-kes [at] yandex.ru
Cc:
AdminCc:

Operating System: Linux
PatchStatus: (no value)
Severity: (no value)
Type: core
Perl Version: 5.24.1
Fixed In: 5.29.5



To: perlbug <perlbug [...] perl.org>
From: KES <kes-kes [...] yandex.ru>
Subject: refaliasing does not work
Date: Sat, 22 Sep 2018 12:56:33 +0300
Reply-To: kes-kes@yandex.ru Message-Id: <5.24.1_18064_1537609447@work> To: perlbug@perl.org Subject: refaliasing does not work From: kes-kes@yandex.ru Cc: kes-kes@yandex.ru This is a bug report for perl from kes-kes@yandex.ru, generated with the help of perlbug 1.40 running under perl 5.24.1. ----------------------------------------------------------------- [Please describe your issue here] https://perldoc.perl.org/perlref.html#Making-References my @list = ( 1, 2, 3 ); # Test 1 my %hash = (); { \( @hash{qw/ a b c /} ) = \(@list); } print %hash; # abc values are destroed from hash when we leave the block It is same for this: my %hash = (); { \( @hash{qw/ a b c /} ) = (\$list[0], \$list[1], \$list[2]); } print %hash; # abc But individual aliasing works fine: # Test 6 %hash = (); { \$hash{a} = \$list[0]; \$hash{b} = \$list[1]; \$hash{c} = \$list[2]; } print "Test 6: @{[ %hash ]}\n"; # a 1 b 2 c 3 See attached file for full test list [Please do not change anything below this line] ----------------------------------------------------------------- --- Flags: category=core severity=critical --- Site configuration information for perl 5.24.1: Configured by kes at Mon May 7 20:59:03 EEST 2018. Summary of my perl5 (revision 5 version 24 subversion 1) configuration: Platform: osname=linux, osvers=4.13.0-26-generic, archname=x86_64-linux uname='linux work 4.13.0-26-generic #29~16.04.2-ubuntu smp tue jan 9 22:00:44 utc 2018 x86_64 x86_64 x86_64 gnulinux ' config_args='-de -Dprefix=/home/kes/perl5/perlbrew/perls/perl-5.24.1 -Aeval:scriptdir=/home/kes/perl5/perlbrew/perls/perl-5.24.1/bin' hint=recommended, useposix=true, d_sigaction=define useithreads=undef, usemultiplicity=undef use64bitint=define, use64bitall=define, uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='cc', ccflags ='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64', optimize='-O2', cppflags='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include' ccversion='', gccversion='5.4.0 20160609', 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='cc', ldflags =' -fstack-protector-strong -L/usr/local/lib' libpth=/usr/local/lib /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed /usr/include/x86_64-linux-gnu /usr/lib /lib/x86_64-linux-gnu /lib/../lib /usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib /lib64 /usr/lib64 libs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc libc=libc-2.23.so, so=so, useshrplib=false, libperl=libperl.a gnulibc_version='2.23' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E' cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector-strong' Locally applied patches: Devel::PatchPerl 1.38 --- @INC for perl 5.24.1: /home/kes/work/projects/tucha/monkeyman/lib /home/kes/work/projects/tucha/monkeyman/local/lib/perl5/5.24.1/x86_64-linux /home/kes/work/projects/tucha/monkeyman/local/lib/perl5/5.24.1 /home/kes/work/projects/tucha/monkeyman/local/lib/perl5/x86_64-linux /home/kes/work/projects/tucha/monkeyman/local/lib/perl5 /home/kes/perl5/perlbrew/perls/perl-5.24.1/lib/site_perl/5.24.1/x86_64-linux /home/kes/perl5/perlbrew/perls/perl-5.24.1/lib/site_perl/5.24.1 /home/kes/perl5/perlbrew/perls/perl-5.24.1/lib/5.24.1/x86_64-linux /home/kes/perl5/perlbrew/perls/perl-5.24.1/lib/5.24.1 --- Environment for perl 5.24.1: HOME=/home/kes LANG=en_US.UTF-8 LANGUAGE=en LC_ADDRESS=uk_UA.UTF-8 LC_IDENTIFICATION=uk_UA.UTF-8 LC_MEASUREMENT=uk_UA.UTF-8 LC_MESSAGES=en_US.UTF-8 LC_MONETARY=uk_UA.UTF-8 LC_NAME=uk_UA.UTF-8 LC_NUMERIC=uk_UA.UTF-8 LC_PAPER=uk_UA.UTF-8 LC_TELEPHONE=uk_UA.UTF-8 LD_LIBRARY_PATH (unset) LOGDIR (unset) PATH=/home/kes/perl5/perlbrew/bin:/home/kes/perl5/perlbrew/perls/perl-5.24.1/bin:/home/kes/bin:/home/kes/work/projects/tucha/monkeyman/local/bin:/home/kes/work/projects/safevpn/repo2/local/bin:/home/kes/bin:/home/kes/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games PERL5DB=use DB::Hooks qw'::Terminal NonStop' PERL5LIB=/home/kes/work/projects/tucha/monkeyman/lib:/home/kes/work/projects/tucha/monkeyman/local/lib/perl5 PERLBREW=command perlbrew PERLBREW_BASHRC_VERSION=0.78 PERLBREW_HOME=/home/kes/.perlbrew PERLBREW_MANPATH=/home/kes/perl5/perlbrew/perls/perl-5.24.1/man PERLBREW_PATH=/home/kes/perl5/perlbrew/bin:/home/kes/perl5/perlbrew/perls/perl-5.24.1/bin PERLBREW_PERL=perl-5.24.1 PERLBREW_ROOT=/home/kes/perl5/perlbrew PERLBREW_VERSION=0.78 PERLDB_OPTS=white_box PERL_BADLANG (unset) SHELL=/bin/bash
Download t.pl
text/x-perl 823b

Message body is not shown because sender requested not to inline it.

RT-Send-CC: perl5-porters [...] perl.org
this is also true on 5.29.3
RT-Send-CC: perl5-porters [...] perl.org
Download (untitled) / with headers
text/plain 1.9k
On Sat, 22 Sep 2018 09:56:45 GMT, kes-kes@yandex.ru wrote: Show quoted text
> Reply-To: kes-kes@yandex.ru > Message-Id: <5.24.1_18064_1537609447@work> > To: perlbug@perl.org > Subject: refaliasing does not work > From: kes-kes@yandex.ru > Cc: kes-kes@yandex.ru > > > This is a bug report for perl from kes-kes@yandex.ru, > generated with the help of perlbug 1.40 running under perl 5.24.1. > > > ----------------------------------------------------------------- > [Please describe your issue here] > > https://perldoc.perl.org/perlref.html#Making-References > > my @list = ( 1, 2, 3 ); > > # Test 1 > my %hash = (); > { > \( @hash{qw/ a b c /} ) = \(@list); > } > print %hash; # abc > > > values are destroed from hash when we leave the block > > It is same for this: > > my %hash = (); > { > \( @hash{qw/ a b c /} ) = (\$list[0], \$list[1], \$list[2]); > } > print %hash; # abc > > > But individual aliasing works fine: > # Test 6 > %hash = (); > { > \$hash{a} = \$list[0]; > \$hash{b} = \$list[1]; > \$hash{c} = \$list[2]; > } > print "Test 6: @{[ %hash ]}\n"; # a 1 b 2 c 3 > > > See attached file for full test list
Do we have a similar problem for array slice assignment with refaliasing within a block? See attachment 133538-refalaising-array-slice.pl. ##### $> perl 133538-refalaising-array-slice.pl ok 1 - simple array slice assignment ok 2 - array slice assignment with refaliasing ok 3 - simple array slice assignment within block not ok 4 - array slice assignment with refaliasing within block # Failed test 'array slice assignment with refaliasing within block' # at 133538-refalaising-array-slice.pl line 25. # Structures begin differing at: # $got->[4] = undef # $expected->[4] = '1' Got: $VAR1 = [undef,undef,undef,undef,undef,undef,undef]; Expected: $VAR1 = [undef,undef,undef,undef,1,2,3]; 1..4 # Looks like you failed 1 test of 4. ##### Thank you very much. -- James E Keenan (jkeenan@cpan.org)
Subject: 133538-refalaising-array-slice.pl
use 5.22.0; use warnings; use experimental 'refaliasing'; use Data::Dumper;$Data::Dumper::Indent=0; use Test::More; my @list = ( 1, 2, 3 ); my @slice; my $expected = [ (undef) x 4, 1, 2, 3 ]; @slice = (); @slice[4..6] = @list; is_deeply(\@slice, $expected, "simple array slice assignment"); @slice = (); \( @slice[4..6] ) = \( @list ); is_deeply(\@slice, $expected, "array slice assignment with refaliasing"); @slice = (); { @slice[4..6] = @list; } is_deeply(\@slice, $expected, "simple array slice assignment within block"); @slice = (); { \( @slice[4..6] ) = \( @list ); } is_deeply(\@slice, $expected, "array slice assignment with refaliasing within block") or print "Got:\n", (Dumper \@slice), "\n", "Expected:\n", (Dumper $expected), "\n"; done_testing();
From: Dave Mitchell <davem [...] iabyn.com>
Date: Mon, 5 Nov 2018 12:39:16 +0000
Subject: Re: [perl #133538] refaliasing does not work
To: perl5-porters [...] perl.org
Download (untitled) / with headers
text/plain 1.1k
On Sat, Sep 22, 2018 at 02:56:46AM -0700, KES (via RT) wrote: Show quoted text
> my @list = ( 1, 2, 3 ); > > # Test 1 > my %hash = (); > { > \( @hash{qw/ a b c /} ) = \(@list); > } > print %hash; # abc > > > values are destroed from hash when we leave the block
Now fixed in blead with the following commit: commit b97fe865adca6799771c93fc17e9f36ae7272e72 Author: David Mitchell <davem@iabyn.com> AuthorDate: Mon Nov 5 12:29:27 2018 +0000 Commit: David Mitchell <davem@iabyn.com> CommitDate: Mon Nov 5 12:29:27 2018 +0000 Don't localise array / hash slice ref assignment RT #133538 The experimental ref assignment aliasing feature, when applied to array or hash slices, was treating the slice as if it was always localized; e.g. \(@a[3,5,7]) = \(....); was being interpreted as local \(@a[3,5,7]) = \(....); The fix is simple: check for the OPpLVAL_INTRO flag actually being set on the op, rather than unconditionally localising the array/hash elements. -- "There's something wrong with our bloody ships today, Chatfield." -- Admiral Beatty at the Battle of Jutland, 31st May 1916.
RT-Send-CC: perl5-porters [...] perl.org
Download (untitled) / with headers
text/plain 1.1k
On Mon, 05 Nov 2018 12:39:29 GMT, davem wrote: Show quoted text
> On Sat, Sep 22, 2018 at 02:56:46AM -0700, KES (via RT) wrote:
> > my @list = ( 1, 2, 3 ); > > > > # Test 1 > > my %hash = (); > > { > > \( @hash{qw/ a b c /} ) = \(@list); > > } > > print %hash; # abc > > > > > > values are destroed from hash when we leave the block
> > > Now fixed in blead with the following commit: > > commit b97fe865adca6799771c93fc17e9f36ae7272e72 > Author: David Mitchell <davem@iabyn.com> > AuthorDate: Mon Nov 5 12:29:27 2018 +0000 > Commit: David Mitchell <davem@iabyn.com> > CommitDate: Mon Nov 5 12:29:27 2018 +0000 > > Don't localise array / hash slice ref assignment > > RT #133538 > > The experimental ref assignment aliasing feature, when applied to > array or hash slices, was treating the slice as if it was always > localized; > e.g. > > \(@a[3,5,7]) = \(....); > > was being interpreted as > > local \(@a[3,5,7]) = \(....); > > The fix is simple: check for the OPpLVAL_INTRO flag actually being set > on the op, rather than unconditionally localising the array/hash > elements.
Works on my test files. Thanks. -- James E Keenan (jkeenan@cpan.org)
Download (untitled) / with headers
text/plain 313b
Thank you for filing this report. You have helped make Perl better. With the release today of Perl 5.30.0, this and 160 other issues have been resolved. Perl 5.30.0 may be downloaded via: https://metacpan.org/release/XSAWYERX/perl-5.30.0 If you find that the problem persists, feel free to reopen this ticket.


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