3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 * 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 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
16 /* This file contains functions to manipulate several of Perl's stacks;
17 * in particular it contains code to push various types of things onto
18 * the savestack, then to pop them off and perform the correct restorative
19 * action for each one. This corresponds to the cleanup Perl does at
24 #define PERL_IN_SCOPE_C
28 Perl_stack_grow(pTHX_ SV **sp, SV **p, int n)
32 PERL_ARGS_ASSERT_STACK_GROW;
35 #ifndef STRESS_REALLOC
36 av_extend(PL_curstack, (p - PL_stack_base) + (n) + 128);
38 av_extend(PL_curstack, (p - PL_stack_base) + (n) + 1);
43 #ifndef STRESS_REALLOC
44 #define GROW(old) ((old) * 3 / 2)
46 #define GROW(old) ((old) + 1)
50 Perl_new_stackinfo(pTHX_ I32 stitems, I32 cxitems)
55 si->si_stack = newAV();
56 AvREAL_off(si->si_stack);
57 av_extend(si->si_stack, stitems > 0 ? stitems-1 : 0);
58 AvALLOC(si->si_stack)[0] = &PL_sv_undef;
59 AvFILLp(si->si_stack) = 0;
62 si->si_cxmax = cxitems - 1;
64 si->si_type = PERLSI_UNDEF;
65 Newx(si->si_cxstack, cxitems, PERL_CONTEXT);
66 /* Without any kind of initialising PUSHSUBST()
67 * in pp_subst() will read uninitialised heap. */
68 PoisonNew(si->si_cxstack, cxitems, PERL_CONTEXT);
76 const IV old_max = cxstack_max;
77 cxstack_max = GROW(cxstack_max);
78 Renew(cxstack, cxstack_max + 1, PERL_CONTEXT); /* XXX should fix CXINC macro */
79 /* Without any kind of initialising deep enough recursion
80 * will end up reading uninitialised PERL_CONTEXTs. */
81 PoisonNew(cxstack + old_max + 1, cxstack_max - old_max, PERL_CONTEXT);
82 return cxstack_ix + 1;
89 if (PL_scopestack_ix == PL_scopestack_max) {
90 PL_scopestack_max = GROW(PL_scopestack_max);
91 Renew(PL_scopestack, PL_scopestack_max, I32);
93 PL_scopestack[PL_scopestack_ix++] = PL_savestack_ix;
101 const I32 oldsave = PL_scopestack[--PL_scopestack_ix];
102 LEAVE_SCOPE(oldsave);
106 Perl_markstack_grow(pTHX)
109 const I32 oldmax = PL_markstack_max - PL_markstack;
110 const I32 newmax = GROW(oldmax);
112 Renew(PL_markstack, newmax, I32);
113 PL_markstack_ptr = PL_markstack + oldmax;
114 PL_markstack_max = PL_markstack + newmax;
118 Perl_savestack_grow(pTHX)
121 PL_savestack_max = GROW(PL_savestack_max) + 4;
122 Renew(PL_savestack, PL_savestack_max, ANY);
126 Perl_savestack_grow_cnt(pTHX_ I32 need)
129 PL_savestack_max = PL_savestack_ix + need;
130 Renew(PL_savestack, PL_savestack_max, ANY);
136 Perl_tmps_grow(pTHX_ I32 n)
139 #ifndef STRESS_REALLOC
141 n = (PL_tmps_max < 512) ? 128 : 512;
143 PL_tmps_max = PL_tmps_ix + n + 1;
144 Renew(PL_tmps_stack, PL_tmps_max, SV*);
152 /* XXX should tmps_floor live in cxstack? */
153 const I32 myfloor = PL_tmps_floor;
154 while (PL_tmps_ix > myfloor) { /* clean up after last statement */
155 SV* const sv = PL_tmps_stack[PL_tmps_ix];
156 PL_tmps_stack[PL_tmps_ix--] = NULL;
157 if (sv && sv != &PL_sv_undef) {
159 SvREFCNT_dec(sv); /* note, can modify tmps_ix!!! */
165 S_save_scalar_at(pTHX_ SV **sptr)
168 SV * const osv = *sptr;
169 register SV * const sv = *sptr = newSV(0);
171 PERL_ARGS_ASSERT_SAVE_SCALAR_AT;
173 if (SvTYPE(osv) >= SVt_PVMG && SvMAGIC(osv) && SvTYPE(osv) != SVt_PVGV) {
174 if (SvGMAGICAL(osv)) {
175 const bool oldtainted = PL_tainted;
176 SvFLAGS(osv) |= (SvFLAGS(osv) &
177 (SVp_IOK|SVp_NOK|SVp_POK)) >> PRIVSHIFT;
178 PL_tainted = oldtainted;
180 mg_localize(osv, sv);
186 Perl_save_scalar(pTHX_ GV *gv)
189 SV ** const sptr = &GvSVn(gv);
191 PERL_ARGS_ASSERT_SAVE_SCALAR;
197 SSPUSHPTR(SvREFCNT_inc_simple(gv));
198 SSPUSHPTR(SvREFCNT_inc(*sptr));
200 return save_scalar_at(sptr);
203 /* Like save_sptr(), but also SvREFCNT_dec()s the new value. Can be used to
204 * restore a global SV to its prior contents, freeing new value. */
206 Perl_save_generic_svref(pTHX_ SV **sptr)
210 PERL_ARGS_ASSERT_SAVE_GENERIC_SVREF;
214 SSPUSHPTR(SvREFCNT_inc(*sptr));
215 SSPUSHINT(SAVEt_GENERIC_SVREF);
218 /* Like save_pptr(), but also Safefree()s the new value if it is different
219 * from the old one. Can be used to restore a global char* to its prior
220 * contents, freeing new value. */
222 Perl_save_generic_pvref(pTHX_ char **str)
226 PERL_ARGS_ASSERT_SAVE_GENERIC_PVREF;
231 SSPUSHINT(SAVEt_GENERIC_PVREF);
234 /* Like save_generic_pvref(), but uses PerlMemShared_free() rather than Safefree().
235 * Can be used to restore a shared global char* to its prior
236 * contents, freeing new value. */
238 Perl_save_shared_pvref(pTHX_ char **str)
242 PERL_ARGS_ASSERT_SAVE_SHARED_PVREF;
247 SSPUSHINT(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;
274 SSPUSHPTR(SvREFCNT_inc(gv));
279 GP *gp = Perl_newGP(aTHX_ gv);
282 mro_method_changed_in(GvSTASH(gv)); /* taking a method out of circulation ("local")*/
283 if (GvIOp(gv) && (IoFLAGS(GvIOp(gv)) & IOf_ARGV)) {
285 IoFLAGS(gp->gp_io) |= IOf_ARGV|IOf_START;
287 #ifdef PERL_DONT_CREATE_GVSV
288 if (gv == PL_errgv) {
289 /* We could scatter this logic everywhere by changing the
290 definition of ERRSV from GvSV() to GvSVn(), but it seems more
291 efficient to do this check once here. */
292 gp->gp_sv = newSV(0);
304 Perl_save_ary(pTHX_ GV *gv)
307 AV * const oav = GvAVn(gv);
310 PERL_ARGS_ASSERT_SAVE_ARY;
312 if (!AvREAL(oav) && AvREIFY(oav))
322 mg_localize((SV*)oav, (SV*)av);
327 Perl_save_hash(pTHX_ GV *gv)
332 PERL_ARGS_ASSERT_SAVE_HASH;
336 SSPUSHPTR(ohv = GvHVn(gv));
342 mg_localize((SV*)ohv, (SV*)hv);
347 Perl_save_item(pTHX_ register SV *item)
350 register SV * const sv = newSVsv(item);
352 PERL_ARGS_ASSERT_SAVE_ITEM;
355 SSPUSHPTR(item); /* remember the pointer */
356 SSPUSHPTR(sv); /* remember the value */
357 SSPUSHINT(SAVEt_ITEM);
361 Perl_save_int(pTHX_ int *intp)
365 PERL_ARGS_ASSERT_SAVE_INT;
370 SSPUSHINT(SAVEt_INT);
374 Perl_save_bool(pTHX_ bool *boolp)
378 PERL_ARGS_ASSERT_SAVE_BOOL;
383 SSPUSHINT(SAVEt_BOOL);
387 Perl_save_I8(pTHX_ I8 *bytep)
391 PERL_ARGS_ASSERT_SAVE_I8;
400 Perl_save_I16(pTHX_ I16 *intp)
404 PERL_ARGS_ASSERT_SAVE_I16;
409 SSPUSHINT(SAVEt_I16);
413 Perl_save_I32(pTHX_ I32 *intp)
417 PERL_ARGS_ASSERT_SAVE_I32;
422 SSPUSHINT(SAVEt_I32);
425 /* Cannot use save_sptr() to store a char* since the SV** cast will
426 * force word-alignment and we'll miss the pointer.
429 Perl_save_pptr(pTHX_ char **pptr)
433 PERL_ARGS_ASSERT_SAVE_PPTR;
438 SSPUSHINT(SAVEt_PPTR);
442 Perl_save_vptr(pTHX_ void *ptr)
446 PERL_ARGS_ASSERT_SAVE_VPTR;
449 SSPUSHPTR(*(char**)ptr);
451 SSPUSHINT(SAVEt_VPTR);
455 Perl_save_sptr(pTHX_ SV **sptr)
459 PERL_ARGS_ASSERT_SAVE_SPTR;
464 SSPUSHINT(SAVEt_SPTR);
468 Perl_save_padsv_and_mortalize(pTHX_ PADOFFSET off)
472 ASSERT_CURPAD_ACTIVE("save_padsv");
473 SSPUSHPTR(SvREFCNT_inc_simple_NN(PL_curpad[off]));
474 SSPUSHPTR(PL_comppad);
475 SSPUSHLONG((long)off);
476 SSPUSHINT(SAVEt_PADSV_AND_MORTALIZE);
480 Perl_save_hptr(pTHX_ HV **hptr)
484 PERL_ARGS_ASSERT_SAVE_HPTR;
489 SSPUSHINT(SAVEt_HPTR);
493 Perl_save_aptr(pTHX_ AV **aptr)
497 PERL_ARGS_ASSERT_SAVE_APTR;
502 SSPUSHINT(SAVEt_APTR);
506 Perl_save_freesv(pTHX_ SV *sv)
511 SSPUSHINT(SAVEt_FREESV);
515 Perl_save_mortalizesv(pTHX_ SV *sv)
519 PERL_ARGS_ASSERT_SAVE_MORTALIZESV;
523 SSPUSHINT(SAVEt_MORTALIZESV);
527 Perl_save_freeop(pTHX_ OP *o)
532 SSPUSHINT(SAVEt_FREEOP);
536 Perl_save_freepv(pTHX_ char *pv)
541 SSPUSHINT(SAVEt_FREEPV);
545 Perl_save_clearsv(pTHX_ SV **svp)
549 PERL_ARGS_ASSERT_SAVE_CLEARSV;
551 ASSERT_CURPAD_ACTIVE("save_clearsv");
553 SSPUSHLONG((long)(svp-PL_curpad));
554 SSPUSHINT(SAVEt_CLEARSV);
555 SvPADSTALE_off(*svp); /* mark lexical as active */
559 Perl_save_delete(pTHX_ HV *hv, char *key, I32 klen)
563 PERL_ARGS_ASSERT_SAVE_DELETE;
568 SSPUSHPTR(SvREFCNT_inc_simple(hv));
569 SSPUSHINT(SAVEt_DELETE);
573 Perl_save_destructor(pTHX_ DESTRUCTORFUNC_NOCONTEXT_t f, void* p)
577 PERL_ARGS_ASSERT_SAVE_DESTRUCTOR;
582 SSPUSHINT(SAVEt_DESTRUCTOR);
586 Perl_save_destructor_x(pTHX_ DESTRUCTORFUNC_t f, void* p)
592 SSPUSHINT(SAVEt_DESTRUCTOR_X);
596 Perl_save_aelem(pTHX_ AV *av, I32 idx, SV **sptr)
601 PERL_ARGS_ASSERT_SAVE_AELEM;
605 SSPUSHPTR(SvREFCNT_inc_simple(av));
607 SSPUSHPTR(SvREFCNT_inc(*sptr));
608 SSPUSHINT(SAVEt_AELEM);
609 /* if it gets reified later, the restore will have the wrong refcnt */
610 if (!AvREAL(av) && AvREIFY(av))
611 SvREFCNT_inc_void(*sptr);
612 save_scalar_at(sptr);
614 /* If we're localizing a tied array element, this new sv
615 * won't actually be stored in the array - 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_helem(pTHX_ HV *hv, SV *key, SV **sptr)
628 PERL_ARGS_ASSERT_SAVE_HELEM;
632 SSPUSHPTR(SvREFCNT_inc_simple(hv));
633 SSPUSHPTR(newSVsv(key));
634 SSPUSHPTR(SvREFCNT_inc(*sptr));
635 SSPUSHINT(SAVEt_HELEM);
636 save_scalar_at(sptr);
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;
656 SSPUSHPTR(SvREFCNT_inc(*sptr));
657 SSPUSHINT(SAVEt_SVREF);
658 return save_scalar_at(sptr);
671 Perl_save_alloc(pTHX_ I32 size, I32 pad)
674 register const I32 start = pad + ((char*)&PL_savestack[PL_savestack_ix]
675 - (char*)PL_savestack);
676 register const I32 elems = 1 + ((size + pad - 1) / sizeof(*PL_savestack));
680 PL_savestack_ix += elems;
682 SSPUSHINT(SAVEt_ALLOC);
687 Perl_leave_scope(pTHX_ I32 base)
700 Perl_croak(aTHX_ "panic: corrupt saved stack index");
701 while (PL_savestack_ix > base) {
703 case SAVEt_ITEM: /* normal string */
704 value = (SV*)SSPOPPTR;
706 sv_replace(sv,value);
711 case SAVEt_SV: /* scalar reference */
712 value = (SV*)SSPOPPTR;
715 av = (AV*)gv; /* what to refcnt_dec */
724 if (av) /* actually an av, hv or gv */
727 case SAVEt_GENERIC_PVREF: /* generic pv */
729 str = (char*)SSPOPPTR;
730 if (*(char**)ptr != str) {
731 Safefree(*(char**)ptr);
735 case SAVEt_SHARED_PVREF: /* shared pv */
736 str = (char*)SSPOPPTR;
738 if (*(char**)ptr != str) {
740 PerlMem_free(*(char**)ptr);
742 PerlMemShared_free(*(char**)ptr);
747 case SAVEt_GENERIC_SVREF: /* generic sv */
748 value = (SV*)SSPOPPTR;
755 case SAVEt_AV: /* array reference */
759 SvREFCNT_dec(GvAV(gv));
768 case SAVEt_HV: /* hash reference */
772 SvREFCNT_dec(GvHV(gv));
781 case SAVEt_INT: /* int reference */
783 *(int*)ptr = (int)SSPOPINT;
785 case SAVEt_BOOL: /* bool reference */
787 *(bool*)ptr = (bool)SSPOPBOOL;
789 case SAVEt_I32: /* I32 reference */
791 #ifdef PERL_DEBUG_READONLY_OPS
793 const I32 val = SSPOPINT;
794 if (*(I32*)ptr != val)
798 *(I32*)ptr = (I32)SSPOPINT;
801 case SAVEt_SPTR: /* SV* reference */
803 *(SV**)ptr = (SV*)SSPOPPTR;
805 case SAVEt_VPTR: /* random* reference */
806 case SAVEt_PPTR: /* char* reference */
808 *(char**)ptr = (char*)SSPOPPTR;
810 case SAVEt_HPTR: /* HV* reference */
812 *(HV**)ptr = (HV*)SSPOPPTR;
814 case SAVEt_APTR: /* AV* reference */
816 *(AV**)ptr = (AV*)SSPOPPTR;
818 case SAVEt_GP: /* scalar reference */
823 /* putting a method back into circulation ("local")*/
824 if (GvCVu(gv) && (hv=GvSTASH(gv)) && HvNAME_get(hv))
825 mro_method_changed_in(hv);
830 SvREFCNT_dec((SV*)ptr);
832 case SAVEt_MORTALIZESV:
834 sv_2mortal((SV*)ptr);
838 ASSERT_CURPAD_LEGAL("SAVEt_FREEOP"); /* XXX DAPM tmp */
846 ptr = (void*)&PL_curpad[SSPOPLONG];
849 DEBUG_Xv(PerlIO_printf(Perl_debug_log,
850 "Pad 0x%"UVxf"[0x%"UVxf"] clearsv: %ld sv=0x%"UVxf"<%"IVdf"> %s\n",
851 PTR2UV(PL_comppad), PTR2UV(PL_curpad),
852 (long)((SV **)ptr-PL_curpad), PTR2UV(sv), (IV)SvREFCNT(sv),
853 (SvREFCNT(sv) <= 1 && !SvOBJECT(sv)) ? "clear" : "abandon"
856 /* Can clear pad variable in place? */
857 if (SvREFCNT(sv) <= 1 && !SvOBJECT(sv)) {
859 * if a my variable that was made readonly is going out of
860 * scope, we want to remove the readonlyness so that it can
861 * go out of scope quietly
863 if (SvPADMY(sv) && !SvFAKE(sv))
866 if (SvTHINKFIRST(sv))
867 sv_force_normal_flags(sv, SV_IMMEDIATE_UNREF);
871 switch (SvTYPE(sv)) {
881 Perl_croak(aTHX_ "panic: leave_scope pad code");
886 SvPADSTALE_on(sv); /* mark as no longer live */
888 else { /* Someone has a claim on this, so abandon it. */
889 const U32 padflags = SvFLAGS(sv) & (SVs_PADMY|SVs_PADTMP);
890 switch (SvTYPE(sv)) { /* Console ourselves with a new value */
891 case SVt_PVAV: *(SV**)ptr = (SV*)newAV(); break;
892 case SVt_PVHV: *(SV**)ptr = (SV*)newHV(); break;
893 default: *(SV**)ptr = newSV(0); break;
895 SvREFCNT_dec(sv); /* Cast current value to the winds. */
896 /* preserve pad nature, but also mark as not live
897 * for any closure capturing */
898 SvFLAGS(*(SV**)ptr) |= padflags | SVs_PADSTALE;
905 (void)hv_delete(hv, (char*)ptr, (I32)SSPOPINT, 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 = (SV*)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((SV*)av, PERL_MAGIC_tied))
937 SvREFCNT_inc_void_NN(sv);
944 case SAVEt_HELEM: /* hash element */
945 value = (SV*)SSPOPPTR;
948 ptr = hv_fetch_ent(hv, sv, 1, 0);
950 const SV * const oval = HeVAL((HE*)ptr);
951 if (oval && oval != &PL_sv_undef) {
952 ptr = &HeVAL((HE*)ptr);
953 if (SvTIED_mg((SV*)hv, PERL_MAGIC_tied))
954 SvREFCNT_inc_void(*(SV**)ptr);
956 av = (AV*)hv; /* what to refcnt_dec */
965 PL_op = (OP*)SSPOPPTR;
968 if ((PL_hints & HINT_LOCALIZE_HH) && GvHV(PL_hintgv)) {
969 SvREFCNT_dec((SV*)GvHV(PL_hintgv));
970 GvHV(PL_hintgv) = NULL;
972 *(I32*)&PL_hints = (I32)SSPOPINT;
973 Perl_refcounted_he_free(aTHX_ PL_compiling.cop_hints_hash);
974 PL_compiling.cop_hints_hash = (struct refcounted_he *) SSPOPPTR;
975 if (PL_hints & HINT_LOCALIZE_HH) {
976 SvREFCNT_dec((SV*)GvHV(PL_hintgv));
977 GvHV(PL_hintgv) = (HV*)SSPOPPTR;
978 assert(GvHV(PL_hintgv));
979 } else if (!GvHV(PL_hintgv)) {
980 /* Need to add a new one manually, else gv_fetchpv() can
981 add one in this code:
983 if (SvTYPE(gv) == SVt_PVGV) {
986 gv_init_sv(gv, sv_type);
987 if (*name=='!' && sv_type == SVt_PVHV && len==1)
993 and it won't have the magic set. */
995 HV *const hv = newHV();
996 hv_magic(hv, NULL, PERL_MAGIC_hints);
997 GvHV(PL_hintgv) = hv;
999 assert(GvHV(PL_hintgv));
1002 PL_comppad = (PAD*)SSPOPPTR;
1004 PL_curpad = AvARRAY(PL_comppad);
1008 case SAVEt_PADSV_AND_MORTALIZE:
1010 const PADOFFSET off = (PADOFFSET)SSPOPLONG;
1014 svp = AvARRAY((PAD*)ptr) + off;
1015 /* This mortalizing used to be done by POPLOOP() via itersave.
1016 But as we have all the information here, we can do it here,
1017 save even having to have itersave in the struct. */
1019 *svp = (SV*)SSPOPPTR;
1022 case SAVEt_SAVESWITCHSTACK:
1025 AV* const t = (AV*)SSPOPPTR;
1026 AV* const f = (AV*)SSPOPPTR;
1028 PL_curstackinfo->si_stack = f;
1031 case SAVEt_SET_SVFLAGS:
1033 const U32 val = (U32)SSPOPINT;
1034 const U32 mask = (U32)SSPOPINT;
1036 SvFLAGS(sv) &= ~mask;
1040 /* These are only saved in mathoms.c */
1041 case SAVEt_SVREF: /* scalar reference */
1042 value = (SV*)SSPOPPTR;
1044 av = NULL; /* what to refcnt_dec */
1046 case SAVEt_LONG: /* long reference */
1048 *(long*)ptr = (long)SSPOPLONG;
1050 case SAVEt_I16: /* I16 reference */
1052 *(I16*)ptr = (I16)SSPOPINT;
1054 case SAVEt_I8: /* I8 reference */
1056 *(I8*)ptr = (I8)SSPOPINT;
1058 case SAVEt_IV: /* IV reference */
1060 *(IV*)ptr = (IV)SSPOPIV;
1064 (void)sv_clear((SV*)gv);
1066 case SAVEt_DESTRUCTOR:
1070 case SAVEt_COP_ARYBASE:
1073 CopARYBASE_set((COP *)ptr, i);
1075 case SAVEt_COMPILE_WARNINGS:
1078 if (!specialWARN(PL_compiling.cop_warnings))
1079 PerlMemShared_free(PL_compiling.cop_warnings);
1081 PL_compiling.cop_warnings = (STRLEN*)ptr;
1083 case SAVEt_RE_STATE:
1085 const struct re_save_state *const state
1086 = (struct re_save_state *)
1087 (PL_savestack + PL_savestack_ix
1088 - SAVESTACK_ALLOC_FOR_RE_SAVE_STATE);
1089 PL_savestack_ix -= SAVESTACK_ALLOC_FOR_RE_SAVE_STATE;
1091 if (PL_reg_start_tmp != state->re_state_reg_start_tmp) {
1092 Safefree(PL_reg_start_tmp);
1094 if (PL_reg_poscache != state->re_state_reg_poscache) {
1095 Safefree(PL_reg_poscache);
1097 Copy(state, &PL_reg_state, 1, struct re_save_state);
1102 parser_free((yy_parser *) ptr);
1105 Perl_croak(aTHX_ "panic: leave_scope inconsistency");
1111 Perl_cx_dump(pTHX_ PERL_CONTEXT *cx)
1115 PERL_ARGS_ASSERT_CX_DUMP;
1118 PerlIO_printf(Perl_debug_log, "CX %ld = %s\n", (long)(cx - cxstack), PL_block_type[CxTYPE(cx)]);
1119 if (CxTYPE(cx) != CXt_SUBST) {
1120 PerlIO_printf(Perl_debug_log, "BLK_OLDSP = %ld\n", (long)cx->blk_oldsp);
1121 PerlIO_printf(Perl_debug_log, "BLK_OLDCOP = 0x%"UVxf"\n",
1122 PTR2UV(cx->blk_oldcop));
1123 PerlIO_printf(Perl_debug_log, "BLK_OLDMARKSP = %ld\n", (long)cx->blk_oldmarksp);
1124 PerlIO_printf(Perl_debug_log, "BLK_OLDSCOPESP = %ld\n", (long)cx->blk_oldscopesp);
1125 PerlIO_printf(Perl_debug_log, "BLK_OLDPM = 0x%"UVxf"\n",
1126 PTR2UV(cx->blk_oldpm));
1127 PerlIO_printf(Perl_debug_log, "BLK_GIMME = %s\n", cx->blk_gimme ? "LIST" : "SCALAR");
1129 switch (CxTYPE(cx)) {
1134 PerlIO_printf(Perl_debug_log, "BLK_FORMAT.CV = 0x%"UVxf"\n",
1135 PTR2UV(cx->blk_format.cv));
1136 PerlIO_printf(Perl_debug_log, "BLK_FORMAT.GV = 0x%"UVxf"\n",
1137 PTR2UV(cx->blk_format.gv));
1138 PerlIO_printf(Perl_debug_log, "BLK_FORMAT.DFOUTGV = 0x%"UVxf"\n",
1139 PTR2UV(cx->blk_format.dfoutgv));
1140 PerlIO_printf(Perl_debug_log, "BLK_FORMAT.HASARGS = %d\n",
1141 (int)CxHASARGS(cx));
1142 PerlIO_printf(Perl_debug_log, "BLK_FORMAT.RETOP = 0x%"UVxf"\n",
1143 PTR2UV(cx->blk_format.retop));
1146 PerlIO_printf(Perl_debug_log, "BLK_SUB.CV = 0x%"UVxf"\n",
1147 PTR2UV(cx->blk_sub.cv));
1148 PerlIO_printf(Perl_debug_log, "BLK_SUB.OLDDEPTH = %ld\n",
1149 (long)cx->blk_sub.olddepth);
1150 PerlIO_printf(Perl_debug_log, "BLK_SUB.HASARGS = %d\n",
1151 (int)CxHASARGS(cx));
1152 PerlIO_printf(Perl_debug_log, "BLK_SUB.LVAL = %d\n", (int)CxLVAL(cx));
1153 PerlIO_printf(Perl_debug_log, "BLK_SUB.RETOP = 0x%"UVxf"\n",
1154 PTR2UV(cx->blk_sub.retop));
1157 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_IN_EVAL = %ld\n",
1158 (long)CxOLD_IN_EVAL(cx));
1159 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_OP_TYPE = %s (%s)\n",
1160 PL_op_name[CxOLD_OP_TYPE(cx)],
1161 PL_op_desc[CxOLD_OP_TYPE(cx)]);
1162 if (cx->blk_eval.old_namesv)
1163 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_NAME = %s\n",
1164 SvPVX_const(cx->blk_eval.old_namesv));
1165 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_EVAL_ROOT = 0x%"UVxf"\n",
1166 PTR2UV(cx->blk_eval.old_eval_root));
1167 PerlIO_printf(Perl_debug_log, "BLK_EVAL.RETOP = 0x%"UVxf"\n",
1168 PTR2UV(cx->blk_eval.retop));
1171 case CXt_LOOP_LAZYIV:
1172 case CXt_LOOP_LAZYSV:
1174 case CXt_LOOP_PLAIN:
1175 PerlIO_printf(Perl_debug_log, "BLK_LOOP.LABEL = %s\n", CxLABEL(cx));
1176 PerlIO_printf(Perl_debug_log, "BLK_LOOP.RESETSP = %ld\n",
1177 (long)cx->blk_loop.resetsp);
1178 PerlIO_printf(Perl_debug_log, "BLK_LOOP.MY_OP = 0x%"UVxf"\n",
1179 PTR2UV(cx->blk_loop.my_op));
1180 PerlIO_printf(Perl_debug_log, "BLK_LOOP.NEXT_OP = 0x%"UVxf"\n",
1181 PTR2UV(CX_LOOP_NEXTOP_GET(cx)));
1182 /* XXX: not accurate for LAZYSV/IV */
1183 PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERARY = 0x%"UVxf"\n",
1184 PTR2UV(cx->blk_loop.state_u.ary.ary));
1185 PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERIX = %ld\n",
1186 (long)cx->blk_loop.state_u.ary.ix);
1187 PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERVAR = 0x%"UVxf"\n",
1188 PTR2UV(CxITERVAR(cx)));
1192 PerlIO_printf(Perl_debug_log, "SB_ITERS = %ld\n",
1193 (long)cx->sb_iters);
1194 PerlIO_printf(Perl_debug_log, "SB_MAXITERS = %ld\n",
1195 (long)cx->sb_maxiters);
1196 PerlIO_printf(Perl_debug_log, "SB_RFLAGS = %ld\n",
1197 (long)cx->sb_rflags);
1198 PerlIO_printf(Perl_debug_log, "SB_ONCE = %ld\n",
1200 PerlIO_printf(Perl_debug_log, "SB_ORIG = %s\n",
1202 PerlIO_printf(Perl_debug_log, "SB_DSTR = 0x%"UVxf"\n",
1203 PTR2UV(cx->sb_dstr));
1204 PerlIO_printf(Perl_debug_log, "SB_TARG = 0x%"UVxf"\n",
1205 PTR2UV(cx->sb_targ));
1206 PerlIO_printf(Perl_debug_log, "SB_S = 0x%"UVxf"\n",
1208 PerlIO_printf(Perl_debug_log, "SB_M = 0x%"UVxf"\n",
1210 PerlIO_printf(Perl_debug_log, "SB_STREND = 0x%"UVxf"\n",
1211 PTR2UV(cx->sb_strend));
1212 PerlIO_printf(Perl_debug_log, "SB_RXRES = 0x%"UVxf"\n",
1213 PTR2UV(cx->sb_rxres));
1217 PERL_UNUSED_CONTEXT;
1218 PERL_UNUSED_ARG(cx);
1219 #endif /* DEBUGGING */
1224 * c-indentation-style: bsd
1226 * indent-tabs-mode: t
1229 * ex: set ts=8 sts=4 sw=4 noet: