in reply to upgrade to 5.8.4 breaks code -- how to fix?
I can confirm this for Perl 5.8.4, compiled from source for Debian Linux:
perl5.8.4 -we 'BEGIN{my %x=()}'
produces
Bizarre copy of HASH in leavesub at -e line 1. BEGIN failed--compilation aborted at -e line 1.
It seems that it is necessary that %x is a lexical variable local to the BEGIN block. The following other variants produce no error:
perl5.8.4 -we '{my %x=()}' perl5.8.4 -we 'my %x=()' perl5.8.4 -we 'BEGIN{ %x=()}' Name "main::x" used only once: possible typo at -e line 1. perl5.8.4 -we 'my%x;BEGIN{ %x=()}' perl5.8.4 -we 'my%x;BEGIN{ {%x=()}}'
This seems to indicate that a possible workaround would be to move the lexical declaration out of the BEGIN block, but into an inner block, so that it gets cleared after the program has started running:
perl5.8.4 -we '{my%x;BEGIN{ {%x=()}}}'
Deparse produces the non-initializing code for the oneliner, so I guess that davido is correct with his diagnosis that the optimization causes this error:
perl5.8.4 -w -MO=Deparse -e 'BEGIN{ my %x=()}' Bizarre copy of HASH in leavesub at -e line 1. BEGIN failed--compilation aborted at -e line 1. BEGIN { $^W = 1; } sub BEGIN { my %x; }
My Perl has the following characteristics:
corion@aliens:~$ perl5.8.4 -V Summary of my perl5 (revision 5 version 8 subversion 4) configuration: Platform: osname=linux, osvers=2.4.25, archname=i686-linux-thread-multi uname='linux aliens 2.4.25 #2 sun feb 22 12:12:48 cet 2004 i686 un +known ' config_args='-Dinc_version_list=none -Dprefix=/opt/perl' hint=recommended, useposix=true, d_sigaction=define usethreads=define use5005threads=undef useithreads=define usemulti +plicity=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 +-fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE +_OFFSET_BITS=64', optimize='-O3', cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -fno-stri +ct-aliasing -I/usr/local/include' ccversion='', gccversion='2.95.4 20011002 (Debian prerelease)', gc +cosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=1 +2 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 -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 May 8 2004 09:58:09 @INC: /opt/perl/lib/5.8.4/i686-linux-thread-multi /opt/perl/lib/5.8.4 /opt/perl/lib/site_perl/5.8.4/i686-linux-thread-multi /opt/perl/lib/site_perl/5.8.4 /opt/perl/lib/site_perl .
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: upgrade to 5.8.4 breaks code -- how to fix?
by ambrus (Abbot) on Jun 05, 2004 at 20:51 UTC | |
by dave_the_m (Monsignor) on Jun 05, 2004 at 21:34 UTC |