CARVIEW |
Select Language
HTTP/2 200
cache-control: max-age=43200
server: Combust/Plack (Perl)
vary: Accept-Encoding
content-encoding: gzip
content-length: 3491
content-type: text/html; charset=utf-8
last-modified: Sat, 11 Oct 2025 21:37:41 GMT
traceparent: e9053d4097f3ed6b4a18366f4ef3c58c
strict-transport-security: max-age=15768000
Re: my $@ - a proposal - nntp.perl.org
Front page | perl.perl5.porters |
Postings from July 2008
nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About

Re: my $@ - a proposal
Thread Previous | Thread NextFrom:
David NicolDate:
July 1, 2008 16:29Subject:
Re: my $@ - a proposalMessage ID:
934f64a20807011629s780e7e2ch41f7d4305fe9ff6c@mail.gmail.comOn Tue, Jul 1, 2008 at 8:48 AM, Aristotle Pagaltzis <pagaltzis@gmx.de> wrote: > it's not just programming language concern > trolling, as Sean O'Rourke put it, but a problem that needs to > be solved despite its low probability of occurence. so if $@, $! and $? were all localized before calling DESTROY methods, with no fancy logic, just localized, as recomended, the only pattern that would interfere with is L<https://en.wikipedia.org/wiki/Resource_acquisition_is_initialization RAII>. Existing RAII code that wants to check things set in DESTROY could be made to use another mechanism, shadowing the globals of concern within the DESTROY method. The recommendation in the documentation could get amended to state "Prior to perl 5.12 ... or without a perl containing the 'PROTECT_PRECIOUS_FROM DESTROY' patch, and for maximum portability, localize $@ before doing an eval within a DESTROY method" Destruction is not documented to occur immediately, the fact that it does is an implementation detail, so any code that does in fact rely on the current behavior could be considered breakable poor form (although RAII is so cool that any kind of alternate destruction deferment system should include some kind of attribute, perhaps :ephemeral, to indicate that the variable in question needs to be destroyed on scope exit instead of simply added to the recyclable pile or whatever) unfortuantely after merely restoring all of them, a unprotected die in a DESTROY doesn't exit the program any more. if it ever did. Anyway here's a patch against 5.8.8 to implicitly localize $!, $@ and $? before DESTROY is called. $ diff -u pristine_perl-5.8.8/sv.c perl-5.8.8/sv.c --- pristine_perl-5.8.8/sv.c 2006-01-16 06:22:21.000000000 -0600 +++ perl-5.8.8/sv.c 2008-07-01 18:23:18.777923600 -0500 @@ -5164,6 +5164,9 @@ stash = SvSTASH(sv); destructor = StashHANDLER(stash,DESTROY); if (destructor) { + SV* orig_error = newSVsv( ERRSV ); /* make local copy of $@ */ + SV* orig_bang = newSVsv( get_sv("!", TRUE )); /* make local copy of $! */ + SV* orig_hook = newSVsv( get_sv("?", TRUE )); /* make local copy of $? */ SV* const tmpref = newRV(sv); SvREADONLY_on(tmpref); /* DESTROY() could be naughty */ ENTER; @@ -5185,6 +5188,15 @@ SvROK_off(tmpref); } SvREFCNT_dec(tmpref); + + /* restore $@, $! and $? from local copies */ + sv_setsv(ERRSV, orig_error); + sv_setsv(get_sv("!", TRUE ), orig_bang); + sv_setsv(get_sv("?", TRUE ), orig_hook); + + SvREFCNT_dec(orig_error); + SvREFCNT_dec(orig_bang); + SvREFCNT_dec(orig_hook); /* Harrrrr, mateys! */ } } while (SvOBJECT(sv) && SvSTASH(sv) != stash);Thread Previous | Thread Next
- my $@ - a proposal by Yuval Kogman
- RE: my $@ - a proposal by Jan Dubois
- Re: my $@ - a proposal by David Nicol
- Re: my $@ - a proposal by Graham Barr
- Re: my $@ - a proposal by David Nicol
- Re: my $@ - a proposal by Mark Mielke
- RE: my $@ - a proposal by Jan Dubois
- Re: my $@ - a proposal by Graham Barr
- Re: my $@ - a proposal by Graham Barr
- RE: my $@ - a proposal by Jan Dubois
- Re: my $@ - a proposal by Ben Morrow
- Re: my $@ - a proposal by Graham Barr
- RE: my $@ - a proposal by Jan Dubois
- Re: my $@ - a proposal by David Nicol
- RE: my $@ - a proposal by Jan Dubois
- Re: my $@ - a proposal by David Nicol
- RE: my $@ - a proposal by Jan Dubois
- Re: my $@ - a proposal by David Golden
- Re: my $@ - a proposal by Johan Vromans
- Re: my $@ - a proposal by Mark Mielke
- Re: my $@ - a proposal by Rafael Garcia-Suarez
- Re: my $@ - a proposal by Mark Mielke
- Re: my $@ - a proposal by Ben Morrow
- Re: my $@ - a proposal by Elliot Shank
- Re: my $@ - a proposal by Abigail
- Re: my $@ - a proposal by Juerd Waalboer
- Re: my $@ - a proposal by David Golden
- Re: my $@ - a proposal by Yuval Kogman
- Re: my $@ - a proposal by David Golden
- Re: my $@ - a proposal by Graham Barr
- Re: my $@ - a proposal by Yuval Kogman
- Re: my $@ - a proposal by Graham Barr
- Re: my $@ - a proposal by Sam Vilain
- Re: my $@ - a proposal by David Nicol
- Re: my $@ - a proposal by David Golden
- Re: my $@ - a proposal by Graham Barr
- Re: my $@ - a proposal by David Nicol
- RE: my $@ - a proposal by Jan Dubois
- Re: my $@ - a proposal by Aristotle Pagaltzis
- Re: my $@ - a proposal by Mark Mielke
- Re: my $@ - a proposal by Raphael_Manfredi
- Re: my $@ - a proposal by Mark Mielke
- Re: my $@ - a proposal by Raphael_Manfredi
- Re: my $@ - a proposal by Abigail
- Re: my $@ - a proposal by Mark Mielke
- Re: my $@ - a proposal by David Golden
- Re: my $@ - a proposal by Raphael_Manfredi
- Re: my $@ - a proposal by Dr.Ruud
- Re: my $@ - a proposal by Yuval Kogman
- Re: my $@ - a proposal by Sam Vilain
- Re: my $@ - a proposal by Abigail
- Re: my $@ - a proposal by Yuval Kogman
- Re: my $@ - a proposal by Sean O'Rourke
- Re: my $@ - a proposal by Yuval Kogman
- Re: my $@ - a proposal by Steffen Mueller
- Re: my $@ - a proposal by Yuval Kogman
- Re: my $@ - a proposal by David Golden
- Re: my $@ - a proposal by Yuval Kogman
- Re: my $@ - a proposal by David Golden
- Re: my $@ - a proposal by Abigail
- Re: my $@ - a proposal by Aristotle Pagaltzis
- Re: my $@ - a proposal by Mark Mielke
- Re: my $@ - a proposal by Yuval Kogman
- Re: my $@ - a proposal by Dr.Ruud
- Re: my $@ - a proposal by Mark Mielke
- Re: my $@ - a proposal by Sam Vilain
- Re: my $@ - a proposal by David Cantrell
- Re: my $@ - a proposal by Sam Vilain
- Re: my $@ - a proposal by Moritz Lenz
- Re: my $@ - a proposal by Sam Vilain
- Re: my $@ - a proposal by Moritz Lenz
- Re: my $@ - a proposal by Sam Vilain
- Re: my $@ - a proposal by Moritz Lenz
- Re: my $@ - a proposal by Sam Vilain
- Re: my $@ - a proposal by Abigail
- Re: my $@ - a proposal by Mark Mielke
- Re: my $@ - a proposal by Aristotle Pagaltzis
- Re: my $@ - a proposal by David Nicol
- Re: my $@ - a proposal by Nicholas Clark
- Re: my $@ - a proposal by David Nicol
- RE: my $@ - a proposal by Jan Dubois
- Re: my $@ - a proposal by David Nicol
- Re: my $@ - a proposal by Reini Urban
- Re: my $@ - a proposal by Dr.Ruud
- Re: my $@ - a proposal by Sam Vilain
nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About