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

Re: deprecating SIGDIE

Thread Previous | Thread Next
From:
Tom Christiansen
Date:
September 30, 1999 06:33
Subject:
Re: deprecating SIGDIE
Message ID:
199909301332.HAA12036@jhereg.perl.com
>>I'd much rather fix this right now than document the bug.  Sarathy?
>>Larry?  Is it toast yet?

>It continues to live on my todo list, and no, I haven't seen any
>patches yet.

The code patch to restore $SIG{__DIE__} to its intended behaviour
is trivial:

--- /usr/src/perl5.005_61-prehack/util.c        Thu Sep 30 06:25:13 1999
+++ /usr/src/perl5.005_61/util.c        Thu Sep 30 06:25:07 1999
@@ -1448,7 +1448,11 @@
     DEBUG_S(PerlIO_printf(PerlIO_stderr(),
                          "%p: die: message = %s\ndiehook = %p\n",
                          thr, message, PL_diehook));
-    if (PL_diehook) {
+    /*
+     * Added test so that a die hook only triggers
+     * if the exception is uncaught.  tchrist 30/Sept/99
+     */
+    if (PL_diehook && !was_in_eval) {
        /* sv_2cv might call Perl_croak() */
        SV *olddiehook = PL_diehook;
        ENTER;


But in that cases, patches would also be needed for:

    pod/perldelta.pod
    pod/perlfunc.pod
    pod/perlvar.pod

    t/op/die.t
    t/op/eval.t
    t/op/ref.t
    t/op/runlevel.t

It would be useful to all of us if the proponents of the interfering
version of $SIG{__DIE__}--and consequently opponents of this bug fix--were
to justify why their special needs are important enough that we have
to complicate the exception model.  It is unfair and clumsy to make
anyone who ever uses exceptions to be aware of potential strange magic
at a distance through included modules.  The status quo as currently
mis-implemented leads to error-prone and non-intuitive code.  It's caused
such obviously post-novitial module authors as Graham, Gisle, Lincoln,
Doug, and Nick to stub their toes.  What about the many thousands of
less capable authors?

Having everyone always write:

    eval {
	local $SIG{__DIE__};
	....
    } 

and 

    $SIG{__DIE__} = sub {
	return if $^S;
	....
    };

is much less convenient than the simple and straight-forward exception
constructs as Larry meant them to be used:

    eval { ....  } 

and

    $SIG{__DIE__} = sub { ....  };

Proponents of action-at-a-distance might kindly care explain why their
special needs should not be met through some other mechanism that has
less impact on everyone else in the Perl universe.  Doing something
clever and convenient involving the new exception objects might be a
cleaner solution.

An analysis of the standard modules that use $SIG{__DIE__}
is also instructive.  They are:

AutoLoader.pm:    eval { local $SIG{__DIE__}; require $filename };
AutoLoader.pm:		eval { local $SIG{__DIE__}; require $filename };
B/assemble:$SIG{__DIE__} = sub { die "$filename: @_" };
CGI/Carp.pm:$main::SIG{__DIE__}=\&CGI::Carp::die;
CPAN.pm:    eval {local $SIG{__DIE__};require $name};
CPAN.pm:		eval {local $SIG{__DIE__};require $name};
CPAN.pm:    $SIG{'__DIE__'} = \&cleanup;
CPAN.pm:  local $SIG{__DIE__} = '';
Exporter/Heavy.pm:    local $SIG{__DIE__} = sub {
Fatal.pm:reported via C<die>, so you can trap them using C<$SIG{__DIE__}> if you
Getopt/Long.pm:in C<eval { ... }> or C<die()> was trapped using C<$SIG{__DIE__}>.
Sys/Hostname.pm:    eval { local $SIG{__DIE__}; $host = (gethostbyname('me'))[0] };
Sys/Hostname.pm:	local $SIG{__DIE__};
Sys/Hostname.pm:	local $SIG{__DIE__};
Sys/Hostname.pm:	local $SIG{__DIE__};
Sys/Hostname.pm:	local $SIG{__DIE__};
Sys/Hostname.pm:	local $SIG{__DIE__};
diagnostics.pm:    $olddie = $SIG{__DIE__};
diagnostics.pm:    $SIG{__DIE__} = \&death_trap;
diagnostics.pm:    $SIG{__DIE__} = $olddie;
diagnostics.pm:    $SIG{__DIE__} = $SIG{__WARN__} = '' unless $in_eval;
perl5db.pl:  local $SIG{__DIE__} = '';
perl5db.pl:  local $SIG{__DIE__} = '';
perl5db.pl:    $prevdie = $SIG{__DIE__} unless $dieLevel;
perl5db.pl:      $SIG{__DIE__} = \&DB::dbdie; # if $dieLevel < 2;
perl5db.pl:      #$SIG{__DIE__} = \&DB::diehard if $dieLevel >= 2;
perl5db.pl:      $SIG{__DIE__} = $prevdie;

A brief perusal on a few important CPAN modules reveals:

CGI.pm-2.55/CGI/Carp.pm:$main::SIG{__DIE__}=\&CGI::Carp::die;
CGI.pm-2.55/blib/lib/CGI/Carp.pm:$main::SIG{__DIE__}=\&CGI::Carp::die;
CPAN-1.50/blib/lib/CPAN.pm:    eval {local $SIG{__DIE__};require $name};
CPAN-1.50/blib/lib/CPAN.pm:		eval {local $SIG{__DIE__};require $name};
CPAN-1.50/blib/lib/CPAN.pm:    $SIG{'__DIE__'} = \&cleanup;
CPAN-1.50/blib/lib/CPAN.pm:  local $SIG{__DIE__} = '';
CPAN-1.50/lib/CPAN.pm:    eval {local $SIG{__DIE__};require $name};
CPAN-1.50/lib/CPAN.pm:		eval {local $SIG{__DIE__};require $name};
CPAN-1.50/lib/CPAN.pm:    $SIG{'__DIE__'} = \&cleanup;
CPAN-1.50/lib/CPAN.pm:  local $SIG{__DIE__} = '';
HTML-Parser-2.23/Changes:   Protect HTML::HeadParser from evil $SIG{__DIE__} hooks.
HTML-Parser-2.23/blib/lib/HTML/HeadParser.pm:	local $SIG{__DIE__};
HTML-Parser-2.23/lib/HTML/HeadParser.pm:	local $SIG{__DIE__};
eperl-2.2.13/ChangeLog:         o added error capturing for Parse::ePerl::Evaluate via __DIE__ hook.
eperl-2.2.13/mod/Parse/ePerl.pm:    local $SIG{'__DIE__'};
eperl-2.2.13/mod/Parse/ePerl.pm:    local $SIG{'__DIE__'}  = sub { $error .= $_[0]; };
eperl-2.2.13/mod/blib/lib/Parse/ePerl.pm:    local $SIG{'__DIE__'};
eperl-2.2.13/mod/blib/lib/Parse/ePerl.pm:    local $SIG{'__DIE__'}  = sub { $error .= $_[0]; };
libwww-perl-5.44/ChangeLog: o  LWP::UserAgent::simple_request: local($SIG{__DIE__}) protects us
libwww-perl-5.44/blib/lib/LWP/UserAgent.pm:    local($SIG{__DIE__});  # protect agains user defined die handlers
libwww-perl-5.44/blib/lib/LWP/UserAgent.pm:    local($SIG{__DIE__});  # protect agains user defined die handlers
libwww-perl-5.44/lib/LWP/UserAgent.pm:    local($SIG{__DIE__});  # protect agains user defined die handlers
libwww-perl-5.44/lib/LWP/UserAgent.pm:    local($SIG{__DIE__});  # protect agains user defined die handlers
mod_perl-1.21/Changes:turn off $SIG{__DIE__} to fix bug spotted by Dan Peterson
mod_perl-1.21/Changes:- added catch_signals method to terminate httpd on __DIE__ or INT
mod_perl-1.21/blib/lib/Apache/Debug.pm:    $SIG{__DIE__} = \&Carp::confess;
mod_perl-1.21/blib/lib/Apache/Status.pm:    local $SIG{__DIE__};
mod_perl-1.21/blib/lib/Apache/httpd_conf.pm:    $SIG{INT} = $SIG{__DIE__} = 
mod_perl-1.21/blib/lib/mod_perl_traps.pod:$SIG{__DIE__} handler will call Carp::confess, giving you a stack
mod_perl-1.21/lib/Apache/Debug.pm:    $SIG{__DIE__} = \&Carp::confess;
mod_perl-1.21/lib/Apache/Status.pm:    local $SIG{__DIE__};
mod_perl-1.21/lib/Apache/httpd_conf.pm:    $SIG{INT} = $SIG{__DIE__} = 
mod_perl-1.21/mod_perl_traps.pod:$SIG{__DIE__} handler will call Carp::confess, giving you a stack
mod_perl-1.21/t/TEST:    $SIG{'__DIE__'} = sub {

I find 

    HTML-Parser-2.23/Changes:   Protect HTML::HeadParser from evil
				$SIG{__DIE__} hooks.

--tom

Thread Previous | 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