diff options
author | Graham Barr <gbarr@ti.com> | 1998-05-15 07:34:05 +1200 |
---|---|---|
committer | Tim Bunce <Tim.Bunce@ig.co.uk> | 1998-05-16 03:02:43 +1200 |
commit | d86cffdc28a829c95453f51e2fbf227ea16bfc4e (patch) | |
tree | 101b55529a82ae62c15cfa0139254fc6d5a0fe67 | |
parent | 782b2911f3789f274063c2176a93a5520f0f74dd (diff) | |
download | perl-d86cffdc28a829c95453f51e2fbf227ea16bfc4e.tar.gz |
allow die $ref
Tim Bunce wrote:
>
> Does
> eval { die $ref };
> die if $@;
>
> propagate the original ref?
No, but here is a new patch against perl5.004_04-m1 which does
> Are 'we' happy to loose the "\n...propagated at ..." functionality
> of a die without arguments when $@ contains a ref? I guess it's the
> only reasonable way to go.
Well this is what started off the definition of Error.pm. The thought
was that maybe that if $ref is an object it should support a given
API. Then we could have methods for propagate and stringify which
perl would call at appropriate times.
Credited: Tim Bunce <Tim.Bunce@ig.co.uk>
Credited: Tim.Bunce@ig.co.uk (Tim Bunce) (Tim Bunce)
p5p-msgid: 355C3E67.AF25B9F7@ti.com
Credited: Tim Bunce <Tim.Bunce@ig.co.uk>
Credited: Tim.Bunce@ig.co.uk (Tim Bunce) (Tim Bunce)
-rw-r--r-- | pp_ctl.c | 40 | ||||
-rw-r--r-- | pp_sys.c | 20 | ||||
-rw-r--r-- | util.c | 14 |
3 files changed, 46 insertions, 28 deletions
@@ -1035,28 +1035,32 @@ char *message; I32 gimme; SV **newsp; - if (in_eval & 4) { - SV **svp; - STRLEN klen = strlen(message); - - svp = hv_fetch(GvHV(errgv), message, klen, TRUE); - if (svp) { - if (!SvIOK(*svp)) { - static char prefix[] = "\t(in cleanup) "; - SV *err = GvSV(errgv); - sv_upgrade(*svp, SVt_IV); - (void)SvIOK_only(*svp); - if (!SvPOK(err)) - sv_setpv(err,""); - SvGROW(err, SvCUR(err)+sizeof(prefix)+klen); - sv_catpvn(err, prefix, sizeof(prefix)-1); - sv_catpvn(err, message, klen); + if(message) { + if (in_eval & 4) { + SV **svp; + STRLEN klen = strlen(message); + + svp = hv_fetch(GvHV(errgv), message, klen, TRUE); + if (svp) { + if (!SvIOK(*svp)) { + static char prefix[] = "\t(in cleanup) "; + SV *err = GvSV(errgv); + sv_upgrade(*svp, SVt_IV); + (void)SvIOK_only(*svp); + if (!SvPOK(err)) + sv_setpv(err,""); + SvGROW(err, SvCUR(err)+sizeof(prefix)+klen); + sv_catpvn(err, prefix, sizeof(prefix)-1); + sv_catpvn(err, message, klen); + } + sv_inc(*svp); } - sv_inc(*svp); } + else + sv_setpv(GvSV(errgv), message); } else - sv_setpv(GvSV(errgv), message); + message = SvPVx(GvSV(errgv),na); cxix = dopoptoeval(cxstack_ix); if (cxix >= 0) { @@ -293,6 +293,8 @@ PP(pp_die) { dSP; dMARK; char *tmps; + SV *tmpsv = Nullsv; + char *pat = "%s"; if (SP - MARK != 1) { dTARGET; do_join(TARG, &sv_no, MARK, SP); @@ -300,18 +302,26 @@ PP(pp_die) SP = MARK + 1; } else { - tmps = SvPV(TOPs, na); + tmpsv = TOPs; + tmps = SvROK(tmpsv) ? Nullch : SvPV(TOPs, na); } if (!tmps || !*tmps) { SV *error = GvSV(errgv); (void)SvUPGRADE(error, SVt_PV); - if (SvPOK(error) && SvCUR(error)) - sv_catpv(error, "\t...propagated"); - tmps = SvPV(error, na); + if(tmpsv ? SvROK(tmpsv) : SvROK(error)) { + if(tmpsv) + SvSetSV(error,tmpsv); + pat = Nullch; + } + else { + if (SvPOK(error) && SvCUR(error)) + sv_catpv(error, "\t...propagated"); + tmps = SvPV(error, na); + } } if (!tmps || !*tmps) tmps = "Died"; - DIE("%s", tmps); + DIE(pat, tmps); } /* I/O. */ @@ -1183,7 +1183,7 @@ die(pat, va_alist) #else va_start(args); #endif - message = mess(pat, &args); + message = pat ? mess(pat, &args) : Nullch; va_end(args); if (diehook) { @@ -1199,10 +1199,14 @@ die(pat, va_alist) SV *msg; ENTER; - msg = newSVpv(message, 0); - SvREADONLY_on(msg); - SAVEFREESV(msg); - + if(message) { + msg = newSVpv(message, 0); + SvREADONLY_on(msg); + SAVEFREESV(msg); + } + else { + msg = GvSV(errgv); + } PUSHMARK(sp); XPUSHs(msg); PUTBACK; |