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

[perl #24108] Goto +foo broken

Thread Next
October 5, 2003 15:54
[perl #24108] Goto +foo broken
Message ID:
# New Ticket Created by  Juerd 
# Please include the string:  [perl #24108]
# in the subject line of all future correspondence about this issue. 
# <URL: >

This is a bug report for perl from,
generated with the help of perlbug 1.34 running under perl v5.8.0.

[Please enter your report here]

goto +foo doesn't properly go to the thing returned by foo().

foo() is called, but goto uses a reference to the value that it returns.

2;0 juerd@ouranos:~$ perl -le'sub foo {print "x"} goto +foo'
Can't find label SCALAR(0x812139c) at -e line 1.
2;255 juerd@ouranos:~$ perl -MO=Deparse -le'sub foo {print "x"} goto +foo'
BEGIN { $/ = "\n"; $\ = "\n"; }
sub foo {
    print 'x';
goto \foo ;
-e syntax OK

Note the \ before foo.

XMATH knows more than I do:

23:36 <@xmath> Juerd: notice the difference of 64 in op_flags.. that's the 
               OPf_STACKED-flag, which means the sub will get its arguments via stack 
               (rather than borrowing caller's @_, which is what &foo does)
23:37 <@xmath> now, goto checks if its argument is an ENTERSUB, and if assumes it's goto 
23:38 <@xmath> it'll pass the argument to an optree-mongler, telling it to turn the arg 
               into a ref-able thing
23:40 <@xmath> Juerd: it should either include OPf_STACKED in the test that decides 
               between goto &NAME and goto EXPR
23:40 <@xmath> Juerd: or use a different optree mongler that doesn't care about 
23:40 <@xmath> the former is probably the better solution
23:41 <@xmath> well, I'm not sure if you can consider it a bug
23:41 <@xmath> and the behavior can be useful
23:41 <@Juerd> Of course you can
23:41 <@Juerd> Useful how?
23:42 <@xmath> I'm thinking very hard about that right now.. my thoughts were reaching 
               towards making foo an lvalue sub and return a var that is actually blessed 
               so that \var will be an object, then use overloading to make it stringify 
               into a label
23:42 <@xmath> but I'm not sure if that would work ;)
23:42 <@Juerd> Dude, just return that string label then
23:43 <@xmath> hehe
23:46 <@xmath> Juerd: actually.... in Perl_newLOOPEX, change
23:46 <@xmath>         if (label->op_type == OP_ENTERSUB)
23:46 <@xmath> to:
23:46 <@xmath>         if (label->op_type == OP_ENTERSUB && !(label->op_flags & 
23:46 <@xmath> that's the fix :-)
23:47 <@xmath> Juerd: just mention that fix in the report

This fix has not been tested.

Note, if the sub is not "foo" but "x":

2;255 juerd@ouranos:~$ perl -le'sub foo {print "x"} goto foo'
Can't find label foo at -e line 1.
2;255 juerd@ouranos:~$ perl -le'sub x {print "x"} goto x'
Can't find label SCALAR(0x812139c) at -e line 1.

(Difference with previous snippet is "goto +foo" => "goto foo")

[Please do not change anything below this line]
Site configuration information for perl v5.8.0:

Configured by root at Sat Aug  9 18:22:36 CEST 2003.

Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration:
    osname=linux, osvers=2.4.21-rc2, archname=i686-linux
    uname='linux ouranos 2.4.21-rc2 #3 sat may 17 00:09:50 cest 2003 i686 amd athlon(tm) processor authenticamd gnulinux '
    config_args='-des -Darchname=i686-linux -Dcc=gcc -Dprefix=/usr -Dvendorprefix=/usr -Dsiteprefix=/usr -Dlocincpth=  -Doptimize=-O2 -march=athlon-tbird -pipe -fomit-frame-pointer  -Duselargefiles -Dd_dosuid -Dd_semctl_semun -Dscriptdir=/usr/bin -Dman3ext=3pm -Dcf_by=Gentoo -Ud_csh -Di_gdbm -Di_db -Di_ndbm'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
    cc='gcc', ccflags ='-DPERL5 -fno-strict-aliasing -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2 -march=athlon-tbird -pipe -fomit-frame-pointer ',
    cppflags='-DPERL5 -DPERL5 -fno-strict-aliasing'
    ccversion='', gccversion='3.2.3 20030422 (Gentoo Linux 1.4 3.2.3-r1, 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=-lpthread -lnsl -lndbm -lgdbm -ldb -ldl -lm -lc -lcrypt -lutil
    perllibs=-lpthread -lnsl -ldl -lm -lc -lcrypt -lutil
    libc=/lib/, so=so, useshrplib=false, libperl=libperl.a
  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.8.0:

Environment for perl v5.8.0:
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PERL_BADLANG (unset)


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About