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)
173 PERL_ARGS_ASSERT_SAVE_SCALAR_AT;
176 sv = (flags & SAVEf_KEEPOLDELEM) ? osv : (*sptr = newSV(0));
178 if (SvTYPE(osv) >= SVt_PVMG && SvMAGIC(osv) && SvTYPE(osv) != SVt_PVGV) {
179 if (SvGMAGICAL(osv)) {
180 const bool oldtainted = PL_tainted;
181 SvFLAGS(osv) |= (SvFLAGS(osv) &
182 (SVp_IOK|SVp_NOK|SVp_POK)) >> PRIVSHIFT;
183 PL_tainted = oldtainted;
185 if (!(flags & SAVEf_KEEPOLDELEM))
186 mg_localize(osv, sv, (flags & SAVEf_SETMAGIC) != 0);
193 Perl_save_pushptrptr(pTHX_ void *const ptr1, void *const ptr2, const int type)
203 Perl_save_scalar(pTHX_ GV *gv)
206 SV ** const sptr = &GvSVn(gv);
208 PERL_ARGS_ASSERT_SAVE_SCALAR;
213 save_pushptrptr(SvREFCNT_inc_simple(gv), SvREFCNT_inc(*sptr), SAVEt_SV);
214 return save_scalar_at(sptr, SAVEf_SETMAGIC); /* XXX - FIXME - see #60360 */
217 /* Like save_sptr(), but also SvREFCNT_dec()s the new value. Can be used to
218 * restore a global SV to its prior contents, freeing new value. */
220 Perl_save_generic_svref(pTHX_ SV **sptr)
224 PERL_ARGS_ASSERT_SAVE_GENERIC_SVREF;
226 save_pushptrptr(sptr, SvREFCNT_inc(*sptr), SAVEt_GENERIC_SVREF);
229 /* Like save_pptr(), but also Safefree()s the new value if it is different
230 * from the old one. Can be used to restore a global char* to its prior
231 * contents, freeing new value. */
233 Perl_save_generic_pvref(pTHX_ char **str)
237 PERL_ARGS_ASSERT_SAVE_GENERIC_PVREF;
239 save_pushptrptr(*str, str, SAVEt_GENERIC_PVREF);
242 /* Like save_generic_pvref(), but uses PerlMemShared_free() rather than Safefree().
243 * Can be used to restore a shared global char* to its prior
244 * contents, freeing new value. */
246 Perl_save_shared_pvref(pTHX_ char **str)
250 PERL_ARGS_ASSERT_SAVE_SHARED_PVREF;
252 save_pushptrptr(str, *str, SAVEt_SHARED_PVREF);
255 /* set the SvFLAGS specified by mask to the values in val */
258 Perl_save_set_svflags(pTHX_ SV* sv, U32 mask, U32 val)
262 PERL_ARGS_ASSERT_SAVE_SET_SVFLAGS;
268 SSPUSHINT(SAVEt_SET_SVFLAGS);
272 Perl_save_gp(pTHX_ GV *gv, I32 empty)
276 PERL_ARGS_ASSERT_SAVE_GP;
278 save_pushptrptr(SvREFCNT_inc(gv), GvGP(gv), SAVEt_GP);
281 GP *gp = Perl_newGP(aTHX_ gv);
284 mro_method_changed_in(GvSTASH(gv)); /* taking a method out of circulation ("local")*/
285 if (GvIOp(gv) && (IoFLAGS(GvIOp(gv)) & IOf_ARGV)) {
287 IoFLAGS(gp->gp_io) |= IOf_ARGV|IOf_START;
289 #ifdef PERL_DONT_CREATE_GVSV
290 if (gv == PL_errgv) {
291 /* We could scatter this logic everywhere by changing the
292 definition of ERRSV from GvSV() to GvSVn(), but it seems more
293 efficient to do this check once here. */
294 gp->gp_sv = newSV(0);
306 Perl_save_ary(pTHX_ GV *gv)
309 AV * const oav = GvAVn(gv);
312 PERL_ARGS_ASSERT_SAVE_ARY;
314 if (!AvREAL(oav) && AvREIFY(oav))
316 save_pushptrptr(gv, oav, SAVEt_AV);
321 mg_localize(MUTABLE_SV(oav), MUTABLE_SV(av), TRUE);
326 Perl_save_hash(pTHX_ GV *gv)
331 PERL_ARGS_ASSERT_SAVE_HASH;
333 save_pushptrptr(gv, (ohv = GvHVn(gv)), SAVEt_HV);
338 mg_localize(MUTABLE_SV(ohv), MUTABLE_SV(hv), TRUE);
343 Perl_save_item(pTHX_ register SV *item)
346 register SV * const sv = newSVsv(item);
348 PERL_ARGS_ASSERT_SAVE_ITEM;
350 save_pushptrptr(item, /* remember the pointer */
351 sv, /* remember the value */
356 Perl_save_bool(pTHX_ bool *boolp)
360 PERL_ARGS_ASSERT_SAVE_BOOL;
365 SSPUSHINT(SAVEt_BOOL);
369 Perl_save_pushi32ptr(pTHX_ const I32 i, void *const ptr, const int type)
379 Perl_save_int(pTHX_ int *intp)
383 PERL_ARGS_ASSERT_SAVE_INT;
385 save_pushi32ptr(*intp, intp, SAVEt_INT);
389 Perl_save_I8(pTHX_ I8 *bytep)
393 PERL_ARGS_ASSERT_SAVE_I8;
395 save_pushi32ptr(*bytep, bytep, SAVEt_I8);
399 Perl_save_I16(pTHX_ I16 *intp)
403 PERL_ARGS_ASSERT_SAVE_I16;
405 save_pushi32ptr(*intp, intp, SAVEt_I16);
409 Perl_save_I32(pTHX_ I32 *intp)
413 PERL_ARGS_ASSERT_SAVE_I32;
415 save_pushi32ptr(*intp, intp, SAVEt_I32);
418 /* Cannot use save_sptr() to store a char* since the SV** cast will
419 * force word-alignment and we'll miss the pointer.
422 Perl_save_pptr(pTHX_ char **pptr)
426 PERL_ARGS_ASSERT_SAVE_PPTR;
428 save_pushptrptr(*pptr, pptr, SAVEt_PPTR);
432 Perl_save_vptr(pTHX_ void *ptr)
436 PERL_ARGS_ASSERT_SAVE_VPTR;
438 save_pushptrptr(*(char**)ptr, ptr, SAVEt_VPTR);
442 Perl_save_sptr(pTHX_ SV **sptr)
446 PERL_ARGS_ASSERT_SAVE_SPTR;
448 save_pushptrptr(*sptr, sptr, SAVEt_SPTR);
452 Perl_save_padsv_and_mortalize(pTHX_ PADOFFSET off)
456 ASSERT_CURPAD_ACTIVE("save_padsv");
457 SSPUSHPTR(SvREFCNT_inc_simple_NN(PL_curpad[off]));
458 SSPUSHPTR(PL_comppad);
459 SSPUSHLONG((long)off);
460 SSPUSHINT(SAVEt_PADSV_AND_MORTALIZE);
464 Perl_save_hptr(pTHX_ HV **hptr)
468 PERL_ARGS_ASSERT_SAVE_HPTR;
470 save_pushptrptr(*hptr, hptr, SAVEt_HPTR);
474 Perl_save_aptr(pTHX_ AV **aptr)
478 PERL_ARGS_ASSERT_SAVE_APTR;
480 save_pushptrptr(*aptr, aptr, SAVEt_APTR);
484 Perl_save_pushptr(pTHX_ void *const ptr, const int type)
493 Perl_save_clearsv(pTHX_ SV **svp)
497 PERL_ARGS_ASSERT_SAVE_CLEARSV;
499 ASSERT_CURPAD_ACTIVE("save_clearsv");
501 SSPUSHLONG((long)(svp-PL_curpad));
502 SSPUSHINT(SAVEt_CLEARSV);
503 SvPADSTALE_off(*svp); /* mark lexical as active */
507 Perl_save_delete(pTHX_ HV *hv, char *key, I32 klen)
511 PERL_ARGS_ASSERT_SAVE_DELETE;
513 save_pushptri32ptr(key, klen, SvREFCNT_inc_simple(hv), SAVEt_DELETE);
517 Perl_save_hdelete(pTHX_ HV *hv, SV *keysv)
523 PERL_ARGS_ASSERT_SAVE_HDELETE;
525 key = SvPV_const(keysv, len);
526 klen = SvUTF8(keysv) ? -(I32)len : (I32)len;
527 SvREFCNT_inc_simple_void_NN(hv);
528 save_pushptri32ptr(savepvn(key, len), klen, hv, SAVEt_DELETE);
532 Perl_save_adelete(pTHX_ AV *av, I32 key)
536 PERL_ARGS_ASSERT_SAVE_ADELETE;
538 SvREFCNT_inc_void(av);
539 save_pushi32ptr(key, av, SAVEt_ADELETE);
543 Perl_save_destructor(pTHX_ DESTRUCTORFUNC_NOCONTEXT_t f, void* p)
547 PERL_ARGS_ASSERT_SAVE_DESTRUCTOR;
552 SSPUSHINT(SAVEt_DESTRUCTOR);
556 Perl_save_destructor_x(pTHX_ DESTRUCTORFUNC_t f, void* p)
562 SSPUSHINT(SAVEt_DESTRUCTOR_X);
566 Perl_save_hints(pTHX)
569 if (PL_compiling.cop_hints_hash) {
571 PL_compiling.cop_hints_hash->refcounted_he_refcnt++;
574 if (PL_hints & HINT_LOCALIZE_HH) {
575 save_pushptri32ptr(GvHV(PL_hintgv), PL_hints,
576 PL_compiling.cop_hints_hash, SAVEt_HINTS);
577 GvHV(PL_hintgv) = Perl_hv_copy_hints_hv(aTHX_ GvHV(PL_hintgv));
579 save_pushi32ptr(PL_hints, PL_compiling.cop_hints_hash, SAVEt_HINTS);
584 S_save_pushptri32ptr(pTHX_ void *const ptr1, const I32 i, void *const ptr2,
595 Perl_save_aelem_flags(pTHX_ AV *av, I32 idx, SV **sptr, const U32 flags)
600 PERL_ARGS_ASSERT_SAVE_AELEM_FLAGS;
603 save_pushptri32ptr(SvREFCNT_inc_simple(av), idx, SvREFCNT_inc(*sptr),
605 /* if it gets reified later, the restore will have the wrong refcnt */
606 if (!AvREAL(av) && AvREIFY(av))
607 SvREFCNT_inc_void(*sptr);
608 save_scalar_at(sptr, flags); /* XXX - FIXME - see #60360 */
609 if (flags & SAVEf_KEEPOLDELEM)
612 /* If we're localizing a tied array element, this new sv
613 * won't actually be stored in the array - so it won't get
614 * reaped when the localize ends. Ensure it gets reaped by
615 * mortifying it instead. DAPM */
616 if (SvTIED_mg(sv, PERL_MAGIC_tiedelem))
621 Perl_save_helem_flags(pTHX_ HV *hv, SV *key, SV **sptr, const U32 flags)
626 PERL_ARGS_ASSERT_SAVE_HELEM_FLAGS;
630 SSPUSHPTR(SvREFCNT_inc_simple(hv));
631 SSPUSHPTR(newSVsv(key));
632 SSPUSHPTR(SvREFCNT_inc(*sptr));
633 SSPUSHINT(SAVEt_HELEM);
634 save_scalar_at(sptr, flags);
635 if (flags & SAVEf_KEEPOLDELEM)
638 /* If we're localizing a tied hash element, this new sv
639 * won't actually be stored in the hash - so it won't get
640 * reaped when the localize ends. Ensure it gets reaped by
641 * mortifying it instead. DAPM */
642 if (SvTIED_mg(sv, PERL_MAGIC_tiedelem))
647 Perl_save_svref(pTHX_ SV **sptr)
651 PERL_ARGS_ASSERT_SAVE_SVREF;
654 save_pushptrptr(sptr, SvREFCNT_inc(*sptr), SAVEt_SVREF);
655 return save_scalar_at(sptr, SAVEf_SETMAGIC); /* XXX - FIXME - see #60360 */
659 Perl_save_alloc(pTHX_ I32 size, I32 pad)
662 register const I32 start = pad + ((char*)&PL_savestack[PL_savestack_ix]
663 - (char*)PL_savestack);
664 register const I32 elems = 1 + ((size + pad - 1) / sizeof(*PL_savestack));
668 PL_savestack_ix += elems;
670 SSPUSHINT(SAVEt_ALLOC);
675 Perl_leave_scope(pTHX_ I32 base)
686 /* Localise the effects of the TAINT_NOT inside the loop. */
687 const bool was = PL_tainted;
690 Perl_croak(aTHX_ "panic: corrupt saved stack index");
691 while (PL_savestack_ix > base) {
695 case SAVEt_ITEM: /* normal string */
696 value = MUTABLE_SV(SSPOPPTR);
697 sv = MUTABLE_SV(SSPOPPTR);
698 sv_replace(sv,value);
703 case SAVEt_SV: /* scalar reference */
704 value = MUTABLE_SV(SSPOPPTR);
705 gv = MUTABLE_GV(SSPOPPTR);
707 av = MUTABLE_AV(gv); /* what to refcnt_dec */
716 if (av) /* actually an av, hv or gv */
719 case SAVEt_GENERIC_PVREF: /* generic pv */
721 str = (char*)SSPOPPTR;
722 if (*(char**)ptr != str) {
723 Safefree(*(char**)ptr);
727 case SAVEt_SHARED_PVREF: /* shared pv */
728 str = (char*)SSPOPPTR;
730 if (*(char**)ptr != str) {
732 PerlMem_free(*(char**)ptr);
734 PerlMemShared_free(*(char**)ptr);
739 case SAVEt_GENERIC_SVREF: /* generic sv */
740 value = MUTABLE_SV(SSPOPPTR);
747 case SAVEt_AV: /* array reference */
748 av = MUTABLE_AV(SSPOPPTR);
749 gv = MUTABLE_GV(SSPOPPTR);
751 SvREFCNT_dec(GvAV(gv));
756 SvSETMAGIC(MUTABLE_SV(av));
760 case SAVEt_HV: /* hash reference */
761 hv = MUTABLE_HV(SSPOPPTR);
762 gv = MUTABLE_GV(SSPOPPTR);
764 SvREFCNT_dec(GvHV(gv));
769 SvSETMAGIC(MUTABLE_SV(hv));
773 case SAVEt_INT: /* int reference */
775 *(int*)ptr = (int)SSPOPINT;
777 case SAVEt_BOOL: /* bool reference */
779 *(bool*)ptr = (bool)SSPOPBOOL;
781 case SAVEt_I32: /* I32 reference */
783 #ifdef PERL_DEBUG_READONLY_OPS
785 const I32 val = SSPOPINT;
786 if (*(I32*)ptr != val)
790 *(I32*)ptr = (I32)SSPOPINT;
793 case SAVEt_SPTR: /* SV* reference */
795 *(SV**)ptr = MUTABLE_SV(SSPOPPTR);
797 case SAVEt_VPTR: /* random* reference */
798 case SAVEt_PPTR: /* char* reference */
800 *(char**)ptr = (char*)SSPOPPTR;
802 case SAVEt_HPTR: /* HV* reference */
804 *(HV**)ptr = MUTABLE_HV(SSPOPPTR);
806 case SAVEt_APTR: /* AV* reference */
808 *(AV**)ptr = MUTABLE_AV(SSPOPPTR);
810 case SAVEt_GP: /* scalar reference */
812 gv = MUTABLE_GV(SSPOPPTR);
815 /* putting a method back into circulation ("local")*/
816 if (GvCVu(gv) && (hv=GvSTASH(gv)) && HvNAME_get(hv))
817 mro_method_changed_in(hv);
822 SvREFCNT_dec(MUTABLE_SV(ptr));
824 case SAVEt_MORTALIZESV:
826 sv_2mortal(MUTABLE_SV(ptr));
830 ASSERT_CURPAD_LEGAL("SAVEt_FREEOP"); /* XXX DAPM tmp */
838 ptr = (void*)&PL_curpad[SSPOPLONG];
841 DEBUG_Xv(PerlIO_printf(Perl_debug_log,
842 "Pad 0x%"UVxf"[0x%"UVxf"] clearsv: %ld sv=0x%"UVxf"<%"IVdf"> %s\n",
843 PTR2UV(PL_comppad), PTR2UV(PL_curpad),
844 (long)((SV **)ptr-PL_curpad), PTR2UV(sv), (IV)SvREFCNT(sv),
845 (SvREFCNT(sv) <= 1 && !SvOBJECT(sv)) ? "clear" : "abandon"
848 /* Can clear pad variable in place? */
849 if (SvREFCNT(sv) <= 1 && !SvOBJECT(sv)) {
851 * if a my variable that was made readonly is going out of
852 * scope, we want to remove the readonlyness so that it can
853 * go out of scope quietly
855 if (SvPADMY(sv) && !SvFAKE(sv))
858 if (SvTHINKFIRST(sv))
859 sv_force_normal_flags(sv, SV_IMMEDIATE_UNREF);
863 switch (SvTYPE(sv)) {
867 av_clear(MUTABLE_AV(sv));
870 hv_clear(MUTABLE_HV(sv));
873 Perl_croak(aTHX_ "panic: leave_scope pad code");
878 SvPADSTALE_on(sv); /* mark as no longer live */
880 else { /* Someone has a claim on this, so abandon it. */
881 const U32 padflags = SvFLAGS(sv) & (SVs_PADMY|SVs_PADTMP);
882 switch (SvTYPE(sv)) { /* Console ourselves with a new value */
883 case SVt_PVAV: *(SV**)ptr = MUTABLE_SV(newAV()); break;
884 case SVt_PVHV: *(SV**)ptr = MUTABLE_SV(newHV()); break;
885 default: *(SV**)ptr = newSV(0); break;
887 SvREFCNT_dec(sv); /* Cast current value to the winds. */
888 /* preserve pad nature, but also mark as not live
889 * for any closure capturing */
890 SvFLAGS(*(SV**)ptr) |= padflags | SVs_PADSTALE;
895 hv = MUTABLE_HV(ptr);
898 (void)hv_delete(hv, (char*)ptr, i, G_DISCARD);
904 av = MUTABLE_AV(ptr);
906 (void)av_delete(av, i, G_DISCARD);
909 case SAVEt_DESTRUCTOR_X:
911 (*SSPOPDXPTR)(aTHX_ ptr);
913 case SAVEt_REGCONTEXT:
916 PL_savestack_ix -= i; /* regexp must have croaked */
918 case SAVEt_STACK_POS: /* Position on Perl stack */
920 PL_stack_sp = PL_stack_base + i;
922 case SAVEt_STACK_CXPOS: /* blk_oldsp on context stack */
924 cxstack[i].blk_oldsp = SSPOPINT;
926 case SAVEt_AELEM: /* array element */
927 value = MUTABLE_SV(SSPOPPTR);
929 av = MUTABLE_AV(SSPOPPTR);
930 ptr = av_fetch(av,i,1);
931 if (!AvREAL(av) && AvREIFY(av)) /* undo reify guard */
935 if (sv && sv != &PL_sv_undef) {
936 if (SvTIED_mg((const SV *)av, PERL_MAGIC_tied))
937 SvREFCNT_inc_void_NN(sv);
944 case SAVEt_HELEM: /* hash element */
945 value = MUTABLE_SV(SSPOPPTR);
946 sv = MUTABLE_SV(SSPOPPTR);
947 hv = MUTABLE_HV(SSPOPPTR);
948 ptr = hv_fetch_ent(hv, sv, 1, 0);
951 const SV * const oval = HeVAL((HE*)ptr);
952 if (oval && oval != &PL_sv_undef) {
953 ptr = &HeVAL((HE*)ptr);
954 if (SvTIED_mg((const SV *)hv, PERL_MAGIC_tied))
955 SvREFCNT_inc_void(*(SV**)ptr);
956 av = MUTABLE_AV(hv); /* what to refcnt_dec */
964 PL_op = (OP*)SSPOPPTR;
967 if ((PL_hints & HINT_LOCALIZE_HH) && GvHV(PL_hintgv)) {
968 SvREFCNT_dec(MUTABLE_SV(GvHV(PL_hintgv)));
969 GvHV(PL_hintgv) = NULL;
971 Perl_refcounted_he_free(aTHX_ PL_compiling.cop_hints_hash);
972 PL_compiling.cop_hints_hash = (struct refcounted_he *) SSPOPPTR;
973 *(I32*)&PL_hints = (I32)SSPOPINT;
974 if (PL_hints & HINT_LOCALIZE_HH) {
975 SvREFCNT_dec(MUTABLE_SV(GvHV(PL_hintgv)));
976 GvHV(PL_hintgv) = MUTABLE_HV(SSPOPPTR);
977 assert(GvHV(PL_hintgv));
978 } else if (!GvHV(PL_hintgv)) {
979 /* Need to add a new one manually, else gv_fetchpv() can
980 add one in this code:
982 if (SvTYPE(gv) == SVt_PVGV) {
985 gv_init_sv(gv, sv_type);
986 if (*name=='!' && sv_type == SVt_PVHV && len==1)
992 and it won't have the magic set. */
994 HV *const hv = newHV();
995 hv_magic(hv, NULL, PERL_MAGIC_hints);
996 GvHV(PL_hintgv) = hv;
998 assert(GvHV(PL_hintgv));
1001 PL_comppad = (PAD*)SSPOPPTR;
1003 PL_curpad = AvARRAY(PL_comppad);
1007 case SAVEt_PADSV_AND_MORTALIZE:
1009 const PADOFFSET off = (PADOFFSET)SSPOPLONG;
1013 svp = AvARRAY((PAD*)ptr) + off;
1014 /* This mortalizing used to be done by POPLOOP() via itersave.
1015 But as we have all the information here, we can do it here,
1016 save even having to have itersave in the struct. */
1018 *svp = MUTABLE_SV(SSPOPPTR);
1021 case SAVEt_SAVESWITCHSTACK:
1024 AV *const t = MUTABLE_AV(SSPOPPTR);
1025 AV *const f = MUTABLE_AV(SSPOPPTR);
1027 PL_curstackinfo->si_stack = f;
1030 case SAVEt_SET_SVFLAGS:
1032 const U32 val = (U32)SSPOPINT;
1033 const U32 mask = (U32)SSPOPINT;
1034 sv = MUTABLE_SV(SSPOPPTR);
1035 SvFLAGS(sv) &= ~mask;
1040 /* This would be a mathom, but Perl_save_svref() calls a static
1041 function, S_save_scalar_at(), so has to stay in this file. */
1042 case SAVEt_SVREF: /* scalar reference */
1043 value = MUTABLE_SV(SSPOPPTR);
1045 av = NULL; /* what to refcnt_dec */
1048 /* These are only saved in mathoms.c */
1050 gv = MUTABLE_GV(SSPOPPTR);
1051 (void)sv_clear(MUTABLE_SV(gv));
1053 case SAVEt_LONG: /* long reference */
1055 *(long*)ptr = (long)SSPOPLONG;
1057 case SAVEt_IV: /* IV reference */
1059 *(IV*)ptr = (IV)SSPOPIV;
1062 case SAVEt_I16: /* I16 reference */
1064 *(I16*)ptr = (I16)SSPOPINT;
1066 case SAVEt_I8: /* I8 reference */
1068 *(I8*)ptr = (I8)SSPOPINT;
1070 case SAVEt_DESTRUCTOR:
1074 case SAVEt_COP_ARYBASE:
1077 CopARYBASE_set((COP *)ptr, i);
1079 case SAVEt_COMPILE_WARNINGS:
1082 if (!specialWARN(PL_compiling.cop_warnings))
1083 PerlMemShared_free(PL_compiling.cop_warnings);
1085 PL_compiling.cop_warnings = (STRLEN*)ptr;
1087 case SAVEt_RE_STATE:
1089 const struct re_save_state *const state
1090 = (struct re_save_state *)
1091 (PL_savestack + PL_savestack_ix
1092 - SAVESTACK_ALLOC_FOR_RE_SAVE_STATE);
1093 PL_savestack_ix -= SAVESTACK_ALLOC_FOR_RE_SAVE_STATE;
1095 if (PL_reg_start_tmp != state->re_state_reg_start_tmp) {
1096 Safefree(PL_reg_start_tmp);
1098 if (PL_reg_poscache != state->re_state_reg_poscache) {
1099 Safefree(PL_reg_poscache);
1101 Copy(state, &PL_reg_state, 1, struct re_save_state);
1106 parser_free((yy_parser *) ptr);
1109 Perl_croak(aTHX_ "panic: leave_scope inconsistency");
1117 Perl_cx_dump(pTHX_ PERL_CONTEXT *cx)
1121 PERL_ARGS_ASSERT_CX_DUMP;
1124 PerlIO_printf(Perl_debug_log, "CX %ld = %s\n", (long)(cx - cxstack), PL_block_type[CxTYPE(cx)]);
1125 if (CxTYPE(cx) != CXt_SUBST) {
1126 PerlIO_printf(Perl_debug_log, "BLK_OLDSP = %ld\n", (long)cx->blk_oldsp);
1127 PerlIO_printf(Perl_debug_log, "BLK_OLDCOP = 0x%"UVxf"\n",
1128 PTR2UV(cx->blk_oldcop));
1129 PerlIO_printf(Perl_debug_log, "BLK_OLDMARKSP = %ld\n", (long)cx->blk_oldmarksp);
1130 PerlIO_printf(Perl_debug_log, "BLK_OLDSCOPESP = %ld\n", (long)cx->blk_oldscopesp);
1131 PerlIO_printf(Perl_debug_log, "BLK_OLDPM = 0x%"UVxf"\n",
1132 PTR2UV(cx->blk_oldpm));
1133 PerlIO_printf(Perl_debug_log, "BLK_GIMME = %s\n", cx->blk_gimme ? "LIST" : "SCALAR");
1135 switch (CxTYPE(cx)) {
1140 PerlIO_printf(Perl_debug_log, "BLK_FORMAT.CV = 0x%"UVxf"\n",
1141 PTR2UV(cx->blk_format.cv));
1142 PerlIO_printf(Perl_debug_log, "BLK_FORMAT.GV = 0x%"UVxf"\n",
1143 PTR2UV(cx->blk_format.gv));
1144 PerlIO_printf(Perl_debug_log, "BLK_FORMAT.DFOUTGV = 0x%"UVxf"\n",
1145 PTR2UV(cx->blk_format.dfoutgv));
1146 PerlIO_printf(Perl_debug_log, "BLK_FORMAT.HASARGS = %d\n",
1147 (int)CxHASARGS(cx));
1148 PerlIO_printf(Perl_debug_log, "BLK_FORMAT.RETOP = 0x%"UVxf"\n",
1149 PTR2UV(cx->blk_format.retop));
1152 PerlIO_printf(Perl_debug_log, "BLK_SUB.CV = 0x%"UVxf"\n",
1153 PTR2UV(cx->blk_sub.cv));
1154 PerlIO_printf(Perl_debug_log, "BLK_SUB.OLDDEPTH = %ld\n",
1155 (long)cx->blk_sub.olddepth);
1156 PerlIO_printf(Perl_debug_log, "BLK_SUB.HASARGS = %d\n",
1157 (int)CxHASARGS(cx));
1158 PerlIO_printf(Perl_debug_log, "BLK_SUB.LVAL = %d\n", (int)CxLVAL(cx));
1159 PerlIO_printf(Perl_debug_log, "BLK_SUB.RETOP = 0x%"UVxf"\n",
1160 PTR2UV(cx->blk_sub.retop));
1163 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_IN_EVAL = %ld\n",
1164 (long)CxOLD_IN_EVAL(cx));
1165 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_OP_TYPE = %s (%s)\n",
1166 PL_op_name[CxOLD_OP_TYPE(cx)],
1167 PL_op_desc[CxOLD_OP_TYPE(cx)]);
1168 if (cx->blk_eval.old_namesv)
1169 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_NAME = %s\n",
1170 SvPVX_const(cx->blk_eval.old_namesv));
1171 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_EVAL_ROOT = 0x%"UVxf"\n",
1172 PTR2UV(cx->blk_eval.old_eval_root));
1173 PerlIO_printf(Perl_debug_log, "BLK_EVAL.RETOP = 0x%"UVxf"\n",
1174 PTR2UV(cx->blk_eval.retop));
1177 case CXt_LOOP_LAZYIV:
1178 case CXt_LOOP_LAZYSV:
1180 case CXt_LOOP_PLAIN:
1181 PerlIO_printf(Perl_debug_log, "BLK_LOOP.LABEL = %s\n", CxLABEL(cx));
1182 PerlIO_printf(Perl_debug_log, "BLK_LOOP.RESETSP = %ld\n",
1183 (long)cx->blk_loop.resetsp);
1184 PerlIO_printf(Perl_debug_log, "BLK_LOOP.MY_OP = 0x%"UVxf"\n",
1185 PTR2UV(cx->blk_loop.my_op));
1186 PerlIO_printf(Perl_debug_log, "BLK_LOOP.NEXT_OP = 0x%"UVxf"\n",
1187 PTR2UV(CX_LOOP_NEXTOP_GET(cx)));
1188 /* XXX: not accurate for LAZYSV/IV */
1189 PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERARY = 0x%"UVxf"\n",
1190 PTR2UV(cx->blk_loop.state_u.ary.ary));
1191 PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERIX = %ld\n",
1192 (long)cx->blk_loop.state_u.ary.ix);
1193 PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERVAR = 0x%"UVxf"\n",
1194 PTR2UV(CxITERVAR(cx)));
1198 PerlIO_printf(Perl_debug_log, "SB_ITERS = %ld\n",
1199 (long)cx->sb_iters);
1200 PerlIO_printf(Perl_debug_log, "SB_MAXITERS = %ld\n",
1201 (long)cx->sb_maxiters);
1202 PerlIO_printf(Perl_debug_log, "SB_RFLAGS = %ld\n",
1203 (long)cx->sb_rflags);
1204 PerlIO_printf(Perl_debug_log, "SB_ONCE = %ld\n",
1206 PerlIO_printf(Perl_debug_log, "SB_ORIG = %s\n",
1208 PerlIO_printf(Perl_debug_log, "SB_DSTR = 0x%"UVxf"\n",
1209 PTR2UV(cx->sb_dstr));
1210 PerlIO_printf(Perl_debug_log, "SB_TARG = 0x%"UVxf"\n",
1211 PTR2UV(cx->sb_targ));
1212 PerlIO_printf(Perl_debug_log, "SB_S = 0x%"UVxf"\n",
1214 PerlIO_printf(Perl_debug_log, "SB_M = 0x%"UVxf"\n",
1216 PerlIO_printf(Perl_debug_log, "SB_STREND = 0x%"UVxf"\n",
1217 PTR2UV(cx->sb_strend));
1218 PerlIO_printf(Perl_debug_log, "SB_RXRES = 0x%"UVxf"\n",
1219 PTR2UV(cx->sb_rxres));
1223 PERL_UNUSED_CONTEXT;
1224 PERL_UNUSED_ARG(cx);
1225 #endif /* DEBUGGING */
1230 * c-indentation-style: bsd
1232 * indent-tabs-mode: t
1235 * ex: set ts=8 sts=4 sw=4 noet: