summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2015-10-21 09:28:52 +0100
committerDavid Mitchell <davem@iabyn.com>2016-02-03 09:18:31 +0000
commit4ebe6e957149a0288810b6241653721d805397aa (patch)
treeed141b6705ef0a1c15337babf3bdce722b665105
parent77189b8c243837b664cb444e867999e67e87ca44 (diff)
downloadperl-4ebe6e957149a0288810b6241653721d805397aa.tar.gz
add CX_CUR() macro
This is simply #define CX_CUR() (&cxstack[cxstack_ix])
-rw-r--r--cop.h22
-rw-r--r--op.c4
-rw-r--r--perl.c2
-rw-r--r--pp.c6
-rw-r--r--pp_ctl.c48
-rw-r--r--pp_hot.c8
-rw-r--r--pp_sort.c2
-rw-r--r--pp_sys.c4
-rw-r--r--toke.c2
9 files changed, 51 insertions, 47 deletions
diff --git a/cop.h b/cop.h
index 4eefc4ce9e..94e58afa7c 100644
--- a/cop.h
+++ b/cop.h
@@ -570,6 +570,10 @@ struct block_format {
GV * dfoutgv;
};
+/* return a pointer to the current context */
+
+#define CX_CUR() (&cxstack[cxstack_ix])
+
/* free all savestack items back to the watermark of the specified context */
#define CX_LEAVE_SCOPE(cx) LEAVE_SCOPE(cx->blk_oldsaveix)
@@ -579,7 +583,7 @@ struct block_format {
* uses it - because after doing cxstack_ix--, any ties, exceptions etc
* may overwrite the current stack frame */
# define CX_POP(cx) \
- assert(&cxstack[cxstack_ix] == cx); \
+ assert(CX_CUR() == cx); \
cxstack_ix--; \
cx = NULL;
#else
@@ -931,15 +935,15 @@ struct block {
Perl_deb(aTHX_ "CX %ld %s %s (scope %ld,%ld) (save %ld,%ld) at %s:%d\n",\
(long)cxstack_ix, \
action, \
- PL_block_type[CxTYPE(&cxstack[cxstack_ix])], \
+ PL_block_type[CxTYPE(CX_CUR())], \
(long)PL_scopestack_ix, \
- (long)(cxstack[cxstack_ix].blk_oldscopesp), \
+ (long)(CX_CUR()->blk_oldscopesp), \
(long)PL_savestack_ix, \
- (long)(cxstack[cxstack_ix].blk_oldsaveix), \
+ (long)(CX_CUR()->blk_oldsaveix), \
__FILE__, __LINE__));
/* Enter a block. */
-#define PUSHBLOCK(cx,t,sp) CXINC, cx = &cxstack[cxstack_ix], \
+#define PUSHBLOCK(cx,t,sp) CXINC, cx = CX_CUR(), \
cx->cx_type = t, \
cx->blk_oldsp = sp - PL_stack_base, \
cx->blk_oldcop = PL_curcop, \
@@ -968,7 +972,7 @@ struct block {
/* Continue a block elsewhere (NEXT and REDO). */
#define TOPBLOCK(cx) \
DEBUG_CX("TOP"); \
- cx = &cxstack[cxstack_ix], \
+ cx = CX_CUR(), \
PL_stack_sp = PL_stack_base + cx->blk_oldsp, \
PL_markstack_ptr = PL_markstack + cx->blk_oldmarksp, \
PL_scopestack_ix = cx->blk_oldscopesp, \
@@ -1006,7 +1010,7 @@ struct subst {
#define sb_rx cx_u.cx_subst.sbu_rx
#ifdef PERL_CORE
-# define PUSHSUBST(cx) CXINC, cx = &cxstack[cxstack_ix], \
+# define PUSHSUBST(cx) CXINC, cx = CX_CUR(), \
cx->blk_oldsaveix = oldsave, \
cx->sb_iters = iters, \
cx->sb_maxiters = maxiters, \
@@ -1333,7 +1337,7 @@ See L<perlcall/LIGHTWEIGHT CALLBACKS>.
#define POP_MULTICALL \
STMT_START { \
- cx = &cxstack[cxstack_ix]; \
+ cx = CX_CUR(); \
CX_LEAVE_SCOPE(cx); \
POPSUB_COMMON(cx); \
newsp = PL_stack_base + cx->blk_oldsp; \
@@ -1355,7 +1359,7 @@ See L<perlcall/LIGHTWEIGHT CALLBACKS>.
CV * const _nOnclAshIngNamE_ = the_cv; \
CV * const cv = _nOnclAshIngNamE_; \
PADLIST * const padlist = CvPADLIST(cv); \
- cx = &cxstack[cxstack_ix]; \
+ cx = CX_CUR(); \
assert(CxMULTICALL(cx)); \
POPSUB_COMMON(cx); \
cx->cx_type = (CXt_SUB|CXp_MULTICALL|flags); \
diff --git a/op.c b/op.c
index 15ced90de2..b5bc54614c 100644
--- a/op.c
+++ b/op.c
@@ -4056,7 +4056,7 @@ Perl_newPROG(pTHX_ OP *o)
((PL_in_eval & EVAL_KEEPERR)
? OPf_SPECIAL : 0), o);
- cx = &cxstack[cxstack_ix];
+ cx = CX_CUR();
assert(CxTYPE(cx) == CXt_EVAL);
if ((cx->blk_gimme & G_WANT) == G_VOID)
@@ -4400,7 +4400,7 @@ S_fold_constants(pTHX_ OP *o)
* may or may not have already been popped */
if (cxstack_ix > old_cxix) {
assert(cxstack_ix == old_cxix + 1);
- assert(CxTYPE(&cxstack[cxstack_ix]) == CXt_EVAL);
+ assert(CxTYPE(CX_CUR()) == CXt_EVAL);
delete_eval_scope();
}
if (ret)
diff --git a/perl.c b/perl.c
index a7938bd774..ab8f0128d3 100644
--- a/perl.c
+++ b/perl.c
@@ -2824,7 +2824,7 @@ Perl_call_sv(pTHX_ SV *sv, VOL I32 flags)
* may or may not have already been popped */
if (cxstack_ix > old_cxix) {
assert(cxstack_ix == old_cxix + 1);
- assert(CxTYPE(&cxstack[cxstack_ix]) == CXt_EVAL);
+ assert(CxTYPE(CX_CUR()) == CXt_EVAL);
delete_eval_scope();
}
JMPENV_POP;
diff --git a/pp.c b/pp.c
index ac8498ef66..f4a7dcdc3c 100644
--- a/pp.c
+++ b/pp.c
@@ -6354,7 +6354,7 @@ PP(pp_coreargs)
to return. nextstate usually does this on sub entry, but we need
to run the next op with the caller's hints, so we cannot have a
nextstate. */
- SP = PL_stack_base + cxstack[cxstack_ix].blk_oldsp;
+ SP = PL_stack_base + CX_CUR()->blk_oldsp;
if(!maxargs) RETURN;
@@ -6438,10 +6438,10 @@ PP(pp_coreargs)
);
PUSHs(SvRV(*svp));
if (opnum == OP_UNDEF && SvRV(*svp) == (SV *)PL_defgv
- && cxstack[cxstack_ix].cx_type & CXp_HASARGS) {
+ && CX_CUR()->cx_type & CXp_HASARGS) {
/* Undo @_ localisation, so that sub exit does not undo
part of our undeffing. */
- PERL_CONTEXT *cx = &cxstack[cxstack_ix];
+ PERL_CONTEXT *cx = CX_CUR();
assert(CxHASARGS(cx));
POPSUB_ARGS(cx);;
diff --git a/pp_ctl.c b/pp_ctl.c
index 74c4f584fe..045e1d350b 100644
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -190,7 +190,7 @@ PP(pp_regcomp)
PP(pp_substcont)
{
dSP;
- PERL_CONTEXT *cx = &cxstack[cxstack_ix];
+ PERL_CONTEXT *cx = CX_CUR();
PMOP * const pm = (PMOP*) cLOGOP->op_other;
SV * const dstr = cx->sb_dstr;
char *s = cx->sb_s;
@@ -1512,8 +1512,8 @@ Perl_dounwind(pTHX_ I32 cxix)
return;
while (cxstack_ix > cxix) {
- PERL_CONTEXT *cx = &cxstack[cxstack_ix];
- DEBUG_CX("UNWIND"); \
+ PERL_CONTEXT *cx = CX_CUR();
+ DEBUG_CX("UNWIND");
/* Note: we don't need to restore the base context info till the end. */
CX_LEAVE_SCOPE(cx);
@@ -1671,7 +1671,7 @@ Perl_die_unwind(pTHX_ SV *msv)
if (cxix < cxstack_ix)
dounwind(cxix);
- cx = &cxstack[cxstack_ix];
+ cx = CX_CUR();
assert(CxTYPE(cx) == CXt_EVAL);
/* return false to the caller of eval */
@@ -1964,7 +1964,7 @@ PP(pp_dbstate)
{
PL_curcop = (COP*)PL_op;
TAINT_NOT; /* Each statement is presumed innocent */
- PL_stack_sp = PL_stack_base + cxstack[cxstack_ix].blk_oldsp;
+ PL_stack_sp = PL_stack_base + CX_CUR()->blk_oldsp;
FREETMPS;
PERL_ASYNC_CHECK();
@@ -2095,7 +2095,7 @@ PP(pp_leave)
SV **newsp;
I32 gimme;
- cx = &cxstack[cxstack_ix];
+ cx = CX_CUR();
assert(CxTYPE(cx) == CXt_BLOCK);
if (PL_op->op_flags & OPf_SPECIAL)
@@ -2268,7 +2268,7 @@ PP(pp_leaveloop)
SV **newsp;
SV **mark;
- cx = &cxstack[cxstack_ix];
+ cx = CX_CUR();
assert(CxTYPE_is_LOOP(cx));
mark = PL_stack_base + cx->blk_oldsp;
newsp = CxTYPE(cx) == CXt_LOOP_LIST
@@ -2310,7 +2310,7 @@ PP(pp_leavesublv)
const char *what = NULL;
OP *retop;
- cx = &cxstack[cxstack_ix];
+ cx = CX_CUR();
assert(CxTYPE(cx) == CXt_SUB);
if (CxMULTICALL(cx)) {
@@ -2575,7 +2575,7 @@ PP(pp_last)
S_unwind_loop(aTHX_ "last");
- cx = &cxstack[cxstack_ix];
+ cx = CX_CUR();
assert(CxTYPE_is_LOOP(cx));
PL_stack_sp = PL_stack_base
@@ -2617,7 +2617,7 @@ PP(pp_redo)
if (redo_op->op_type == OP_ENTER) {
/* pop one less context to avoid $x being freed in while (my $x..) */
cxstack_ix++;
- assert(CxTYPE(&cxstack[cxstack_ix]) == CXt_BLOCK);
+ assert(CxTYPE(CX_CUR()) == CXt_BLOCK);
redo_op = redo_op->op_next;
}
@@ -3172,8 +3172,8 @@ S_docatch(pTHX_ OP *o)
switch (ret) {
case 0:
assert(cxstack_ix >= 0);
- assert(CxTYPE(&cxstack[cxstack_ix]) == CXt_EVAL);
- cxstack[cxstack_ix].blk_eval.cur_top_env = PL_top_env;
+ assert(CxTYPE(CX_CUR()) == CXt_EVAL);
+ CX_CUR()->blk_eval.cur_top_env = PL_top_env;
redo_body:
CALLRUNOPS(aTHX);
break;
@@ -3277,7 +3277,7 @@ S_try_yyparse(pTHX_ int gramtype)
int ret;
dJMPENV;
- assert(CxTYPE(&cxstack[cxstack_ix]) == CXt_EVAL);
+ assert(CxTYPE(CX_CUR()) == CXt_EVAL);
JMPENV_PUSH(ret);
switch (ret) {
case 0:
@@ -3330,9 +3330,9 @@ S_doeval_compile(pTHX_ int gimme, CV* outside, U32 seq, HV *hh)
evalcv = MUTABLE_CV(newSV_type(SVt_PVCV));
CvEVAL_on(evalcv);
- assert(CxTYPE(&cxstack[cxstack_ix]) == CXt_EVAL);
- cxstack[cxstack_ix].blk_eval.cv = evalcv;
- cxstack[cxstack_ix].blk_gimme = gimme;
+ assert(CxTYPE(CX_CUR()) == CXt_EVAL);
+ CX_CUR()->blk_eval.cv = evalcv;
+ CX_CUR()->blk_gimme = gimme;
CvOUTSIDE_SEQ(evalcv) = seq;
CvOUTSIDE(evalcv) = MUTABLE_CV(SvREFCNT_inc_simple(outside));
@@ -3448,7 +3448,7 @@ S_doeval_compile(pTHX_ int gimme, CV* outside, U32 seq, HV *hh)
PL_eval_root = NULL;
}
SP = PL_stack_base + POPMARK; /* pop original mark */
- cx = &cxstack[cxstack_ix];
+ cx = CX_CUR();
CX_LEAVE_SCOPE(cx);
POPEVAL(cx);
POPBLOCK(cx);
@@ -3460,7 +3460,7 @@ S_doeval_compile(pTHX_ int gimme, CV* outside, U32 seq, HV *hh)
errsv = ERRSV;
if (in_require) {
if (yystatus == 3) {
- cx = &cxstack[cxstack_ix];
+ cx = CX_CUR();
assert(CxTYPE(cx) == CXt_EVAL);
namesv = cx->blk_eval.old_namesv;
}
@@ -4270,7 +4270,7 @@ PP(pp_leaveeval)
PERL_ASYNC_CHECK();
- cx = &cxstack[cxstack_ix];
+ cx = CX_CUR();
assert(CxTYPE(cx) == CXt_EVAL);
newsp = PL_stack_base + cx->blk_oldsp;
@@ -4328,7 +4328,7 @@ Perl_delete_eval_scope(pTHX)
{
PERL_CONTEXT *cx;
- cx = &cxstack[cxstack_ix];
+ cx = CX_CUR();
CX_LEAVE_SCOPE(cx);
POPEVAL(cx);
POPBLOCK(cx);
@@ -4374,7 +4374,7 @@ PP(pp_leavetry)
PERL_ASYNC_CHECK();
- cx = &cxstack[cxstack_ix];
+ cx = CX_CUR();
assert(CxTYPE(cx) == CXt_EVAL);
newsp = PL_stack_base + cx->blk_oldsp;
gimme = cx->blk_gimme;
@@ -4417,7 +4417,7 @@ PP(pp_leavegiven)
SV **newsp;
PERL_UNUSED_CONTEXT;
- cx = &cxstack[cxstack_ix];
+ cx = CX_CUR();
assert(CxTYPE(cx) == CXt_GIVEN);
newsp = PL_stack_base + cx->blk_oldsp;
gimme = cx->blk_gimme;
@@ -4997,7 +4997,7 @@ PP(pp_leavewhen)
I32 gimme;
SV **newsp;
- cx = &cxstack[cxstack_ix];
+ cx = CX_CUR();
assert(CxTYPE(cx) == CXt_WHEN);
gimme = cx->blk_gimme;
@@ -5045,7 +5045,7 @@ PP(pp_continue)
if (cxix < cxstack_ix)
dounwind(cxix);
- cx = &cxstack[cxstack_ix];
+ cx = CX_CUR();
assert(CxTYPE(cx) == CXt_WHEN);
PL_stack_sp = PL_stack_base + cx->blk_oldsp;
CX_LEAVE_SCOPE(cx);
diff --git a/pp_hot.c b/pp_hot.c
index 89f3bb83c2..7a5ad78490 100644
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -48,7 +48,7 @@ PP(pp_nextstate)
{
PL_curcop = (COP*)PL_op;
TAINT_NOT; /* Each statement is presumed innocent */
- PL_stack_sp = PL_stack_base + cxstack[cxstack_ix].blk_oldsp;
+ PL_stack_sp = PL_stack_base + CX_CUR()->blk_oldsp;
FREETMPS;
PERL_ASYNC_CHECK();
return NORMAL;
@@ -243,7 +243,7 @@ PP(pp_unstack)
PERL_CONTEXT *cx;
PERL_ASYNC_CHECK();
TAINT_NOT; /* Each statement is presumed innocent */
- cx = &cxstack[cxstack_ix];
+ cx = CX_CUR();
PL_stack_sp = PL_stack_base + cx->blk_oldsp;
FREETMPS;
if (!(PL_op->op_flags & OPf_SPECIAL)) {
@@ -2630,7 +2630,7 @@ PP(pp_iter)
SV **itersvp;
SV *retsv;
- cx = &cxstack[cxstack_ix];
+ cx = CX_CUR();
itersvp = CxITERVAR(cx);
switch (CxTYPE(cx)) {
@@ -3291,7 +3291,7 @@ PP(pp_leavesub)
PERL_CONTEXT *cx;
OP *retop;
- cx = &cxstack[cxstack_ix];
+ cx = CX_CUR();
assert(CxTYPE(cx) == CXt_SUB);
if (CxMULTICALL(cx)) {
diff --git a/pp_sort.c b/pp_sort.c
index a95796d01c..4079eef2be 100644
--- a/pp_sort.c
+++ b/pp_sort.c
@@ -1699,7 +1699,7 @@ PP(pp_sort)
sort_flags);
/* Reset cx, in case the context stack has been reallocated. */
- cx = &cxstack[cxstack_ix];
+ cx = CX_CUR();
PL_stack_sp = PL_stack_base + cx->blk_oldsp;
diff --git a/pp_sys.c b/pp_sys.c
index 99f718e522..ff56179b60 100644
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -1443,7 +1443,7 @@ PP(pp_enterwrite)
PP(pp_leavewrite)
{
dSP;
- GV * const gv = cxstack[cxstack_ix].blk_format.gv;
+ GV * const gv = CX_CUR()->blk_format.gv;
IO * const io = GvIOp(gv);
PerlIO *ofp;
PerlIO *fp;
@@ -1523,7 +1523,7 @@ PP(pp_leavewrite)
}
forget_top:
- cx = &cxstack[cxstack_ix];
+ cx = CX_CUR();
assert(CxTYPE(cx) == CXt_FORMAT);
SP = PL_stack_base + cx->blk_oldsp; /* ignore retval of formline */
CX_LEAVE_SCOPE(cx);
diff --git a/toke.c b/toke.c
index e2f2bfe830..4a67857c15 100644
--- a/toke.c
+++ b/toke.c
@@ -9542,7 +9542,7 @@ S_scan_heredoc(pTHX_ char *s)
SV *linestr;
char *bufend;
char * const olds = s;
- PERL_CONTEXT * const cx = &cxstack[cxstack_ix];
+ PERL_CONTEXT * const cx = CX_CUR();
/* These two fields are not set until an inner lexing scope is
entered. But we need them set here. */
shared->ls_bufptr = s;