Skip to content

Commit 3ab1cbe

Browse files
committed
try isn't treated as a sub call like eval is
The try change added code to pp_return to skip past try contexts when looking for the sub/sort/eval context to return from. This was only needed because cx_pusheval() sets si_cxsubix to the current frame and try uses that function to push it's context, that value is then used by the dopopto_cursub() macro to shortcut walking the context stack. Since we don't need to treat try as a sub for return, list vs array checks or lvalue sub checks, don't set si_cxsubix on try.
1 parent 869f54b commit 3ab1cbe

File tree

5 files changed

+28
-11
lines changed

5 files changed

+28
-11
lines changed

embed.fnc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3647,6 +3647,8 @@ Cixp |void |cx_pushformat |NN PERL_CONTEXT *cx|NN CV *cv \
36473647
Cixp |void |cx_popformat |NN PERL_CONTEXT *cx
36483648
Cixp |void |cx_pusheval |NN PERL_CONTEXT *cx \
36493649
|NULLOK OP *retop|NULLOK SV *namesv
3650+
Cixp |void |cx_pushtry |NN PERL_CONTEXT *cx \
3651+
|NULLOK OP *retop|NULLOK SV *namesv
36503652
Cixp |void |cx_popeval |NN PERL_CONTEXT *cx
36513653
Cixp |void |cx_pushloop_plain|NN PERL_CONTEXT *cx
36523654
Cixp |void |cx_pushloop_for |NN PERL_CONTEXT *cx \

embed.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,7 @@
822822
#define cx_pushloop_for(a,b,c) Perl_cx_pushloop_for(aTHX_ a,b,c)
823823
#define cx_pushloop_plain(a) Perl_cx_pushloop_plain(aTHX_ a)
824824
#define cx_pushsub(a,b,c,d) Perl_cx_pushsub(aTHX_ a,b,c,d)
825+
#define cx_pushtry(a,b,c) Perl_cx_pushtry(aTHX_ a,b,c)
825826
#define cx_pushwhen(a) Perl_cx_pushwhen(aTHX_ a)
826827
#define cx_topblock(a) Perl_cx_topblock(aTHX_ a)
827828
#define gimme_V() Perl_gimme_V(aTHX)

inline.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2331,6 +2331,25 @@ Perl_cx_pusheval(pTHX_ PERL_CONTEXT *cx, OP *retop, SV *namesv)
23312331
cx->blk_u16 = (PL_in_eval & 0x3F) | ((U16)PL_op->op_type << 7);
23322332
}
23332333

2334+
PERL_STATIC_INLINE void
2335+
Perl_cx_pushtry(pTHX_ PERL_CONTEXT *cx, OP *retop, SV *namesv)
2336+
{
2337+
PERL_ARGS_ASSERT_CX_PUSHTRY;
2338+
2339+
/* just so it's restored by the common eval finished code */
2340+
cx->blk_eval.old_cxsubix = PL_curstackinfo->si_cxsubix;
2341+
cx->blk_eval.retop = retop;
2342+
cx->blk_eval.old_namesv = namesv;
2343+
cx->blk_eval.old_eval_root = PL_eval_root;
2344+
cx->blk_eval.cur_text = PL_parser ? PL_parser->linestr : NULL;
2345+
cx->blk_eval.cv = NULL; /* later set by doeval_compile() */
2346+
cx->blk_eval.cur_top_env = PL_top_env;
2347+
2348+
assert(!(PL_in_eval & ~ 0x3F));
2349+
assert(!(PL_op->op_type & ~0x1FF));
2350+
cx->blk_u16 = (PL_in_eval & 0x3F) | ((U16)PL_op->op_type << 7);
2351+
}
2352+
23342353

23352354
PERL_STATIC_INLINE void
23362355
Perl_cx_popeval(pTHX_ PERL_CONTEXT *cx)

pp_ctl.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2486,16 +2486,6 @@ PP(pp_return)
24862486
PERL_CONTEXT *cx;
24872487
I32 cxix = dopopto_cursub();
24882488

2489-
again:
2490-
if (cxix >= 0) {
2491-
cx = &cxstack[cxix];
2492-
if (CxTRY(cx)) {
2493-
/* This was a try {}. keep going */
2494-
cxix = dopoptosub_at(cxstack, cxix - 1);
2495-
goto again;
2496-
}
2497-
}
2498-
24992489
assert(cxstack_ix >= 0);
25002490
if (cxix < cxstack_ix) {
25012491
if (cxix < 0) {
@@ -4639,7 +4629,7 @@ PP(pp_entertrycatch)
46394629

46404630
cx = cx_pushblock((CXt_EVAL|CXp_EVALBLOCK|CXp_TRY), gimme,
46414631
PL_stack_sp, PL_savestack_ix);
4642-
cx_pusheval(cx, cLOGOP->op_other, NULL);
4632+
cx_pushtry(cx, cLOGOP->op_other, NULL);
46434633

46444634
PL_in_eval = EVAL_INEVAL;
46454635

proto.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4479,6 +4479,11 @@ PERL_STATIC_INLINE void Perl_cx_pushsub(pTHX_ PERL_CONTEXT *cx, CV *cv, OP *reto
44794479
assert(cx); assert(cv)
44804480
#endif
44814481
#ifndef PERL_NO_INLINE_FUNCTIONS
4482+
PERL_STATIC_INLINE void Perl_cx_pushtry(pTHX_ PERL_CONTEXT *cx, OP *retop, SV *namesv);
4483+
#define PERL_ARGS_ASSERT_CX_PUSHTRY \
4484+
assert(cx)
4485+
#endif
4486+
#ifndef PERL_NO_INLINE_FUNCTIONS
44824487
PERL_STATIC_INLINE void Perl_cx_pushwhen(pTHX_ PERL_CONTEXT *cx);
44834488
#define PERL_ARGS_ASSERT_CX_PUSHWHEN \
44844489
assert(cx)

0 commit comments

Comments
 (0)