From b95eccd3c957974356edd3c076146c996d76431d Mon Sep 17 00:00:00 2001 From: David Mitchell Date: Fri, 2 Oct 2015 17:28:00 +0100 Subject: pp_given: avoid using savestack for old var Add a new field, defsv_save, to struct block_givwhen, and use this to save the previous $_ in 'when(expr)' rather than saving it on the save stack. Also add POPWHEN and POPGIVEN macros. The former is a no-op for now. --- cop.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'cop.h') diff --git a/cop.h b/cop.h index a01ddda392..d455478396 100644 --- a/cop.h +++ b/cop.h @@ -836,12 +836,23 @@ struct block_loop { /* given/when context */ struct block_givwhen { OP *leave_op; + SV *defsv_save; /* the original $_ */ }; -#define PUSHGIVEN(cx) \ +#define PUSHWHEN(cx) \ cx->blk_givwhen.leave_op = cLOGOP->op_other; -#define PUSHWHEN PUSHGIVEN +#define PUSHGIVEN(cx, orig_var) \ + PUSHWHEN(cx); \ + cx->blk_givwhen.defsv_save = orig_var; + +#define POPWHEN(cx) \ + NOOP; + +#define POPGIVEN(cx) \ + SvREFCNT_dec(GvSV(PL_defgv)); \ + GvSV(PL_defgv) = cx->blk_givwhen.defsv_save; + /* context common to subroutines, evals and loops */ struct block { -- cgit v1.2.1