summaryrefslogtreecommitdiff
path: root/regcomp.h
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2015-10-12 14:56:35 +0100
committerDavid Mitchell <davem@iabyn.com>2016-02-03 08:59:42 +0000
commit4df352a81ba92beb6467d6dafdf988d8aba963c4 (patch)
tree2a4af08aab3d7918c60d7fb316d7358093639d00 /regcomp.h
parentc7764d57491b2cc21ae721b2de1e960a792ccc93 (diff)
downloadperl-4df352a81ba92beb6467d6dafdf988d8aba963c4.tar.gz
reverse the order of POPBLOCK; POPFOO
Currently most pp_leavefoo subs have something along the lines of POPBLOCK(cx); POPFOO(cx); where POPBLOCK does cxstack_ix-- and sets cx to point to the top CX stack entry. It then restores a bunch of PL_ vars saved in the CX struct. Then POPFOO does any type-specific restoration, e.g. POPSUB decrements the ref count of the cv that was just executed. However, this is logically the wrong order. When we *enter* a scope, we do PUSHBLOCK; PUSHFOO; so undoing the PUSHBLOCK should be the last thing we do. As it happens, it doesn't really make any difference to the running, which is why we've never fixed it before. Reordering it has two advantages. First, it allows the steps for scope exit to be the exact logical reverse of scope exit, which makes understanding what's going on and debugging easier. It allows us to make the code cleaner. This commit also removes the cxstack_ix-- and setting cx steps from POPBLOCK; now we already expect cx to be set (which it usually already is) and we do the cxstack_ix-- ourselves. This also means we can remove a whole bunch of cxstack_ix++'s that were added immediately after the POPBLOCK in order to prevent the context being inadvertently overwritten before we've finished using it. So in full, POPBLOCK(cx); POPFOO(cx); is now implemented as: cx = &cxstack[cxstack_ix]; ... other stuff done with cx ... POPFOO(cx); POPBLOCK(cx); cxstack_ix--; Finally, this commit also tweaks PL_curcop in pp_leaveeval, since otherwise PL_curcop could temporarily be NULL when debugging code is called in the presence of 'use re Debug'. It also stops the debugging code crashing if PL_curcop is still NULL.
Diffstat (limited to 'regcomp.h')
-rw-r--r--regcomp.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/regcomp.h b/regcomp.h
index b9c0613946..44c2c1c8de 100644
--- a/regcomp.h
+++ b/regcomp.h
@@ -1055,7 +1055,7 @@ re.pm, especially to the documentation.
/* get_sv() can return NULL during global destruction. */
#define GET_RE_DEBUG_FLAGS DEBUG_r({ \
SV * re_debug_flags_sv = NULL; \
- re_debug_flags_sv = get_sv(RE_DEBUG_FLAGS, 1); \
+ re_debug_flags_sv = PL_curcop ? get_sv(RE_DEBUG_FLAGS, 1) : NULL; \
if (re_debug_flags_sv) { \
if (!SvIOK(re_debug_flags_sv)) \
sv_setuv(re_debug_flags_sv, RE_DEBUG_COMPILE_DUMP | RE_DEBUG_EXECUTE_MASK ); \