Skip to content

Commit

Permalink
pp_return(): tail call pp_leavetry()
Browse files Browse the repository at this point in the history
When 'return'ing from an eval { BLOCK }, rather than handling it
ourselves, fall through to pp_leavetry(). pp_return() is now only
responsible for popping any extra contexts and junk from the stack.

This helps avoid two different blocks of code doing roughly the same
thing.

The functional changes caused by this commit signify the divergence over
time between pp_leavetry and the try-ish parts of pp_return. After this
commit, a return will:

    * now do an PERL_ASYNC_CHECK();
    * be smarter about not unnecessarily creating mortal copies
      of returned args;
    * restore PL_curpm *before* the LEAVE() rather than after.

The first two are probably good things; I'm not sure about the latter; it
may well be a regression, but nothing tests for it. At least it's
consistent now.
  • Loading branch information
iabyn committed Jun 19, 2015
1 parent 1f0ba93 commit 334ea17
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pp_ctl.c
Expand Up @@ -2448,7 +2448,9 @@ PP(pp_return)

cx = &cxstack[cxix];

if (CxTYPE(cx) == CXt_SUB) {
if (CxTYPE(cx) == CXt_SUB
|| (CxTYPE(cx) == CXt_EVAL && CxTRYBLOCK(cx)))
{
SV **oldsp = PL_stack_base + cx->blk_oldsp;
if (oldsp != MARK) {
/* Handle extra junk on the stack. For example,
Expand All @@ -2473,6 +2475,8 @@ PP(pp_return)
else
PL_stack_sp = oldsp;
}
if (CxTYPE(cx) == CXt_EVAL)
return Perl_pp_leavetry(aTHX);
/* fall through to a normal sub exit */
return CvLVALUE(cx->blk_sub.cv)
? Perl_pp_leavesublv(aTHX)
Expand All @@ -2487,8 +2491,6 @@ PP(pp_return)
POPEVAL(cx);
namesv = cx->blk_eval.old_namesv;
retop = cx->blk_eval.retop;
if (CxTRYBLOCK(cx))
break;
if (optype == OP_REQUIRE &&
(MARK == SP || (gimme == G_SCALAR && !SvTRUE(*SP))) )
{
Expand Down Expand Up @@ -4379,9 +4381,11 @@ PP(pp_leavetry)
I32 gimme;
PERL_CONTEXT *cx;
I32 optype;
OP *retop;

PERL_ASYNC_CHECK();
POPBLOCK(cx,newpm);
retop = cx->blk_eval.retop;
POPEVAL(cx);
PERL_UNUSED_VAR(optype);

Expand All @@ -4391,7 +4395,7 @@ PP(pp_leavetry)

LEAVE_with_name("eval_scope");
CLEAR_ERRSV();
RETURN;
RETURNOP(retop);
}

PP(pp_entergiven)
Expand Down

0 comments on commit 334ea17

Please sign in to comment.