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 Renew(PL_scopestack_name, PL_scopestack_max, const char*);
99 PL_scopestack_name[PL_scopestack_ix] = "unknown";
101 PL_scopestack[PL_scopestack_ix++] = PL_savestack_ix;
109 const I32 oldsave = PL_scopestack[--PL_scopestack_ix];
110 LEAVE_SCOPE(oldsave);
114 Perl_markstack_grow(pTHX)
117 const I32 oldmax = PL_markstack_max - PL_markstack;
118 const I32 newmax = GROW(oldmax);
120 Renew(PL_markstack, newmax, I32);
121 PL_markstack_ptr = PL_markstack + oldmax;
122 PL_markstack_max = PL_markstack + newmax;
126 Perl_savestack_grow(pTHX)
129 PL_savestack_max = GROW(PL_savestack_max) + 4;
130 Renew(PL_savestack, PL_savestack_max, ANY);
134 Perl_savestack_grow_cnt(pTHX_ I32 need)
137 PL_savestack_max = PL_savestack_ix + need;
138 Renew(PL_savestack, PL_savestack_max, ANY);
144 Perl_tmps_grow(pTHX_ I32 n)
147 #ifndef STRESS_REALLOC
149 n = (PL_tmps_max < 512) ? 128 : 512;
151 PL_tmps_max = PL_tmps_ix + n + 1;
152 Renew(PL_tmps_stack, PL_tmps_max, SV*);
160 /* XXX should tmps_floor live in cxstack? */
161 const I32 myfloor = PL_tmps_floor;
162 while (PL_tmps_ix > myfloor) { /* clean up after last statement */
163 SV* const sv = PL_tmps_stack[PL_tmps_ix];
164 PL_tmps_stack[PL_tmps_ix--] = NULL;
165 if (sv && sv != &PL_sv_undef) {
167 SvREFCNT_dec(sv); /* note, can modify tmps_ix!!! */
173 S_save_scalar_at(pTHX_ SV **sptr, const U32 flags)
179 PERL_ARGS_ASSERT_SAVE_SCALAR_AT;
182 sv = (flags & SAVEf_KEEPOLDELEM) ? osv : (*sptr = newSV(0));
184 if (SvTYPE(osv) >= SVt_PVMG && SvMAGIC(osv) && SvTYPE(osv) != SVt_PVGV) {
185 if (SvGMAGICAL(osv)) {
186 const bool oldtainted = PL_tainted;
187 SvFLAGS(osv) |= (SvFLAGS(osv) &
188 (SVp_IOK|SVp_NOK|SVp_POK)) >> PRIVSHIFT;
189 PL_tainted = oldtainted;
191 if (!(flags & SAVEf_KEEPOLDELEM))
192 mg_localize(osv, sv, (flags & SAVEf_SETMAGIC) != 0);
199 Perl_save_pushptrptr(pTHX_ void *const ptr1, void *const ptr2, const int type)
209 Perl_save_scalar(pTHX_ GV *gv)
212 SV ** const sptr = &GvSVn(gv);
214 PERL_ARGS_ASSERT_SAVE_SCALAR;
219 save_pushptrptr(SvREFCNT_inc_simple(gv), SvREFCNT_inc(*sptr), SAVEt_SV);
220 return save_scalar_at(sptr, SAVEf_SETMAGIC); /* XXX - FIXME - see #60360 */
223 /* Like save_sptr(), but also SvREFCNT_dec()s the new value. Can be used to
224 * restore a global SV to its prior contents, freeing new value. */
226 Perl_save_generic_svref(pTHX_ SV **sptr)
230 PERL_ARGS_ASSERT_SAVE_GENERIC_SVREF;
232 save_pushptrptr(sptr, SvREFCNT_inc(*sptr), SAVEt_GENERIC_SVREF);
235 /* Like save_pptr(), but also Safefree()s the new value if it is different
236 * from the old one. Can be used to restore a global char* to its prior
237 * contents, freeing new value. */
239 Perl_save_generic_pvref(pTHX_ char **str)
243 PERL_ARGS_ASSERT_SAVE_GENERIC_PVREF;
245 save_pushptrptr(*str, str, SAVEt_GENERIC_PVREF);
248 /* Like save_generic_pvref(), but uses PerlMemShared_free() rather than Safefree().
249 * Can be used to restore a shared global char* to its prior
250 * contents, freeing new value. */
252 Perl_save_shared_pvref(pTHX_ char **str)
256 PERL_ARGS_ASSERT_SAVE_SHARED_PVREF;
258 save_pushptrptr(str, *str, SAVEt_SHARED_PVREF);
261 /* set the SvFLAGS specified by mask to the values in val */
264 Perl_save_set_svflags(pTHX_ SV* sv, U32 mask, U32 val)
268 PERL_ARGS_ASSERT_SAVE_SET_SVFLAGS;
274 SSPUSHUV(SAVEt_SET_SVFLAGS);
278 Perl_save_gp(pTHX_ GV *gv, I32 empty)
282 PERL_ARGS_ASSERT_SAVE_GP;
285 SSPUSHINT(SvFAKE(gv));
287 SSPUSHPTR(SvREFCNT_inc(gv));
290 /* Don't let the localized GV coerce into non-glob, otherwise we would
291 * not be able to restore GP upon leave from context if that happened */
295 GP *gp = Perl_newGP(aTHX_ gv);
298 mro_method_changed_in(GvSTASH(gv)); /* taking a method out of circulation ("local")*/
299 if (GvIOp(gv) && (IoFLAGS(GvIOp(gv)) & IOf_ARGV)) {
301 IoFLAGS(gp->gp_io) |= IOf_ARGV|IOf_START;
303 #ifdef PERL_DONT_CREATE_GVSV
304 if (gv == PL_errgv) {
305 /* We could scatter this logic everywhere by changing the
306 definition of ERRSV from GvSV() to GvSVn(), but it seems more
307 efficient to do this check once here. */
308 gp->gp_sv = newSV(0);
320 Perl_save_ary(pTHX_ GV *gv)
323 AV * const oav = GvAVn(gv);
326 PERL_ARGS_ASSERT_SAVE_ARY;
328 if (!AvREAL(oav) && AvREIFY(oav))
330 save_pushptrptr(gv, oav, SAVEt_AV);
335 mg_localize(MUTABLE_SV(oav), MUTABLE_SV(av), TRUE);
340 Perl_save_hash(pTHX_ GV *gv)
345 PERL_ARGS_ASSERT_SAVE_HASH;
347 save_pushptrptr(gv, (ohv = GvHVn(gv)), SAVEt_HV);
352 mg_localize(MUTABLE_SV(ohv), MUTABLE_SV(hv), TRUE);
357 Perl_save_item(pTHX_ register SV *item)
360 register SV * const sv = newSVsv(item);
362 PERL_ARGS_ASSERT_SAVE_ITEM;
364 save_pushptrptr(item, /* remember the pointer */
365 sv, /* remember the value */
370 Perl_save_bool(pTHX_ bool *boolp)
374 PERL_ARGS_ASSERT_SAVE_BOOL;
378 SSPUSHUV(SAVEt_BOOL | (*boolp << 8));
382 Perl_save_pushi32ptr(pTHX_ const I32 i, void *const ptr, const int type)
392 Perl_save_int(pTHX_ int *intp)
396 PERL_ARGS_ASSERT_SAVE_INT;
398 save_pushi32ptr(*intp, intp, SAVEt_INT);
402 Perl_save_I8(pTHX_ I8 *bytep)
406 PERL_ARGS_ASSERT_SAVE_I8;
408 save_pushi32ptr(*bytep, bytep, SAVEt_I8);
412 Perl_save_I16(pTHX_ I16 *intp)
416 PERL_ARGS_ASSERT_SAVE_I16;
418 save_pushi32ptr(*intp, intp, SAVEt_I16);
422 Perl_save_I32(pTHX_ I32 *intp)
426 PERL_ARGS_ASSERT_SAVE_I32;
428 save_pushi32ptr(*intp, intp, SAVEt_I32);
431 /* Cannot use save_sptr() to store a char* since the SV** cast will
432 * force word-alignment and we'll miss the pointer.
435 Perl_save_pptr(pTHX_ char **pptr)
439 PERL_ARGS_ASSERT_SAVE_PPTR;
441 save_pushptrptr(*pptr, pptr, SAVEt_PPTR);
445 Perl_save_vptr(pTHX_ void *ptr)
449 PERL_ARGS_ASSERT_SAVE_VPTR;
451 save_pushptrptr(*(char**)ptr, ptr, SAVEt_VPTR);
455 Perl_save_sptr(pTHX_ SV **sptr)
459 PERL_ARGS_ASSERT_SAVE_SPTR;
461 save_pushptrptr(*sptr, sptr, SAVEt_SPTR);
465 Perl_save_padsv_and_mortalize(pTHX_ PADOFFSET off)
469 ASSERT_CURPAD_ACTIVE("save_padsv");
470 SSPUSHPTR(SvREFCNT_inc_simple_NN(PL_curpad[off]));
471 SSPUSHPTR(PL_comppad);
472 SSPUSHLONG((long)off);
473 SSPUSHUV(SAVEt_PADSV_AND_MORTALIZE);
477 Perl_save_hptr(pTHX_ HV **hptr)
481 PERL_ARGS_ASSERT_SAVE_HPTR;
483 save_pushptrptr(*hptr, hptr, SAVEt_HPTR);
487 Perl_save_aptr(pTHX_ AV **aptr)
491 PERL_ARGS_ASSERT_SAVE_APTR;
493 save_pushptrptr(*aptr, aptr, SAVEt_APTR);
497 Perl_save_pushptr(pTHX_ void *const ptr, const int type)
506 Perl_save_clearsv(pTHX_ SV **svp)
509 const UV offset = svp - PL_curpad;
510 const UV offset_shifted = offset << SAVE_TIGHT_SHIFT;
512 PERL_ARGS_ASSERT_SAVE_CLEARSV;
514 ASSERT_CURPAD_ACTIVE("save_clearsv");
515 if ((offset_shifted >> SAVE_TIGHT_SHIFT) != offset)
516 Perl_croak(aTHX_ "panic: pad offset %"UVuf" out of range (%p-%p)",
517 offset, svp, PL_curpad);
520 SSPUSHUV(offset_shifted | SAVEt_CLEARSV);
521 SvPADSTALE_off(*svp); /* mark lexical as active */
525 Perl_save_delete(pTHX_ HV *hv, char *key, I32 klen)
529 PERL_ARGS_ASSERT_SAVE_DELETE;
531 save_pushptri32ptr(key, klen, SvREFCNT_inc_simple(hv), SAVEt_DELETE);
535 Perl_save_hdelete(pTHX_ HV *hv, SV *keysv)
541 PERL_ARGS_ASSERT_SAVE_HDELETE;
543 key = SvPV_const(keysv, len);
544 klen = SvUTF8(keysv) ? -(I32)len : (I32)len;
545 SvREFCNT_inc_simple_void_NN(hv);
546 save_pushptri32ptr(savepvn(key, len), klen, hv, SAVEt_DELETE);
550 Perl_save_adelete(pTHX_ AV *av, I32 key)
554 PERL_ARGS_ASSERT_SAVE_ADELETE;
556 SvREFCNT_inc_void(av);
557 save_pushi32ptr(key, av, SAVEt_ADELETE);
561 Perl_save_destructor(pTHX_ DESTRUCTORFUNC_NOCONTEXT_t f, void* p)
565 PERL_ARGS_ASSERT_SAVE_DESTRUCTOR;
570 SSPUSHUV(SAVEt_DESTRUCTOR);
574 Perl_save_destructor_x(pTHX_ DESTRUCTORFUNC_t f, void* p)
580 SSPUSHUV(SAVEt_DESTRUCTOR_X);
584 Perl_save_hints(pTHX)
587 if (PL_compiling.cop_hints_hash) {
589 PL_compiling.cop_hints_hash->refcounted_he_refcnt++;
592 if (PL_hints & HINT_LOCALIZE_HH) {
593 save_pushptri32ptr(GvHV(PL_hintgv), PL_hints,
594 PL_compiling.cop_hints_hash, SAVEt_HINTS);
595 GvHV(PL_hintgv) = Perl_hv_copy_hints_hv(aTHX_ GvHV(PL_hintgv));
597 save_pushi32ptr(PL_hints, PL_compiling.cop_hints_hash, SAVEt_HINTS);
602 S_save_pushptri32ptr(pTHX_ void *const ptr1, const I32 i, void *const ptr2,
613 Perl_save_aelem_flags(pTHX_ AV *av, I32 idx, SV **sptr, const U32 flags)
618 PERL_ARGS_ASSERT_SAVE_AELEM_FLAGS;
621 save_pushptri32ptr(SvREFCNT_inc_simple(av), idx, SvREFCNT_inc(*sptr),
623 /* if it gets reified later, the restore will have the wrong refcnt */
624 if (!AvREAL(av) && AvREIFY(av))
625 SvREFCNT_inc_void(*sptr);
626 save_scalar_at(sptr, flags); /* XXX - FIXME - see #60360 */
627 if (flags & SAVEf_KEEPOLDELEM)
630 /* If we're localizing a tied array element, this new sv
631 * won't actually be stored in the array - so it won't get
632 * reaped when the localize ends. Ensure it gets reaped by
633 * mortifying it instead. DAPM */
634 if (SvTIED_mg((const SV *)av, PERL_MAGIC_tied))
639 Perl_save_helem_flags(pTHX_ HV *hv, SV *key, SV **sptr, const U32 flags)
644 PERL_ARGS_ASSERT_SAVE_HELEM_FLAGS;
648 SSPUSHPTR(SvREFCNT_inc_simple(hv));
649 SSPUSHPTR(newSVsv(key));
650 SSPUSHPTR(SvREFCNT_inc(*sptr));
651 SSPUSHUV(SAVEt_HELEM);
652 save_scalar_at(sptr, flags);
653 if (flags & SAVEf_KEEPOLDELEM)
656 /* If we're localizing a tied hash element, this new sv
657 * won't actually be stored in the hash - so it won't get
658 * reaped when the localize ends. Ensure it gets reaped by
659 * mortifying it instead. DAPM */
660 if (SvTIED_mg((const SV *)hv, PERL_MAGIC_tied))
665 Perl_save_svref(pTHX_ SV **sptr)
669 PERL_ARGS_ASSERT_SAVE_SVREF;
672 save_pushptrptr(sptr, SvREFCNT_inc(*sptr), SAVEt_SVREF);
673 return save_scalar_at(sptr, SAVEf_SETMAGIC); /* XXX - FIXME - see #60360 */
677 Perl_save_alloc(pTHX_ I32 size, I32 pad)
680 register const I32 start = pad + ((char*)&PL_savestack[PL_savestack_ix]
681 - (char*)PL_savestack);
682 const UV elems = 1 + ((size + pad - 1) / sizeof(*PL_savestack));
683 const UV elems_shifted = elems << SAVE_TIGHT_SHIFT;
685 if ((elems_shifted >> SAVE_TIGHT_SHIFT) != elems)
686 Perl_croak(aTHX_ "panic: save_alloc elems %"UVuf" out of range (%ld-%ld)",
691 PL_savestack_ix += elems;
692 SSPUSHUV(SAVEt_ALLOC | elems_shifted);
697 Perl_leave_scope(pTHX_ I32 base)
708 /* Localise the effects of the TAINT_NOT inside the loop. */
709 const bool was = PL_tainted;
712 Perl_croak(aTHX_ "panic: corrupt saved stack index");
713 DEBUG_l(Perl_deb(aTHX_ "savestack: releasing items %ld -> %ld\n",
714 (long)PL_savestack_ix, (long)base));
715 while (PL_savestack_ix > base) {
717 const U8 type = (U8)uv & SAVE_MASK;
721 case SAVEt_ITEM: /* normal string */
722 value = MUTABLE_SV(SSPOPPTR);
723 sv = MUTABLE_SV(SSPOPPTR);
724 sv_replace(sv,value);
729 case SAVEt_SV: /* scalar reference */
730 value = MUTABLE_SV(SSPOPPTR);
731 gv = MUTABLE_GV(SSPOPPTR);
733 av = MUTABLE_AV(gv); /* what to refcnt_dec */
742 if (av) /* actually an av, hv or gv */
745 case SAVEt_GENERIC_PVREF: /* generic pv */
747 str = (char*)SSPOPPTR;
748 if (*(char**)ptr != str) {
749 Safefree(*(char**)ptr);
753 case SAVEt_SHARED_PVREF: /* shared pv */
754 str = (char*)SSPOPPTR;
756 if (*(char**)ptr != str) {
758 PerlMem_free(*(char**)ptr);
760 PerlMemShared_free(*(char**)ptr);
765 case SAVEt_GENERIC_SVREF: /* generic sv */
766 value = MUTABLE_SV(SSPOPPTR);
773 case SAVEt_AV: /* array reference */
774 av = MUTABLE_AV(SSPOPPTR);
775 gv = MUTABLE_GV(SSPOPPTR);
776 SvREFCNT_dec(GvAV(gv));
780 SvSETMAGIC(MUTABLE_SV(av));
784 case SAVEt_HV: /* hash reference */
785 hv = MUTABLE_HV(SSPOPPTR);
786 gv = MUTABLE_GV(SSPOPPTR);
787 SvREFCNT_dec(GvHV(gv));
791 SvSETMAGIC(MUTABLE_SV(hv));
795 case SAVEt_INT: /* int reference */
797 *(int*)ptr = (int)SSPOPINT;
799 case SAVEt_BOOL: /* bool reference */
801 *(bool*)ptr = cBOOL(uv >> 8);
803 case SAVEt_I32: /* I32 reference */
805 #ifdef PERL_DEBUG_READONLY_OPS
807 const I32 val = SSPOPINT;
808 if (*(I32*)ptr != val)
812 *(I32*)ptr = (I32)SSPOPINT;
815 case SAVEt_SPTR: /* SV* reference */
817 *(SV**)ptr = MUTABLE_SV(SSPOPPTR);
819 case SAVEt_VPTR: /* random* reference */
820 case SAVEt_PPTR: /* char* reference */
822 *(char**)ptr = (char*)SSPOPPTR;
824 case SAVEt_HPTR: /* HV* reference */
826 *(HV**)ptr = MUTABLE_HV(SSPOPPTR);
828 case SAVEt_APTR: /* AV* reference */
830 *(AV**)ptr = MUTABLE_AV(SSPOPPTR);
832 case SAVEt_GP: /* scalar reference */
833 gv = MUTABLE_GV(SSPOPPTR);
835 GvGP(gv) = (GP*)SSPOPPTR;
838 /* putting a method back into circulation ("local")*/
839 if (GvCVu(gv) && (hv=GvSTASH(gv)) && HvNAME_get(hv))
840 mro_method_changed_in(hv);
845 SvREFCNT_dec(MUTABLE_SV(ptr));
847 case SAVEt_MORTALIZESV:
849 sv_2mortal(MUTABLE_SV(ptr));
853 ASSERT_CURPAD_LEGAL("SAVEt_FREEOP"); /* XXX DAPM tmp */
861 ptr = (void*)&PL_curpad[uv >> SAVE_TIGHT_SHIFT];
864 DEBUG_Xv(PerlIO_printf(Perl_debug_log,
865 "Pad 0x%"UVxf"[0x%"UVxf"] clearsv: %ld sv=0x%"UVxf"<%"IVdf"> %s\n",
866 PTR2UV(PL_comppad), PTR2UV(PL_curpad),
867 (long)((SV **)ptr-PL_curpad), PTR2UV(sv), (IV)SvREFCNT(sv),
868 (SvREFCNT(sv) <= 1 && !SvOBJECT(sv)) ? "clear" : "abandon"
871 /* Can clear pad variable in place? */
872 if (SvREFCNT(sv) <= 1 && !SvOBJECT(sv)) {
874 * if a my variable that was made readonly is going out of
875 * scope, we want to remove the readonlyness so that it can
876 * go out of scope quietly
878 if (SvPADMY(sv) && !SvFAKE(sv))
881 if (SvTHINKFIRST(sv))
882 sv_force_normal_flags(sv, SV_IMMEDIATE_UNREF);
886 switch (SvTYPE(sv)) {
890 av_clear(MUTABLE_AV(sv));
893 hv_clear(MUTABLE_HV(sv));
896 Perl_croak(aTHX_ "panic: leave_scope pad code");
901 SvPADSTALE_on(sv); /* mark as no longer live */
903 else { /* Someone has a claim on this, so abandon it. */
904 const U32 padflags = SvFLAGS(sv) & (SVs_PADMY|SVs_PADTMP);
905 switch (SvTYPE(sv)) { /* Console ourselves with a new value */
906 case SVt_PVAV: *(SV**)ptr = MUTABLE_SV(newAV()); break;
907 case SVt_PVHV: *(SV**)ptr = MUTABLE_SV(newHV()); break;
908 default: *(SV**)ptr = newSV(0); break;
910 SvREFCNT_dec(sv); /* Cast current value to the winds. */
911 /* preserve pad nature, but also mark as not live
912 * for any closure capturing */
913 SvFLAGS(*(SV**)ptr) |= padflags | SVs_PADSTALE;
918 hv = MUTABLE_HV(ptr);
921 (void)hv_delete(hv, (char*)ptr, i, G_DISCARD);
927 av = MUTABLE_AV(ptr);
929 (void)av_delete(av, i, G_DISCARD);
932 case SAVEt_DESTRUCTOR_X:
934 (*SSPOPDXPTR)(aTHX_ ptr);
936 case SAVEt_REGCONTEXT:
937 /* regexp must have croaked */
939 PL_savestack_ix -= uv >> SAVE_TIGHT_SHIFT;
941 case SAVEt_STACK_POS: /* Position on Perl stack */
943 PL_stack_sp = PL_stack_base + i;
945 case SAVEt_STACK_CXPOS: /* blk_oldsp on context stack */
947 cxstack[i].blk_oldsp = SSPOPINT;
949 case SAVEt_AELEM: /* array element */
950 value = MUTABLE_SV(SSPOPPTR);
952 av = MUTABLE_AV(SSPOPPTR);
953 ptr = av_fetch(av,i,1);
954 if (!AvREAL(av) && AvREIFY(av)) /* undo reify guard */
958 if (sv && sv != &PL_sv_undef) {
959 if (SvTIED_mg((const SV *)av, PERL_MAGIC_tied))
960 SvREFCNT_inc_void_NN(sv);
967 case SAVEt_HELEM: /* hash element */
968 value = MUTABLE_SV(SSPOPPTR);
969 sv = MUTABLE_SV(SSPOPPTR);
970 hv = MUTABLE_HV(SSPOPPTR);
971 ptr = hv_fetch_ent(hv, sv, 1, 0);
974 const SV * const oval = HeVAL((HE*)ptr);
975 if (oval && oval != &PL_sv_undef) {
976 ptr = &HeVAL((HE*)ptr);
977 if (SvTIED_mg((const SV *)hv, PERL_MAGIC_tied))
978 SvREFCNT_inc_void(*(SV**)ptr);
979 av = MUTABLE_AV(hv); /* what to refcnt_dec */
987 PL_op = (OP*)SSPOPPTR;
990 if ((PL_hints & HINT_LOCALIZE_HH) && GvHV(PL_hintgv)) {
991 SvREFCNT_dec(MUTABLE_SV(GvHV(PL_hintgv)));
992 GvHV(PL_hintgv) = NULL;
994 Perl_refcounted_he_free(aTHX_ PL_compiling.cop_hints_hash);
995 PL_compiling.cop_hints_hash = (struct refcounted_he *) SSPOPPTR;
996 *(I32*)&PL_hints = (I32)SSPOPINT;
997 if (PL_hints & HINT_LOCALIZE_HH) {
998 SvREFCNT_dec(MUTABLE_SV(GvHV(PL_hintgv)));
999 GvHV(PL_hintgv) = MUTABLE_HV(SSPOPPTR);
1000 assert(GvHV(PL_hintgv));
1001 } else if (!GvHV(PL_hintgv)) {
1002 /* Need to add a new one manually, else gv_fetchpv() can
1003 add one in this code:
1005 if (SvTYPE(gv) == SVt_PVGV) {
1008 gv_init_sv(gv, sv_type);
1009 if (*name=='!' && sv_type == SVt_PVHV && len==1)
1015 and it won't have the magic set. */
1017 HV *const hv = newHV();
1018 hv_magic(hv, NULL, PERL_MAGIC_hints);
1019 GvHV(PL_hintgv) = hv;
1021 assert(GvHV(PL_hintgv));
1024 PL_comppad = (PAD*)SSPOPPTR;
1026 PL_curpad = AvARRAY(PL_comppad);
1030 case SAVEt_PADSV_AND_MORTALIZE:
1032 const PADOFFSET off = (PADOFFSET)SSPOPLONG;
1036 svp = AvARRAY((PAD*)ptr) + off;
1037 /* This mortalizing used to be done by POPLOOP() via itersave.
1038 But as we have all the information here, we can do it here,
1039 save even having to have itersave in the struct. */
1041 *svp = MUTABLE_SV(SSPOPPTR);
1044 case SAVEt_SAVESWITCHSTACK:
1047 AV *const t = MUTABLE_AV(SSPOPPTR);
1048 AV *const f = MUTABLE_AV(SSPOPPTR);
1050 PL_curstackinfo->si_stack = f;
1053 case SAVEt_SET_SVFLAGS:
1055 const U32 val = (U32)SSPOPINT;
1056 const U32 mask = (U32)SSPOPINT;
1057 sv = MUTABLE_SV(SSPOPPTR);
1058 SvFLAGS(sv) &= ~mask;
1063 /* This would be a mathom, but Perl_save_svref() calls a static
1064 function, S_save_scalar_at(), so has to stay in this file. */
1065 case SAVEt_SVREF: /* scalar reference */
1066 value = MUTABLE_SV(SSPOPPTR);
1068 av = NULL; /* what to refcnt_dec */
1071 /* These are only saved in mathoms.c */
1073 gv = MUTABLE_GV(SSPOPPTR);
1074 (void)sv_clear(MUTABLE_SV(gv));
1076 case SAVEt_LONG: /* long reference */
1078 *(long*)ptr = (long)SSPOPLONG;
1080 case SAVEt_IV: /* IV reference */
1082 *(IV*)ptr = (IV)SSPOPIV;
1085 case SAVEt_I16: /* I16 reference */
1087 *(I16*)ptr = (I16)SSPOPINT;
1089 case SAVEt_I8: /* I8 reference */
1091 *(I8*)ptr = (I8)SSPOPINT;
1093 case SAVEt_DESTRUCTOR:
1097 case SAVEt_COP_ARYBASE:
1100 CopARYBASE_set((COP *)ptr, i);
1102 case SAVEt_COMPILE_WARNINGS:
1105 if (!specialWARN(PL_compiling.cop_warnings))
1106 PerlMemShared_free(PL_compiling.cop_warnings);
1108 PL_compiling.cop_warnings = (STRLEN*)ptr;
1110 case SAVEt_RE_STATE:
1112 const struct re_save_state *const state
1113 = (struct re_save_state *)
1114 (PL_savestack + PL_savestack_ix
1115 - SAVESTACK_ALLOC_FOR_RE_SAVE_STATE);
1116 PL_savestack_ix -= SAVESTACK_ALLOC_FOR_RE_SAVE_STATE;
1118 if (PL_reg_start_tmp != state->re_state_reg_start_tmp) {
1119 Safefree(PL_reg_start_tmp);
1121 if (PL_reg_poscache != state->re_state_reg_poscache) {
1122 Safefree(PL_reg_poscache);
1124 Copy(state, &PL_reg_state, 1, struct re_save_state);
1129 parser_free((yy_parser *) ptr);
1132 Perl_croak(aTHX_ "panic: leave_scope inconsistency");
1142 Perl_cx_dump(pTHX_ PERL_CONTEXT *cx)
1146 PERL_ARGS_ASSERT_CX_DUMP;
1149 PerlIO_printf(Perl_debug_log, "CX %ld = %s\n", (long)(cx - cxstack), PL_block_type[CxTYPE(cx)]);
1150 if (CxTYPE(cx) != CXt_SUBST) {
1151 PerlIO_printf(Perl_debug_log, "BLK_OLDSP = %ld\n", (long)cx->blk_oldsp);
1152 PerlIO_printf(Perl_debug_log, "BLK_OLDCOP = 0x%"UVxf"\n",
1153 PTR2UV(cx->blk_oldcop));
1154 PerlIO_printf(Perl_debug_log, "BLK_OLDMARKSP = %ld\n", (long)cx->blk_oldmarksp);
1155 PerlIO_printf(Perl_debug_log, "BLK_OLDSCOPESP = %ld\n", (long)cx->blk_oldscopesp);
1156 PerlIO_printf(Perl_debug_log, "BLK_OLDPM = 0x%"UVxf"\n",
1157 PTR2UV(cx->blk_oldpm));
1158 PerlIO_printf(Perl_debug_log, "BLK_GIMME = %s\n", cx->blk_gimme ? "LIST" : "SCALAR");
1160 switch (CxTYPE(cx)) {
1165 PerlIO_printf(Perl_debug_log, "BLK_FORMAT.CV = 0x%"UVxf"\n",
1166 PTR2UV(cx->blk_format.cv));
1167 PerlIO_printf(Perl_debug_log, "BLK_FORMAT.GV = 0x%"UVxf"\n",
1168 PTR2UV(cx->blk_format.gv));
1169 PerlIO_printf(Perl_debug_log, "BLK_FORMAT.DFOUTGV = 0x%"UVxf"\n",
1170 PTR2UV(cx->blk_format.dfoutgv));
1171 PerlIO_printf(Perl_debug_log, "BLK_FORMAT.HASARGS = %d\n",
1172 (int)CxHASARGS(cx));
1173 PerlIO_printf(Perl_debug_log, "BLK_FORMAT.RETOP = 0x%"UVxf"\n",
1174 PTR2UV(cx->blk_format.retop));
1177 PerlIO_printf(Perl_debug_log, "BLK_SUB.CV = 0x%"UVxf"\n",
1178 PTR2UV(cx->blk_sub.cv));
1179 PerlIO_printf(Perl_debug_log, "BLK_SUB.OLDDEPTH = %ld\n",
1180 (long)cx->blk_sub.olddepth);
1181 PerlIO_printf(Perl_debug_log, "BLK_SUB.HASARGS = %d\n",
1182 (int)CxHASARGS(cx));
1183 PerlIO_printf(Perl_debug_log, "BLK_SUB.LVAL = %d\n", (int)CxLVAL(cx));
1184 PerlIO_printf(Perl_debug_log, "BLK_SUB.RETOP = 0x%"UVxf"\n",
1185 PTR2UV(cx->blk_sub.retop));
1188 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_IN_EVAL = %ld\n",
1189 (long)CxOLD_IN_EVAL(cx));
1190 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_OP_TYPE = %s (%s)\n",
1191 PL_op_name[CxOLD_OP_TYPE(cx)],
1192 PL_op_desc[CxOLD_OP_TYPE(cx)]);
1193 if (cx->blk_eval.old_namesv)
1194 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_NAME = %s\n",
1195 SvPVX_const(cx->blk_eval.old_namesv));
1196 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_EVAL_ROOT = 0x%"UVxf"\n",
1197 PTR2UV(cx->blk_eval.old_eval_root));
1198 PerlIO_printf(Perl_debug_log, "BLK_EVAL.RETOP = 0x%"UVxf"\n",
1199 PTR2UV(cx->blk_eval.retop));
1202 case CXt_LOOP_LAZYIV:
1203 case CXt_LOOP_LAZYSV:
1205 case CXt_LOOP_PLAIN:
1206 PerlIO_printf(Perl_debug_log, "BLK_LOOP.LABEL = %s\n", CxLABEL(cx));
1207 PerlIO_printf(Perl_debug_log, "BLK_LOOP.RESETSP = %ld\n",
1208 (long)cx->blk_loop.resetsp);
1209 PerlIO_printf(Perl_debug_log, "BLK_LOOP.MY_OP = 0x%"UVxf"\n",
1210 PTR2UV(cx->blk_loop.my_op));
1211 PerlIO_printf(Perl_debug_log, "BLK_LOOP.NEXT_OP = 0x%"UVxf"\n",
1212 PTR2UV(CX_LOOP_NEXTOP_GET(cx)));
1213 /* XXX: not accurate for LAZYSV/IV */
1214 PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERARY = 0x%"UVxf"\n",
1215 PTR2UV(cx->blk_loop.state_u.ary.ary));
1216 PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERIX = %ld\n",
1217 (long)cx->blk_loop.state_u.ary.ix);
1218 PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERVAR = 0x%"UVxf"\n",
1219 PTR2UV(CxITERVAR(cx)));
1223 PerlIO_printf(Perl_debug_log, "SB_ITERS = %ld\n",
1224 (long)cx->sb_iters);
1225 PerlIO_printf(Perl_debug_log, "SB_MAXITERS = %ld\n",
1226 (long)cx->sb_maxiters);
1227 PerlIO_printf(Perl_debug_log, "SB_RFLAGS = %ld\n",
1228 (long)cx->sb_rflags);
1229 PerlIO_printf(Perl_debug_log, "SB_ONCE = %ld\n",
1231 PerlIO_printf(Perl_debug_log, "SB_ORIG = %s\n",
1233 PerlIO_printf(Perl_debug_log, "SB_DSTR = 0x%"UVxf"\n",
1234 PTR2UV(cx->sb_dstr));
1235 PerlIO_printf(Perl_debug_log, "SB_TARG = 0x%"UVxf"\n",
1236 PTR2UV(cx->sb_targ));
1237 PerlIO_printf(Perl_debug_log, "SB_S = 0x%"UVxf"\n",
1239 PerlIO_printf(Perl_debug_log, "SB_M = 0x%"UVxf"\n",
1241 PerlIO_printf(Perl_debug_log, "SB_STREND = 0x%"UVxf"\n",
1242 PTR2UV(cx->sb_strend));
1243 PerlIO_printf(Perl_debug_log, "SB_RXRES = 0x%"UVxf"\n",
1244 PTR2UV(cx->sb_rxres));
1248 PERL_UNUSED_CONTEXT;
1249 PERL_UNUSED_ARG(cx);
1250 #endif /* DEBUGGING */
1255 * c-indentation-style: bsd
1257 * indent-tabs-mode: t
1260 * ex: set ts=8 sts=4 sw=4 noet: