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

@_ autovivifies hash slices #8153

Open
p5pRT opened this issue Oct 14, 2005 · 10 comments
Open

@_ autovivifies hash slices #8153

p5pRT opened this issue Oct 14, 2005 · 10 comments
Assignees

Comments

@p5pRT
Copy link

p5pRT commented Oct 14, 2005

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

Searchable as RT37441$

@p5pRT
Copy link
Author

p5pRT commented Oct 14, 2005

From @kenahoo

This is a bug report for perl from ken@​mathforum.org,
generated with the help of perlbug 1.34 running under perl v5.8.1.


As the following three one-liners demonstrate, perl is autovivifying
some hash entries in a case it seems like it ought not to​:

% perl -le 'sub foo{} foo(@x{'a','b'}); print for keys %x'
b
a
% perl -le 'sub foo{} foo($x{a},$x{b}); print for keys %x'
% perl -le 'sub foo{$_=5 for @_} foo($x{a},$x{b}); print for keys %x'
a
b

The main difference is between the first two examples, which my
intuition tells me ought to be equivalent. The third example shows
that even when not using slices (and thus not autovivifying
unnecessarily), @​_ still manages to create read/write aliases to the
original hash entries.

Credit goes to Thomas L. Shinnick, who figured out why
File​::Spec->tmpdir was autovivifying an undef value for $ENV{TMPDIR}.

  -Ken

Perl Info
Flags:
category=core
severity=medium
---
Site configuration information for perl v5.8.1:

Configured by root at Fri Sep 12 19:46:46 PDT 2003.

Summary of my perl5 (revision 5.0 version 8 subversion 1 RC3)
configuration:
Platform:
osname=darwin, osvers=7.0, archname=darwin-thread-multi-2level
uname='darwin hampsten 7.0 darwin kernel version 6.0: fri jul 25
16:58:41 pdt 2003;
root:xnu-344.frankd.rootsxnu-344.frankd~objrelease_ppc power macintosh
powerpc '
config_args='-ds -e -Dprefix=/usr -Dccflags=-g -pipe
-Dldflags=-Dman3ext=3pm -Duseithreads -Duseshrplib'
hint=recommended, useposix=true, d_sigaction=define
usethreads=define use5005threads=undef useithreads=define
usemultiplicity=define
useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
use64bitint=undef use64bitall=undef uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='cc', ccflags ='-g -pipe -pipe -fno-common -DPERL_DARWIN
-no-cpp-precomp -fno-strict-aliasing -I/usr/local/include',
optimize='-Os',
cppflags='-no-cpp-precomp -g -pipe -pipe -fno-common -DPERL_DARWIN
-no-cpp-precomp -fno-strict-aliasing -I/usr/local/include'
ccversion='', gccversion='3.3 20030304 (Apple Computer, Inc. build
1495)', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries:
ld='MACOSX_DEPLOYMENT_TARGET=10.3 cc', ldflags ='-L/usr/local/lib'
libpth=/usr/local/lib /usr/lib
libs=-ldbm -ldl -lm -lc
perllibs=-ldl -lm -lc
libc=/usr/lib/libc.dylib, so=dylib, useshrplib=true,
libperl=libperl.dylib
gnulibc_version=''
Dynamic Linking:
dlsrc=dl_dyld.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
cccdlflags=' ', lddlflags='-bundle -undefined dynamic_lookup
-L/usr/local/lib'

Locally applied patches:
RC3

---
@INC for perl v5.8.1:
/sw/lib/perl5/5.8.1/darwin-thread-multi-2level
/sw/lib/perl5/5.8.1
/sw/lib/perl5
/sw/lib/perl5/darwin
/Users/ken/lib/darwin-thread-multi-2level
/Users/ken/lib
/System/Library/Perl/5.8.1/darwin-thread-multi-2level
/System/Library/Perl/5.8.1
/Library/Perl/5.8.1/darwin-thread-multi-2level
/Library/Perl/5.8.1
/Library/Perl
/Network/Library/Perl/5.8.1/darwin-thread-multi-2level
/Network/Library/Perl/5.8.1
/Network/Library/Perl
.

---
Environment for perl v5.8.1:
DYLD_LIBRARY_PATH (unset)
HOME=/Users/ken
LANG (unset)
LANGUAGE (unset)
LC_ALL=C
LD_LIBRARY_PATH (unset)
LOGDIR (unset)

PATH=/sw/bin:/sw/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/
usr/local/teTeX/bin/powerpc-apple-darwin-current:/usr/local/bin:/opt/
local/bin:/Users/ken/bin:/Developer/Tools:.:/usr/X11R6/bin
PERL5LIB=/sw/lib/perl5:/sw/lib/perl5/darwin:/Users/ken/lib
PERL_BADLANG (unset)
SHELL=/bin/tcsh

@p5pRT
Copy link
Author

p5pRT commented Jun 21, 2012

From @doy

This is still true in 5.16.

@p5pRT
Copy link
Author

p5pRT commented Jun 21, 2012

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

@p5pRT
Copy link
Author

p5pRT commented Jun 21, 2012

From @demerphq

On 21 June 2012 19​:47, Jesse Luehrs via RT <perlbug-followup@​perl.org> wrote​:

This is still true in 5.16.

But why is it a bug? Afaik it is supposed to happen.

sub one { $_=1 for @​_ }

one(@​foo{qw(x y z)});

print $_,"​:", $foo{$_}, $/ for keys %foo;

__END__

y​:1
x​:1
z​:1

--
perl -Mre=debug -e "/just|another|perl|hacker/"

@p5pRT
Copy link
Author

p5pRT commented Jun 21, 2012

From @doy

Sure, it's clearly necessary in that case. But​:

Sure, it's clearly necessary in that case. But:

sub nop { }
my (%foo, %bar);
nop(@foo{'a', 'b'});
nop($bar{'a'}, $bar{'b'});
say "foo:";
say for sort keys %foo;
say "bar:";
say for sort keys %bar;

__END__
foo:
a
b
bar:

I don't see a reason why %foo and %bar should end up being any different
there.

-doy

@p5pRT
Copy link
Author

p5pRT commented Jun 21, 2012

From @demerphq

Ok, I see. That makes sense. Maybe rename the bug?

Yves

@p5pRT
Copy link
Author

p5pRT commented Jun 18, 2013

From @jkeenan

@doy @demerphq

Dicussion in this RT petered out about a year ago. Do you see any way
we could move this ticket toward resolution?

Thank you very much.
Jim Keenan

@p5pRT
Copy link
Author

p5pRT commented Jun 18, 2013

From @cpansprout

This is on my to-do list, but rather low. Please leave it open if you will.

--

Father Chrysostomos

@p5pRT
Copy link
Author

p5pRT commented Jun 18, 2013

From @cpansprout

In case someone wants to beat me to it, it’s matter of extending defelem
magic (search for PERL_MAGIC_defelem in pp_hot.c) to hslice and aslice.

--

Father Chrysostomos

@p5pRT
Copy link
Author

p5pRT commented Jun 18, 2013

From ruz@bestpractical.com

On Tue, Jun 18, 2013 at 8​:40 AM, Father Chrysostomos via RT <
perlbug-followup@​perl.org> wrote​:

In case someone wants to beat me to it, it’s matter of extending defelem
magic (search for PERL_MAGIC_defelem in pp_hot.c) to hslice and aslice.

As far as I recall similar situation applies to for loops​:

perl -E '1 for @​h{qw(1 2 3)}; say %h'
132

But it spreads over more operations​:

perl -E '1 for $h{a}, $h{b}; say %h'
ab

Sorry, if it's not releated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants