P
PeterSShenkin
Here's a code excerpt that isn't sufficient to duplicate the problem as
a standalone, but does illustrate what the problem is. For the bug to
appear, $self->compute_base() has to be called from a class that
inherits from the one where the subroutine is defined. Then, on the
call to $self->compute_base(), the "while" loop behaves as if the
type_stats hash is empty; that is, the body is not executed. The hash
actually does have elements, so I expected the body to be executed for
each one. (The hash elements both exist and are defined.)
In the course of inserting printouts to determine what was going on, I
discovered that computing ntype_stats as shown below causes the "while"
to behave properly. Presumably, the call to "keys" makes the hash
contents visible.
Following the code excerpt is the output of "perl -V".
Apologies if this is a known bug; if so, please refer me to where it is
documented.
sub compute_base {
# compute() each child and return hash of results:
my $self = shift;
if( not ref $self ) {
confess
"$self" . "::compute_base: '$self' is not an object";
}
my $nsample = $self->{nsample};
my $results;
# the while finds no k,v pairs on the 1st call to compute_base
# without the following line; this seems to be a bug in Perl:
my $ntype_stats = scalar keys %{$self->{type_stats}};
while( my ($k,$v) = each %{$self->{type_stats}} ) {
$results->{$k} = $v->compute($nsample);
}
return $results;
}
Summary of my perl5 (revision 5 version 8 subversion 6) configuration:
Platform:
osname=linux, osvers=2.4.20-28.7, archname=i686-linux-thread-multi
uname='linux rosaleen 2.4.20-28.7 #1 thu dec 18 11:31:59 est 2003
i686 unknown '
config_args='-Dprefix=/utils -Dusethreads
-Accflags=-DPERL_REENTRANT_MAXSIZE=65536'
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 ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS
-DPERL_REENTRANT_MAXSIZE=65536 -fno-strict-aliasing -pipe
-I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
-I/usr/include/gdbm',
optimize='-O2',
cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS
-DPERL_REENTRANT_MAXSIZE=65536 -fno-strict-aliasing -pipe
-I/usr/local/include -I/usr/include/gdbm'
ccversion='', gccversion='2.96 20000731 (Red Hat Linux 7.3
2.96-113)', 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, prototype=define
Linker and Libraries:
ld='cc', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib
libs=-lnsl -lndbm -lgdbm -ldl -lm -lcrypt -lutil -lpthread -lc
perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
libc=/lib/libc-2.2.5.so, so=so, useshrplib=false, libperl=libperl.a
gnulibc_version='2.2.5'
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'
Characteristics of this binary (from libperl):
Compile-time options: MULTIPLICITY USE_ITHREADS USE_LARGE_FILES
PERL_IMPLICIT_CONTEXT
Built under linux
Compiled at Mar 12 2005 15:27:25
@INC:
/utils/lib/perl5/5.8.6/i686-linux-thread-multi
/utils/lib/perl5/5.8.6
/utils/lib/perl5/site_perl/5.8.6/i686-linux-thread-multi
/utils/lib/perl5/site_perl/5.8.6
/utils/lib/perl5/site_perl/5.8.1
/utils/lib/perl5/site_perl
a standalone, but does illustrate what the problem is. For the bug to
appear, $self->compute_base() has to be called from a class that
inherits from the one where the subroutine is defined. Then, on the
call to $self->compute_base(), the "while" loop behaves as if the
type_stats hash is empty; that is, the body is not executed. The hash
actually does have elements, so I expected the body to be executed for
each one. (The hash elements both exist and are defined.)
In the course of inserting printouts to determine what was going on, I
discovered that computing ntype_stats as shown below causes the "while"
to behave properly. Presumably, the call to "keys" makes the hash
contents visible.
Following the code excerpt is the output of "perl -V".
Apologies if this is a known bug; if so, please refer me to where it is
documented.
sub compute_base {
# compute() each child and return hash of results:
my $self = shift;
if( not ref $self ) {
confess
"$self" . "::compute_base: '$self' is not an object";
}
my $nsample = $self->{nsample};
my $results;
# the while finds no k,v pairs on the 1st call to compute_base
# without the following line; this seems to be a bug in Perl:
my $ntype_stats = scalar keys %{$self->{type_stats}};
while( my ($k,$v) = each %{$self->{type_stats}} ) {
$results->{$k} = $v->compute($nsample);
}
return $results;
}
Summary of my perl5 (revision 5 version 8 subversion 6) configuration:
Platform:
osname=linux, osvers=2.4.20-28.7, archname=i686-linux-thread-multi
uname='linux rosaleen 2.4.20-28.7 #1 thu dec 18 11:31:59 est 2003
i686 unknown '
config_args='-Dprefix=/utils -Dusethreads
-Accflags=-DPERL_REENTRANT_MAXSIZE=65536'
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 ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS
-DPERL_REENTRANT_MAXSIZE=65536 -fno-strict-aliasing -pipe
-I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
-I/usr/include/gdbm',
optimize='-O2',
cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS
-DPERL_REENTRANT_MAXSIZE=65536 -fno-strict-aliasing -pipe
-I/usr/local/include -I/usr/include/gdbm'
ccversion='', gccversion='2.96 20000731 (Red Hat Linux 7.3
2.96-113)', 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, prototype=define
Linker and Libraries:
ld='cc', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib
libs=-lnsl -lndbm -lgdbm -ldl -lm -lcrypt -lutil -lpthread -lc
perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
libc=/lib/libc-2.2.5.so, so=so, useshrplib=false, libperl=libperl.a
gnulibc_version='2.2.5'
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'
Characteristics of this binary (from libperl):
Compile-time options: MULTIPLICITY USE_ITHREADS USE_LARGE_FILES
PERL_IMPLICIT_CONTEXT
Built under linux
Compiled at Mar 12 2005 15:27:25
@INC:
/utils/lib/perl5/5.8.6/i686-linux-thread-multi
/utils/lib/perl5/5.8.6
/utils/lib/perl5/site_perl/5.8.6/i686-linux-thread-multi
/utils/lib/perl5/site_perl/5.8.6
/utils/lib/perl5/site_perl/5.8.1
/utils/lib/perl5/site_perl