It's less hackish and more resilient to core changes.
SV *old_err = NULL;
if (SvTRUE(ERRSV)) {
- old_err = ERRSV;
- ERRSV = newSV(0);
+ old_err = newSVsv(ERRSV);
+ sv_setsv(ERRSV, &PL_sv_undef);
}
cxix = (cxstack_ix < cxstack_max) ? (cxstack_ix + 1) : Perl_cxinc(aTHX);
cxstack[cxix] = saved_cx;
if (SvTRUE(ERRSV)) {
- if (old_err) {
- sv_setsv(old_err, ERRSV);
- SvREFCNT_dec(ERRSV);
- ERRSV = old_err;
- }
+ SvREFCNT_dec(old_err);
+
if (IN_PERL_COMPILETIME) {
if (!PL_in_eval) {
if (PL_errors)
}
} else {
if (old_err) {
- SvREFCNT_dec(ERRSV);
- ERRSV = old_err;
+ sv_setsv(ERRSV, old_err);
+ SvREFCNT_dec(old_err);
}
}