develooper Front page | perl.perl5.porters | Postings from September 2003

[perl #23810] Tied methods break when combined with eval() of failing compile-time code

Thread Next
From:
Jason Rhinelander
Date:
September 15, 2003 08:16
Subject:
[perl #23810] Tied methods break when combined with eval() of failing compile-time code
Message ID:
rt-23810-64584.3.66590348984531@rt.perl.org
# New Ticket Created by  Jason Rhinelander 
# Please include the string:  [perl #23810]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=23810 >


The following example demonstrates the problem quite well:

perl -e '
package Breaks;
use Tie::Hash;
@ISA = qw(Tie::StdHash);
sub FETCH { eval "BEGIN { some bad code }"; return 1 }

package main;
my %foo;
my $f = tie %foo, "Breaks";

print "Calling FETCH explicitly ...\n";
$f->FETCH("bar");

print "\tdone.\nCalling FETCH implicitly ...\n";
$foo{bar};

print "\tdone.\n"
'

The output from this is:

Calling FETCH explicitly ...
        done.
Calling FETCH implicitly ...
Can't return outside a subroutine at -e line 5.




In more complex situations, this causes Perl to segfault (at once point
I also got a "panic: pp_iter").  I've also tested it with other tied
methods and types - it seems that _any_ tied method (i.e. FETCH, STORE,
KEYS, etc.) for _any_ tied object type (I tested with tied hashes,
arrays, and scalars) that does this sort of eval causes the error.  It
doesn't have to be an explicit BEGIN block either - 'use Foo' in the
eval (where Foo.pm doesn't exist) causes this to occur as well - which
is how I originally discovered the bug.

Just for fun, I threw the implicit FETCH inside a subroutine (sub main)
and called it - the result was that the return value of the FETCH is
returned to the point where I called main, ignoring any remaining code
in sub main.


I figured out a rather nasty workaround, by wrapping the eval around
another eval, something like:

eval q{my $ret = eval "BEGIN { some bad code }"; die "$@\n" if $@; $ret};

I'm curious why the extra eval makes this work - admittedly it was
something of a shot in the dark to fixing my specific problem.  I'll
have to live with this solution, as the code I'm working on needs to
work in older Perl's, but it obviously isn't a very nice solution.



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

Configured by jagerman at Mon Aug 25 13:49:17 PDT 2003.

Summary of my perl5 (revision 5.0 version 8 subversion 1) configuration:
  Platform:
    osname=linux, osvers=2.4.21-pfeifer-r1_pre4, archname=i686-linux-thread-multi
    uname='linux cytherea.office.gossamer-threads.com 2.4.21-pfeifer-r1_pre4 #1 wed jul 23 21:38:48 pdt 2003 i686 amd athlon(tm) authenticamd gnulinux '
    config_args='-des -Darchname=i686-linux-thread -Dcc=gcc -Dprefix=/usr -Dvendorprefix=/usr -Dsiteprefix=/usr -Dlocincpth=  -Doptimize=-march=athlon-xp -O3 -mmmx -msse -m3dnow -mfpmath=sse -pipe -fomit-frame-pointer -fforce-addr -funroll-loops -frerun-loop-opt -Duselargefiles -Dd_dosuid -Dd_semctl_semun -Dscriptdir=/usr/bin -Dman3ext=3pm -Dcf_by=Gentoo -Ud_csh -Dusethreads -Di_gdbm -Di_db -Di_ndbm'
    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='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -fno-strict-aliasing -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-march=athlon-xp -O3 -mmmx -msse -m3dnow -mfpmath=sse -pipe -fomit-frame-pointer -fforce-addr -funroll-loops -frerun-loop-opt',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -fno-strict-aliasing'
    ccversion='', gccversion='3.3.1  (Gentoo Linux 3.3.1, propolice)', 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='gcc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lndbm -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    libc=/lib/libc-2.3.2.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.3.2'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    RC4

---
@INC for perl v5.8.1:
    /etc/perl
    /usr/lib/perl5/site_perl/5.8.1/i686-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.1
    /usr/lib/perl5/site_perl/5.8.0/i686-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.0
    /usr/lib/perl5/site_perl
    /usr/lib/perl5/vendor_perl/5.8.1/i686-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.1
    /usr/lib/perl5/vendor_perl
    /usr/lib/perl5/5.8.1/i686-linux-thread-multi
    /usr/lib/perl5/5.8.1
    /usr/local/lib/site_perl
    /usr/lib/perl5/site_perl/5.8.0/i686-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.0
    .

---
Environment for perl v5.8.1:
    HOME=/home/jagerman
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/usr/bin/wrappers:/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/3.3:/opt/ati/bin:/opt/Acrobat5:/opt/f-prot:/usr/X11R6/bin:/opt/sun-j2sdk-1.4.1/bin:/opt/sun-j2sdk-1.4.1/jre/bin:/usr/qt/3/bin:/usr/games/bin:/opt/quake3:/opt/vmware/bin:/usr/X11R6/bin:/home/jagerman/bin:/opt/perl/perl-5.00404/bin:/opt/perl/perl-5.005/bin:/opt/perl/perl-5.00503/bin:/opt/perl/perl-5.6.1/bin
    PERL_BADLANG (unset)
    SHELL=/bin/bash


-- 
-- Jason Rhinelander
-- Gossamer Threads, Inc.



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