Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

goto in CORE::GLOBAL::exit #9010

Open
p5pRT opened this issue Aug 31, 2007 · 3 comments
Open

goto in CORE::GLOBAL::exit #9010

p5pRT opened this issue Aug 31, 2007 · 3 comments

Comments

@p5pRT
Copy link

p5pRT commented Aug 31, 2007

Migrated from rt.perl.org#45091 (status was 'open')

Searchable as RT45091$

@p5pRT
Copy link
Author

p5pRT commented Aug 31, 2007

From powerman@powerman.asdfGroup.com

Created by powerman@powerman.asdfgroup.com

In this case 'goto' doesn't work properly, and instead of jumping to the
label, it work like 'die' and jump to the first command after 'eval'​:

perl -e '
BEGIN {
  *CORE​::GLOBAL​::exit = sub {
  goto FASTCGI_NEXT_REQUEST;
  };
}
while (1) {
  eval { that_cgi_script() };
FASTCGI_NEXT_REQUEST​:
  last;
}

sub that_cgi_script {
  local $SIG{__DIE__} = sub { print "<p>error​: $_[0]"; exit; print "XXX\n" };
  print "before buggy code\n";
  eval { buggy_code() };
  print "after buggy code\n";
}
sub buggy_code {
  die "error!";
  print "after die\n";
}
'

This example output​:

  before buggy code
  <p>error​: error! at -e line 20.
  after buggy code

I've found a workaround for this bug. In BEGIN block must be added no-op
handler for CORE​::GLOBAL​::die (which just emulate how perl's handler work)​:

  *CORE​::GLOBAL​::die = sub {
  if ($SIG{__DIE__}) {
  my $s = $_[0];
  $s .= sprintf " at %s line %d.\n", (caller)[1,2] if $s !~ /\n\z/;
  $SIG{__DIE__}->($s);
  }
  };

and now this example work correctly and output​:

  before buggy code
  <p>error​: error! at -e line 27.

I've no idea why my workaround is working, and why 'goto' doesn't work
properly in my example. Maybe this is bug in perl... or maybe I'm just
misunderstand how that should work. I'll appreciate if somebody will
explain this to me.

More details available here​: http​://perlmonks.org/?node_id=636089

Perl Info

Flags:
    category=core
    severity=high

Site configuration information for perl v5.8.8:

Configured by Gentoo at Mon Jun 11 18:03:37 EEST 2007.

Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
  Platform:
    osname=linux, osvers=2.6.20-hardened-r2, archname=i686-linux
    uname='linux home 2.6.20-hardened-r2 #8 smp thu may 10 00:27:57 eest 2007 i686 intel(r) core(tm)2 cpu 6600 @ 2.40ghz genuineintel gnulinux '
    config_args='-des -Darchname=i686-linux -Dcccdlflags=-fPIC -Dccdlflags=-rdynamic -Dcc=i686-pc-linux-gnu-gcc -Dprefix=/usr -Dvendorprefix=/usr -Dsiteprefix=/usr -Dlocincpth=  -Doptimize=-march=pentium-m -O2 -pipe -Duselargefiles -Dd_semctl_semun -Dscriptdir=/usr/bin -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dinstallman1dir=/usr/share/man/man1 -Dinstallman3dir=/usr/share/man/man3 -Dman1ext=1 -Dman3ext=3pm -Dinc_version_list=5.8.0 5.8.0/i686-linux 5.8.2 5.8.2/i686-linux 5.8.4 5.8.4/i686-linux 5.8.5 5.8.5/i686-linux 5.8.6 5.8.6/i686-linux 5.8.7 5.8.7/i686-linux  -Dinc_version_list=5.8.0 5.8.0/i686-linux 5.8.2 5.8.2/i686-linux 5.8.4 5.8.4/i686-linux 5.8.5 5.8.5/i686-linux 5.8.6 5.8.6/i686-linux 5.8.7 5.8.7/i686-linux  -Dcf_by=Gentoo -Ud_csh -Dusenm -Di_ndbm -Di_gdbm -Di_db'
    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
  Compiler:
    cc='i686-pc-linux-gnu-gcc', ccflags ='-fno-strict-aliasing -pipe -Wdeclaration-after-statement -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
    optimize='-march=pentium-m -O2 -pipe',
    cppflags='-fno-strict-aliasing -pipe -Wdeclaration-after-statement -I/usr/include/gdbm'
    ccversion='', gccversion='3.4.6 (Gentoo Hardened 3.4.6-r2, ssp-3.4.6-1.0, pie-8.7.10)', 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='i686-pc-linux-gnu-gcc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lpthread -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    libc=/lib/libc-2.5.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.5'
  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.8:
    /etc/perl
    /usr/lib/perl5/vendor_perl/5.8.8/i686-linux
    /usr/lib/perl5/vendor_perl/5.8.8
    /usr/lib/perl5/vendor_perl
    /usr/lib/perl5/site_perl/5.8.8/i686-linux
    /usr/lib/perl5/site_perl/5.8.8
    /usr/lib/perl5/site_perl
    /usr/lib/perl5/5.8.8/i686-linux
    /usr/lib/perl5/5.8.8
    /usr/local/lib/site_perl
    .


Environment for perl v5.8.8:
    HOME=/home/powerman
    LANG=ru_RU.KOI8-R
    LANGUAGE (unset)
    LC_NUMERIC=POSIX
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/powerman/bin:/home/powerman/inferno-os/Linux/386/bin:/usr/local/bin:/bin:/usr/bin:/home/powerman/bin:/home/powerman/inferno-os/Linux/386/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/bin:/usr/bin:/bin:/opt/bin:/sbin:/usr/sbin:/usr/local/sbin:/usr/games/bin:/usr/i686-pc-linux-gnu/gcc-bin/3.4.6:/opt/sun-jdk-1.4.2.15/bin:/opt/sun-jdk-1.4.2.15/jre/bin:/opt/sun-jdk-1.4.2.15/jre/javaws:/usr/kde/3.5/bin:/usr/qt/3/bin:/opt/vmware/workstation/bin:/var/qmail/bin
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Sep 26, 2010

From @cpansprout

On Fri Aug 31 09​:11​:00 2007, powerman@​powerman.asdfGroup.com wrote​:

In this case 'goto' doesn't work properly, and instead of jumping to
the
label, it work like 'die' and jump to the first command after 'eval'​:

perl -e '
BEGIN {
*CORE​::GLOBAL​::exit = sub {
goto FASTCGI_NEXT_REQUEST;
};
}
while (1) {
eval { that_cgi_script() };
FASTCGI_NEXT_REQUEST​:
last;
}

sub that_cgi_script {
local $SIG{__DIE__} = sub { print "<p>error​: $_[0]"; exit; print
"XXX\n" };
print "before buggy code\n";
eval { buggy_code() };
print "after buggy code\n";
}
sub buggy_code {
die "error!";
print "after die\n";
}
'

This example output​:

before buggy code
\<p>error&#8203;: error\! at \-e line 20\.
after buggy code

Exiting a signal handler via goto is not supported. goto() can’t see the
label, which causes an error that is caught by the eval.
This is related to bug #44367.

If errors in signal handlers work, why not goto?

@p5pRT
Copy link
Author

p5pRT commented Sep 26, 2010

The RT System itself - Status changed from 'new' to 'open'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants