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_scalar(pTHX_ GV *gv)
191 SV ** const sptr = &GvSVn(gv);
193 PERL_ARGS_ASSERT_SAVE_SCALAR;
199 SSPUSHPTR(SvREFCNT_inc_simple(gv));
200 SSPUSHPTR(SvREFCNT_inc(*sptr));
202 return save_scalar_at(sptr, SAVEf_SETMAGIC); /* XXX - FIXME - see #60360 */
205 /* Like save_sptr(), but also SvREFCNT_dec()s the new value. Can be used to
206 * restore a global SV to its prior contents, freeing new value. */
208 Perl_save_generic_svref(pTHX_ SV **sptr)
212 PERL_ARGS_ASSERT_SAVE_GENERIC_SVREF;
216 SSPUSHPTR(SvREFCNT_inc(*sptr));
217 SSPUSHINT(SAVEt_GENERIC_SVREF);
220 /* Like save_pptr(), but also Safefree()s the new value if it is different
221 * from the old one. Can be used to restore a global char* to its prior
222 * contents, freeing new value. */
224 Perl_save_generic_pvref(pTHX_ char **str)
228 PERL_ARGS_ASSERT_SAVE_GENERIC_PVREF;
233 SSPUSHINT(SAVEt_GENERIC_PVREF);
236 /* Like save_generic_pvref(), but uses PerlMemShared_free() rather than Safefree().
237 * Can be used to restore a shared global char* to its prior
238 * contents, freeing new value. */
240 Perl_save_shared_pvref(pTHX_ char **str)
244 PERL_ARGS_ASSERT_SAVE_SHARED_PVREF;
249 SSPUSHINT(SAVEt_SHARED_PVREF);
252 /* set the SvFLAGS specified by mask to the values in val */
255 Perl_save_set_svflags(pTHX_ SV* sv, U32 mask, U32 val)
259 PERL_ARGS_ASSERT_SAVE_SET_SVFLAGS;
265 SSPUSHINT(SAVEt_SET_SVFLAGS);
269 Perl_save_gp(pTHX_ GV *gv, I32 empty)
273 PERL_ARGS_ASSERT_SAVE_GP;
276 SSPUSHPTR(SvREFCNT_inc(gv));
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))
324 mg_localize(MUTABLE_SV(oav), MUTABLE_SV(av), TRUE);
329 Perl_save_hash(pTHX_ GV *gv)
334 PERL_ARGS_ASSERT_SAVE_HASH;
338 SSPUSHPTR(ohv = GvHVn(gv));
344 mg_localize(MUTABLE_SV(ohv), MUTABLE_SV(hv), TRUE);
349 Perl_save_item(pTHX_ register SV *item)
352 register SV * const sv = newSVsv(item);
354 PERL_ARGS_ASSERT_SAVE_ITEM;
357 SSPUSHPTR(item); /* remember the pointer */
358 SSPUSHPTR(sv); /* remember the value */
359 SSPUSHINT(SAVEt_ITEM);
363 Perl_save_int(pTHX_ int *intp)
367 PERL_ARGS_ASSERT_SAVE_INT;
372 SSPUSHINT(SAVEt_INT);
376 Perl_save_bool(pTHX_ bool *boolp)
380 PERL_ARGS_ASSERT_SAVE_BOOL;
385 SSPUSHINT(SAVEt_BOOL);
389 Perl_save_I8(pTHX_ I8 *bytep)
393 PERL_ARGS_ASSERT_SAVE_I8;
402 Perl_save_I16(pTHX_ I16 *intp)
406 PERL_ARGS_ASSERT_SAVE_I16;
411 SSPUSHINT(SAVEt_I16);
415 Perl_save_I32(pTHX_ I32 *intp)
419 PERL_ARGS_ASSERT_SAVE_I32;
424 SSPUSHINT(SAVEt_I32);
427 /* Cannot use save_sptr() to store a char* since the SV** cast will
428 * force word-alignment and we'll miss the pointer.
431 Perl_save_pptr(pTHX_ char **pptr)
435 PERL_ARGS_ASSERT_SAVE_PPTR;
440 SSPUSHINT(SAVEt_PPTR);
444 Perl_save_vptr(pTHX_ void *ptr)
448 PERL_ARGS_ASSERT_SAVE_VPTR;
451 SSPUSHPTR(*(char**)ptr);
453 SSPUSHINT(SAVEt_VPTR);
457 Perl_save_sptr(pTHX_ SV **sptr)
461 PERL_ARGS_ASSERT_SAVE_SPTR;
466 SSPUSHINT(SAVEt_SPTR);
470 Perl_save_padsv_and_mortalize(pTHX_ PADOFFSET off)
474 ASSERT_CURPAD_ACTIVE("save_padsv");
475 SSPUSHPTR(SvREFCNT_inc_simple_NN(PL_curpad[off]));
476 SSPUSHPTR(PL_comppad);
477 SSPUSHLONG((long)off);
478 SSPUSHINT(SAVEt_PADSV_AND_MORTALIZE);
482 Perl_save_hptr(pTHX_ HV **hptr)
486 PERL_ARGS_ASSERT_SAVE_HPTR;
491 SSPUSHINT(SAVEt_HPTR);
495 Perl_save_aptr(pTHX_ AV **aptr)
499 PERL_ARGS_ASSERT_SAVE_APTR;
504 SSPUSHINT(SAVEt_APTR);
508 Perl_save_freesv(pTHX_ SV *sv)
513 SSPUSHINT(SAVEt_FREESV);
517 Perl_save_mortalizesv(pTHX_ SV *sv)
521 PERL_ARGS_ASSERT_SAVE_MORTALIZESV;
525 SSPUSHINT(SAVEt_MORTALIZESV);
529 Perl_save_freeop(pTHX_ OP *o)
534 SSPUSHINT(SAVEt_FREEOP);
538 Perl_save_freepv(pTHX_ char *pv)
543 SSPUSHINT(SAVEt_FREEPV);
547 Perl_save_clearsv(pTHX_ SV **svp)
551 PERL_ARGS_ASSERT_SAVE_CLEARSV;
553 ASSERT_CURPAD_ACTIVE("save_clearsv");
555 SSPUSHLONG((long)(svp-PL_curpad));
556 SSPUSHINT(SAVEt_CLEARSV);
557 SvPADSTALE_off(*svp); /* mark lexical as active */
561 Perl_save_delete(pTHX_ HV *hv, char *key, I32 klen)
565 PERL_ARGS_ASSERT_SAVE_DELETE;
570 SSPUSHPTR(SvREFCNT_inc_simple(hv));
571 SSPUSHINT(SAVEt_DELETE);
575 Perl_save_destructor(pTHX_ DESTRUCTORFUNC_NOCONTEXT_t f, void* p)
579 PERL_ARGS_ASSERT_SAVE_DESTRUCTOR;
584 SSPUSHINT(SAVEt_DESTRUCTOR);
588 Perl_save_destructor_x(pTHX_ DESTRUCTORFUNC_t f, void* p)
594 SSPUSHINT(SAVEt_DESTRUCTOR_X);
598 Perl_save_aelem(pTHX_ AV *av, I32 idx, SV **sptr)
603 PERL_ARGS_ASSERT_SAVE_AELEM;
607 SSPUSHPTR(SvREFCNT_inc_simple(av));
609 SSPUSHPTR(SvREFCNT_inc(*sptr));
610 SSPUSHINT(SAVEt_AELEM);
611 /* if it gets reified later, the restore will have the wrong refcnt */
612 if (!AvREAL(av) && AvREIFY(av))
613 SvREFCNT_inc_void(*sptr);
614 save_scalar_at(sptr, SAVEf_SETMAGIC); /* XXX - FIXME - see #60360 */
616 /* If we're localizing a tied array element, this new sv
617 * won't actually be stored in the array - so it won't get
618 * reaped when the localize ends. Ensure it gets reaped by
619 * mortifying it instead. DAPM */
620 if (SvTIED_mg(sv, PERL_MAGIC_tiedelem))
625 Perl_save_helem_flags(pTHX_ HV *hv, SV *key, SV **sptr, const U32 flags)
630 PERL_ARGS_ASSERT_SAVE_HELEM_FLAGS;
634 SSPUSHPTR(SvREFCNT_inc_simple(hv));
635 SSPUSHPTR(newSVsv(key));
636 SSPUSHPTR(SvREFCNT_inc(*sptr));
637 SSPUSHINT(SAVEt_HELEM);
638 save_scalar_at(sptr, flags);
640 /* If we're localizing a tied hash element, this new sv
641 * won't actually be stored in the hash - so it won't get
642 * reaped when the localize ends. Ensure it gets reaped by
643 * mortifying it instead. DAPM */
644 if (SvTIED_mg(sv, PERL_MAGIC_tiedelem))
649 Perl_save_svref(pTHX_ SV **sptr)
653 PERL_ARGS_ASSERT_SAVE_SVREF;
658 SSPUSHPTR(SvREFCNT_inc(*sptr));
659 SSPUSHINT(SAVEt_SVREF);
660 return save_scalar_at(sptr, SAVEf_SETMAGIC); /* XXX - FIXME - see #60360 */
673 Perl_save_alloc(pTHX_ I32 size, I32 pad)
676 register const I32 start = pad + ((char*)&PL_savestack[PL_savestack_ix]
677 - (char*)PL_savestack);
678 register const I32 elems = 1 + ((size + pad - 1) / sizeof(*PL_savestack));
682 PL_savestack_ix += elems;
684 SSPUSHINT(SAVEt_ALLOC);
689 Perl_leave_scope(pTHX_ I32 base)
702 Perl_croak(aTHX_ "panic: corrupt saved stack index");
703 while (PL_savestack_ix > base) {
705 case SAVEt_ITEM: /* normal string */
706 value = MUTABLE_SV(SSPOPPTR);
707 sv = MUTABLE_SV(SSPOPPTR);
708 sv_replace(sv,value);
713 case SAVEt_SV: /* scalar reference */
714 value = MUTABLE_SV(SSPOPPTR);
715 gv = MUTABLE_GV(SSPOPPTR);
717 av = MUTABLE_AV(gv); /* what to refcnt_dec */
726 if (av) /* actually an av, hv or gv */
729 case SAVEt_GENERIC_PVREF: /* generic pv */
731 str = (char*)SSPOPPTR;
732 if (*(char**)ptr != str) {
733 Safefree(*(char**)ptr);
737 case SAVEt_SHARED_PVREF: /* shared pv */
738 str = (char*)SSPOPPTR;
740 if (*(char**)ptr != str) {
742 PerlMem_free(*(char**)ptr);
744 PerlMemShared_free(*(char**)ptr);
749 case SAVEt_GENERIC_SVREF: /* generic sv */
750 value = MUTABLE_SV(SSPOPPTR);
757 case SAVEt_AV: /* array reference */
758 av = MUTABLE_AV(SSPOPPTR);
759 gv = MUTABLE_GV(SSPOPPTR);
761 SvREFCNT_dec(GvAV(gv));
766 SvSETMAGIC(MUTABLE_SV(av));
770 case SAVEt_HV: /* hash reference */
771 hv = MUTABLE_HV(SSPOPPTR);
772 gv = MUTABLE_GV(SSPOPPTR);
774 SvREFCNT_dec(GvHV(gv));
779 SvSETMAGIC(MUTABLE_SV(hv));
783 case SAVEt_INT: /* int reference */
785 *(int*)ptr = (int)SSPOPINT;
787 case SAVEt_BOOL: /* bool reference */
789 *(bool*)ptr = (bool)SSPOPBOOL;
791 case SAVEt_I32: /* I32 reference */
793 #ifdef PERL_DEBUG_READONLY_OPS
795 const I32 val = SSPOPINT;
796 if (*(I32*)ptr != val)
800 *(I32*)ptr = (I32)SSPOPINT;
803 case SAVEt_SPTR: /* SV* reference */
805 *(SV**)ptr = MUTABLE_SV(SSPOPPTR);
807 case SAVEt_VPTR: /* random* reference */
808 case SAVEt_PPTR: /* char* reference */
810 *(char**)ptr = (char*)SSPOPPTR;
812 case SAVEt_HPTR: /* HV* reference */
814 *(HV**)ptr = MUTABLE_HV(SSPOPPTR);
816 case SAVEt_APTR: /* AV* reference */
818 *(AV**)ptr = MUTABLE_AV(SSPOPPTR);
820 case SAVEt_GP: /* scalar reference */
822 gv = MUTABLE_GV(SSPOPPTR);
825 /* putting a method back into circulation ("local")*/
826 if (GvCVu(gv) && (hv=GvSTASH(gv)) && HvNAME_get(hv))
827 mro_method_changed_in(hv);
832 SvREFCNT_dec(MUTABLE_SV(ptr));
834 case SAVEt_MORTALIZESV:
836 sv_2mortal(MUTABLE_SV(ptr));
840 ASSERT_CURPAD_LEGAL("SAVEt_FREEOP"); /* XXX DAPM tmp */
848 ptr = (void*)&PL_curpad[SSPOPLONG];
851 DEBUG_Xv(PerlIO_printf(Perl_debug_log,
852 "Pad 0x%"UVxf"[0x%"UVxf"] clearsv: %ld sv=0x%"UVxf"<%"IVdf"> %s\n",
853 PTR2UV(PL_comppad), PTR2UV(PL_curpad),
854 (long)((SV **)ptr-PL_curpad), PTR2UV(sv), (IV)SvREFCNT(sv),
855 (SvREFCNT(sv) <= 1 && !SvOBJECT(sv)) ? "clear" : "abandon"
858 /* Can clear pad variable in place? */
859 if (SvREFCNT(sv) <= 1 && !SvOBJECT(sv)) {
861 * if a my variable that was made readonly is going out of
862 * scope, we want to remove the readonlyness so that it can
863 * go out of scope quietly
865 if (SvPADMY(sv) && !SvFAKE(sv))
868 if (SvTHINKFIRST(sv))
869 sv_force_normal_flags(sv, SV_IMMEDIATE_UNREF);
873 switch (SvTYPE(sv)) {
877 av_clear(MUTABLE_AV(sv));
880 hv_clear(MUTABLE_HV(sv));
883 Perl_croak(aTHX_ "panic: leave_scope pad code");
888 SvPADSTALE_on(sv); /* mark as no longer live */
890 else { /* Someone has a claim on this, so abandon it. */
891 const U32 padflags = SvFLAGS(sv) & (SVs_PADMY|SVs_PADTMP);
892 switch (SvTYPE(sv)) { /* Console ourselves with a new value */
893 case SVt_PVAV: *(SV**)ptr = MUTABLE_SV(newAV()); break;
894 case SVt_PVHV: *(SV**)ptr = MUTABLE_SV(newHV()); break;
895 default: *(SV**)ptr = newSV(0); break;
897 SvREFCNT_dec(sv); /* Cast current value to the winds. */
898 /* preserve pad nature, but also mark as not live
899 * for any closure capturing */
900 SvFLAGS(*(SV**)ptr) |= padflags | SVs_PADSTALE;
905 hv = MUTABLE_HV(ptr);
907 (void)hv_delete(hv, (char*)ptr, (I32)SSPOPINT, G_DISCARD);
911 case SAVEt_DESTRUCTOR_X:
913 (*SSPOPDXPTR)(aTHX_ ptr);
915 case SAVEt_REGCONTEXT:
918 PL_savestack_ix -= i; /* regexp must have croaked */
920 case SAVEt_STACK_POS: /* Position on Perl stack */
922 PL_stack_sp = PL_stack_base + i;
924 case SAVEt_STACK_CXPOS: /* blk_oldsp on context stack */
926 cxstack[i].blk_oldsp = SSPOPINT;
928 case SAVEt_AELEM: /* array element */
929 value = MUTABLE_SV(SSPOPPTR);
931 av = MUTABLE_AV(SSPOPPTR);
932 ptr = av_fetch(av,i,1);
933 if (!AvREAL(av) && AvREIFY(av)) /* undo reify guard */
937 if (sv && sv != &PL_sv_undef) {
938 if (SvTIED_mg((const SV *)av, PERL_MAGIC_tied))
939 SvREFCNT_inc_void_NN(sv);
946 case SAVEt_HELEM: /* hash element */
947 value = MUTABLE_SV(SSPOPPTR);
948 sv = MUTABLE_SV(SSPOPPTR);
949 hv = MUTABLE_HV(SSPOPPTR);
950 ptr = hv_fetch_ent(hv, sv, 1, 0);
952 const SV * const oval = HeVAL((HE*)ptr);
953 if (oval && oval != &PL_sv_undef) {
954 ptr = &HeVAL((HE*)ptr);
955 if (SvTIED_mg((const SV *)hv, PERL_MAGIC_tied))
956 SvREFCNT_inc_void(*(SV**)ptr);
958 av = MUTABLE_AV(hv); /* what to refcnt_dec */
967 PL_op = (OP*)SSPOPPTR;
970 if ((PL_hints & HINT_LOCALIZE_HH) && GvHV(PL_hintgv)) {
971 SvREFCNT_dec(MUTABLE_SV(GvHV(PL_hintgv)));
972 GvHV(PL_hintgv) = NULL;
974 *(I32*)&PL_hints = (I32)SSPOPINT;
975 Perl_refcounted_he_free(aTHX_ PL_compiling.cop_hints_hash);
976 PL_compiling.cop_hints_hash = (struct refcounted_he *) SSPOPPTR;
977 if (PL_hints & HINT_LOCALIZE_HH) {
978 SvREFCNT_dec(MUTABLE_SV(GvHV(PL_hintgv)));
979 GvHV(PL_hintgv) = MUTABLE_HV(SSPOPPTR);
980 assert(GvHV(PL_hintgv));
981 } else if (!GvHV(PL_hintgv)) {
982 /* Need to add a new one manually, else gv_fetchpv() can
983 add one in this code:
985 if (SvTYPE(gv) == SVt_PVGV) {
988 gv_init_sv(gv, sv_type);
989 if (*name=='!' && sv_type == SVt_PVHV && len==1)
995 and it won't have the magic set. */
997 HV *const hv = newHV();
998 hv_magic(hv, NULL, PERL_MAGIC_hints);
999 GvHV(PL_hintgv) = hv;
1001 assert(GvHV(PL_hintgv));
1004 PL_comppad = (PAD*)SSPOPPTR;
1006 PL_curpad = AvARRAY(PL_comppad);
1010 case SAVEt_PADSV_AND_MORTALIZE:
1012 const PADOFFSET off = (PADOFFSET)SSPOPLONG;
1016 svp = AvARRAY((PAD*)ptr) + off;
1017 /* This mortalizing used to be done by POPLOOP() via itersave.
1018 But as we have all the information here, we can do it here,
1019 save even having to have itersave in the struct. */
1021 *svp = MUTABLE_SV(SSPOPPTR);
1024 case SAVEt_SAVESWITCHSTACK:
1027 AV *const t = MUTABLE_AV(SSPOPPTR);
1028 AV *const f = MUTABLE_AV(SSPOPPTR);
1030 PL_curstackinfo->si_stack = f;
1033 case SAVEt_SET_SVFLAGS:
1035 const U32 val = (U32)SSPOPINT;
1036 const U32 mask = (U32)SSPOPINT;
1037 sv = MUTABLE_SV(SSPOPPTR);
1038 SvFLAGS(sv) &= ~mask;
1043 /* This would be a mathom, but Perl_save_svref() calls a static
1044 function, S_save_scalar_at(), so has to stay in this file. */
1045 case SAVEt_SVREF: /* scalar reference */
1046 value = MUTABLE_SV(SSPOPPTR);
1048 av = NULL; /* what to refcnt_dec */
1051 /* These are only saved in mathoms.c */
1053 gv = MUTABLE_GV(SSPOPPTR);
1054 (void)sv_clear(MUTABLE_SV(gv));
1056 case SAVEt_LONG: /* long reference */
1058 *(long*)ptr = (long)SSPOPLONG;
1060 case SAVEt_IV: /* IV reference */
1062 *(IV*)ptr = (IV)SSPOPIV;
1065 case SAVEt_I16: /* I16 reference */
1067 *(I16*)ptr = (I16)SSPOPINT;
1069 case SAVEt_I8: /* I8 reference */
1071 *(I8*)ptr = (I8)SSPOPINT;
1073 case SAVEt_DESTRUCTOR:
1077 case SAVEt_COP_ARYBASE:
1080 CopARYBASE_set((COP *)ptr, i);
1082 case SAVEt_COMPILE_WARNINGS:
1085 if (!specialWARN(PL_compiling.cop_warnings))
1086 PerlMemShared_free(PL_compiling.cop_warnings);
1088 PL_compiling.cop_warnings = (STRLEN*)ptr;
1090 case SAVEt_RE_STATE:
1092 const struct re_save_state *const state
1093 = (struct re_save_state *)
1094 (PL_savestack + PL_savestack_ix
1095 - SAVESTACK_ALLOC_FOR_RE_SAVE_STATE);
1096 PL_savestack_ix -= SAVESTACK_ALLOC_FOR_RE_SAVE_STATE;
1098 if (PL_reg_start_tmp != state->re_state_reg_start_tmp) {
1099 Safefree(PL_reg_start_tmp);
1101 if (PL_reg_poscache != state->re_state_reg_poscache) {
1102 Safefree(PL_reg_poscache);
1104 Copy(state, &PL_reg_state, 1, struct re_save_state);
1109 parser_free((yy_parser *) ptr);
1112 Perl_croak(aTHX_ "panic: leave_scope inconsistency");
1118 Perl_cx_dump(pTHX_ PERL_CONTEXT *cx)
1122 PERL_ARGS_ASSERT_CX_DUMP;
1125 PerlIO_printf(Perl_debug_log, "CX %ld = %s\n", (long)(cx - cxstack), PL_block_type[CxTYPE(cx)]);
1126 if (CxTYPE(cx) != CXt_SUBST) {
1127 PerlIO_printf(Perl_debug_log, "BLK_OLDSP = %ld\n", (long)cx->blk_oldsp);
1128 PerlIO_printf(Perl_debug_log, "BLK_OLDCOP = 0x%"UVxf"\n",
1129 PTR2UV(cx->blk_oldcop));
1130 PerlIO_printf(Perl_debug_log, "BLK_OLDMARKSP = %ld\n", (long)cx->blk_oldmarksp);
1131 PerlIO_printf(Perl_debug_log, "BLK_OLDSCOPESP = %ld\n", (long)cx->blk_oldscopesp);
1132 PerlIO_printf(Perl_debug_log, "BLK_OLDPM = 0x%"UVxf"\n",
1133 PTR2UV(cx->blk_oldpm));
1134 PerlIO_printf(Perl_debug_log, "BLK_GIMME = %s\n", cx->blk_gimme ? "LIST" : "SCALAR");
1136 switch (CxTYPE(cx)) {
1141 PerlIO_printf(Perl_debug_log, "BLK_FORMAT.CV = 0x%"UVxf"\n",
1142 PTR2UV(cx->blk_format.cv));
1143 PerlIO_printf(Perl_debug_log, "BLK_FORMAT.GV = 0x%"UVxf"\n",
1144 PTR2UV(cx->blk_format.gv));
1145 PerlIO_printf(Perl_debug_log, "BLK_FORMAT.DFOUTGV = 0x%"UVxf"\n",
1146 PTR2UV(cx->blk_format.dfoutgv));
1147 PerlIO_printf(Perl_debug_log, "BLK_FORMAT.HASARGS = %d\n",
1148 (int)CxHASARGS(cx));
1149 PerlIO_printf(Perl_debug_log, "BLK_FORMAT.RETOP = 0x%"UVxf"\n",
1150 PTR2UV(cx->blk_format.retop));
1153 PerlIO_printf(Perl_debug_log, "BLK_SUB.CV = 0x%"UVxf"\n",
1154 PTR2UV(cx->blk_sub.cv));
1155 PerlIO_printf(Perl_debug_log, "BLK_SUB.OLDDEPTH = %ld\n",
1156 (long)cx->blk_sub.olddepth);
1157 PerlIO_printf(Perl_debug_log, "BLK_SUB.HASARGS = %d\n",
1158 (int)CxHASARGS(cx));
1159 PerlIO_printf(Perl_debug_log, "BLK_SUB.LVAL = %d\n", (int)CxLVAL(cx));
1160 PerlIO_printf(Perl_debug_log, "BLK_SUB.RETOP = 0x%"UVxf"\n",
1161 PTR2UV(cx->blk_sub.retop));
1164 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_IN_EVAL = %ld\n",
1165 (long)CxOLD_IN_EVAL(cx));
1166 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_OP_TYPE = %s (%s)\n",
1167 PL_op_name[CxOLD_OP_TYPE(cx)],
1168 PL_op_desc[CxOLD_OP_TYPE(cx)]);
1169 if (cx->blk_eval.old_namesv)
1170 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_NAME = %s\n",
1171 SvPVX_const(cx->blk_eval.old_namesv));
1172 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_EVAL_ROOT = 0x%"UVxf"\n",
1173 PTR2UV(cx->blk_eval.old_eval_root));
1174 PerlIO_printf(Perl_debug_log, "BLK_EVAL.RETOP = 0x%"UVxf"\n",
1175 PTR2UV(cx->blk_eval.retop));
1178 case CXt_LOOP_LAZYIV:
1179 case CXt_LOOP_LAZYSV:
1181 case CXt_LOOP_PLAIN:
1182 PerlIO_printf(Perl_debug_log, "BLK_LOOP.LABEL = %s\n", CxLABEL(cx));
1183 PerlIO_printf(Perl_debug_log, "BLK_LOOP.RESETSP = %ld\n",
1184 (long)cx->blk_loop.resetsp);
1185 PerlIO_printf(Perl_debug_log, "BLK_LOOP.MY_OP = 0x%"UVxf"\n",
1186 PTR2UV(cx->blk_loop.my_op));
1187 PerlIO_printf(Perl_debug_log, "BLK_LOOP.NEXT_OP = 0x%"UVxf"\n",
1188 PTR2UV(CX_LOOP_NEXTOP_GET(cx)));
1189 /* XXX: not accurate for LAZYSV/IV */
1190 PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERARY = 0x%"UVxf"\n",
1191 PTR2UV(cx->blk_loop.state_u.ary.ary));
1192 PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERIX = %ld\n",
1193 (long)cx->blk_loop.state_u.ary.ix);
1194 PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERVAR = 0x%"UVxf"\n",
1195 PTR2UV(CxITERVAR(cx)));
1199 PerlIO_printf(Perl_debug_log, "SB_ITERS = %ld\n",
1200 (long)cx->sb_iters);
1201 PerlIO_printf(Perl_debug_log, "SB_MAXITERS = %ld\n",
1202 (long)cx->sb_maxiters);
1203 PerlIO_printf(Perl_debug_log, "SB_RFLAGS = %ld\n",
1204 (long)cx->sb_rflags);
1205 PerlIO_printf(Perl_debug_log, "SB_ONCE = %ld\n",
1207 PerlIO_printf(Perl_debug_log, "SB_ORIG = %s\n",
1209 PerlIO_printf(Perl_debug_log, "SB_DSTR = 0x%"UVxf"\n",
1210 PTR2UV(cx->sb_dstr));
1211 PerlIO_printf(Perl_debug_log, "SB_TARG = 0x%"UVxf"\n",
1212 PTR2UV(cx->sb_targ));
1213 PerlIO_printf(Perl_debug_log, "SB_S = 0x%"UVxf"\n",
1215 PerlIO_printf(Perl_debug_log, "SB_M = 0x%"UVxf"\n",
1217 PerlIO_printf(Perl_debug_log, "SB_STREND = 0x%"UVxf"\n",
1218 PTR2UV(cx->sb_strend));
1219 PerlIO_printf(Perl_debug_log, "SB_RXRES = 0x%"UVxf"\n",
1220 PTR2UV(cx->sb_rxres));
1224 PERL_UNUSED_CONTEXT;
1225 PERL_UNUSED_ARG(cx);
1226 #endif /* DEBUGGING */
1231 * c-indentation-style: bsd
1233 * indent-tabs-mode: t
1236 * ex: set ts=8 sts=4 sw=4 noet: