Perl

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • Sighandlers clobbering $@?

    4 answers - 1243 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    Hello porters,
    Witness this test program:
    $ cat errsig.pl
    $@ = 'test';
    $SIG{'INT'} = sub {
    $in = $@;
    };
    kill('INT', $$);
    $after = $@;
    if ($in eq 'test' && $after eq 'test') {
    print("\$\@ preserved by sighandler\n");
    } elsif ($after eq 'test') {
    print("\$\@ localized in sighandler\n");
    } else {
    print("\$\@ clobbered by sighandler!\n");
    }
    Run with various version of Perl:
    $ perl5.004 errsig.pl
    $@ preserved by sighandler
    $ perl5.005 errsig.pl
    $@ preserved by sighandler
    $ perl5.6 errsig.pl
    $@ preserved by sighandler
    $ perl5.8.4 errsig.pl
    $@ clobbered by sighandler!
    $ perl5.8.8 errsig.pl
    $@ clobbered by sighandler!
    I can see the C code that causes the behavior in mg.c:Perl_sighandler.
    The G_EVAL flag was added in the call to call_sv(). The function should
    enter scope and localize ERRSV before call_sv, and copy ERRSV and leave
    scope thereafter. Then it should test and (if true) die with the copy,
    rather than ERRSV, after the special processing that motivated the use
    of G_EVAL.
    Is this a bug? is it a feature?
    Cheers,
  • No.1 | | 682 bytes | |

    09/02/07, Merijn Broeren <merijnb (AT) iloquent (DOT) comwrote:
    I can see the C code that causes the behavior in mg.c:Perl_sighandler.
    The G_EVAL flag was added in the call to call_sv(). The function should
    enter scope and localize ERRSV before call_sv, and copy ERRSV and leave
    scope thereafter. Then it should test and (if true) die with the copy,
    rather than ERRSV, after the special processing that motivated the use
    of G_EVAL.

    Is this a bug? is it a feature?

    What if there is a die() from within the signal handler ? Shouldn't $@
    be propagated ? (not tested with older perls)

    BTW, this was added by this change:
  • No.2 | | 679 bytes | |

    09/02/07, Merijn Broeren <merijnb (AT) iloquent (DOT) comwrote:
    What if there is a die() from within the signal handler ? Shouldn't $@
    be propagated ? (not tested with older perls)

    Yes, dieing with the copy would propagate the die message from the
    signal handler. I just don't want the G_EVAL to clobber the results of
    an eval. If I get a signal between the end of the eval block and my
    testing $@ I'll get a false positive.

    You confuse me, since there's no eval in your first example.

    BTW, this was added by this change:

    Mind if I supply a patch that preserves it?

    K (even better with tests :)
  • No.3 | | 1130 bytes | |

    Quoting Rafael Garcia-Suarez (rgarciasuarez (AT) gmail (DOT) com):
    09/02/07, Merijn Broeren <merijnb (AT) iloquent (DOT) comwrote:
    >I can see the C code that causes the behavior in mg.c:Perl_sighandler.
    >The G_EVAL flag was added in the call to call_sv(). The function should
    >enter scope and localize ERRSV before call_sv, and copy ERRSV and leave
    >scope thereafter. Then it should test and (if true) die with the copy,
    >rather than ERRSV, after the special processing that motivated the use
    >of G_EVAL.
    >
    >Is this a bug? is it a feature?


    What if there is a die() from within the signal handler ? Shouldn't $@
    be propagated ? (not tested with older perls)

    Yes, dieing with the copy would propagate the die message from the
    signal handler. I just don't want the G_EVAL to clobber the results of
    an eval. If I get a signal between the end of the eval block and my
    testing $@ I'll get a false positive.

    BTW, this was added by this change:

    Mind if I supply a patch that preserves it?

    Cheers,
  • No.4 | | 949 bytes | |

    Quoting Rafael Garcia-Suarez (rgarciasuarez (AT) gmail (DOT) com):
    09/02/07, Merijn Broeren <merijnb (AT) iloquent (DOT) comwrote:
    >What if there is a die() from within the signal handler ? Shouldn't $@
    >be propagated ? (not tested with older perls)
    >>

    >Yes, dieing with the copy would propagate the die message from the
    >signal handler. I just don't want the G_EVAL to clobber the results of
    >an eval. If I get a signal between the end of the eval block and my
    >testing $@ I'll get a false positive.


    You confuse me, since there's no eval in your first example.

    My first example was just a simple test case to see what happens to $@
    when we call a signal handler. Normally I only care about $@ after an
    eval.

    K (even better with tests :)

    Tests should always be there ofcourse.

    Cheers,

Re: Sighandlers clobbering $@?


max 4000 letters.
Your nickname that display:
In order to stop the spam: 0 + 9 =
QUESTION ON "Perl"

EMSDN.COM