} STMT_END
#endif /* USE_THREADS */
-#define POPSUB(cx) \
+#define POPSUB(cx,sv) \
+ STMT_START { \
if (cx->blk_sub.hasargs) { \
POPSAVEARRAY(); \
/* abandon @_ if it got reified */ \
PL_curpad[0] = (SV*)cx->blk_sub.argarray; \
} \
} \
- if (cx->blk_sub.cv) { \
- if (!(CvDEPTH(cx->blk_sub.cv) = cx->blk_sub.olddepth)) \
- SvREFCNT_dec(cx->blk_sub.cv); \
- }
+ sv = (SV*)cx->blk_sub.cv; \
+ if (sv && (CvDEPTH((CV*)sv) = cx->blk_sub.olddepth)) \
+ sv = Nullsv; \
+ } STMT_END
+
+#define LEAVESUB(sv) \
+ STMT_START { \
+ if (sv) \
+ SvREFCNT_dec(sv); \
+ } STMT_END
#define POPFORMAT(cx) \
setdefout(cx->blk_sub.dfoutgv); \
I32 optype;
while (cxstack_ix > cxix) {
+ SV *sv;
cx = &cxstack[cxstack_ix];
DEBUG_l(PerlIO_printf(Perl_debug_log, "Unwinding block %ld, type %s\n",
(long) cxstack_ix, PL_block_type[CxTYPE(cx)]));
POPSUBST(cx);
continue; /* not break */
case CXt_SUB:
- POPSUB(cx);
+ POPSUB(cx,sv);
+ LEAVESUB(sv);
break;
case CXt_EVAL:
POPEVAL(cx);
SV **newsp;
PMOP *newpm;
I32 optype = 0;
+ SV *sv;
if (PL_curstackinfo->si_type == PERLSI_SORT) {
if (cxstack_ix == PL_sortcxix || dopoptosub(cxstack_ix) <= PL_sortcxix) {
/* Stack values are safe: */
if (popsub2) {
- POPSUB(cx); /* release CV and @_ ... */
+ POPSUB(cx,sv); /* release CV and @_ ... */
}
+ else
+ sv = Nullsv;
PL_curpm = newpm; /* ... and pop $1 et al */
LEAVE;
+ LEAVESUB(sv);
return pop_return();
}
SV **newsp;
PMOP *newpm;
SV **mark;
+ SV *sv = Nullsv;
if (PL_op->op_flags & OPf_SPECIAL) {
cxix = dopoptoloop(cxstack_ix);
LEAVE;
break;
case CXt_SUB:
- POPSUB(cx); /* release CV and @_ ... */
+ POPSUB(cx,sv); /* release CV and @_ ... */
break;
}
PL_curpm = newpm; /* ... and pop $1 et al */
LEAVE;
+ LEAVESUB(sv);
return nextop;
}
PMOP *newpm;
I32 gimme;
register PERL_CONTEXT *cx;
+ SV *sv;
POPBLOCK(cx,newpm);
}
PUTBACK;
- POPSUB(cx); /* Stack values are safe: release CV and @_ ... */
+ POPSUB(cx,sv); /* Stack values are safe: release CV and @_ ... */
PL_curpm = newpm; /* ... and pop $1 et al */
LEAVE;
+ LEAVESUB(sv);
return pop_return();
}
PMOP *newpm;
I32 gimme;
register PERL_CONTEXT *cx;
+ SV *sv;
POPBLOCK(cx,newpm);
* the refcounts so the caller gets a live guy. Cannot set
* TEMP, so sv_2mortal is out of question. */
if (!CvLVALUE(cx->blk_sub.cv)) {
- POPSUB(cx);
+ POPSUB(cx,sv);
PL_curpm = newpm;
+ LEAVE;
+ LEAVESUB(sv);
DIE(aTHX_ "Can't modify non-lvalue subroutine call");
}
if (gimme == G_SCALAR) {
EXTEND_MORTAL(1);
if (MARK == SP) {
if (SvFLAGS(TOPs) & (SVs_TEMP | SVs_PADTMP | SVf_READONLY)) {
- POPSUB(cx);
+ POPSUB(cx,sv);
PL_curpm = newpm;
+ LEAVE;
+ LEAVESUB(sv);
DIE(aTHX_ "Can't return a %s from lvalue subroutine",
SvREADONLY(TOPs) ? "readonly value" : "temporary");
}
}
}
else { /* Should not happen? */
- POPSUB(cx);
+ POPSUB(cx,sv);
PL_curpm = newpm;
+ LEAVE;
+ LEAVESUB(sv);
DIE(aTHX_ "%s returned from lvalue subroutine in scalar context",
(MARK > SP ? "Empty array" : "Array"));
}
if (SvFLAGS(*mark) & (SVs_TEMP | SVs_PADTMP | SVf_READONLY)) {
/* Might be flattened array after $#array = */
PUTBACK;
- POPSUB(cx);
+ POPSUB(cx,sv);
PL_curpm = newpm;
+ LEAVE;
+ LEAVESUB(sv);
DIE(aTHX_ "Can't return %s from lvalue subroutine",
(*mark != &PL_sv_undef)
? (SvREADONLY(TOPs)
}
PUTBACK;
- POPSUB(cx); /* Stack values are safe: release CV and @_ ... */
+ POPSUB(cx,sv); /* Stack values are safe: release CV and @_ ... */
PL_curpm = newpm; /* ... and pop $1 et al */
LEAVE;
+ LEAVESUB(sv);
return pop_return();
}