X-Git-Url: https://perl5.git.perl.org/perl5.git/blobdiff_plain/212a001eeef9c1e3202a57c1ca8551e1002fc8e3..f204f8ac3d8cbbd10eafba2593e808144f1661f0:/scope.c diff --git a/scope.c b/scope.c index d78857b..d9b51f7 100644 --- a/scope.c +++ b/scope.c @@ -25,6 +25,7 @@ #include "EXTERN.h" #define PERL_IN_SCOPE_C #include "perl.h" +#include "feature.h" SV** Perl_stack_grow(pTHX_ SV **sp, SV **p, SSize_t n) @@ -36,7 +37,7 @@ Perl_stack_grow(pTHX_ SV **sp, SV **p, SSize_t n) if (UNLIKELY(n < 0)) Perl_croak(aTHX_ - "panic: stack_grow() negative count (%"IVdf")", (IV)n); + "panic: stack_grow() negative count (%" IVdf ")", (IV)n); PL_stack_sp = sp; extra = @@ -55,6 +56,10 @@ Perl_stack_grow(pTHX_ SV **sp, SV **p, SSize_t n) Perl_croak(aTHX_ "Out of memory during stack extend"); av_extend(PL_curstack, current + n + extra); +#ifdef DEBUGGING + PL_curstackinfo->si_stack_hwm = current + n + extra; +#endif + return PL_stack_sp; } @@ -78,6 +83,7 @@ Perl_new_stackinfo(pTHX_ I32 stitems, I32 cxitems) si->si_next = 0; si->si_cxmax = cxitems - 1; si->si_cxix = -1; + si->si_cxsubix = -1; si->si_type = PERLSI_UNDEF; Newx(si->si_cxstack, cxitems, PERL_CONTEXT); /* Without any kind of initialising CX_PUSHSUBST() @@ -90,11 +96,12 @@ I32 Perl_cxinc(pTHX) { const IV old_max = cxstack_max; - cxstack_max = GROW(cxstack_max); - Renew(cxstack, cxstack_max + 1, PERL_CONTEXT); + const IV new_max = GROW(cxstack_max); + Renew(cxstack, new_max + 1, PERL_CONTEXT); + cxstack_max = new_max; /* Without any kind of initialising deep enough recursion * will end up reading uninitialised PERL_CONTEXTs. */ - PoisonNew(cxstack + old_max + 1, cxstack_max - old_max, PERL_CONTEXT); + PoisonNew(cxstack + old_max + 1, new_max - old_max, PERL_CONTEXT); return cxstack_ix + 1; } @@ -102,11 +109,12 @@ void Perl_push_scope(pTHX) { if (UNLIKELY(PL_scopestack_ix == PL_scopestack_max)) { - PL_scopestack_max = GROW(PL_scopestack_max); - Renew(PL_scopestack, PL_scopestack_max, I32); + const IV new_max = GROW(PL_scopestack_max); + Renew(PL_scopestack, new_max, I32); #ifdef DEBUGGING - Renew(PL_scopestack_name, PL_scopestack_max, const char*); + Renew(PL_scopestack_name, new_max, const char*); #endif + PL_scopestack_max = new_max; } #ifdef DEBUGGING PL_scopestack_name[PL_scopestack_ix] = "unknown"; @@ -132,7 +140,7 @@ Perl_markstack_grow(pTHX) PL_markstack_max = PL_markstack + newmax; PL_markstack_ptr = PL_markstack + oldmax; DEBUG_s(DEBUG_v(PerlIO_printf(Perl_debug_log, - "MARK grow %p %"IVdf" by %"IVdf"\n", + "MARK grow %p %" IVdf " by %" IVdf "\n", PL_markstack_ptr, (IV)*PL_markstack_ptr, (IV)oldmax))); return PL_markstack_ptr; } @@ -140,23 +148,26 @@ Perl_markstack_grow(pTHX) void Perl_savestack_grow(pTHX) { + IV new_max; #ifdef STRESS_REALLOC - PL_savestack_max += SS_MAXPUSH; + new_max = PL_savestack_max + SS_MAXPUSH; #else - PL_savestack_max = GROW(PL_savestack_max); + new_max = GROW(PL_savestack_max); #endif /* Note that we allocate SS_MAXPUSH slots higher than ss_max * so that SS_ADD_END(), SSGROW() etc can do a simper check */ - Renew(PL_savestack, PL_savestack_max + SS_MAXPUSH, ANY); + Renew(PL_savestack, new_max + SS_MAXPUSH, ANY); + PL_savestack_max = new_max; } void Perl_savestack_grow_cnt(pTHX_ I32 need) { - PL_savestack_max = PL_savestack_ix + need; + const IV new_max = PL_savestack_ix + need; /* Note that we allocate SS_MAXPUSH slots higher than ss_max * so that SS_ADD_END(), SSGROW() etc can do a simper check */ - Renew(PL_savestack, PL_savestack_max + SS_MAXPUSH, ANY); + Renew(PL_savestack, new_max + SS_MAXPUSH, ANY); + PL_savestack_max = new_max; } #undef GROW @@ -186,8 +197,8 @@ Perl_tmps_grow_p(pTHX_ SSize_t ix) if (ix - PL_tmps_max < 128) extend_to += (PL_tmps_max < 512) ? 128 : 512; #endif + Renew(PL_tmps_stack, extend_to + 1, SV*); PL_tmps_max = extend_to + 1; - Renew(PL_tmps_stack, PL_tmps_max, SV*); return ix; } @@ -304,6 +315,9 @@ Perl_save_set_svflags(pTHX_ SV* sv, U32 mask, U32 val) } /* + +=for apidoc_section GV Handling + =for apidoc save_gp Saves the current GP of gv on the save stack to be restored on scope exit. @@ -321,6 +335,17 @@ Perl_save_gp(pTHX_ GV *gv, I32 empty) { PERL_ARGS_ASSERT_SAVE_GP; + /* XXX For now, we just upgrade any coderef in the stash to a full GV + during localisation. Maybe at some point we could make localis- + ation work without needing the upgrade. (In which case our + callers should probably call a different function, not save_gp.) + */ + if (!isGV(gv)) { + assert(isGV_or_RVCV(gv)); + (void)CvGV(SvRV((SV *)gv)); /* CvGV does the upgrade */ + assert(isGV(gv)); + } + save_pushptrptr(SvREFCNT_inc(gv), GvGP(gv), SAVEt_GP); if (empty) { @@ -329,7 +354,7 @@ Perl_save_gp(pTHX_ GV *gv, I32 empty) bool isa_changed = 0; if (stash && HvENAME(stash)) { - if (GvNAMELEN(gv) == 3 && strnEQ(GvNAME(gv), "ISA", 3)) + if (memEQs(GvNAME(gv), GvNAMELEN(gv), "ISA")) isa_changed = TRUE; else if (GvCVu(gv)) /* taking a method out of circulation ("local")*/ @@ -584,7 +609,7 @@ Perl_save_clearsv(pTHX_ SV **svp) ASSERT_CURPAD_ACTIVE("save_clearsv"); SvPADSTALE_off(*svp); /* mark lexical as active */ if (UNLIKELY((offset_shifted >> SAVE_TIGHT_SHIFT) != offset)) { - Perl_croak(aTHX_ "panic: pad offset %"UVuf" out of range (%p-%p)", + Perl_croak(aTHX_ "panic: pad offset %" UVuf " out of range (%p-%p)", offset, svp, PL_curpad); } @@ -661,9 +686,17 @@ Perl_save_hints(pTHX) COPHH *save_cophh = cophh_copy(CopHINTHASH_get(&PL_compiling)); if (PL_hints & HINT_LOCALIZE_HH) { HV *oldhh = GvHV(PL_hintgv); - save_pushptri32ptr(oldhh, PL_hints, save_cophh, SAVEt_HINTS); + { + dSS_ADD; + SS_ADD_INT(PL_hints); + SS_ADD_PTR(save_cophh); + SS_ADD_PTR(oldhh); + SS_ADD_UV(SAVEt_HINTS_HH); + SS_ADD_END(4); + } GvHV(PL_hintgv) = NULL; /* in case copying dies */ GvHV(PL_hintgv) = hv_copy_hints_hv(oldhh); + SAVEFEATUREBITS(); } else { save_pushi32ptr(PL_hints, save_cophh, SAVEt_HINTS); } @@ -772,7 +805,7 @@ Perl_save_alloc(pTHX_ I32 size, I32 pad) if (UNLIKELY((elems_shifted >> SAVE_TIGHT_SHIFT) != elems)) Perl_croak(aTHX_ - "panic: save_alloc elems %"UVuf" out of range (%"IVdf"-%"IVdf")", + "panic: save_alloc elems %" UVuf " out of range (%" IVdf "-%" IVdf ")", elems, (IV)size, (IV)pad); SSGROW(elems + 1); @@ -783,7 +816,7 @@ Perl_save_alloc(pTHX_ I32 size, I32 pad) } -static U8 arg_counts[] = { +static const U8 arg_counts[] = { 0, /* SAVEt_ALLOC */ 0, /* SAVEt_CLEARPADRANGE */ 0, /* SAVEt_CLEARSV */ @@ -837,7 +870,8 @@ static U8 arg_counts[] = { 3, /* SAVEt_SET_SVFLAGS */ 3, /* SAVEt_GVSLOT */ 3, /* SAVEt_AELEM */ - 3 /* SAVEt_DELETE */ + 3, /* SAVEt_DELETE */ + 3 /* SAVEt_HINTS_HH */ }; @@ -1027,7 +1061,7 @@ Perl_leave_scope(pTHX_ I32 base) #ifdef NO_TAINT_SUPPORT PERL_UNUSED_VAR(was); #else - if (UNLIKELY(a0.any_ptr == &(TAINT_get))) { + if (UNLIKELY(a0.any_ptr == &(PL_tainted))) { /* If we don't update , to reflect what was saved on the * stack for PL_tainted, then we will overwrite this attempt to * restore it when we exit this routine. Note that this won't @@ -1071,9 +1105,7 @@ Perl_leave_scope(pTHX_ I32 base) gp_free(a0.any_gv); GvGP_set(a0.any_gv, (GP*)a1.any_ptr); if ((hv=GvSTASH(a0.any_gv)) && HvENAME_get(hv)) { - if ( GvNAMELEN(a0.any_gv) == 3 - && strnEQ(GvNAME(a0.any_gv), "ISA", 3) - ) + if (memEQs(GvNAME(a0.any_gv), GvNAMELEN(a0.any_gv), "ISA")) mro_isa_changed_in(hv); else if (had_method || GvCVu(a0.any_gv)) /* putting a method back into circulation ("local")*/ @@ -1106,7 +1138,7 @@ Perl_leave_scope(pTHX_ I32 base) case SAVEt_FREEOP: a0 = ap[0]; ASSERT_CURPAD_LEGAL("SAVEt_FREEOP"); - op_free((OP*)a0.any_ptr); + op_free(a0.any_op); break; case SAVEt_FREEPV: @@ -1116,8 +1148,10 @@ Perl_leave_scope(pTHX_ I32 base) case SAVEt_CLEARPADRANGE: { - I32 i = (I32)((uv >> SAVE_TIGHT_SHIFT) & OPpPADRANGE_COUNTMASK); - SV **svp = &PL_curpad[uv >> + I32 i; + SV **svp; + i = (I32)((uv >> SAVE_TIGHT_SHIFT) & OPpPADRANGE_COUNTMASK); + svp = &PL_curpad[uv >> (OPpPADRANGE_COUNTSHIFT + SAVE_TIGHT_SHIFT)] + i - 1; goto clearsv; case SAVEt_CLEARSV: @@ -1128,7 +1162,7 @@ Perl_leave_scope(pTHX_ I32 base) SV *sv = *svp; DEBUG_Xv(PerlIO_printf(Perl_debug_log, - "Pad 0x%"UVxf"[0x%"UVxf"] clearsv: %ld sv=0x%"UVxf"<%"IVdf"> %s\n", + "Pad 0x%" UVxf "[0x%" UVxf "] clearsv: %ld sv=0x%" UVxf "<%" IVdf "> %s\n", PTR2UV(PL_comppad), PTR2UV(PL_curpad), (long)(svp-PL_curpad), PTR2UV(sv), (IV)SvREFCNT(sv), (SvREFCNT(sv) <= 1 && !SvOBJECT(sv)) ? "clear" : "abandon" @@ -1183,10 +1217,7 @@ Perl_leave_scope(pTHX_ I32 base) break; case SVt_PVCV: { - HEK *hek = - CvNAMED(sv) - ? CvNAME_HEK((CV *)sv) - : GvNAME_HEK(CvGV(sv)); + HEK *hek = CvGvNAME_HEK(sv); assert(hek); (void)share_hek_hek(hek); cv_undef((CV *)sv); @@ -1212,9 +1243,7 @@ Perl_leave_scope(pTHX_ I32 base) case SVt_PVHV: *svp = MUTABLE_SV(newHV()); break; case SVt_PVCV: { - HEK * const hek = CvNAMED(sv) - ? CvNAME_HEK((CV *)sv) - : GvNAME_HEK(CvGV(sv)); + HEK * const hek = CvGvNAME_HEK(sv); /* Create a stub */ *svp = newSV_type(SVt_PVCV); @@ -1238,15 +1267,26 @@ Perl_leave_scope(pTHX_ I32 base) case SAVEt_DELETE: a0 = ap[0]; a1 = ap[1]; a2 = ap[2]; + /* hv_delete could die, so free the key and SvREFCNT_dec the + * hv by pushing new save actions + */ + /* ap[0] is the key */ + ap[1].any_uv = SAVEt_FREEPV; /* was len */ + /* ap[2] is the hv */ + ap[3].any_uv = SAVEt_FREESV; /* was SAVEt_DELETE */ + PL_savestack_ix += 4; (void)hv_delete(a2.any_hv, a0.any_pv, a1.any_i32, G_DISCARD); - SvREFCNT_dec(a2.any_hv); - Safefree(a0.any_ptr); break; case SAVEt_ADELETE: a0 = ap[0]; a1 = ap[1]; + /* av_delete could die, so SvREFCNT_dec the av by pushing a + * new save action + */ + ap[0].any_av = a1.any_av; + ap[1].any_uv = SAVEt_FREESV; + PL_savestack_ix += 2; (void)av_delete(a1.any_av, a0.any_iv, G_DISCARD); - SvREFCNT_dec(a1.any_av); break; case SAVEt_DESTRUCTOR_X: @@ -1315,7 +1355,10 @@ Perl_leave_scope(pTHX_ I32 base) PL_op = (OP*)a0.any_ptr; break; - case SAVEt_HINTS: + case SAVEt_HINTS_HH: + a2 = ap[2]; + /* FALLTHROUGH */ + case SAVEt_HINTS: a0 = ap[0]; a1 = ap[1]; if ((PL_hints & HINT_LOCALIZE_HH)) { while (GvHV(PL_hintgv)) { @@ -1327,9 +1370,9 @@ Perl_leave_scope(pTHX_ I32 base) cophh_free(CopHINTHASH_get(&PL_compiling)); CopHINTHASH_set(&PL_compiling, (COPHH*)a1.any_ptr); *(I32*)&PL_hints = a0.any_i32; - if (PL_hints & HINT_LOCALIZE_HH) { + if (type == SAVEt_HINTS_HH) { SvREFCNT_dec(MUTABLE_SV(GvHV(PL_hintgv))); - GvHV(PL_hintgv) = MUTABLE_HV(SSPOPPTR); + GvHV(PL_hintgv) = MUTABLE_HV(a2.any_ptr); } if (!GvHV(PL_hintgv)) { /* Need to add a new one manually, else rv2hv can @@ -1416,9 +1459,7 @@ Perl_leave_scope(pTHX_ I32 base) case SAVEt_COMPILE_WARNINGS: a0 = ap[0]; - if (!specialWARN(PL_compiling.cop_warnings)) - PerlMemShared_free(PL_compiling.cop_warnings); - PL_compiling.cop_warnings = (STRLEN*)a0.any_ptr; + free_and_set_cop_warnings(&PL_compiling, (STRLEN*) a0.any_ptr); break; case SAVEt_PARSER: @@ -1450,12 +1491,12 @@ Perl_cx_dump(pTHX_ PERL_CONTEXT *cx) if (CxTYPE(cx) != CXt_SUBST) { const char *gimme_text; PerlIO_printf(Perl_debug_log, "BLK_OLDSP = %ld\n", (long)cx->blk_oldsp); - PerlIO_printf(Perl_debug_log, "BLK_OLDCOP = 0x%"UVxf"\n", + PerlIO_printf(Perl_debug_log, "BLK_OLDCOP = 0x%" UVxf "\n", PTR2UV(cx->blk_oldcop)); PerlIO_printf(Perl_debug_log, "BLK_OLDMARKSP = %ld\n", (long)cx->blk_oldmarksp); PerlIO_printf(Perl_debug_log, "BLK_OLDSCOPESP = %ld\n", (long)cx->blk_oldscopesp); PerlIO_printf(Perl_debug_log, "BLK_OLDSAVEIX = %ld\n", (long)cx->blk_oldsaveix); - PerlIO_printf(Perl_debug_log, "BLK_OLDPM = 0x%"UVxf"\n", + PerlIO_printf(Perl_debug_log, "BLK_OLDPM = 0x%" UVxf "\n", PTR2UV(cx->blk_oldpm)); switch (cx->blk_gimme) { case G_VOID: @@ -1478,26 +1519,26 @@ Perl_cx_dump(pTHX_ PERL_CONTEXT *cx) case CXt_BLOCK: break; case CXt_FORMAT: - PerlIO_printf(Perl_debug_log, "BLK_FORMAT.CV = 0x%"UVxf"\n", + PerlIO_printf(Perl_debug_log, "BLK_FORMAT.CV = 0x%" UVxf "\n", PTR2UV(cx->blk_format.cv)); - PerlIO_printf(Perl_debug_log, "BLK_FORMAT.GV = 0x%"UVxf"\n", + PerlIO_printf(Perl_debug_log, "BLK_FORMAT.GV = 0x%" UVxf "\n", PTR2UV(cx->blk_format.gv)); - PerlIO_printf(Perl_debug_log, "BLK_FORMAT.DFOUTGV = 0x%"UVxf"\n", + PerlIO_printf(Perl_debug_log, "BLK_FORMAT.DFOUTGV = 0x%" UVxf "\n", PTR2UV(cx->blk_format.dfoutgv)); PerlIO_printf(Perl_debug_log, "BLK_FORMAT.HASARGS = %d\n", (int)CxHASARGS(cx)); - PerlIO_printf(Perl_debug_log, "BLK_FORMAT.RETOP = 0x%"UVxf"\n", + PerlIO_printf(Perl_debug_log, "BLK_FORMAT.RETOP = 0x%" UVxf "\n", PTR2UV(cx->blk_format.retop)); break; case CXt_SUB: - PerlIO_printf(Perl_debug_log, "BLK_SUB.CV = 0x%"UVxf"\n", + PerlIO_printf(Perl_debug_log, "BLK_SUB.CV = 0x%" UVxf "\n", PTR2UV(cx->blk_sub.cv)); PerlIO_printf(Perl_debug_log, "BLK_SUB.OLDDEPTH = %ld\n", (long)cx->blk_sub.olddepth); PerlIO_printf(Perl_debug_log, "BLK_SUB.HASARGS = %d\n", (int)CxHASARGS(cx)); PerlIO_printf(Perl_debug_log, "BLK_SUB.LVAL = %d\n", (int)CxLVAL(cx)); - PerlIO_printf(Perl_debug_log, "BLK_SUB.RETOP = 0x%"UVxf"\n", + PerlIO_printf(Perl_debug_log, "BLK_SUB.RETOP = 0x%" UVxf "\n", PTR2UV(cx->blk_sub.retop)); break; case CXt_EVAL: @@ -1509,9 +1550,9 @@ Perl_cx_dump(pTHX_ PERL_CONTEXT *cx) if (cx->blk_eval.old_namesv) PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_NAME = %s\n", SvPVX_const(cx->blk_eval.old_namesv)); - PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_EVAL_ROOT = 0x%"UVxf"\n", + PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_EVAL_ROOT = 0x%" UVxf "\n", PTR2UV(cx->blk_eval.old_eval_root)); - PerlIO_printf(Perl_debug_log, "BLK_EVAL.RETOP = 0x%"UVxf"\n", + PerlIO_printf(Perl_debug_log, "BLK_EVAL.RETOP = 0x%" UVxf "\n", PTR2UV(cx->blk_eval.retop)); break; @@ -1521,15 +1562,16 @@ Perl_cx_dump(pTHX_ PERL_CONTEXT *cx) case CXt_LOOP_LIST: case CXt_LOOP_ARY: PerlIO_printf(Perl_debug_log, "BLK_LOOP.LABEL = %s\n", CxLABEL(cx)); - PerlIO_printf(Perl_debug_log, "BLK_LOOP.MY_OP = 0x%"UVxf"\n", + PerlIO_printf(Perl_debug_log, "BLK_LOOP.MY_OP = 0x%" UVxf "\n", PTR2UV(cx->blk_loop.my_op)); if (CxTYPE(cx) != CXt_LOOP_PLAIN) { - PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERVAR = 0x%"UVxf"\n", + PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERVAR = 0x%" UVxf "\n", PTR2UV(CxITERVAR(cx))); - PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERSAVE = 0x%"UVxf"\n", + PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERSAVE = 0x%" UVxf "\n", PTR2UV(cx->blk_loop.itersave)); - /* XXX: not accurate for LAZYSV/IV/LIST */ - PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERARY = 0x%"UVxf"\n", + } + if (CxTYPE(cx) == CXt_LOOP_ARY) { + PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERARY = 0x%" UVxf "\n", PTR2UV(cx->blk_loop.state_u.ary.ary)); PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERIX = %ld\n", (long)cx->blk_loop.state_u.ary.ix); @@ -1547,17 +1589,17 @@ Perl_cx_dump(pTHX_ PERL_CONTEXT *cx) (long)CxONCE(cx)); PerlIO_printf(Perl_debug_log, "SB_ORIG = %s\n", cx->sb_orig); - PerlIO_printf(Perl_debug_log, "SB_DSTR = 0x%"UVxf"\n", + PerlIO_printf(Perl_debug_log, "SB_DSTR = 0x%" UVxf "\n", PTR2UV(cx->sb_dstr)); - PerlIO_printf(Perl_debug_log, "SB_TARG = 0x%"UVxf"\n", + PerlIO_printf(Perl_debug_log, "SB_TARG = 0x%" UVxf "\n", PTR2UV(cx->sb_targ)); - PerlIO_printf(Perl_debug_log, "SB_S = 0x%"UVxf"\n", + PerlIO_printf(Perl_debug_log, "SB_S = 0x%" UVxf "\n", PTR2UV(cx->sb_s)); - PerlIO_printf(Perl_debug_log, "SB_M = 0x%"UVxf"\n", + PerlIO_printf(Perl_debug_log, "SB_M = 0x%" UVxf "\n", PTR2UV(cx->sb_m)); - PerlIO_printf(Perl_debug_log, "SB_STREND = 0x%"UVxf"\n", + PerlIO_printf(Perl_debug_log, "SB_STREND = 0x%" UVxf "\n", PTR2UV(cx->sb_strend)); - PerlIO_printf(Perl_debug_log, "SB_RXRES = 0x%"UVxf"\n", + PerlIO_printf(Perl_debug_log, "SB_RXRES = 0x%" UVxf "\n", PTR2UV(cx->sb_rxres)); break; }