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_adelete(pTHX_ AV *av, I32 key)
516 PERL_ARGS_ASSERT_SAVE_ADELETE;
518 SvREFCNT_inc_void(av);
519 save_pushi32ptr(key, av, SAVEt_ADELETE);
523 Perl_save_destructor(pTHX_ DESTRUCTORFUNC_NOCONTEXT_t f, void* p)
527 PERL_ARGS_ASSERT_SAVE_DESTRUCTOR;
532 SSPUSHINT(SAVEt_DESTRUCTOR);
536 Perl_save_destructor_x(pTHX_ DESTRUCTORFUNC_t f, void* p)
542 SSPUSHINT(SAVEt_DESTRUCTOR_X);
546 Perl_save_hints(pTHX)
549 if (PL_compiling.cop_hints_hash) {
551 PL_compiling.cop_hints_hash->refcounted_he_refcnt++;
554 if (PL_hints & HINT_LOCALIZE_HH) {
555 save_pushptri32ptr(GvHV(PL_hintgv), PL_hints,
556 PL_compiling.cop_hints_hash, SAVEt_HINTS);
557 GvHV(PL_hintgv) = Perl_hv_copy_hints_hv(aTHX_ GvHV(PL_hintgv));
559 save_pushi32ptr(PL_hints, PL_compiling.cop_hints_hash, SAVEt_HINTS);
564 S_save_pushptri32ptr(pTHX_ void *const ptr1, const I32 i, void *const ptr2,
575 Perl_save_aelem(pTHX_ AV *av, I32 idx, SV **sptr)
580 PERL_ARGS_ASSERT_SAVE_AELEM;
583 save_pushptri32ptr(SvREFCNT_inc_simple(av), idx, SvREFCNT_inc(*sptr),
585 /* if it gets reified later, the restore will have the wrong refcnt */
586 if (!AvREAL(av) && AvREIFY(av))
587 SvREFCNT_inc_void(*sptr);
588 save_scalar_at(sptr, SAVEf_SETMAGIC); /* XXX - FIXME - see #60360 */
590 /* If we're localizing a tied array element, this new sv
591 * won't actually be stored in the array - so it won't get
592 * reaped when the localize ends. Ensure it gets reaped by
593 * mortifying it instead. DAPM */
594 if (SvTIED_mg(sv, PERL_MAGIC_tiedelem))
599 Perl_save_helem_flags(pTHX_ HV *hv, SV *key, SV **sptr, const U32 flags)
604 PERL_ARGS_ASSERT_SAVE_HELEM_FLAGS;
608 SSPUSHPTR(SvREFCNT_inc_simple(hv));
609 SSPUSHPTR(newSVsv(key));
610 SSPUSHPTR(SvREFCNT_inc(*sptr));
611 SSPUSHINT(SAVEt_HELEM);
612 save_scalar_at(sptr, flags);
614 /* If we're localizing a tied hash element, this new sv
615 * won't actually be stored in the hash - so it won't get
616 * reaped when the localize ends. Ensure it gets reaped by
617 * mortifying it instead. DAPM */
618 if (SvTIED_mg(sv, PERL_MAGIC_tiedelem))
623 Perl_save_svref(pTHX_ SV **sptr)
627 PERL_ARGS_ASSERT_SAVE_SVREF;
630 save_pushptrptr(sptr, SvREFCNT_inc(*sptr), SAVEt_SVREF);
631 return save_scalar_at(sptr, SAVEf_SETMAGIC); /* XXX - FIXME - see #60360 */
635 Perl_save_alloc(pTHX_ I32 size, I32 pad)
638 register const I32 start = pad + ((char*)&PL_savestack[PL_savestack_ix]
639 - (char*)PL_savestack);
640 register const I32 elems = 1 + ((size + pad - 1) / sizeof(*PL_savestack));
644 PL_savestack_ix += elems;
646 SSPUSHINT(SAVEt_ALLOC);
651 Perl_leave_scope(pTHX_ I32 base)
662 /* Localise the effects of the TAINT_NOT inside the loop. */
663 const bool was = PL_tainted;
666 Perl_croak(aTHX_ "panic: corrupt saved stack index");
667 while (PL_savestack_ix > base) {
671 case SAVEt_ITEM: /* normal string */
672 value = MUTABLE_SV(SSPOPPTR);
673 sv = MUTABLE_SV(SSPOPPTR);
674 sv_replace(sv,value);
679 case SAVEt_SV: /* scalar reference */
680 value = MUTABLE_SV(SSPOPPTR);
681 gv = MUTABLE_GV(SSPOPPTR);
683 av = MUTABLE_AV(gv); /* what to refcnt_dec */
692 if (av) /* actually an av, hv or gv */
695 case SAVEt_GENERIC_PVREF: /* generic pv */
697 str = (char*)SSPOPPTR;
698 if (*(char**)ptr != str) {
699 Safefree(*(char**)ptr);
703 case SAVEt_SHARED_PVREF: /* shared pv */
704 str = (char*)SSPOPPTR;
706 if (*(char**)ptr != str) {
708 PerlMem_free(*(char**)ptr);
710 PerlMemShared_free(*(char**)ptr);
715 case SAVEt_GENERIC_SVREF: /* generic sv */
716 value = MUTABLE_SV(SSPOPPTR);
723 case SAVEt_AV: /* array reference */
724 av = MUTABLE_AV(SSPOPPTR);
725 gv = MUTABLE_GV(SSPOPPTR);
727 SvREFCNT_dec(GvAV(gv));
732 SvSETMAGIC(MUTABLE_SV(av));
736 case SAVEt_HV: /* hash reference */
737 hv = MUTABLE_HV(SSPOPPTR);
738 gv = MUTABLE_GV(SSPOPPTR);
740 SvREFCNT_dec(GvHV(gv));
745 SvSETMAGIC(MUTABLE_SV(hv));
749 case SAVEt_INT: /* int reference */
751 *(int*)ptr = (int)SSPOPINT;
753 case SAVEt_BOOL: /* bool reference */
755 *(bool*)ptr = (bool)SSPOPBOOL;
757 case SAVEt_I32: /* I32 reference */
759 #ifdef PERL_DEBUG_READONLY_OPS
761 const I32 val = SSPOPINT;
762 if (*(I32*)ptr != val)
766 *(I32*)ptr = (I32)SSPOPINT;
769 case SAVEt_SPTR: /* SV* reference */
771 *(SV**)ptr = MUTABLE_SV(SSPOPPTR);
773 case SAVEt_VPTR: /* random* reference */
774 case SAVEt_PPTR: /* char* reference */
776 *(char**)ptr = (char*)SSPOPPTR;
778 case SAVEt_HPTR: /* HV* reference */
780 *(HV**)ptr = MUTABLE_HV(SSPOPPTR);
782 case SAVEt_APTR: /* AV* reference */
784 *(AV**)ptr = MUTABLE_AV(SSPOPPTR);
786 case SAVEt_GP: /* scalar reference */
788 gv = MUTABLE_GV(SSPOPPTR);
791 /* putting a method back into circulation ("local")*/
792 if (GvCVu(gv) && (hv=GvSTASH(gv)) && HvNAME_get(hv))
793 mro_method_changed_in(hv);
798 SvREFCNT_dec(MUTABLE_SV(ptr));
800 case SAVEt_MORTALIZESV:
802 sv_2mortal(MUTABLE_SV(ptr));
806 ASSERT_CURPAD_LEGAL("SAVEt_FREEOP"); /* XXX DAPM tmp */
814 ptr = (void*)&PL_curpad[SSPOPLONG];
817 DEBUG_Xv(PerlIO_printf(Perl_debug_log,
818 "Pad 0x%"UVxf"[0x%"UVxf"] clearsv: %ld sv=0x%"UVxf"<%"IVdf"> %s\n",
819 PTR2UV(PL_comppad), PTR2UV(PL_curpad),
820 (long)((SV **)ptr-PL_curpad), PTR2UV(sv), (IV)SvREFCNT(sv),
821 (SvREFCNT(sv) <= 1 && !SvOBJECT(sv)) ? "clear" : "abandon"
824 /* Can clear pad variable in place? */
825 if (SvREFCNT(sv) <= 1 && !SvOBJECT(sv)) {
827 * if a my variable that was made readonly is going out of
828 * scope, we want to remove the readonlyness so that it can
829 * go out of scope quietly
831 if (SvPADMY(sv) && !SvFAKE(sv))
834 if (SvTHINKFIRST(sv))
835 sv_force_normal_flags(sv, SV_IMMEDIATE_UNREF);
839 switch (SvTYPE(sv)) {
843 av_clear(MUTABLE_AV(sv));
846 hv_clear(MUTABLE_HV(sv));
849 Perl_croak(aTHX_ "panic: leave_scope pad code");
854 SvPADSTALE_on(sv); /* mark as no longer live */
856 else { /* Someone has a claim on this, so abandon it. */
857 const U32 padflags = SvFLAGS(sv) & (SVs_PADMY|SVs_PADTMP);
858 switch (SvTYPE(sv)) { /* Console ourselves with a new value */
859 case SVt_PVAV: *(SV**)ptr = MUTABLE_SV(newAV()); break;
860 case SVt_PVHV: *(SV**)ptr = MUTABLE_SV(newHV()); break;
861 default: *(SV**)ptr = newSV(0); break;
863 SvREFCNT_dec(sv); /* Cast current value to the winds. */
864 /* preserve pad nature, but also mark as not live
865 * for any closure capturing */
866 SvFLAGS(*(SV**)ptr) |= padflags | SVs_PADSTALE;
871 hv = MUTABLE_HV(ptr);
874 (void)hv_delete(hv, (char*)ptr, i, G_DISCARD);
880 av = MUTABLE_AV(ptr);
882 (void)av_delete(av, i, G_DISCARD);
885 case SAVEt_DESTRUCTOR_X:
887 (*SSPOPDXPTR)(aTHX_ ptr);
889 case SAVEt_REGCONTEXT:
892 PL_savestack_ix -= i; /* regexp must have croaked */
894 case SAVEt_STACK_POS: /* Position on Perl stack */
896 PL_stack_sp = PL_stack_base + i;
898 case SAVEt_STACK_CXPOS: /* blk_oldsp on context stack */
900 cxstack[i].blk_oldsp = SSPOPINT;
902 case SAVEt_AELEM: /* array element */
903 value = MUTABLE_SV(SSPOPPTR);
905 av = MUTABLE_AV(SSPOPPTR);
906 ptr = av_fetch(av,i,1);
907 if (!AvREAL(av) && AvREIFY(av)) /* undo reify guard */
911 if (sv && sv != &PL_sv_undef) {
912 if (SvTIED_mg((const SV *)av, PERL_MAGIC_tied))
913 SvREFCNT_inc_void_NN(sv);
920 case SAVEt_HELEM: /* hash element */
921 value = MUTABLE_SV(SSPOPPTR);
922 sv = MUTABLE_SV(SSPOPPTR);
923 hv = MUTABLE_HV(SSPOPPTR);
924 ptr = hv_fetch_ent(hv, sv, 1, 0);
927 const SV * const oval = HeVAL((HE*)ptr);
928 if (oval && oval != &PL_sv_undef) {
929 ptr = &HeVAL((HE*)ptr);
930 if (SvTIED_mg((const SV *)hv, PERL_MAGIC_tied))
931 SvREFCNT_inc_void(*(SV**)ptr);
932 av = MUTABLE_AV(hv); /* what to refcnt_dec */
940 PL_op = (OP*)SSPOPPTR;
943 if ((PL_hints & HINT_LOCALIZE_HH) && GvHV(PL_hintgv)) {
944 SvREFCNT_dec(MUTABLE_SV(GvHV(PL_hintgv)));
945 GvHV(PL_hintgv) = NULL;
947 Perl_refcounted_he_free(aTHX_ PL_compiling.cop_hints_hash);
948 PL_compiling.cop_hints_hash = (struct refcounted_he *) SSPOPPTR;
949 *(I32*)&PL_hints = (I32)SSPOPINT;
950 if (PL_hints & HINT_LOCALIZE_HH) {
951 SvREFCNT_dec(MUTABLE_SV(GvHV(PL_hintgv)));
952 GvHV(PL_hintgv) = MUTABLE_HV(SSPOPPTR);
953 assert(GvHV(PL_hintgv));
954 } else if (!GvHV(PL_hintgv)) {
955 /* Need to add a new one manually, else gv_fetchpv() can
956 add one in this code:
958 if (SvTYPE(gv) == SVt_PVGV) {
961 gv_init_sv(gv, sv_type);
962 if (*name=='!' && sv_type == SVt_PVHV && len==1)
968 and it won't have the magic set. */
970 HV *const hv = newHV();
971 hv_magic(hv, NULL, PERL_MAGIC_hints);
972 GvHV(PL_hintgv) = hv;
974 assert(GvHV(PL_hintgv));
977 PL_comppad = (PAD*)SSPOPPTR;
979 PL_curpad = AvARRAY(PL_comppad);
983 case SAVEt_PADSV_AND_MORTALIZE:
985 const PADOFFSET off = (PADOFFSET)SSPOPLONG;
989 svp = AvARRAY((PAD*)ptr) + off;
990 /* This mortalizing used to be done by POPLOOP() via itersave.
991 But as we have all the information here, we can do it here,
992 save even having to have itersave in the struct. */
994 *svp = MUTABLE_SV(SSPOPPTR);
997 case SAVEt_SAVESWITCHSTACK:
1000 AV *const t = MUTABLE_AV(SSPOPPTR);
1001 AV *const f = MUTABLE_AV(SSPOPPTR);
1003 PL_curstackinfo->si_stack = f;
1006 case SAVEt_SET_SVFLAGS:
1008 const U32 val = (U32)SSPOPINT;
1009 const U32 mask = (U32)SSPOPINT;
1010 sv = MUTABLE_SV(SSPOPPTR);
1011 SvFLAGS(sv) &= ~mask;
1016 /* This would be a mathom, but Perl_save_svref() calls a static
1017 function, S_save_scalar_at(), so has to stay in this file. */
1018 case SAVEt_SVREF: /* scalar reference */
1019 value = MUTABLE_SV(SSPOPPTR);
1021 av = NULL; /* what to refcnt_dec */
1024 /* These are only saved in mathoms.c */
1026 gv = MUTABLE_GV(SSPOPPTR);
1027 (void)sv_clear(MUTABLE_SV(gv));
1029 case SAVEt_LONG: /* long reference */
1031 *(long*)ptr = (long)SSPOPLONG;
1033 case SAVEt_IV: /* IV reference */
1035 *(IV*)ptr = (IV)SSPOPIV;
1038 case SAVEt_I16: /* I16 reference */
1040 *(I16*)ptr = (I16)SSPOPINT;
1042 case SAVEt_I8: /* I8 reference */
1044 *(I8*)ptr = (I8)SSPOPINT;
1046 case SAVEt_DESTRUCTOR:
1050 case SAVEt_COP_ARYBASE:
1053 CopARYBASE_set((COP *)ptr, i);
1055 case SAVEt_COMPILE_WARNINGS:
1058 if (!specialWARN(PL_compiling.cop_warnings))
1059 PerlMemShared_free(PL_compiling.cop_warnings);
1061 PL_compiling.cop_warnings = (STRLEN*)ptr;
1063 case SAVEt_RE_STATE:
1065 const struct re_save_state *const state
1066 = (struct re_save_state *)
1067 (PL_savestack + PL_savestack_ix
1068 - SAVESTACK_ALLOC_FOR_RE_SAVE_STATE);
1069 PL_savestack_ix -= SAVESTACK_ALLOC_FOR_RE_SAVE_STATE;
1071 if (PL_reg_start_tmp != state->re_state_reg_start_tmp) {
1072 Safefree(PL_reg_start_tmp);
1074 if (PL_reg_poscache != state->re_state_reg_poscache) {
1075 Safefree(PL_reg_poscache);
1077 Copy(state, &PL_reg_state, 1, struct re_save_state);
1082 parser_free((yy_parser *) ptr);
1085 Perl_croak(aTHX_ "panic: leave_scope inconsistency");
1093 Perl_cx_dump(pTHX_ PERL_CONTEXT *cx)
1097 PERL_ARGS_ASSERT_CX_DUMP;
1100 PerlIO_printf(Perl_debug_log, "CX %ld = %s\n", (long)(cx - cxstack), PL_block_type[CxTYPE(cx)]);
1101 if (CxTYPE(cx) != CXt_SUBST) {
1102 PerlIO_printf(Perl_debug_log, "BLK_OLDSP = %ld\n", (long)cx->blk_oldsp);
1103 PerlIO_printf(Perl_debug_log, "BLK_OLDCOP = 0x%"UVxf"\n",
1104 PTR2UV(cx->blk_oldcop));
1105 PerlIO_printf(Perl_debug_log, "BLK_OLDMARKSP = %ld\n", (long)cx->blk_oldmarksp);
1106 PerlIO_printf(Perl_debug_log, "BLK_OLDSCOPESP = %ld\n", (long)cx->blk_oldscopesp);
1107 PerlIO_printf(Perl_debug_log, "BLK_OLDPM = 0x%"UVxf"\n",
1108 PTR2UV(cx->blk_oldpm));
1109 PerlIO_printf(Perl_debug_log, "BLK_GIMME = %s\n", cx->blk_gimme ? "LIST" : "SCALAR");
1111 switch (CxTYPE(cx)) {
1116 PerlIO_printf(Perl_debug_log, "BLK_FORMAT.CV = 0x%"UVxf"\n",
1117 PTR2UV(cx->blk_format.cv));
1118 PerlIO_printf(Perl_debug_log, "BLK_FORMAT.GV = 0x%"UVxf"\n",
1119 PTR2UV(cx->blk_format.gv));
1120 PerlIO_printf(Perl_debug_log, "BLK_FORMAT.DFOUTGV = 0x%"UVxf"\n",
1121 PTR2UV(cx->blk_format.dfoutgv));
1122 PerlIO_printf(Perl_debug_log, "BLK_FORMAT.HASARGS = %d\n",
1123 (int)CxHASARGS(cx));
1124 PerlIO_printf(Perl_debug_log, "BLK_FORMAT.RETOP = 0x%"UVxf"\n",
1125 PTR2UV(cx->blk_format.retop));
1128 PerlIO_printf(Perl_debug_log, "BLK_SUB.CV = 0x%"UVxf"\n",
1129 PTR2UV(cx->blk_sub.cv));
1130 PerlIO_printf(Perl_debug_log, "BLK_SUB.OLDDEPTH = %ld\n",
1131 (long)cx->blk_sub.olddepth);
1132 PerlIO_printf(Perl_debug_log, "BLK_SUB.HASARGS = %d\n",
1133 (int)CxHASARGS(cx));
1134 PerlIO_printf(Perl_debug_log, "BLK_SUB.LVAL = %d\n", (int)CxLVAL(cx));
1135 PerlIO_printf(Perl_debug_log, "BLK_SUB.RETOP = 0x%"UVxf"\n",
1136 PTR2UV(cx->blk_sub.retop));
1139 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_IN_EVAL = %ld\n",
1140 (long)CxOLD_IN_EVAL(cx));
1141 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_OP_TYPE = %s (%s)\n",
1142 PL_op_name[CxOLD_OP_TYPE(cx)],
1143 PL_op_desc[CxOLD_OP_TYPE(cx)]);
1144 if (cx->blk_eval.old_namesv)
1145 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_NAME = %s\n",
1146 SvPVX_const(cx->blk_eval.old_namesv));
1147 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_EVAL_ROOT = 0x%"UVxf"\n",
1148 PTR2UV(cx->blk_eval.old_eval_root));
1149 PerlIO_printf(Perl_debug_log, "BLK_EVAL.RETOP = 0x%"UVxf"\n",
1150 PTR2UV(cx->blk_eval.retop));
1153 case CXt_LOOP_LAZYIV:
1154 case CXt_LOOP_LAZYSV:
1156 case CXt_LOOP_PLAIN:
1157 PerlIO_printf(Perl_debug_log, "BLK_LOOP.LABEL = %s\n", CxLABEL(cx));
1158 PerlIO_printf(Perl_debug_log, "BLK_LOOP.RESETSP = %ld\n",
1159 (long)cx->blk_loop.resetsp);
1160 PerlIO_printf(Perl_debug_log, "BLK_LOOP.MY_OP = 0x%"UVxf"\n",
1161 PTR2UV(cx->blk_loop.my_op));
1162 PerlIO_printf(Perl_debug_log, "BLK_LOOP.NEXT_OP = 0x%"UVxf"\n",
1163 PTR2UV(CX_LOOP_NEXTOP_GET(cx)));
1164 /* XXX: not accurate for LAZYSV/IV */
1165 PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERARY = 0x%"UVxf"\n",
1166 PTR2UV(cx->blk_loop.state_u.ary.ary));
1167 PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERIX = %ld\n",
1168 (long)cx->blk_loop.state_u.ary.ix);
1169 PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERVAR = 0x%"UVxf"\n",
1170 PTR2UV(CxITERVAR(cx)));
1174 PerlIO_printf(Perl_debug_log, "SB_ITERS = %ld\n",
1175 (long)cx->sb_iters);
1176 PerlIO_printf(Perl_debug_log, "SB_MAXITERS = %ld\n",
1177 (long)cx->sb_maxiters);
1178 PerlIO_printf(Perl_debug_log, "SB_RFLAGS = %ld\n",
1179 (long)cx->sb_rflags);
1180 PerlIO_printf(Perl_debug_log, "SB_ONCE = %ld\n",
1182 PerlIO_printf(Perl_debug_log, "SB_ORIG = %s\n",
1184 PerlIO_printf(Perl_debug_log, "SB_DSTR = 0x%"UVxf"\n",
1185 PTR2UV(cx->sb_dstr));
1186 PerlIO_printf(Perl_debug_log, "SB_TARG = 0x%"UVxf"\n",
1187 PTR2UV(cx->sb_targ));
1188 PerlIO_printf(Perl_debug_log, "SB_S = 0x%"UVxf"\n",
1190 PerlIO_printf(Perl_debug_log, "SB_M = 0x%"UVxf"\n",
1192 PerlIO_printf(Perl_debug_log, "SB_STREND = 0x%"UVxf"\n",
1193 PTR2UV(cx->sb_strend));
1194 PerlIO_printf(Perl_debug_log, "SB_RXRES = 0x%"UVxf"\n",
1195 PTR2UV(cx->sb_rxres));
1199 PERL_UNUSED_CONTEXT;
1200 PERL_UNUSED_ARG(cx);
1201 #endif /* DEBUGGING */
1206 * c-indentation-style: bsd
1208 * indent-tabs-mode: t
1211 * ex: set ts=8 sts=4 sw=4 noet: