Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.91k stars 542 forks source link

Weirdness: nested fetches of array references on tied hashes #5734

Closed p5pRT closed 21 years ago

p5pRT commented 22 years ago

Migrated from rt.perl.org#10080 (status was 'resolved')

Searchable as RT10080$

p5pRT commented 22 years ago

From argggh@linpro.no

Created by argggh@linpro.no

(Resent\, apologies if it turns up twice.)

I'm experiencing what I consider to be strange behaviour regarding nested FETCH-calls on tied hashes. Given the following program​:

  #!/usr/bin/perl -l  
  use strict;  
  package Foo;  
  sub TIEHASH { bless [$]] }  
  sub FETCH {   my ($self\, $key) = @​_;  
  $main​::bar{5} if $main​::zoo;  
  return $self;   }  
 
  package Bar;  
  sub TIEHASH { bless [13] }  
  sub FETCH { return 1; }  
 
  package main;  
  use vars qw(%foo %bar $zoo);  
  tie %foo\, 'Foo';   tie %bar\, 'Bar';  
  print $foo{5}[0];   $zoo = 1;   print $foo{5}[0];

I'm expecting $] to be printed twice. Instead I get​:

  $ ./test-bug.pl   5.00503   Can't use an undefined value as an ARRAY reference at ./test-bug.pl line 34.   $

Why is this? If I replace $foo{5}[0] with $foo{5} in the last lines the output is the more sane​:

  $ ./test-bug.pl   Foo=ARRAY(0x80d3030)   Foo=ARRAY(0x80d3030)   $

Which makes me assume that the above is not intended behaviour.

This seems to happen with Perl 5.8rc3 as well as my standard Debian Woody Perl 5.6.1.

Thanks\,

  Arne.

Perl Info ``` Flags: category=core severity=medium Site configuration information for perl v5.6.1: Configured by bod at Fri Jan 11 04:14:18 EST 2002. Summary of my perl5 (revision 5.0 version 6 subversion 1) configuration: Platform: osname=linux, osvers=2.4.13, archname=i386-linux uname='linux duende 2.4.13 #1 wed oct 31 19:18:07 est 2001 i686 unknown ' config_args='-Dccflags=-DDEBIAN -Dcccdlflags=-fPIC -Darchname=i386-linux -Dprefix=/usr -Dprivlib=/usr/share/perl/5.6.1 -Darchlib=/usr/lib/perl/5.6.1 -Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5 -Dvendorarch=/usr/lib/perl5 -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl/5.6.1 -Dsitearch=/usr/local/lib/perl/5.6.1 -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dman1ext=1 -Dman3ext=3perl -Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -Uusesfio -Duseshrplib -Dlibperl=libperl.so.5.6.1 -Dd_dosuid -des' 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='cc', ccflags ='-DDEBIAN -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64', optimize='-O2', cppflags='-DDEBIAN -fno-strict-aliasing -I/usr/local/include' ccversion='', gccversion='2.95.4 (Debian prerelease)', 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, usemymalloc=n, prototype=define Linker and Libraries: ld='cc', ldflags =' -L/usr/local/lib' libpth=/usr/local/lib /lib /usr/lib libs=-lgdbm -ldb -ldl -lm -lc -lcrypt perllibs=-ldl -lm -lc -lcrypt libc=/lib/libc-2.2.4.so, so=so, useshrplib=true, libperl=libperl.so.5.6.1 Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic' cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib' Locally applied patches: @INC for perl v5.6.1: /usr/local/lib/perl/5.6.1 /usr/local/share/perl/5.6.1 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.6.1 /usr/share/perl/5.6.1 /usr/local/lib/site_perl/i386-linux /usr/local/lib/site_perl . Environment for perl v5.6.1: HOME=/false/home/argggh LANG=C LANGUAGE (unset) LC_CTYPE=no_NO LD_LIBRARY_PATH (unset) LOGDIR (unset) PATH=/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games:/linpro/local/bin:/store/bin:/store/sbin:/linpro/local/ia32-linux/bin:/linpro/local/bin PERL_BADLANG (unset) SHELL=/bin/bash ```
p5pRT commented 22 years ago

From @iabyn

On Tue\, Jul 16\, 2002 at 03​:37​:14PM +0200\, Arne Georg Gleditsch wrote​:

This is a bug report for perl from argggh@​linpro.no\, generated with the help of perlbug 1.33 running under perl v5.6.1.

----------------------------------------------------------------- [Please enter your report here]

(Resent\, apologies if it turns up twice.)

I'm experiencing what I consider to be strange behaviour regarding nested FETCH-calls on tied hashes. Given the following program​:

Confirmed in bleedperl. At first glance\, it appears to be the nested hash FETCHes fighting over the static PL_hv_fetch_ent_mh (I did a quick hack in hv.c to make it alternate between 2 such statics\, and the problem seemed to go away).

For 5.9\, perhaps we could hijack unused fields in the tiedelem magic mortals we create\, in order to store there what we currently store in the statics PL_hv_fetch_ent_mh\, PL_hv_fetch\, and PL_av_fetch? (Consider my hand to have been vaguely waved.)

Dave.

\#\!/usr/bin/perl \-l

use strict;

package Foo;

sub TIEHASH \{ bless \[$\]\] \}

sub FETCH \{
    my \($self\, $key\) = @​\_;

    $main​::bar\{5\} if $main​::zoo;

    return $self;
\}

package Bar;

sub TIEHASH \{ bless \[13\] \}

sub FETCH \{ return 1; \}

package main;

use vars qw\(%foo %bar $zoo\);

tie %foo\, 'Foo';
tie %bar\, 'Bar';

print $foo\{5\}\[0\];
$zoo = 1;
print $foo\{5\}\[0\];

I'm expecting $] to be printed twice. Instead I get​:

$ \./test\-bug\.pl
5\.00503
Can't use an undefined value as an ARRAY reference at \./test\-bug\.pl line 34\.
$

Why is this? If I replace $foo{5}[0] with $foo{5} in the last lines the output is the more sane​:

$ \./test\-bug\.pl
Foo=ARRAY\(0x80d3030\)
Foo=ARRAY\(0x80d3030\)
$

Which makes me assume that the above is not intended behaviour.

This seems to happen with Perl 5.8rc3 as well as my standard Debian Woody Perl 5.6.1.

Thanks\,

                        Arne\.

[Please do not change anything below this line] ----------------------------------------------------------------- --- Flags​: category=core severity=medium --- Site configuration information for perl v5.6.1​:

Configured by bod at Fri Jan 11 04​:14​:18 EST 2002.

Summary of my perl5 (revision 5.0 version 6 subversion 1) configuration​: Platform​: osname=linux\, osvers=2.4.13\, archname=i386-linux uname='linux duende 2.4.13 #1 wed oct 31 19​:18​:07 est 2001 i686 unknown ' config_args='-Dccflags=-DDEBIAN -Dcccdlflags=-fPIC -Darchname=i386-linux -Dprefix=/usr -Dprivlib=/usr/share/perl/5.6.1 -Darchlib=/usr/lib/perl/5.6.1 -Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5 -Dvendorarch=/usr/lib/perl5 -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl/5.6.1 -Dsitearch=/usr/local/lib/perl/5.6.1 -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dman1ext=1 -Dman3ext=3perl -Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -Uusesfio -Duseshrplib -Dlibperl=libperl.so.5.6.1 -Dd_dosuid -des' 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='cc'\, ccflags ='-DDEBIAN -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'\, optimize='-O2'\, cppflags='-DDEBIAN -fno-strict-aliasing -I/usr/local/include' ccversion=''\, gccversion='2.95.4 (Debian prerelease)'\, 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\, usemymalloc=n\, prototype=define Linker and Libraries​: ld='cc'\, ldflags =' -L/usr/local/lib' libpth=/usr/local/lib /lib /usr/lib libs=-lgdbm -ldb -ldl -lm -lc -lcrypt perllibs=-ldl -lm -lc -lcrypt libc=/lib/libc-2.2.4.so\, so=so\, useshrplib=true\, libperl=libperl.so.5.6.1 Dynamic Linking​: dlsrc=dl_dlopen.xs\, dlext=so\, d_dlsymun=undef\, ccdlflags='-rdynamic' cccdlflags='-fPIC'\, lddlflags='-shared -L/usr/local/lib'

Locally applied patches​:

--- @​INC for perl v5.6.1​: /usr/local/lib/perl/5.6.1 /usr/local/share/perl/5.6.1 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.6.1 /usr/share/perl/5.6.1 /usr/local/lib/site_perl/i386-linux /usr/local/lib/site_perl .

--- Environment for perl v5.6.1​: HOME=/false/home/argggh LANG=C LANGUAGE (unset) LC_CTYPE=no_NO LD_LIBRARY_PATH (unset) LOGDIR (unset) PATH=/usr/local/bin​:/usr/bin​:/bin​:/usr/bin/X11​:/usr/games​:/linpro/local/bin​:/store/bin​:/store/sbin​:/linpro/local/ia32-linux/bin​:/linpro/local/bin PERL_BADLANG (unset) SHELL=/bin/bash

-- This email is confidential\, and now that you have read it you are legally obliged to shoot yourself. Or shoot a lawyer\, if you prefer. If you have received this email in error\, place it in its original wrapping and return for a full refund. By opening this email\, you accept that Elvis lives.

p5pRT commented 21 years ago

From @iabyn

Just to let you know that this bug you reported back in July\, has now been fixed in the development version of Perl\, by patch number 19268. This patch will probably get backported to the forthcoming 5.8.1 maintenance release too.

Regards\,

Dave M.

p5pRT commented 21 years ago

@iabyn - Status changed from 'open' to 'resolved'