3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
4 * 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 by Larry Wall and others
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Artistic License, as specified in the README file.
12 * For the fashion of Minas Tirith was such that it was built on seven
15 * [p.751 of _The Lord of the Rings_, V/i: "Minas Tirith"]
18 /* This file contains functions to manipulate several of Perl's stacks;
19 * in particular it contains code to push various types of things onto
20 * the savestack, then to pop them off and perform the correct restorative
21 * action for each one. This corresponds to the cleanup Perl does at
26 #define PERL_IN_SCOPE_C
30 Perl_stack_grow(pTHX_ SV **sp, SV **p, int n)
34 PERL_ARGS_ASSERT_STACK_GROW;
37 #ifndef STRESS_REALLOC
38 av_extend(PL_curstack, (p - PL_stack_base) + (n) + 128);
40 av_extend(PL_curstack, (p - PL_stack_base) + (n) + 1);
45 #ifndef STRESS_REALLOC
46 #define GROW(old) ((old) * 3 / 2)
48 #define GROW(old) ((old) + 1)
52 Perl_new_stackinfo(pTHX_ I32 stitems, I32 cxitems)
57 si->si_stack = newAV();
58 AvREAL_off(si->si_stack);
59 av_extend(si->si_stack, stitems > 0 ? stitems-1 : 0);
60 AvALLOC(si->si_stack)[0] = &PL_sv_undef;
61 AvFILLp(si->si_stack) = 0;
64 si->si_cxmax = cxitems - 1;
66 si->si_type = PERLSI_UNDEF;
67 Newx(si->si_cxstack, cxitems, PERL_CONTEXT);
68 /* Without any kind of initialising PUSHSUBST()
69 * in pp_subst() will read uninitialised heap. */
70 PoisonNew(si->si_cxstack, cxitems, PERL_CONTEXT);
78 const IV old_max = cxstack_max;
79 cxstack_max = GROW(cxstack_max);
80 Renew(cxstack, cxstack_max + 1, PERL_CONTEXT); /* XXX should fix CXINC macro */
81 /* Without any kind of initialising deep enough recursion
82 * will end up reading uninitialised PERL_CONTEXTs. */
83 PoisonNew(cxstack + old_max + 1, cxstack_max - old_max, PERL_CONTEXT);
84 return cxstack_ix + 1;
91 if (PL_scopestack_ix == PL_scopestack_max) {
92 PL_scopestack_max = GROW(PL_scopestack_max);
93 Renew(PL_scopestack, PL_scopestack_max, I32);
95 PL_scopestack[PL_scopestack_ix++] = PL_savestack_ix;
103 const I32 oldsave = PL_scopestack[--PL_scopestack_ix];
104 LEAVE_SCOPE(oldsave);
108 Perl_markstack_grow(pTHX)
111 const I32 oldmax = PL_markstack_max - PL_markstack;
112 const I32 newmax = GROW(oldmax);
114 Renew(PL_markstack, newmax, I32);
115 PL_markstack_ptr = PL_markstack + oldmax;
116 PL_markstack_max = PL_markstack + newmax;
120 Perl_savestack_grow(pTHX)
123 PL_savestack_max = GROW(PL_savestack_max) + 4;
124 Renew(PL_savestack, PL_savestack_max, ANY);
128 Perl_savestack_grow_cnt(pTHX_ I32 need)
131 PL_savestack_max = PL_savestack_ix + need;
132 Renew(PL_savestack, PL_savestack_max, ANY);
138 Perl_tmps_grow(pTHX_ I32 n)
141 #ifndef STRESS_REALLOC
143 n = (PL_tmps_max < 512) ? 128 : 512;
145 PL_tmps_max = PL_tmps_ix + n + 1;
146 Renew(PL_tmps_stack, PL_tmps_max, SV*);
154 /* XXX should tmps_floor live in cxstack? */
155 const I32 myfloor = PL_tmps_floor;
156 while (PL_tmps_ix > myfloor) { /* clean up after last statement */
157 SV* const sv = PL_tmps_stack[PL_tmps_ix];
158 PL_tmps_stack[PL_tmps_ix--] = NULL;
159 if (sv && sv != &PL_sv_undef) {
161 SvREFCNT_dec(sv); /* note, can modify tmps_ix!!! */
167 S_save_scalar_at(pTHX_ SV **sptr, const U32 flags)
170 SV * const osv = *sptr;
171 register SV * const sv = *sptr = newSV(0);
173 PERL_ARGS_ASSERT_SAVE_SCALAR_AT;
175 if (SvTYPE(osv) >= SVt_PVMG && SvMAGIC(osv) && SvTYPE(osv) != SVt_PVGV) {
176 if (SvGMAGICAL(osv)) {
177 const bool oldtainted = PL_tainted;
178 SvFLAGS(osv) |= (SvFLAGS(osv) &
179 (SVp_IOK|SVp_NOK|SVp_POK)) >> PRIVSHIFT;
180 PL_tainted = oldtainted;
182 mg_localize(osv, sv, (flags & SAVEf_SETMAGIC) != 0);
188 Perl_save_pushptrptr(pTHX_ void *const ptr1, void *const ptr2, const int type)
198 Perl_save_scalar(pTHX_ GV *gv)
201 SV ** const sptr = &GvSVn(gv);
203 PERL_ARGS_ASSERT_SAVE_SCALAR;
208 save_pushptrptr(SvREFCNT_inc_simple(gv), SvREFCNT_inc(*sptr), SAVEt_SV);
209 return save_scalar_at(sptr, SAVEf_SETMAGIC); /* XXX - FIXME - see #60360 */
212 /* Like save_sptr(), but also SvREFCNT_dec()s the new value. Can be used to
213 * restore a global SV to its prior contents, freeing new value. */
215 Perl_save_generic_svref(pTHX_ SV **sptr)
219 PERL_ARGS_ASSERT_SAVE_GENERIC_SVREF;
221 save_pushptrptr(sptr, SvREFCNT_inc(*sptr), SAVEt_GENERIC_SVREF);
224 /* Like save_pptr(), but also Safefree()s the new value if it is different
225 * from the old one. Can be used to restore a global char* to its prior
226 * contents, freeing new value. */
228 Perl_save_generic_pvref(pTHX_ char **str)
232 PERL_ARGS_ASSERT_SAVE_GENERIC_PVREF;
234 save_pushptrptr(*str, str, SAVEt_GENERIC_PVREF);
237 /* Like save_generic_pvref(), but uses PerlMemShared_free() rather than Safefree().
238 * Can be used to restore a shared global char* to its prior
239 * contents, freeing new value. */
241 Perl_save_shared_pvref(pTHX_ char **str)
245 PERL_ARGS_ASSERT_SAVE_SHARED_PVREF;
247 save_pushptrptr(str, *str, SAVEt_SHARED_PVREF);
250 /* set the SvFLAGS specified by mask to the values in val */
253 Perl_save_set_svflags(pTHX_ SV* sv, U32 mask, U32 val)
257 PERL_ARGS_ASSERT_SAVE_SET_SVFLAGS;
263 SSPUSHINT(SAVEt_SET_SVFLAGS);
267 Perl_save_gp(pTHX_ GV *gv, I32 empty)
271 PERL_ARGS_ASSERT_SAVE_GP;
273 save_pushptrptr(SvREFCNT_inc(gv), GvGP(gv), SAVEt_GP);
276 GP *gp = Perl_newGP(aTHX_ gv);
279 mro_method_changed_in(GvSTASH(gv)); /* taking a method out of circulation ("local")*/
280 if (GvIOp(gv) && (IoFLAGS(GvIOp(gv)) & IOf_ARGV)) {
282 IoFLAGS(gp->gp_io) |= IOf_ARGV|IOf_START;
284 #ifdef PERL_DONT_CREATE_GVSV
285 if (gv == PL_errgv) {
286 /* We could scatter this logic everywhere by changing the
287 definition of ERRSV from GvSV() to GvSVn(), but it seems more
288 efficient to do this check once here. */
289 gp->gp_sv = newSV(0);
301 Perl_save_ary(pTHX_ GV *gv)
304 AV * const oav = GvAVn(gv);
307 PERL_ARGS_ASSERT_SAVE_ARY;
309 if (!AvREAL(oav) && AvREIFY(oav))
311 save_pushptrptr(gv, oav, SAVEt_AV);
316 mg_localize(MUTABLE_SV(oav), MUTABLE_SV(av), TRUE);
321 Perl_save_hash(pTHX_ GV *gv)
326 PERL_ARGS_ASSERT_SAVE_HASH;
328 save_pushptrptr(gv, (ohv = GvHVn(gv)), SAVEt_HV);
333 mg_localize(MUTABLE_SV(ohv), MUTABLE_SV(hv), TRUE);
338 Perl_save_item(pTHX_ register SV *item)
341 register SV * const sv = newSVsv(item);
343 PERL_ARGS_ASSERT_SAVE_ITEM;
345 save_pushptrptr(item, /* remember the pointer */
346 sv, /* remember the value */
351 Perl_save_bool(pTHX_ bool *boolp)
355 PERL_ARGS_ASSERT_SAVE_BOOL;
360 SSPUSHINT(SAVEt_BOOL);
364 Perl_save_pushi32ptr(pTHX_ const I32 i, void *const ptr, const int type)
374 Perl_save_int(pTHX_ int *intp)
378 PERL_ARGS_ASSERT_SAVE_INT;
380 save_pushi32ptr(*intp, intp, SAVEt_INT);
384 Perl_save_I8(pTHX_ I8 *bytep)
388 PERL_ARGS_ASSERT_SAVE_I8;
390 save_pushi32ptr(*bytep, bytep, SAVEt_I8);
394 Perl_save_I16(pTHX_ I16 *intp)
398 PERL_ARGS_ASSERT_SAVE_I16;
400 save_pushi32ptr(*intp, intp, SAVEt_I16);
404 Perl_save_I32(pTHX_ I32 *intp)
408 PERL_ARGS_ASSERT_SAVE_I32;
410 save_pushi32ptr(*intp, intp, SAVEt_I32);
413 /* Cannot use save_sptr() to store a char* since the SV** cast will
414 * force word-alignment and we'll miss the pointer.
417 Perl_save_pptr(pTHX_ char **pptr)
421 PERL_ARGS_ASSERT_SAVE_PPTR;
423 save_pushptrptr(*pptr, pptr, SAVEt_PPTR);
427 Perl_save_vptr(pTHX_ void *ptr)
431 PERL_ARGS_ASSERT_SAVE_VPTR;
433 save_pushptrptr(*(char**)ptr, ptr, SAVEt_VPTR);
437 Perl_save_sptr(pTHX_ SV **sptr)
441 PERL_ARGS_ASSERT_SAVE_SPTR;
443 save_pushptrptr(*sptr, sptr, SAVEt_SPTR);
447 Perl_save_padsv_and_mortalize(pTHX_ PADOFFSET off)
451 ASSERT_CURPAD_ACTIVE("save_padsv");
452 SSPUSHPTR(SvREFCNT_inc_simple_NN(PL_curpad[off]));
453 SSPUSHPTR(PL_comppad);
454 SSPUSHLONG((long)off);
455 SSPUSHINT(SAVEt_PADSV_AND_MORTALIZE);
459 Perl_save_hptr(pTHX_ HV **hptr)
463 PERL_ARGS_ASSERT_SAVE_HPTR;
465 save_pushptrptr(*hptr, hptr, SAVEt_HPTR);
469 Perl_save_aptr(pTHX_ AV **aptr)
473 PERL_ARGS_ASSERT_SAVE_APTR;
475 save_pushptrptr(*aptr, aptr, SAVEt_APTR);
479 Perl_save_pushptr(pTHX_ void *const ptr, const int type)
488 Perl_save_clearsv(pTHX_ SV **svp)
492 PERL_ARGS_ASSERT_SAVE_CLEARSV;
494 ASSERT_CURPAD_ACTIVE("save_clearsv");
496 SSPUSHLONG((long)(svp-PL_curpad));
497 SSPUSHINT(SAVEt_CLEARSV);
498 SvPADSTALE_off(*svp); /* mark lexical as active */
502 Perl_save_delete(pTHX_ HV *hv, char *key, I32 klen)
506 PERL_ARGS_ASSERT_SAVE_DELETE;
508 save_pushptri32ptr(key, klen, SvREFCNT_inc_simple(hv), SAVEt_DELETE);
512 Perl_save_destructor(pTHX_ DESTRUCTORFUNC_NOCONTEXT_t f, void* p)
516 PERL_ARGS_ASSERT_SAVE_DESTRUCTOR;
521 SSPUSHINT(SAVEt_DESTRUCTOR);
525 Perl_save_destructor_x(pTHX_ DESTRUCTORFUNC_t f, void* p)
531 SSPUSHINT(SAVEt_DESTRUCTOR_X);
535 Perl_save_hints(pTHX)
538 if (PL_compiling.cop_hints_hash) {
540 PL_compiling.cop_hints_hash->refcounted_he_refcnt++;
543 if (PL_hints & HINT_LOCALIZE_HH) {
544 save_pushptri32ptr(GvHV(PL_hintgv), PL_hints,
545 PL_compiling.cop_hints_hash, SAVEt_HINTS);
546 GvHV(PL_hintgv) = Perl_hv_copy_hints_hv(aTHX_ GvHV(PL_hintgv));
548 save_pushi32ptr(PL_hints, PL_compiling.cop_hints_hash, SAVEt_HINTS);
553 S_save_pushptri32ptr(pTHX_ void *const ptr1, const I32 i, void *const ptr2,
564 Perl_save_aelem(pTHX_ AV *av, I32 idx, SV **sptr)
569 PERL_ARGS_ASSERT_SAVE_AELEM;
572 save_pushptri32ptr(SvREFCNT_inc_simple(av), idx, SvREFCNT_inc(*sptr),
574 /* if it gets reified later, the restore will have the wrong refcnt */
575 if (!AvREAL(av) && AvREIFY(av))
576 SvREFCNT_inc_void(*sptr);
577 save_scalar_at(sptr, SAVEf_SETMAGIC); /* XXX - FIXME - see #60360 */
579 /* If we're localizing a tied array element, this new sv
580 * won't actually be stored in the array - so it won't get
581 * reaped when the localize ends. Ensure it gets reaped by
582 * mortifying it instead. DAPM */
583 if (SvTIED_mg(sv, PERL_MAGIC_tiedelem))
588 Perl_save_helem_flags(pTHX_ HV *hv, SV *key, SV **sptr, const U32 flags)
593 PERL_ARGS_ASSERT_SAVE_HELEM_FLAGS;
597 SSPUSHPTR(SvREFCNT_inc_simple(hv));
598 SSPUSHPTR(newSVsv(key));
599 SSPUSHPTR(SvREFCNT_inc(*sptr));
600 SSPUSHINT(SAVEt_HELEM);
601 save_scalar_at(sptr, flags);
603 /* If we're localizing a tied hash element, this new sv
604 * won't actually be stored in the hash - so it won't get
605 * reaped when the localize ends. Ensure it gets reaped by
606 * mortifying it instead. DAPM */
607 if (SvTIED_mg(sv, PERL_MAGIC_tiedelem))
612 Perl_save_svref(pTHX_ SV **sptr)
616 PERL_ARGS_ASSERT_SAVE_SVREF;
619 save_pushptrptr(sptr, SvREFCNT_inc(*sptr), SAVEt_SVREF);
620 return save_scalar_at(sptr, SAVEf_SETMAGIC); /* XXX - FIXME - see #60360 */
624 Perl_save_alloc(pTHX_ I32 size, I32 pad)
627 register const I32 start = pad + ((char*)&PL_savestack[PL_savestack_ix]
628 - (char*)PL_savestack);
629 register const I32 elems = 1 + ((size + pad - 1) / sizeof(*PL_savestack));
633 PL_savestack_ix += elems;
635 SSPUSHINT(SAVEt_ALLOC);
640 Perl_leave_scope(pTHX_ I32 base)
653 Perl_croak(aTHX_ "panic: corrupt saved stack index");
654 while (PL_savestack_ix > base) {
658 case SAVEt_ITEM: /* normal string */
659 value = MUTABLE_SV(SSPOPPTR);
660 sv = MUTABLE_SV(SSPOPPTR);
661 sv_replace(sv,value);
666 case SAVEt_SV: /* scalar reference */
667 value = MUTABLE_SV(SSPOPPTR);
668 gv = MUTABLE_GV(SSPOPPTR);
670 av = MUTABLE_AV(gv); /* what to refcnt_dec */
679 if (av) /* actually an av, hv or gv */
682 case SAVEt_GENERIC_PVREF: /* generic pv */
684 str = (char*)SSPOPPTR;
685 if (*(char**)ptr != str) {
686 Safefree(*(char**)ptr);
690 case SAVEt_SHARED_PVREF: /* shared pv */
691 str = (char*)SSPOPPTR;
693 if (*(char**)ptr != str) {
695 PerlMem_free(*(char**)ptr);
697 PerlMemShared_free(*(char**)ptr);
702 case SAVEt_GENERIC_SVREF: /* generic sv */
703 value = MUTABLE_SV(SSPOPPTR);
710 case SAVEt_AV: /* array reference */
711 av = MUTABLE_AV(SSPOPPTR);
712 gv = MUTABLE_GV(SSPOPPTR);
714 SvREFCNT_dec(GvAV(gv));
719 SvSETMAGIC(MUTABLE_SV(av));
723 case SAVEt_HV: /* hash reference */
724 hv = MUTABLE_HV(SSPOPPTR);
725 gv = MUTABLE_GV(SSPOPPTR);
727 SvREFCNT_dec(GvHV(gv));
732 SvSETMAGIC(MUTABLE_SV(hv));
736 case SAVEt_INT: /* int reference */
738 *(int*)ptr = (int)SSPOPINT;
740 case SAVEt_BOOL: /* bool reference */
742 *(bool*)ptr = (bool)SSPOPBOOL;
744 case SAVEt_I32: /* I32 reference */
746 #ifdef PERL_DEBUG_READONLY_OPS
748 const I32 val = SSPOPINT;
749 if (*(I32*)ptr != val)
753 *(I32*)ptr = (I32)SSPOPINT;
756 case SAVEt_SPTR: /* SV* reference */
758 *(SV**)ptr = MUTABLE_SV(SSPOPPTR);
760 case SAVEt_VPTR: /* random* reference */
761 case SAVEt_PPTR: /* char* reference */
763 *(char**)ptr = (char*)SSPOPPTR;
765 case SAVEt_HPTR: /* HV* reference */
767 *(HV**)ptr = MUTABLE_HV(SSPOPPTR);
769 case SAVEt_APTR: /* AV* reference */
771 *(AV**)ptr = MUTABLE_AV(SSPOPPTR);
773 case SAVEt_GP: /* scalar reference */
775 gv = MUTABLE_GV(SSPOPPTR);
778 /* putting a method back into circulation ("local")*/
779 if (GvCVu(gv) && (hv=GvSTASH(gv)) && HvNAME_get(hv))
780 mro_method_changed_in(hv);
785 SvREFCNT_dec(MUTABLE_SV(ptr));
787 case SAVEt_MORTALIZESV:
789 sv_2mortal(MUTABLE_SV(ptr));
793 ASSERT_CURPAD_LEGAL("SAVEt_FREEOP"); /* XXX DAPM tmp */
801 ptr = (void*)&PL_curpad[SSPOPLONG];
804 DEBUG_Xv(PerlIO_printf(Perl_debug_log,
805 "Pad 0x%"UVxf"[0x%"UVxf"] clearsv: %ld sv=0x%"UVxf"<%"IVdf"> %s\n",
806 PTR2UV(PL_comppad), PTR2UV(PL_curpad),
807 (long)((SV **)ptr-PL_curpad), PTR2UV(sv), (IV)SvREFCNT(sv),
808 (SvREFCNT(sv) <= 1 && !SvOBJECT(sv)) ? "clear" : "abandon"
811 /* Can clear pad variable in place? */
812 if (SvREFCNT(sv) <= 1 && !SvOBJECT(sv)) {
814 * if a my variable that was made readonly is going out of
815 * scope, we want to remove the readonlyness so that it can
816 * go out of scope quietly
818 if (SvPADMY(sv) && !SvFAKE(sv))
821 if (SvTHINKFIRST(sv))
822 sv_force_normal_flags(sv, SV_IMMEDIATE_UNREF);
826 switch (SvTYPE(sv)) {
830 av_clear(MUTABLE_AV(sv));
833 hv_clear(MUTABLE_HV(sv));
836 Perl_croak(aTHX_ "panic: leave_scope pad code");
841 SvPADSTALE_on(sv); /* mark as no longer live */
843 else { /* Someone has a claim on this, so abandon it. */
844 const U32 padflags = SvFLAGS(sv) & (SVs_PADMY|SVs_PADTMP);
845 switch (SvTYPE(sv)) { /* Console ourselves with a new value */
846 case SVt_PVAV: *(SV**)ptr = MUTABLE_SV(newAV()); break;
847 case SVt_PVHV: *(SV**)ptr = MUTABLE_SV(newHV()); break;
848 default: *(SV**)ptr = newSV(0); break;
850 SvREFCNT_dec(sv); /* Cast current value to the winds. */
851 /* preserve pad nature, but also mark as not live
852 * for any closure capturing */
853 SvFLAGS(*(SV**)ptr) |= padflags | SVs_PADSTALE;
858 hv = MUTABLE_HV(ptr);
861 (void)hv_delete(hv, (char*)ptr, i, G_DISCARD);
865 case SAVEt_DESTRUCTOR_X:
867 (*SSPOPDXPTR)(aTHX_ ptr);
869 case SAVEt_REGCONTEXT:
872 PL_savestack_ix -= i; /* regexp must have croaked */
874 case SAVEt_STACK_POS: /* Position on Perl stack */
876 PL_stack_sp = PL_stack_base + i;
878 case SAVEt_STACK_CXPOS: /* blk_oldsp on context stack */
880 cxstack[i].blk_oldsp = SSPOPINT;
882 case SAVEt_AELEM: /* array element */
883 value = MUTABLE_SV(SSPOPPTR);
885 av = MUTABLE_AV(SSPOPPTR);
886 ptr = av_fetch(av,i,1);
887 if (!AvREAL(av) && AvREIFY(av)) /* undo reify guard */
891 if (sv && sv != &PL_sv_undef) {
892 if (SvTIED_mg((const SV *)av, PERL_MAGIC_tied))
893 SvREFCNT_inc_void_NN(sv);
900 case SAVEt_HELEM: /* hash element */
901 value = MUTABLE_SV(SSPOPPTR);
902 sv = MUTABLE_SV(SSPOPPTR);
903 hv = MUTABLE_HV(SSPOPPTR);
904 ptr = hv_fetch_ent(hv, sv, 1, 0);
906 const SV * const oval = HeVAL((HE*)ptr);
907 if (oval && oval != &PL_sv_undef) {
908 ptr = &HeVAL((HE*)ptr);
909 if (SvTIED_mg((const SV *)hv, PERL_MAGIC_tied))
910 SvREFCNT_inc_void(*(SV**)ptr);
912 av = MUTABLE_AV(hv); /* what to refcnt_dec */
921 PL_op = (OP*)SSPOPPTR;
924 if ((PL_hints & HINT_LOCALIZE_HH) && GvHV(PL_hintgv)) {
925 SvREFCNT_dec(MUTABLE_SV(GvHV(PL_hintgv)));
926 GvHV(PL_hintgv) = NULL;
928 Perl_refcounted_he_free(aTHX_ PL_compiling.cop_hints_hash);
929 PL_compiling.cop_hints_hash = (struct refcounted_he *) SSPOPPTR;
930 *(I32*)&PL_hints = (I32)SSPOPINT;
931 if (PL_hints & HINT_LOCALIZE_HH) {
932 SvREFCNT_dec(MUTABLE_SV(GvHV(PL_hintgv)));
933 GvHV(PL_hintgv) = MUTABLE_HV(SSPOPPTR);
934 assert(GvHV(PL_hintgv));
935 } else if (!GvHV(PL_hintgv)) {
936 /* Need to add a new one manually, else gv_fetchpv() can
937 add one in this code:
939 if (SvTYPE(gv) == SVt_PVGV) {
942 gv_init_sv(gv, sv_type);
943 if (*name=='!' && sv_type == SVt_PVHV && len==1)
949 and it won't have the magic set. */
951 HV *const hv = newHV();
952 hv_magic(hv, NULL, PERL_MAGIC_hints);
953 GvHV(PL_hintgv) = hv;
955 assert(GvHV(PL_hintgv));
958 PL_comppad = (PAD*)SSPOPPTR;
960 PL_curpad = AvARRAY(PL_comppad);
964 case SAVEt_PADSV_AND_MORTALIZE:
966 const PADOFFSET off = (PADOFFSET)SSPOPLONG;
970 svp = AvARRAY((PAD*)ptr) + off;
971 /* This mortalizing used to be done by POPLOOP() via itersave.
972 But as we have all the information here, we can do it here,
973 save even having to have itersave in the struct. */
975 *svp = MUTABLE_SV(SSPOPPTR);
978 case SAVEt_SAVESWITCHSTACK:
981 AV *const t = MUTABLE_AV(SSPOPPTR);
982 AV *const f = MUTABLE_AV(SSPOPPTR);
984 PL_curstackinfo->si_stack = f;
987 case SAVEt_SET_SVFLAGS:
989 const U32 val = (U32)SSPOPINT;
990 const U32 mask = (U32)SSPOPINT;
991 sv = MUTABLE_SV(SSPOPPTR);
992 SvFLAGS(sv) &= ~mask;
997 /* This would be a mathom, but Perl_save_svref() calls a static
998 function, S_save_scalar_at(), so has to stay in this file. */
999 case SAVEt_SVREF: /* scalar reference */
1000 value = MUTABLE_SV(SSPOPPTR);
1002 av = NULL; /* what to refcnt_dec */
1005 /* These are only saved in mathoms.c */
1007 gv = MUTABLE_GV(SSPOPPTR);
1008 (void)sv_clear(MUTABLE_SV(gv));
1010 case SAVEt_LONG: /* long reference */
1012 *(long*)ptr = (long)SSPOPLONG;
1014 case SAVEt_IV: /* IV reference */
1016 *(IV*)ptr = (IV)SSPOPIV;
1019 case SAVEt_I16: /* I16 reference */
1021 *(I16*)ptr = (I16)SSPOPINT;
1023 case SAVEt_I8: /* I8 reference */
1025 *(I8*)ptr = (I8)SSPOPINT;
1027 case SAVEt_DESTRUCTOR:
1031 case SAVEt_COP_ARYBASE:
1034 CopARYBASE_set((COP *)ptr, i);
1036 case SAVEt_COMPILE_WARNINGS:
1039 if (!specialWARN(PL_compiling.cop_warnings))
1040 PerlMemShared_free(PL_compiling.cop_warnings);
1042 PL_compiling.cop_warnings = (STRLEN*)ptr;
1044 case SAVEt_RE_STATE:
1046 const struct re_save_state *const state
1047 = (struct re_save_state *)
1048 (PL_savestack + PL_savestack_ix
1049 - SAVESTACK_ALLOC_FOR_RE_SAVE_STATE);
1050 PL_savestack_ix -= SAVESTACK_ALLOC_FOR_RE_SAVE_STATE;
1052 if (PL_reg_start_tmp != state->re_state_reg_start_tmp) {
1053 Safefree(PL_reg_start_tmp);
1055 if (PL_reg_poscache != state->re_state_reg_poscache) {
1056 Safefree(PL_reg_poscache);
1058 Copy(state, &PL_reg_state, 1, struct re_save_state);
1063 parser_free((yy_parser *) ptr);
1066 Perl_croak(aTHX_ "panic: leave_scope inconsistency");
1072 Perl_cx_dump(pTHX_ PERL_CONTEXT *cx)
1076 PERL_ARGS_ASSERT_CX_DUMP;
1079 PerlIO_printf(Perl_debug_log, "CX %ld = %s\n", (long)(cx - cxstack), PL_block_type[CxTYPE(cx)]);
1080 if (CxTYPE(cx) != CXt_SUBST) {
1081 PerlIO_printf(Perl_debug_log, "BLK_OLDSP = %ld\n", (long)cx->blk_oldsp);
1082 PerlIO_printf(Perl_debug_log, "BLK_OLDCOP = 0x%"UVxf"\n",
1083 PTR2UV(cx->blk_oldcop));
1084 PerlIO_printf(Perl_debug_log, "BLK_OLDMARKSP = %ld\n", (long)cx->blk_oldmarksp);
1085 PerlIO_printf(Perl_debug_log, "BLK_OLDSCOPESP = %ld\n", (long)cx->blk_oldscopesp);
1086 PerlIO_printf(Perl_debug_log, "BLK_OLDPM = 0x%"UVxf"\n",
1087 PTR2UV(cx->blk_oldpm));
1088 PerlIO_printf(Perl_debug_log, "BLK_GIMME = %s\n", cx->blk_gimme ? "LIST" : "SCALAR");
1090 switch (CxTYPE(cx)) {
1095 PerlIO_printf(Perl_debug_log, "BLK_FORMAT.CV = 0x%"UVxf"\n",
1096 PTR2UV(cx->blk_format.cv));
1097 PerlIO_printf(Perl_debug_log, "BLK_FORMAT.GV = 0x%"UVxf"\n",
1098 PTR2UV(cx->blk_format.gv));
1099 PerlIO_printf(Perl_debug_log, "BLK_FORMAT.DFOUTGV = 0x%"UVxf"\n",
1100 PTR2UV(cx->blk_format.dfoutgv));
1101 PerlIO_printf(Perl_debug_log, "BLK_FORMAT.HASARGS = %d\n",
1102 (int)CxHASARGS(cx));
1103 PerlIO_printf(Perl_debug_log, "BLK_FORMAT.RETOP = 0x%"UVxf"\n",
1104 PTR2UV(cx->blk_format.retop));
1107 PerlIO_printf(Perl_debug_log, "BLK_SUB.CV = 0x%"UVxf"\n",
1108 PTR2UV(cx->blk_sub.cv));
1109 PerlIO_printf(Perl_debug_log, "BLK_SUB.OLDDEPTH = %ld\n",
1110 (long)cx->blk_sub.olddepth);
1111 PerlIO_printf(Perl_debug_log, "BLK_SUB.HASARGS = %d\n",
1112 (int)CxHASARGS(cx));
1113 PerlIO_printf(Perl_debug_log, "BLK_SUB.LVAL = %d\n", (int)CxLVAL(cx));
1114 PerlIO_printf(Perl_debug_log, "BLK_SUB.RETOP = 0x%"UVxf"\n",
1115 PTR2UV(cx->blk_sub.retop));
1118 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_IN_EVAL = %ld\n",
1119 (long)CxOLD_IN_EVAL(cx));
1120 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_OP_TYPE = %s (%s)\n",
1121 PL_op_name[CxOLD_OP_TYPE(cx)],
1122 PL_op_desc[CxOLD_OP_TYPE(cx)]);
1123 if (cx->blk_eval.old_namesv)
1124 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_NAME = %s\n",
1125 SvPVX_const(cx->blk_eval.old_namesv));
1126 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_EVAL_ROOT = 0x%"UVxf"\n",
1127 PTR2UV(cx->blk_eval.old_eval_root));
1128 PerlIO_printf(Perl_debug_log, "BLK_EVAL.RETOP = 0x%"UVxf"\n",
1129 PTR2UV(cx->blk_eval.retop));
1132 case CXt_LOOP_LAZYIV:
1133 case CXt_LOOP_LAZYSV:
1135 case CXt_LOOP_PLAIN:
1136 PerlIO_printf(Perl_debug_log, "BLK_LOOP.LABEL = %s\n", CxLABEL(cx));
1137 PerlIO_printf(Perl_debug_log, "BLK_LOOP.RESETSP = %ld\n",
1138 (long)cx->blk_loop.resetsp);
1139 PerlIO_printf(Perl_debug_log, "BLK_LOOP.MY_OP = 0x%"UVxf"\n",
1140 PTR2UV(cx->blk_loop.my_op));
1141 PerlIO_printf(Perl_debug_log, "BLK_LOOP.NEXT_OP = 0x%"UVxf"\n",
1142 PTR2UV(CX_LOOP_NEXTOP_GET(cx)));
1143 /* XXX: not accurate for LAZYSV/IV */
1144 PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERARY = 0x%"UVxf"\n",
1145 PTR2UV(cx->blk_loop.state_u.ary.ary));
1146 PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERIX = %ld\n",
1147 (long)cx->blk_loop.state_u.ary.ix);
1148 PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERVAR = 0x%"UVxf"\n",
1149 PTR2UV(CxITERVAR(cx)));
1153 PerlIO_printf(Perl_debug_log, "SB_ITERS = %ld\n",
1154 (long)cx->sb_iters);
1155 PerlIO_printf(Perl_debug_log, "SB_MAXITERS = %ld\n",
1156 (long)cx->sb_maxiters);
1157 PerlIO_printf(Perl_debug_log, "SB_RFLAGS = %ld\n",
1158 (long)cx->sb_rflags);
1159 PerlIO_printf(Perl_debug_log, "SB_ONCE = %ld\n",
1161 PerlIO_printf(Perl_debug_log, "SB_ORIG = %s\n",
1163 PerlIO_printf(Perl_debug_log, "SB_DSTR = 0x%"UVxf"\n",
1164 PTR2UV(cx->sb_dstr));
1165 PerlIO_printf(Perl_debug_log, "SB_TARG = 0x%"UVxf"\n",
1166 PTR2UV(cx->sb_targ));
1167 PerlIO_printf(Perl_debug_log, "SB_S = 0x%"UVxf"\n",
1169 PerlIO_printf(Perl_debug_log, "SB_M = 0x%"UVxf"\n",
1171 PerlIO_printf(Perl_debug_log, "SB_STREND = 0x%"UVxf"\n",
1172 PTR2UV(cx->sb_strend));
1173 PerlIO_printf(Perl_debug_log, "SB_RXRES = 0x%"UVxf"\n",
1174 PTR2UV(cx->sb_rxres));
1178 PERL_UNUSED_CONTEXT;
1179 PERL_UNUSED_ARG(cx);
1180 #endif /* DEBUGGING */
1185 * c-indentation-style: bsd
1187 * indent-tabs-mode: t
1190 * ex: set ts=8 sts=4 sw=4 noet: