develooper Front page | perl.perl5.porters | Postings from October 2013

[perl #120172] pp_each needs its own hash iterator

Thread Next
From:
Mark R . Bannister
Date:
October 11, 2013 00:26
Subject:
[perl #120172] pp_each needs its own hash iterator
Message ID:
rt-3.6.HEAD-26210-1381402789-1187.120172-75-0@perl.org
# New Ticket Created by  Mark R. Bannister 
# Please include the string:  [perl #120172]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=120172 >


This is a bug report for perl from chapter34@yahoo.com,generated with the help of perlbug 1.39 running under perl 5.14.2.


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

As I have described in my blog article:

http://technicalprose.blogspot.co.uk/2013/10/perl-each-function-is-not-re-entrant.html

the 'each' function is not re-entrant because it relies on hv_iternext()
to get an iterator for a hash.  This should be fixed so that 'each' uses
its own local scope iterator.

The following code should work:

#!/usr/bin/perl
use warnings;
use strict;

my %global_hash;
my $max_depth = 3;

sub recurse
{
my ($depth, $hash) = @_;
while (my ($key, $val) = each %$hash) {
print "|" . ("-" x ($depth * 4)) . " $key$val\n";
recurse($depth+1, $hash) if $depth < $max_depth;
}
}

$global_hash{a} = 1;
$global_hash{b} = 2;

recurse(0, \%global_hash);

....and it would work if 'each' had its own iterator instead of using
one tied to the hash.  Instead, one has to do this:

my %hashcopy = %$hash;
while (my ($key, $val) = each %hashcopy) {

or:

for my $key (keys %$hash) {
my $val = $hash->{$key};

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

Configured by zbanai at Tue Oct  4 11:54:09 BST 2011.

Summary of my perl5 (revision 5 version 14 subversion 2) configuration:

Platform:
osname=solaris, osvers=2.10, archname=i86pc-solaris-thread-multi
uname='sunos oy605c1n6 5.10 generic_141415-08 i86pc i386 i86pc '
config_args='-des -Dusemymalloc=n -Duselargefiles -Ud_flock -Accflags=-DPERL_DISABLE_PMC -Duseithreads -Dcc=cc -Doptimize=-O -Ui_db -Ui_gdbm -Duselargefiles -Dafsroot=/ms -Darchlib=//ms/dist/perl5/PROJ/core/5.14.2-0/.exec/ia32.sunos.5.10/lib/perl5 -Darchlibexp=//ms/dist/perl5/PROJ/core/5.14.2-0/.exec/ia32.sunos.5.10/lib/perl5 -Dbin=//ms/dist/perl5/PROJ/core/5.14.2-0/.exec/ia32.sunos.5.10/bin -Dbinexp=//ms/dist/perl5/PROJ/core/5.14.2-0/.exec/ia32.sunos.5.10/bin -Dccflags=-DAPPLLIB_EXP="/ms/dist/perl5/VERS/5.14.2-0-core/lib/perl5:/ms/dist/perl5/VERS/5.14-core/lib/perl5" -Dinstallarchlib=//ms/dev/perl5/core/5.14.2-0/install/.exec/ia32.sunos..5.10/lib/perl5 -Dinstallbin=//ms/dev/perl5/core/5.14.2-0/install/.exec/ia32.sunos.5.10/bin -Dinstallman1dir=//ms/dev/perl5/core/5.14.2-0/install/..exec/ia32.sunos.5.10/man/man1 -Dinstallman3dir=//ms/dev/perl5/core/5.14.2-0/install/.exec/ia32.sunos.5.10/man/man3 -Dinstallprivlib=//ms/dev/perl5/core/5.14.2-0/install/.exec/ia32.sunos.5.10/lib/p
 erl5 -Dinstallscript=//ms/dev/perl5/core/5.14.2-0/install/.exec/ia32.sunos.5.10/bin -Dinstallsitearch=//ms/dev/perl5/core/5.14.2-0/install/.exec/ia32.sunos.5.10/lib/perl5 -Dinstallsitelib=//ms/dev/perl5/core/5.14.2-0/install/.exec/ia32.sunos.5..10/lib/perl5 -Dman1dir=//ms/dist/perl5/PROJ/core/5.14.2-0/.exec/ia32.sunos.5.10/man/man1 -Dman1direxp=//ms/dist/perl5/PROJ/core/5.14.2-0/.exec/ia32.sunos.5.10/man/man1 -Dman3dir=//ms/dist/perl5/PROJ/core/5.14.2-0/.exec/ia32.sunos.5.10/man/man3 -Dman3direxp=//ms/dist/perl5/PROJ/core/5.14.2-0/.exec/ia32.sunos.5.10/man/man3 -Dpager=/ms/dist/fsf/bin/less -Dperladmin=perlcore@ms.com -Dperlpath=//ms/dist/perl5/PROJ/core/5.14.2-0/.exec/ia32.sunos.5.10/bin/perl -Dprefix=/ms/dist/perl5 -Dprefixexp=/ms/dist/perl5 -Dprivlib=//ms/dist/perl5/PROJ/core/5.14.2-0/.exec/ia32.sunos.5.10/lib/perl5 -Dprivlibexp=//ms/dist/perl5/PROJ/core/5.14.2-0/.exec/ia32.sunos.5..10/lib/perl5 -Dscriptdir=//ms/dist/perl5/PROJ/core/5.14.2-0/.exec/ia32.sunos.5.10/bin -Dsc
 riptdirexp=//ms/dist/perl5/PROJ/core/5.14.2-0/.exec/ia32.sunos.5.10/bin -Dstartperl=#!//ms/dist/perl5/PROJ/core/5.14.2-0/.exec/ia32.sunos.5.10/bin/perl'
hint=recommended, useposix=true, d_sigaction=define
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 -DAPPLLIB_EXP="/ms/dist/perl5/VERS/5.14.2-0-core/lib/perl5:/ms/dist/perl5/VERS/5.14-core/lib/perl5" -DPERL_DISABLE_PMC -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DPERL_USE_SAFE_PUTENV',
optimize='-O',
cppflags='-D_REENTRANT -DAPPLLIB_EXP="/ms/dist/perl5/VERS/5.14.2-0-core/lib/perl5:/ms/dist/perl5/VERS/5.14-core/lib/perl5" -DPERL_DISABLE_PMC -I/usr/local/include'
ccversion='Sun C 5.8 Patch 121016-07 2007/10/03', gccversion='', 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/lib -L/usr/ccs/lib -L/ms/dist/3rd/PROJ/SUNWspro/11.1-0/.exec/@sys/SUNWspro/prod/lib -L/lib -L/usr/local/lib '
libpth=/usr/lib /usr/ccs/lib /ms/dist/3rd/PROJ/SUNWspro/11.1-0/.exec/@sys/SUNWspro/prod/lib /lib /usr/local/lib
libs=-lsocket -lnsl -ldl -lm -lpthread -lc
perllibs=-lsocket -lnsl -ldl -lm -lpthread -lc
libc=/lib/libc.so, so=so, useshrplib=false, libperl=libperl.a
gnulibc_version=''
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' '
cccdlflags='-KPIC', lddlflags='-G -L/usr/lib -L/usr/ccs/lib -L/ms/dist/3rd/PROJ/SUNWspro/11.1-0/.exec/@sys/SUNWspro/prod/lib -L/lib -L/usr/local/lib'

Locally applied patches:


---
@INC for perl 5.14.2:
/ms/dist/perl5/VERS/5.14.2-0-core/lib/perl5
/ms/dist/perl5/VERS/5.14-core/lib/perl5
//ms/dist/perl5/PROJ/core/5.14.2-0/.exec/ia32.sunos.5.10/lib/perl5
.

---
Environment for perl 5.14.2:
HOME=/v/global/user/b/ba/bannimar
LANG (unset)
LANGUAGE (unset)
LC_ALL=C
LD_LIBRARY_PATH=/ms/dist/storage/PROJ/widesky/prod/shlib:/opt/VRTSvcs/lib
LOGDIR (unset)
PATH=/v/global/user/b/ba/bannimar/bin:/usr/bin:/sbin:/usr/sbin://ms/dist/sec/PROJ/openssh/prod/bin://ms/dist/fsf/PROJ/make/prod/bin:/ms/dist/fsf/PROJ/gnuemacs/23.3/exec/bin://ms/dist/afs/PROJ/vms/beta/common/bin://ms/dist/afs/PROJ/vms/beta/common/sbin:/ms/dist/unixops/PROJ/ddt/beta/bin://ms/dist/fsf/PROJ/git/prod-1.8/bin:/ms/dist/aquilon/PROJ/aqd/prod/bin:/ms/dist/aquilon/PROJ/aqdw/prod/bin://ms/dist/python/PROJ/core/2.7.3-64/bin://ms/dist/perl5/PROJ/core/5.10/bin://ms/dist/perl5/bin://ms/dist/fsf/PROJ/mutt/incr/bin://ms/dist/fsf/PROJ/mutt/1.5.13/bin:/ms/dist/fsf/PROJ/bash/4.1/bin:/ms/dist/storage/PROJ/sandy/beta/common/sbin:/ms/dist/aurora/PROJ/astro/prod/common/bin:/ms/dist/storage/PROJ/widesky/prod/bin:/ms/dist/storage/PROJ/infra/prod/bin:/ms/dist/storage/sbin:/ms/dist/storage/bin:/v/global/user/b/ba/bannimar/bin:/ms/dist/aurora/bin:/usr/local/bin:/usr/bin:/bin:/usr/ccs/bin:/usr/ucb:/ms/dist/perl5/bin:/ms/dist/fsf/bin:/ms/dist/afs/bin:/usr/X11R6/bin:/usr/openwin/bin:.:/ms/
 dist/unixops/bin:/ms/dist/aurora/sbin:/ms/dist/fsf/PROJ/xmlstarlet/1.3.0/bin:/ms/dist/perl5/PROJ/Perl-Critic/1.116/bin:/ms/dist/msjava/PROJ/sunjdk/1.6.0_31/exec/bin:/ms/dist/fsf/PROJ/git/prod-1.8/exec/bin:/ms/dist/aquilon/PROJ/tellme/prod/bin:/sbin:/opt/VRTSllt:/opt/VRTSvcs/bin:/ms/dist/ha/PROJ/msvcs/prod/scripts:/ms/dist/ha/PROJ/utils/incr/bin:/ms/dist/ha/PROJ/signoff/prod/bin:/ms/dist/ha/PROJ/aqvcs/prod/bin:/ms/dist/fsf/PROJ/git/master/bin:/ms/dist/elfms/PROJ/panc/prod/bin
PERL_BADLANG (unset)
SHELL=/bin/ksh



--------------------------------------------------------------------------------

NOTICE: Morgan Stanley is not acting as a municipal advisor and the opinions or views contained herein are not intended to be, and do not constitute, advice within the meaning of Section 975 of the Dodd-Frank Wall Street Reform and Consumer Protection Act. If you have received this communication in error, please destroy all electronic and paper copies and notify the sender immediately. Mistransmission is not intended to waive confidentiality or privilege. Morgan Stanley reserves the right, to the extent permitted under applicable law, to monitor electronic communications. This message is subject to terms available at the following link: http://www.morganstanley.com/disclaimers. If you cannot access these links, please notify us by reply message and we will send the contents to you. By messaging with Morgan Stanley you consent to the foregoing.=


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