This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
leave_scope(): eliminate a couple of local vars
[perl5.git] / scope.c
CommitLineData
a0d0e21e 1/* scope.c
79072805 2 *
1129b882
NC
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
79072805
LW
5 *
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.
8 *
a0d0e21e
LW
9 */
10
11/*
4ac71550
TC
12 * For the fashion of Minas Tirith was such that it was built on seven
13 * levels...
14 *
15 * [p.751 of _The Lord of the Rings_, V/i: "Minas Tirith"]
79072805
LW
16 */
17
ddfa107c 18/* This file contains functions to manipulate several of Perl's stacks;
166f8a29
DM
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
22 * each scope exit.
23 */
24
79072805 25#include "EXTERN.h"
864dbfa3 26#define PERL_IN_SCOPE_C
79072805
LW
27#include "perl.h"
28
a0d0e21e 29SV**
fc16c392 30Perl_stack_grow(pTHX_ SV **sp, SV **p, SSize_t n)
a0d0e21e 31{
402d079e
DM
32 SSize_t extra;
33 SSize_t current = (p - PL_stack_base);
34
7918f24d
NC
35 PERL_ARGS_ASSERT_STACK_GROW;
36
402d079e 37 if (UNLIKELY(n < 0))
6768377c
DM
38 Perl_croak(aTHX_
39 "panic: stack_grow() negative count (%"IVdf")", (IV)n);
40
3280af22 41 PL_stack_sp = sp;
402d079e
DM
42 extra =
43#ifdef STRESS_REALLOC
44 1;
2ce36478 45#else
402d079e 46 128;
2ce36478 47#endif
402d079e
DM
48 /* If the total might wrap, panic instead. This is really testing
49 * that (current + n + extra < SSize_t_MAX), but done in a way that
50 * can't wrap */
51 if (UNLIKELY( current > SSize_t_MAX - extra
52 || current + extra > SSize_t_MAX - n
53 ))
54 /* diag_listed_as: Out of memory during %s extend */
55 Perl_croak(aTHX_ "Out of memory during stack extend");
56
57 av_extend(PL_curstack, current + n + extra);
3280af22 58 return PL_stack_sp;
a0d0e21e
LW
59}
60
2ce36478
SM
61#ifndef STRESS_REALLOC
62#define GROW(old) ((old) * 3 / 2)
63#else
64#define GROW(old) ((old) + 1)
65#endif
66
e336de0d 67PERL_SI *
864dbfa3 68Perl_new_stackinfo(pTHX_ I32 stitems, I32 cxitems)
e336de0d
GS
69{
70 PERL_SI *si;
a02a5408 71 Newx(si, 1, PERL_SI);
e336de0d
GS
72 si->si_stack = newAV();
73 AvREAL_off(si->si_stack);
74 av_extend(si->si_stack, stitems > 0 ? stitems-1 : 0);
3280af22 75 AvALLOC(si->si_stack)[0] = &PL_sv_undef;
e336de0d
GS
76 AvFILLp(si->si_stack) = 0;
77 si->si_prev = 0;
78 si->si_next = 0;
79 si->si_cxmax = cxitems - 1;
80 si->si_cxix = -1;
e788e7d3 81 si->si_type = PERLSI_UNDEF;
a02a5408 82 Newx(si->si_cxstack, cxitems, PERL_CONTEXT);
490576d1 83 /* Without any kind of initialising CX_PUSHSUBST()
9965345d 84 * in pp_subst() will read uninitialised heap. */
7e337ee0 85 PoisonNew(si->si_cxstack, cxitems, PERL_CONTEXT);
e336de0d
GS
86 return si;
87}
88
79072805 89I32
864dbfa3 90Perl_cxinc(pTHX)
79072805 91{
a3b680e6 92 const IV old_max = cxstack_max;
2ce36478 93 cxstack_max = GROW(cxstack_max);
401a9b14 94 Renew(cxstack, cxstack_max + 1, PERL_CONTEXT);
9965345d
JH
95 /* Without any kind of initialising deep enough recursion
96 * will end up reading uninitialised PERL_CONTEXTs. */
109bf713 97 PoisonNew(cxstack + old_max + 1, cxstack_max - old_max, PERL_CONTEXT);
79072805
LW
98 return cxstack_ix + 1;
99}
100
79072805 101void
864dbfa3 102Perl_push_scope(pTHX)
79072805 103{
5d9574c1 104 if (UNLIKELY(PL_scopestack_ix == PL_scopestack_max)) {
3280af22
NIS
105 PL_scopestack_max = GROW(PL_scopestack_max);
106 Renew(PL_scopestack, PL_scopestack_max, I32);
d343c3ef
GG
107#ifdef DEBUGGING
108 Renew(PL_scopestack_name, PL_scopestack_max, const char*);
520bb150 109#endif
79072805 110 }
d343c3ef
GG
111#ifdef DEBUGGING
112 PL_scopestack_name[PL_scopestack_ix] = "unknown";
113#endif
3280af22 114 PL_scopestack[PL_scopestack_ix++] = PL_savestack_ix;
79072805
LW
115
116}
117
118void
864dbfa3 119Perl_pop_scope(pTHX)
79072805 120{
35a4481c 121 const I32 oldsave = PL_scopestack[--PL_scopestack_ix];
8990e307 122 LEAVE_SCOPE(oldsave);
79072805
LW
123}
124
ba5248fc 125I32 *
864dbfa3 126Perl_markstack_grow(pTHX)
a0d0e21e 127{
35a4481c
AL
128 const I32 oldmax = PL_markstack_max - PL_markstack;
129 const I32 newmax = GROW(oldmax);
a0d0e21e 130
3280af22 131 Renew(PL_markstack, newmax, I32);
3280af22 132 PL_markstack_max = PL_markstack + newmax;
ba5248fc 133 PL_markstack_ptr = PL_markstack + oldmax;
30773234
DM
134 DEBUG_s(DEBUG_v(PerlIO_printf(Perl_debug_log,
135 "MARK grow %p %"IVdf" by %"IVdf"\n",
136 PL_markstack_ptr, (IV)*PL_markstack_ptr, (IV)oldmax)));
ba5248fc 137 return PL_markstack_ptr;
a0d0e21e
LW
138}
139
140void
864dbfa3 141Perl_savestack_grow(pTHX)
79072805 142{
49706441
FC
143#ifdef STRESS_REALLOC
144 PL_savestack_max += SS_MAXPUSH;
145#else
3caf0269 146 PL_savestack_max = GROW(PL_savestack_max);
49706441 147#endif
3caf0269
DM
148 /* Note that we allocate SS_MAXPUSH slots higher than ss_max
149 * so that SS_ADD_END(), SSGROW() etc can do a simper check */
150 Renew(PL_savestack, PL_savestack_max + SS_MAXPUSH, ANY);
79072805
LW
151}
152
4b3c1a47
AE
153void
154Perl_savestack_grow_cnt(pTHX_ I32 need)
155{
156 PL_savestack_max = PL_savestack_ix + need;
3caf0269
DM
157 /* Note that we allocate SS_MAXPUSH slots higher than ss_max
158 * so that SS_ADD_END(), SSGROW() etc can do a simper check */
159 Renew(PL_savestack, PL_savestack_max + SS_MAXPUSH, ANY);
4b3c1a47
AE
160}
161
2ce36478
SM
162#undef GROW
163
a953aca5
DD
164/* The original function was called Perl_tmps_grow and was removed from public
165 API, Perl_tmps_grow_p is the replacement and it used in public macros but
166 isn't public itself.
167
168 Perl_tmps_grow_p takes a proposed ix. A proposed ix is PL_tmps_ix + extend_by,
169 where the result of (PL_tmps_ix + extend_by) is >= PL_tmps_max
170 Upon return, PL_tmps_stack[ix] will be a valid address. For machine code
171 optimization and register usage reasons, the proposed ix passed into
172 tmps_grow is returned to the caller which the caller can then use to write
173 an SV * to PL_tmps_stack[ix]. If the caller was using tmps_grow in
174 pre-extend mode (EXTEND_MORTAL macro), then it ignores the return value of
175 tmps_grow. Note, tmps_grow DOES NOT write ix to PL_tmps_ix, the caller
176 must assign ix or ret val of tmps_grow to PL_temps_ix themselves if that is
177 appropriate. The assignment to PL_temps_ix can happen before or after
178 tmps_grow call since tmps_grow doesn't look at PL_tmps_ix.
179 */
180
181SSize_t
182Perl_tmps_grow_p(pTHX_ SSize_t ix)
677b06e3 183{
a953aca5 184 SSize_t extend_to = ix;
677b06e3 185#ifndef STRESS_REALLOC
a953aca5
DD
186 if (ix - PL_tmps_max < 128)
187 extend_to += (PL_tmps_max < 512) ? 128 : 512;
677b06e3 188#endif
a953aca5 189 PL_tmps_max = extend_to + 1;
677b06e3 190 Renew(PL_tmps_stack, PL_tmps_max, SV*);
a953aca5 191 return ix;
677b06e3
GS
192}
193
194
195void
864dbfa3 196Perl_free_tmps(pTHX)
79072805
LW
197{
198 /* XXX should tmps_floor live in cxstack? */
e8eb279c 199 const SSize_t myfloor = PL_tmps_floor;
3280af22 200 while (PL_tmps_ix > myfloor) { /* clean up after last statement */
22ade07d 201 SV* const sv = PL_tmps_stack[PL_tmps_ix--];
72581b5b
VP
202#ifdef PERL_POISON
203 PoisonWith(PL_tmps_stack + PL_tmps_ix + 1, 1, SV *, 0xAB);
22ade07d 204#endif
520275ba 205 if (LIKELY(sv)) {
463ee0b2 206 SvTEMP_off(sv);
4a9a56a7 207 SvREFCNT_dec_NN(sv); /* note, can modify tmps_ix!!! */
463ee0b2 208 }
79072805
LW
209 }
210}
211
76e3520e 212STATIC SV *
af7df257 213S_save_scalar_at(pTHX_ SV **sptr, const U32 flags)
79072805 214{
75d34a09 215 SV * osv;
eb578fdb 216 SV *sv;
79072805 217
7918f24d
NC
218 PERL_ARGS_ASSERT_SAVE_SCALAR_AT;
219
75d34a09 220 osv = *sptr;
3c84a230
DM
221 if (flags & SAVEf_KEEPOLDELEM)
222 sv = osv;
223 else {
224 sv = (*sptr = newSV(0));
225 if (SvTYPE(osv) >= SVt_PVMG && SvMAGIC(osv))
226 mg_localize(osv, sv, cBOOL(flags & SAVEf_SETMAGIC));
79072805 227 }
75d34a09 228
79072805
LW
229 return sv;
230}
231
dfcd3de5
NC
232void
233Perl_save_pushptrptr(pTHX_ void *const ptr1, void *const ptr2, const int type)
e22024d3 234{
a3444cc5
DM
235 dSS_ADD;
236 SS_ADD_PTR(ptr1);
237 SS_ADD_PTR(ptr2);
238 SS_ADD_UV(type);
239 SS_ADD_END(3);
e22024d3
NC
240}
241
7a4c00b4 242SV *
864dbfa3 243Perl_save_scalar(pTHX_ GV *gv)
7a4c00b4 244{
13c59d41 245 SV ** const sptr = &GvSVn(gv);
7918f24d
NC
246
247 PERL_ARGS_ASSERT_SAVE_SCALAR;
248
13c59d41 249 if (UNLIKELY(SvGMAGICAL(*sptr))) {
b492a59e 250 PL_localizing = 1;
13c59d41 251 (void)mg_get(*sptr);
b492a59e
DM
252 PL_localizing = 0;
253 }
13c59d41
MH
254 save_pushptrptr(SvREFCNT_inc_simple(gv), SvREFCNT_inc(*sptr), SAVEt_SV);
255 return save_scalar_at(sptr, SAVEf_SETMAGIC); /* XXX - FIXME - see #60360 */
7a4c00b4
PP
256}
257
f4dd75d9 258/* Like save_sptr(), but also SvREFCNT_dec()s the new value. Can be used to
b9d12d37
GS
259 * restore a global SV to its prior contents, freeing new value. */
260void
864dbfa3 261Perl_save_generic_svref(pTHX_ SV **sptr)
b9d12d37 262{
7918f24d
NC
263 PERL_ARGS_ASSERT_SAVE_GENERIC_SVREF;
264
e22024d3 265 save_pushptrptr(sptr, SvREFCNT_inc(*sptr), SAVEt_GENERIC_SVREF);
b9d12d37
GS
266}
267
f4dd75d9
GS
268/* Like save_pptr(), but also Safefree()s the new value if it is different
269 * from the old one. Can be used to restore a global char* to its prior
270 * contents, freeing new value. */
271void
272Perl_save_generic_pvref(pTHX_ char **str)
273{
7918f24d
NC
274 PERL_ARGS_ASSERT_SAVE_GENERIC_PVREF;
275
e22024d3 276 save_pushptrptr(*str, str, SAVEt_GENERIC_PVREF);
f4dd75d9
GS
277}
278
05ec9bb3
NIS
279/* Like save_generic_pvref(), but uses PerlMemShared_free() rather than Safefree().
280 * Can be used to restore a shared global char* to its prior
281 * contents, freeing new value. */
282void
283Perl_save_shared_pvref(pTHX_ char **str)
284{
7918f24d
NC
285 PERL_ARGS_ASSERT_SAVE_SHARED_PVREF;
286
e22024d3 287 save_pushptrptr(str, *str, SAVEt_SHARED_PVREF);
05ec9bb3
NIS
288}
289
14f338dc
DM
290/* set the SvFLAGS specified by mask to the values in val */
291
292void
293Perl_save_set_svflags(pTHX_ SV* sv, U32 mask, U32 val)
294{
a3444cc5 295 dSS_ADD;
7918f24d
NC
296
297 PERL_ARGS_ASSERT_SAVE_SET_SVFLAGS;
298
a3444cc5
DM
299 SS_ADD_PTR(sv);
300 SS_ADD_INT(mask);
301 SS_ADD_INT(val);
302 SS_ADD_UV(SAVEt_SET_SVFLAGS);
303 SS_ADD_END(4);
14f338dc
DM
304}
305
364bbfa4
TC
306/*
307=for apidoc save_gp
308
309Saves the current GP of gv on the save stack to be restored on scope exit.
310
311If empty is true, replace the GP with a new GP.
312
313If empty is false, mark gv with GVf_INTRO so the next reference
314assigned is localized, which is how C< local *foo = $someref; > works.
315
316=cut
317*/
318
79072805 319void
864dbfa3 320Perl_save_gp(pTHX_ GV *gv, I32 empty)
79072805 321{
7918f24d
NC
322 PERL_ARGS_ASSERT_SAVE_GP;
323
10507e11 324 save_pushptrptr(SvREFCNT_inc(gv), GvGP(gv), SAVEt_GP);
79072805 325
5f05dabc 326 if (empty) {
12816592 327 GP *gp = Perl_newGP(aTHX_ gv);
959f7ad7 328 HV * const stash = GvSTASH(gv);
3d460042
FC
329 bool isa_changed = 0;
330
331 if (stash && HvENAME(stash)) {
332 if (GvNAMELEN(gv) == 3 && strnEQ(GvNAME(gv), "ISA", 3))
333 isa_changed = TRUE;
334 else if (GvCVu(gv))
335 /* taking a method out of circulation ("local")*/
336 mro_method_changed_in(stash);
337 }
146174a9
CB
338 if (GvIOp(gv) && (IoFLAGS(GvIOp(gv)) & IOf_ARGV)) {
339 gp->gp_io = newIO();
340 IoFLAGS(gp->gp_io) |= IOf_ARGV|IOf_START;
341 }
c43ae56f 342 GvGP_set(gv,gp);
3d460042 343 if (isa_changed) mro_isa_changed_in(stash);
5f05dabc
PP
344 }
345 else {
44a8e56a 346 gp_ref(GvGP(gv));
5f05dabc
PP
347 GvINTRO_on(gv);
348 }
79072805 349}
79072805 350
79072805 351AV *
864dbfa3 352Perl_save_ary(pTHX_ GV *gv)
79072805 353{
901017d6 354 AV * const oav = GvAVn(gv);
67a38de0 355 AV *av;
fb73857a 356
7918f24d
NC
357 PERL_ARGS_ASSERT_SAVE_ARY;
358
5d9574c1 359 if (UNLIKELY(!AvREAL(oav) && AvREIFY(oav)))
67a38de0 360 av_reify(oav);
01433346 361 save_pushptrptr(SvREFCNT_inc_simple_NN(gv), oav, SAVEt_AV);
79072805 362
4608196e 363 GvAV(gv) = NULL;
fb73857a 364 av = GvAVn(gv);
5d9574c1 365 if (UNLIKELY(SvMAGIC(oav)))
9711599e 366 mg_localize(MUTABLE_SV(oav), MUTABLE_SV(av), TRUE);
fb73857a 367 return av;
79072805
LW
368}
369
370HV *
864dbfa3 371Perl_save_hash(pTHX_ GV *gv)
79072805 372{
fb73857a
PP
373 HV *ohv, *hv;
374
7918f24d
NC
375 PERL_ARGS_ASSERT_SAVE_HASH;
376
01433346
FC
377 save_pushptrptr(
378 SvREFCNT_inc_simple_NN(gv), (ohv = GvHVn(gv)), SAVEt_HV
379 );
79072805 380
4608196e 381 GvHV(gv) = NULL;
fb73857a 382 hv = GvHVn(gv);
5d9574c1 383 if (UNLIKELY(SvMAGIC(ohv)))
9711599e 384 mg_localize(MUTABLE_SV(ohv), MUTABLE_SV(hv), TRUE);
fb73857a 385 return hv;
79072805
LW
386}
387
388void
5aaab254 389Perl_save_item(pTHX_ SV *item)
79072805 390{
eb578fdb 391 SV * const sv = newSVsv(item);
79072805 392
7918f24d
NC
393 PERL_ARGS_ASSERT_SAVE_ITEM;
394
e22024d3
NC
395 save_pushptrptr(item, /* remember the pointer */
396 sv, /* remember the value */
397 SAVEt_ITEM);
79072805
LW
398}
399
400void
1409bc06 401Perl_save_bool(pTHX_ bool *boolp)
79072805 402{
a3444cc5 403 dSS_ADD;
7918f24d 404
1409bc06 405 PERL_ARGS_ASSERT_SAVE_BOOL;
7918f24d 406
a3444cc5
DM
407 SS_ADD_PTR(boolp);
408 SS_ADD_UV(SAVEt_BOOL | (*boolp << 8));
409 SS_ADD_END(2);
1409bc06
NC
410}
411
7623d426
NC
412void
413Perl_save_pushi32ptr(pTHX_ const I32 i, void *const ptr, const int type)
1409bc06 414{
a3444cc5
DM
415 dSS_ADD;
416
417 SS_ADD_INT(i);
418 SS_ADD_PTR(ptr);
419 SS_ADD_UV(type);
420 SS_ADD_END(3);
79072805
LW
421}
422
423void
1409bc06 424Perl_save_int(pTHX_ int *intp)
9febdf04 425{
d172696c 426 const int i = *intp;
9b139d09 427 UV type = ((UV)((UV)i << SAVE_TIGHT_SHIFT) | SAVEt_INT_SMALL);
d172696c
DM
428 int size = 2;
429 dSS_ADD;
7918f24d 430
1409bc06 431 PERL_ARGS_ASSERT_SAVE_INT;
7918f24d 432
5d9574c1 433 if (UNLIKELY((int)(type >> SAVE_TIGHT_SHIFT) != i)) {
d172696c
DM
434 SS_ADD_INT(i);
435 type = SAVEt_INT;
436 size++;
437 }
438 SS_ADD_PTR(intp);
439 SS_ADD_UV(type);
440 SS_ADD_END(size);
9febdf04
RH
441}
442
443void
58188858
RGS
444Perl_save_I8(pTHX_ I8 *bytep)
445{
a3444cc5 446 dSS_ADD;
7918f24d
NC
447
448 PERL_ARGS_ASSERT_SAVE_I8;
449
a3444cc5
DM
450 SS_ADD_PTR(bytep);
451 SS_ADD_UV(SAVEt_I8 | ((UV)*bytep << 8));
452 SS_ADD_END(2);
58188858
RGS
453}
454
455void
87a84751
JH
456Perl_save_I16(pTHX_ I16 *intp)
457{
a3444cc5 458 dSS_ADD;
7918f24d
NC
459
460 PERL_ARGS_ASSERT_SAVE_I16;
461
a3444cc5
DM
462 SS_ADD_PTR(intp);
463 SS_ADD_UV(SAVEt_I16 | ((UV)*intp << 8));
464 SS_ADD_END(2);
87a84751
JH
465}
466
467void
864dbfa3 468Perl_save_I32(pTHX_ I32 *intp)
79072805 469{
d172696c 470 const I32 i = *intp;
9b139d09 471 UV type = ((I32)((U32)i << SAVE_TIGHT_SHIFT) | SAVEt_I32_SMALL);
d172696c
DM
472 int size = 2;
473 dSS_ADD;
7918f24d
NC
474
475 PERL_ARGS_ASSERT_SAVE_I32;
476
5d9574c1 477 if (UNLIKELY((I32)(type >> SAVE_TIGHT_SHIFT) != i)) {
d172696c
DM
478 SS_ADD_INT(i);
479 type = SAVEt_I32;
480 size++;
481 }
482 SS_ADD_PTR(intp);
483 SS_ADD_UV(type);
484 SS_ADD_END(size);
79072805
LW
485}
486
e8eb279c
FC
487void
488Perl_save_strlen(pTHX_ STRLEN *ptr)
489{
e8eb279c
FC
490 dSS_ADD;
491
492 PERL_ARGS_ASSERT_SAVE_STRLEN;
493
494 SS_ADD_IV(*ptr);
495 SS_ADD_PTR(ptr);
496 SS_ADD_UV(SAVEt_STRLEN);
497 SS_ADD_END(3);
498}
499
f8c11501
FC
500void
501Perl_save_iv(pTHX_ IV *ivp)
502{
503 PERL_ARGS_ASSERT_SAVE_IV;
504
505 SSCHECK(3);
506 SSPUSHIV(*ivp);
507 SSPUSHPTR(ivp);
508 SSPUSHUV(SAVEt_IV);
509}
510
85e6fe83
LW
511/* Cannot use save_sptr() to store a char* since the SV** cast will
512 * force word-alignment and we'll miss the pointer.
513 */
514void
864dbfa3 515Perl_save_pptr(pTHX_ char **pptr)
85e6fe83 516{
7918f24d
NC
517 PERL_ARGS_ASSERT_SAVE_PPTR;
518
e22024d3 519 save_pushptrptr(*pptr, pptr, SAVEt_PPTR);
85e6fe83
LW
520}
521
79072805 522void
146174a9
CB
523Perl_save_vptr(pTHX_ void *ptr)
524{
7918f24d
NC
525 PERL_ARGS_ASSERT_SAVE_VPTR;
526
e22024d3 527 save_pushptrptr(*(char**)ptr, ptr, SAVEt_VPTR);
146174a9
CB
528}
529
530void
864dbfa3 531Perl_save_sptr(pTHX_ SV **sptr)
79072805 532{
7918f24d
NC
533 PERL_ARGS_ASSERT_SAVE_SPTR;
534
e22024d3 535 save_pushptrptr(*sptr, sptr, SAVEt_SPTR);
79072805
LW
536}
537
c3564e5c 538void
09edbca0 539Perl_save_padsv_and_mortalize(pTHX_ PADOFFSET off)
c3564e5c 540{
a3444cc5
DM
541 dSS_ADD;
542
f3548bdc 543 ASSERT_CURPAD_ACTIVE("save_padsv");
a3444cc5
DM
544 SS_ADD_PTR(SvREFCNT_inc_simple_NN(PL_curpad[off]));
545 SS_ADD_PTR(PL_comppad);
03dba561 546 SS_ADD_UV((UV)off);
a3444cc5
DM
547 SS_ADD_UV(SAVEt_PADSV_AND_MORTALIZE);
548 SS_ADD_END(4);
c3564e5c
GS
549}
550
79072805 551void
864dbfa3 552Perl_save_hptr(pTHX_ HV **hptr)
79072805 553{
7918f24d
NC
554 PERL_ARGS_ASSERT_SAVE_HPTR;
555
e22024d3 556 save_pushptrptr(*hptr, hptr, SAVEt_HPTR);
79072805
LW
557}
558
559void
864dbfa3 560Perl_save_aptr(pTHX_ AV **aptr)
79072805 561{
7918f24d
NC
562 PERL_ARGS_ASSERT_SAVE_APTR;
563
e22024d3 564 save_pushptrptr(*aptr, aptr, SAVEt_APTR);
79072805
LW
565}
566
567void
2fd8beea 568Perl_save_pushptr(pTHX_ void *const ptr, const int type)
8990e307 569{
a3444cc5
DM
570 dSS_ADD;
571 SS_ADD_PTR(ptr);
572 SS_ADD_UV(type);
573 SS_ADD_END(2);
8990e307
LW
574}
575
576void
864dbfa3 577Perl_save_clearsv(pTHX_ SV **svp)
8990e307 578{
cdcdfc56
NC
579 const UV offset = svp - PL_curpad;
580 const UV offset_shifted = offset << SAVE_TIGHT_SHIFT;
7918f24d
NC
581
582 PERL_ARGS_ASSERT_SAVE_CLEARSV;
583
f3548bdc 584 ASSERT_CURPAD_ACTIVE("save_clearsv");
623e28c6 585 SvPADSTALE_off(*svp); /* mark lexical as active */
5d9574c1 586 if (UNLIKELY((offset_shifted >> SAVE_TIGHT_SHIFT) != offset)) {
cdcdfc56
NC
587 Perl_croak(aTHX_ "panic: pad offset %"UVuf" out of range (%p-%p)",
588 offset, svp, PL_curpad);
a3444cc5 589 }
cdcdfc56 590
a3444cc5
DM
591 {
592 dSS_ADD;
593 SS_ADD_UV(offset_shifted | SAVEt_CLEARSV);
594 SS_ADD_END(1);
595 }
8990e307
LW
596}
597
598void
864dbfa3 599Perl_save_delete(pTHX_ HV *hv, char *key, I32 klen)
8990e307 600{
7918f24d
NC
601 PERL_ARGS_ASSERT_SAVE_DELETE;
602
85a721ca 603 save_pushptri32ptr(key, klen, SvREFCNT_inc_simple(hv), SAVEt_DELETE);
8990e307
LW
604}
605
606void
af097752
VP
607Perl_save_hdelete(pTHX_ HV *hv, SV *keysv)
608{
609 STRLEN len;
610 I32 klen;
611 const char *key;
612
613 PERL_ARGS_ASSERT_SAVE_HDELETE;
614
615 key = SvPV_const(keysv, len);
616 klen = SvUTF8(keysv) ? -(I32)len : (I32)len;
617 SvREFCNT_inc_simple_void_NN(hv);
618 save_pushptri32ptr(savepvn(key, len), klen, hv, SAVEt_DELETE);
619}
620
621void
c70927a6 622Perl_save_adelete(pTHX_ AV *av, SSize_t key)
c68ec7a9 623{
c70927a6 624 dSS_ADD;
c68ec7a9
VP
625
626 PERL_ARGS_ASSERT_SAVE_ADELETE;
627
628 SvREFCNT_inc_void(av);
c70927a6
FC
629 SS_ADD_UV(key);
630 SS_ADD_PTR(av);
631 SS_ADD_IV(SAVEt_ADELETE);
632 SS_ADD_END(3);
c68ec7a9
VP
633}
634
635void
12ab1f58
JH
636Perl_save_destructor(pTHX_ DESTRUCTORFUNC_NOCONTEXT_t f, void* p)
637{
a3444cc5 638 dSS_ADD;
7918f24d
NC
639 PERL_ARGS_ASSERT_SAVE_DESTRUCTOR;
640
a3444cc5
DM
641 SS_ADD_DPTR(f);
642 SS_ADD_PTR(p);
643 SS_ADD_UV(SAVEt_DESTRUCTOR);
644 SS_ADD_END(3);
12ab1f58
JH
645}
646
647void
146174a9
CB
648Perl_save_destructor_x(pTHX_ DESTRUCTORFUNC_t f, void* p)
649{
a3444cc5
DM
650 dSS_ADD;
651
652 SS_ADD_DXPTR(f);
653 SS_ADD_PTR(p);
654 SS_ADD_UV(SAVEt_DESTRUCTOR_X);
655 SS_ADD_END(3);
146174a9
CB
656}
657
658void
da8315f8
NC
659Perl_save_hints(pTHX)
660{
20439bc7 661 COPHH *save_cophh = cophh_copy(CopHINTHASH_get(&PL_compiling));
da8315f8 662 if (PL_hints & HINT_LOCALIZE_HH) {
52c7aca6
FC
663 HV *oldhh = GvHV(PL_hintgv);
664 save_pushptri32ptr(oldhh, PL_hints, save_cophh, SAVEt_HINTS);
665 GvHV(PL_hintgv) = NULL; /* in case copying dies */
666 GvHV(PL_hintgv) = hv_copy_hints_hv(oldhh);
be84297e 667 } else {
20439bc7 668 save_pushi32ptr(PL_hints, save_cophh, SAVEt_HINTS);
da8315f8 669 }
be84297e
NC
670}
671
672static void
673S_save_pushptri32ptr(pTHX_ void *const ptr1, const I32 i, void *const ptr2,
674 const int type)
675{
a3444cc5
DM
676 dSS_ADD;
677 SS_ADD_PTR(ptr1);
678 SS_ADD_INT(i);
679 SS_ADD_PTR(ptr2);
680 SS_ADD_UV(type);
681 SS_ADD_END(4);
da8315f8
NC
682}
683
684void
c70927a6
FC
685Perl_save_aelem_flags(pTHX_ AV *av, SSize_t idx, SV **sptr,
686 const U32 flags)
4e4c362e 687{
20b7effb 688 dSS_ADD;
bfc4de9f 689 SV *sv;
7918f24d 690
91d1c79f 691 PERL_ARGS_ASSERT_SAVE_AELEM_FLAGS;
7918f24d 692
0cbee0a4 693 SvGETMAGIC(*sptr);
c70927a6
FC
694 SS_ADD_PTR(SvREFCNT_inc_simple(av));
695 SS_ADD_IV(idx);
696 SS_ADD_PTR(SvREFCNT_inc(*sptr));
697 SS_ADD_UV(SAVEt_AELEM);
698 SS_ADD_END(4);
1cdc9186
FC
699 /* The array needs to hold a reference count on its new element, so it
700 must be AvREAL. */
5d9574c1 701 if (UNLIKELY(!AvREAL(av) && AvREIFY(av)))
1cdc9186 702 av_reify(av);
91d1c79f 703 save_scalar_at(sptr, flags); /* XXX - FIXME - see #60360 */
75d34a09
VP
704 if (flags & SAVEf_KEEPOLDELEM)
705 return;
bfc4de9f
DM
706 sv = *sptr;
707 /* If we're localizing a tied array element, this new sv
708 * won't actually be stored in the array - so it won't get
709 * reaped when the localize ends. Ensure it gets reaped by
710 * mortifying it instead. DAPM */
5d9574c1 711 if (UNLIKELY(SvTIED_mg((const SV *)av, PERL_MAGIC_tied)))
bfc4de9f 712 sv_2mortal(sv);
4e4c362e
GS
713}
714
715void
af7df257 716Perl_save_helem_flags(pTHX_ HV *hv, SV *key, SV **sptr, const U32 flags)
4e4c362e 717{
bfc4de9f 718 SV *sv;
7918f24d 719
af7df257 720 PERL_ARGS_ASSERT_SAVE_HELEM_FLAGS;
7918f24d 721
0cbee0a4 722 SvGETMAGIC(*sptr);
a3444cc5
DM
723 {
724 dSS_ADD;
725 SS_ADD_PTR(SvREFCNT_inc_simple(hv));
726 SS_ADD_PTR(newSVsv(key));
727 SS_ADD_PTR(SvREFCNT_inc(*sptr));
728 SS_ADD_UV(SAVEt_HELEM);
729 SS_ADD_END(4);
730 }
af7df257 731 save_scalar_at(sptr, flags);
75d34a09
VP
732 if (flags & SAVEf_KEEPOLDELEM)
733 return;
bfc4de9f
DM
734 sv = *sptr;
735 /* If we're localizing a tied hash element, this new sv
736 * won't actually be stored in the hash - so it won't get
737 * reaped when the localize ends. Ensure it gets reaped by
738 * mortifying it instead. DAPM */
5d9574c1 739 if (UNLIKELY(SvTIED_mg((const SV *)hv, PERL_MAGIC_tied)))
bfc4de9f 740 sv_2mortal(sv);
4e4c362e
GS
741}
742
2053acbf
NC
743SV*
744Perl_save_svref(pTHX_ SV **sptr)
745{
7918f24d
NC
746 PERL_ARGS_ASSERT_SAVE_SVREF;
747
2053acbf 748 SvGETMAGIC(*sptr);
e22024d3 749 save_pushptrptr(sptr, SvREFCNT_inc(*sptr), SAVEt_SVREF);
af7df257 750 return save_scalar_at(sptr, SAVEf_SETMAGIC); /* XXX - FIXME - see #60360 */
2053acbf
NC
751}
752
2ef9a108
DM
753
754void
755Perl_savetmps(pTHX)
756{
757 dSS_ADD;
758 SS_ADD_IV(PL_tmps_floor);
759 PL_tmps_floor = PL_tmps_ix;
760 SS_ADD_UV(SAVEt_TMPSFLOOR);
761 SS_ADD_END(2);
762}
763
764
455ece5e 765I32
864dbfa3 766Perl_save_alloc(pTHX_ I32 size, I32 pad)
455ece5e 767{
eb578fdb
KW
768 const I32 start = pad + ((char*)&PL_savestack[PL_savestack_ix]
769 - (char*)PL_savestack);
1be36ce0
NC
770 const UV elems = 1 + ((size + pad - 1) / sizeof(*PL_savestack));
771 const UV elems_shifted = elems << SAVE_TIGHT_SHIFT;
455ece5e 772
5d9574c1 773 if (UNLIKELY((elems_shifted >> SAVE_TIGHT_SHIFT) != elems))
93a641ae
DM
774 Perl_croak(aTHX_
775 "panic: save_alloc elems %"UVuf" out of range (%"IVdf"-%"IVdf")",
776 elems, (IV)size, (IV)pad);
1be36ce0
NC
777
778 SSGROW(elems + 1);
455ece5e
AD
779
780 PL_savestack_ix += elems;
1be36ce0 781 SSPUSHUV(SAVEt_ALLOC | elems_shifted);
455ece5e
AD
782 return start;
783}
784
03dba561 785
9a2fefd6
DM
786static U8 arg_counts[] = {
787 0, /* SAVEt_ALLOC */
788 0, /* SAVEt_CLEARPADRANGE */
789 0, /* SAVEt_CLEARSV */
790 0, /* SAVEt_REGCONTEXT */
791 1, /* SAVEt_TMPSFLOOR */
792 1, /* SAVEt_BOOL */
793 1, /* SAVEt_COMPILE_WARNINGS */
794 1, /* SAVEt_COMPPAD */
795 1, /* SAVEt_FREECOPHH */
796 1, /* SAVEt_FREEOP */
797 1, /* SAVEt_FREEPV */
798 1, /* SAVEt_FREESV */
799 1, /* SAVEt_I16 */
800 1, /* SAVEt_I32_SMALL */
801 1, /* SAVEt_I8 */
802 1, /* SAVEt_INT_SMALL */
803 1, /* SAVEt_MORTALIZESV */
804 1, /* SAVEt_NSTAB */
805 1, /* SAVEt_OP */
806 1, /* SAVEt_PARSER */
807 1, /* SAVEt_STACK_POS */
808 1, /* SAVEt_READONLY_OFF */
809 1, /* SAVEt_FREEPADNAME */
810 2, /* SAVEt_AV */
811 2, /* SAVEt_DESTRUCTOR */
812 2, /* SAVEt_DESTRUCTOR_X */
813 2, /* SAVEt_GENERIC_PVREF */
814 2, /* SAVEt_GENERIC_SVREF */
815 2, /* SAVEt_GP */
816 2, /* SAVEt_GVSV */
817 2, /* SAVEt_HINTS */
818 2, /* SAVEt_HPTR */
819 2, /* SAVEt_HV */
820 2, /* SAVEt_I32 */
821 2, /* SAVEt_INT */
822 2, /* SAVEt_ITEM */
823 2, /* SAVEt_IV */
824 2, /* SAVEt_LONG */
825 2, /* SAVEt_PPTR */
826 2, /* SAVEt_SAVESWITCHSTACK */
827 2, /* SAVEt_SHARED_PVREF */
828 2, /* SAVEt_SPTR */
829 2, /* SAVEt_STRLEN */
830 2, /* SAVEt_SV */
831 2, /* SAVEt_SVREF */
832 2, /* SAVEt_VPTR */
833 2, /* SAVEt_ADELETE */
834 2, /* SAVEt_APTR */
835 3, /* SAVEt_HELEM */
836 3, /* SAVEt_PADSV_AND_MORTALIZE*/
837 3, /* SAVEt_SET_SVFLAGS */
838 3, /* SAVEt_GVSLOT */
839 3, /* SAVEt_AELEM */
840 3 /* SAVEt_DELETE */
841};
842
03dba561 843
462e5cf6 844void
864dbfa3 845Perl_leave_scope(pTHX_ I32 base)
79072805 846{
302c0c93 847 /* Localise the effects of the TAINT_NOT inside the loop. */
284167a5 848 bool was = TAINT_get;
79072805 849
5d9574c1 850 if (UNLIKELY(base < -1))
5637ef5b 851 Perl_croak(aTHX_ "panic: corrupt saved stack index %ld", (long) base);
1c98cc53
DM
852 DEBUG_l(Perl_deb(aTHX_ "savestack: releasing items %ld -> %ld\n",
853 (long)PL_savestack_ix, (long)base));
3280af22 854 while (PL_savestack_ix > base) {
03dba561
DM
855 UV uv;
856 U8 type;
9a2fefd6 857 ANY *ap; /* arg pointer */
c9728782 858 ANY a0, a1, a2; /* up to 3 args */
03dba561 859
c6ae7647
NC
860 TAINT_NOT;
861
03dba561 862 {
9a2fefd6 863 U8 argcount;
03dba561 864 I32 ix = PL_savestack_ix - 1;
9a2fefd6
DM
865
866 ap = &PL_savestack[ix];
867 uv = ap->any_uv;
03dba561 868 type = (U8)uv & SAVE_MASK;
9a2fefd6
DM
869 argcount = arg_counts[type];
870 PL_savestack_ix = ix - argcount;
871 ap -= argcount;
03dba561
DM
872 }
873
c6bf6a65 874 switch (type) {
79072805 875 case SAVEt_ITEM: /* normal string */
c9728782
DM
876 a0 = ap[0]; a1 = ap[1];
877 sv_replace(a0.any_sv, a1.any_sv);
878 if (UNLIKELY(SvSMAGICAL(a0.any_sv))) {
b492a59e 879 PL_localizing = 2;
c9728782 880 mg_set(a0.any_sv);
b492a59e
DM
881 PL_localizing = 0;
882 }
79072805 883 break;
03dba561
DM
884
885 /* This would be a mathom, but Perl_save_svref() calls a static
886 function, S_save_scalar_at(), so has to stay in this file. */
887 case SAVEt_SVREF: /* scalar reference */
c9728782 888 a0 = ap[0]; a1 = ap[1];
75ebea3c 889 a2.any_svp = a0.any_svp;
c9728782 890 a0.any_sv = NULL; /* what to refcnt_dec */
03dba561
DM
891 goto restore_sv;
892
8aacddc1 893 case SAVEt_SV: /* scalar reference */
c9728782 894 a0 = ap[0]; a1 = ap[1];
75ebea3c 895 a2.any_svp = &GvSV(a0.any_gv);
2053acbf 896 restore_sv:
03dba561 897 {
75ebea3c
DM
898 /* do *a2.any_svp = a1 and free a0 */
899 SV * const sv = *a2.any_svp;
900 *a2.any_svp = a1.any_sv;
2053acbf 901 SvREFCNT_dec(sv);
c9728782
DM
902 if (UNLIKELY(SvSMAGICAL(a1.any_sv))) {
903 /* mg_set could die, skipping the freeing of a0 and
904 * a1; Ensure that they're always freed in that case */
2baebb98 905 dSS_ADD;
c9728782 906 SS_ADD_PTR(a1.any_sv);
2baebb98 907 SS_ADD_UV(SAVEt_FREESV);
c9728782 908 SS_ADD_PTR(a0.any_sv);
2baebb98
DM
909 SS_ADD_UV(SAVEt_FREESV);
910 SS_ADD_END(4);
b492a59e 911 PL_localizing = 2;
c9728782 912 mg_set(a1.any_sv);
b492a59e 913 PL_localizing = 0;
2baebb98 914 break;
b492a59e 915 }
c9728782
DM
916 SvREFCNT_dec_NN(a1.any_sv);
917 SvREFCNT_dec(a0.any_sv);
2053acbf 918 break;
03dba561 919 }
c9728782 920
8aacddc1 921 case SAVEt_GENERIC_PVREF: /* generic pv */
c9728782
DM
922 a0 = ap[0]; a1 = ap[1];
923 if (*a1.any_pvp != a0.any_pv) {
924 Safefree(*a1.any_pvp);
925 *a1.any_pvp = a0.any_pv;
f4dd75d9
GS
926 }
927 break;
c9728782 928
05ec9bb3 929 case SAVEt_SHARED_PVREF: /* shared pv */
c9728782
DM
930 a0 = ap[0]; a1 = ap[1];
931 if (*a0.any_pvp != a1.any_pv) {
5e54c26f 932#ifdef NETWARE
c9728782 933 PerlMem_free(*a0.any_pvp);
5e54c26f 934#else
c9728782 935 PerlMemShared_free(*a0.any_pvp);
5e54c26f 936#endif
c9728782 937 *a0.any_pvp = a1.any_pv;
05ec9bb3
NIS
938 }
939 break;
c9728782 940
f83b46a0 941 case SAVEt_GVSV: /* scalar slot in GV */
c9728782 942 a0 = ap[0]; a1 = ap[1];
75ebea3c 943 a0.any_svp = &GvSV(a0.any_gv);
f83b46a0 944 goto restore_svp;
c9728782 945
8aacddc1 946 case SAVEt_GENERIC_SVREF: /* generic sv */
c9728782 947 a0 = ap[0]; a1 = ap[1];
f83b46a0 948 restore_svp:
03dba561 949 {
75ebea3c
DM
950 /* do *a0.any_svp = a1 */
951 SV * const sv = *a0.any_svp;
952 *a0.any_svp = a1.any_sv;
f4dd75d9 953 SvREFCNT_dec(sv);
c9728782 954 SvREFCNT_dec(a1.any_sv);
b9d12d37 955 break;
03dba561 956 }
c9728782 957
db9306af 958 case SAVEt_GVSLOT: /* any slot in GV */
03dba561 959 {
9a2fefd6 960 HV * hv;
c9728782
DM
961 a0 = ap[0]; a1 = ap[1]; a2 = ap[2];
962 hv = GvSTASH(a0.any_gv);
db9306af 963 if (hv && HvENAME(hv) && (
c9728782 964 (a2.any_sv && SvTYPE(a2.any_sv) == SVt_PVCV)
75ebea3c 965 || (*a1.any_svp && SvTYPE(*a1.any_svp) == SVt_PVCV)
db9306af
FC
966 ))
967 {
75ebea3c
DM
968 if ((char *)a1.any_svp < (char *)GvGP(a0.any_gv)
969 || (char *)a1.any_svp > (char *)GvGP(a0.any_gv) + sizeof(struct gp)
c9728782 970 || GvREFCNT(a0.any_gv) > 2) /* "> 2" to ignore savestack's ref */
db9306af
FC
971 PL_sub_generation++;
972 else mro_method_changed_in(hv);
973 }
75ebea3c
DM
974 a0.any_svp = a1.any_svp;
975 a1.any_sv = a2.any_sv;
db9306af 976 goto restore_svp;
03dba561 977 }
c9728782 978
8aacddc1 979 case SAVEt_AV: /* array reference */
c9728782
DM
980 a0 = ap[0]; a1 = ap[1];
981 SvREFCNT_dec(GvAV(a0.any_gv));
982 GvAV(a0.any_gv) = a1.any_av;
2baebb98 983 avhv_common:
c9728782
DM
984 if (UNLIKELY(SvSMAGICAL(a1.any_sv))) {
985 /* mg_set might die, so make sure a0 isn't leaked */
2baebb98 986 dSS_ADD;
c9728782 987 SS_ADD_PTR(a0.any_sv);
2baebb98
DM
988 SS_ADD_UV(SAVEt_FREESV);
989 SS_ADD_END(2);
b492a59e 990 PL_localizing = 2;
c9728782 991 mg_set(a1.any_sv);
b492a59e 992 PL_localizing = 0;
2baebb98 993 break;
b492a59e 994 }
c9728782 995 SvREFCNT_dec_NN(a0.any_sv);
8aacddc1 996 break;
c9728782 997
8aacddc1 998 case SAVEt_HV: /* hash reference */
c9728782
DM
999 a0 = ap[0]; a1 = ap[1];
1000 SvREFCNT_dec(GvHV(a0.any_gv));
1001 GvHV(a0.any_gv) = a1.any_hv;
2baebb98
DM
1002 goto avhv_common;
1003
994d373a 1004 case SAVEt_INT_SMALL:
c9728782
DM
1005 a0 = ap[0];
1006 *(int*)a0.any_ptr = (int)(uv >> SAVE_TIGHT_SHIFT);
994d373a 1007 break;
c9728782 1008
79072805 1009 case SAVEt_INT: /* int reference */
c9728782
DM
1010 a0 = ap[0]; a1 = ap[1];
1011 *(int*)a1.any_ptr = (int)a0.any_i32;
79072805 1012 break;
c9728782 1013
e8eb279c 1014 case SAVEt_STRLEN: /* STRLEN/size_t ref */
c9728782
DM
1015 a0 = ap[0]; a1 = ap[1];
1016 *(STRLEN*)a1.any_ptr = (STRLEN)a0.any_iv;
e8eb279c 1017 break;
c9728782 1018
2ef9a108 1019 case SAVEt_TMPSFLOOR: /* restore PL_tmps_floor */
c9728782
DM
1020 a0 = ap[0];
1021 PL_tmps_floor = (SSize_t)a0.any_iv;
2ef9a108 1022 break;
c9728782 1023
9febdf04 1024 case SAVEt_BOOL: /* bool reference */
c9728782
DM
1025 a0 = ap[0];
1026 *(bool*)a0.any_ptr = cBOOL(uv >> 8);
9a9b5ec9
DM
1027#ifdef NO_TAINT_SUPPORT
1028 PERL_UNUSED_VAR(was);
1029#else
c9728782 1030 if (UNLIKELY(a0.any_ptr == &(TAINT_get))) {
b6f93e7a
KW
1031 /* If we don't update <was>, to reflect what was saved on the
1032 * stack for PL_tainted, then we will overwrite this attempt to
1033 * restore it when we exit this routine. Note that this won't
1034 * work if this value was saved in a wider-than necessary type,
1035 * such as I32 */
c9728782 1036 was = *(bool*)a0.any_ptr;
b6f93e7a 1037 }
284167a5 1038#endif
9febdf04 1039 break;
c9728782 1040
89abef21 1041 case SAVEt_I32_SMALL:
c9728782
DM
1042 a0 = ap[0];
1043 *(I32*)a0.any_ptr = (I32)(uv >> SAVE_TIGHT_SHIFT);
89abef21 1044 break;
c9728782 1045
79072805 1046 case SAVEt_I32: /* I32 reference */
c9728782 1047 a0 = ap[0]; a1 = ap[1];
3235b7a3 1048#ifdef PERL_DEBUG_READONLY_OPS
c9728782 1049 if (*(I32*)a1.any_ptr != a0.any_i32)
3235b7a3 1050#endif
c9728782 1051 *(I32*)a1.any_ptr = a0.any_i32;
79072805 1052 break;
c9728782 1053
79072805 1054 case SAVEt_SPTR: /* SV* reference */
c9728782
DM
1055 a0 = ap[0]; a1 = ap[1];
1056 *a1.any_svp= a0.any_sv;
79072805 1057 break;
c9728782 1058
146174a9 1059 case SAVEt_VPTR: /* random* reference */
85e6fe83 1060 case SAVEt_PPTR: /* char* reference */
c9728782
DM
1061 a0 = ap[0]; a1 = ap[1];
1062 *a1.any_pvp = a0.any_pv;
85e6fe83 1063 break;
c9728782 1064
79072805 1065 case SAVEt_HPTR: /* HV* reference */
c9728782
DM
1066 a0 = ap[0]; a1 = ap[1];
1067 *(HV**)a1.any_ptr = a0.any_hv;
79072805 1068 break;
c9728782 1069
79072805 1070 case SAVEt_APTR: /* AV* reference */
c9728782
DM
1071 a0 = ap[0]; a1 = ap[1];
1072 *(AV**)a1.any_ptr = a0.any_av;
79072805 1073 break;
c9728782 1074
fb73857a 1075 case SAVEt_GP: /* scalar reference */
03dba561
DM
1076 {
1077 HV *hv;
9a2fefd6
DM
1078 bool had_method;
1079
c9728782 1080 a0 = ap[0]; a1 = ap[1];
03dba561 1081 /* possibly taking a method out of circulation */
c9728782
DM
1082 had_method = !!GvCVu(a0.any_gv);
1083 gp_free(a0.any_gv);
1084 GvGP_set(a0.any_gv, (GP*)a1.any_ptr);
1085 if ((hv=GvSTASH(a0.any_gv)) && HvENAME_get(hv)) {
1086 if ( GvNAMELEN(a0.any_gv) == 3
1087 && strnEQ(GvNAME(a0.any_gv), "ISA", 3)
03dba561
DM
1088 )
1089 mro_isa_changed_in(hv);
c9728782 1090 else if (had_method || GvCVu(a0.any_gv))
03dba561 1091 /* putting a method back into circulation ("local")*/
c9728782 1092 gv_method_changed(a0.any_gv);
3d460042 1093 }
c9728782 1094 SvREFCNT_dec_NN(a0.any_gv);
8aacddc1 1095 break;
03dba561 1096 }
c9728782 1097
8990e307 1098 case SAVEt_FREESV:
c9728782
DM
1099 a0 = ap[0];
1100 SvREFCNT_dec(a0.any_sv);
8990e307 1101 break;
c9728782 1102
0f94cb1f 1103 case SAVEt_FREEPADNAME:
c9728782
DM
1104 a0 = ap[0];
1105 PadnameREFCNT_dec((PADNAME *)a0.any_ptr);
0f94cb1f 1106 break;
c9728782 1107
3987a177 1108 case SAVEt_FREECOPHH:
c9728782
DM
1109 a0 = ap[0];
1110 cophh_free((COPHH *)a0.any_ptr);
3987a177 1111 break;
c9728782 1112
26d9b02f 1113 case SAVEt_MORTALIZESV:
c9728782
DM
1114 a0 = ap[0];
1115 sv_2mortal(a0.any_sv);
26d9b02f 1116 break;
c9728782 1117
8990e307 1118 case SAVEt_FREEOP:
c9728782 1119 a0 = ap[0];
5e5ba94b 1120 ASSERT_CURPAD_LEGAL("SAVEt_FREEOP");
c9728782 1121 op_free((OP*)a0.any_ptr);
8990e307 1122 break;
c9728782 1123
8990e307 1124 case SAVEt_FREEPV:
c9728782
DM
1125 a0 = ap[0];
1126 Safefree(a0.any_ptr);
8990e307 1127 break;
4e09461c 1128
4e09461c 1129 case SAVEt_CLEARPADRANGE:
75ebea3c
DM
1130 {
1131 I32 i = (I32)((uv >> SAVE_TIGHT_SHIFT) & OPpPADRANGE_COUNTMASK);
1132 SV **svp = &PL_curpad[uv >>
4e09461c
DM
1133 (OPpPADRANGE_COUNTSHIFT + SAVE_TIGHT_SHIFT)] + i - 1;
1134 goto clearsv;
8990e307 1135 case SAVEt_CLEARSV:
4e09461c
DM
1136 svp = &PL_curpad[uv >> SAVE_TIGHT_SHIFT];
1137 i = 1;
1138 clearsv:
1139 for (; i; i--, svp--) {
9a2fefd6 1140 SV *sv = *svp;
528ad060
DM
1141
1142 DEBUG_Xv(PerlIO_printf(Perl_debug_log,
1143 "Pad 0x%"UVxf"[0x%"UVxf"] clearsv: %ld sv=0x%"UVxf"<%"IVdf"> %s\n",
1144 PTR2UV(PL_comppad), PTR2UV(PL_curpad),
1145 (long)(svp-PL_curpad), PTR2UV(sv), (IV)SvREFCNT(sv),
1146 (SvREFCNT(sv) <= 1 && !SvOBJECT(sv)) ? "clear" : "abandon"
1147 ));
1148
1149 /* Can clear pad variable in place? */
9af15990 1150 if (SvREFCNT(sv) == 1 && !SvOBJECT(sv)) {
a07f0bef 1151
a07f0bef
DM
1152 /* these flags are the union of all the relevant flags
1153 * in the individual conditions within */
1154 if (UNLIKELY(SvFLAGS(sv) & (
a623f893 1155 SVf_READONLY|SVf_PROTECT /*for SvREADONLY_off*/
a07f0bef 1156 | (SVs_GMG|SVs_SMG|SVs_RMG) /* SvMAGICAL() */
7532eaae 1157 | SVf_OOK
a07f0bef
DM
1158 | SVf_THINKFIRST)))
1159 {
7500fc82
DM
1160 /* if a my variable that was made readonly is
1161 * going out of scope, we want to remove the
1162 * readonlyness so that it can go out of scope
1163 * quietly
1164 */
57c404c9 1165 if (SvREADONLY(sv))
7500fc82
DM
1166 SvREADONLY_off(sv);
1167
7532eaae
DM
1168 if (SvOOK(sv)) { /* OOK or HvAUX */
1169 if (SvTYPE(sv) == SVt_PVHV)
1170 Perl_hv_kill_backrefs(aTHX_ MUTABLE_HV(sv));
1171 else
1172 sv_backoff(sv);
1173 }
1174
7500fc82 1175 if (SvMAGICAL(sv)) {
7532eaae
DM
1176 /* note that backrefs (either in HvAUX or magic)
1177 * must be removed before other magic */
7500fc82
DM
1178 sv_unmagic(sv, PERL_MAGIC_backref);
1179 if (SvTYPE(sv) != SVt_PVCV)
1180 mg_free(sv);
1181 }
1182 if (SvTHINKFIRST(sv))
1183 sv_force_normal_flags(sv, SV_IMMEDIATE_UNREF
1184 |SV_COW_DROP_PV);
528ad060 1185
a07f0bef 1186 }
528ad060
DM
1187 switch (SvTYPE(sv)) {
1188 case SVt_NULL:
1189 break;
1190 case SVt_PVAV:
1191 av_clear(MUTABLE_AV(sv));
1192 break;
1193 case SVt_PVHV:
1194 hv_clear(MUTABLE_HV(sv));
1195 break;
1196 case SVt_PVCV:
1197 {
db5cc3ee 1198 HEK *hek =
db5cc3ee 1199 CvNAMED(sv)
9c98a81f
FC
1200 ? CvNAME_HEK((CV *)sv)
1201 : GvNAME_HEK(CvGV(sv));
528ad060 1202 assert(hek);
6110d17a 1203 (void)share_hek_hek(hek);
528ad060
DM
1204 cv_undef((CV *)sv);
1205 CvNAME_HEK_set(sv, hek);
f3feca7a 1206 CvLEXICAL_on(sv);
528ad060
DM
1207 break;
1208 }
1209 default:
c79d0076
NC
1210 /* This looks odd, but these two macros are for use in
1211 expressions and finish with a trailing comma, so
1212 adding a ; after them would be wrong. */
1213 assert_not_ROK(sv)
1214 assert_not_glob(sv)
5c85b638 1215 SvFLAGS(sv) &=~ (SVf_OK|SVf_IVisUV|SVf_UTF8);
528ad060
DM
1216 break;
1217 }
82e85a9c 1218 SvPADTMP_off(sv);
528ad060
DM
1219 SvPADSTALE_on(sv); /* mark as no longer live */
1220 }
1221 else { /* Someone has a claim on this, so abandon it. */
528ad060
DM
1222 switch (SvTYPE(sv)) { /* Console ourselves with a new value */
1223 case SVt_PVAV: *svp = MUTABLE_SV(newAV()); break;
1224 case SVt_PVHV: *svp = MUTABLE_SV(newHV()); break;
1225 case SVt_PVCV:
1226 {
9c98a81f
FC
1227 HEK * const hek = CvNAMED(sv)
1228 ? CvNAME_HEK((CV *)sv)
1229 : GvNAME_HEK(CvGV(sv));
1230
528ad060
DM
1231 /* Create a stub */
1232 *svp = newSV_type(SVt_PVCV);
1233
1234 /* Share name */
528ad060 1235 CvNAME_HEK_set(*svp,
9c98a81f 1236 share_hek_hek(hek));
f3feca7a 1237 CvLEXICAL_on(*svp);
528ad060
DM
1238 break;
1239 }
1240 default: *svp = newSV(0); break;
1241 }
4a9a56a7 1242 SvREFCNT_dec_NN(sv); /* Cast current value to the winds. */
528ad060
DM
1243 /* preserve pad nature, but also mark as not live
1244 * for any closure capturing */
145bf8ee 1245 SvFLAGS(*svp) |= SVs_PADSTALE;
528ad060 1246 }
4e09461c 1247 }
8990e307 1248 break;
75ebea3c 1249 }
c9728782 1250
8990e307 1251 case SAVEt_DELETE:
c9728782
DM
1252 a0 = ap[0]; a1 = ap[1]; a2 = ap[2];
1253 (void)hv_delete(a2.any_hv, a0.any_pv, a1.any_i32, G_DISCARD);
1254 SvREFCNT_dec(a2.any_hv);
1255 Safefree(a0.any_ptr);
8990e307 1256 break;
c9728782 1257
c68ec7a9 1258 case SAVEt_ADELETE:
c9728782
DM
1259 a0 = ap[0]; a1 = ap[1];
1260 (void)av_delete(a1.any_av, a0.any_iv, G_DISCARD);
1261 SvREFCNT_dec(a1.any_av);
c68ec7a9 1262 break;
c9728782 1263
146174a9 1264 case SAVEt_DESTRUCTOR_X:
c9728782
DM
1265 a0 = ap[0]; a1 = ap[1];
1266 (*a0.any_dxptr)(aTHX_ a1.any_ptr);
a0d0e21e 1267 break;
c9728782 1268
a0d0e21e 1269 case SAVEt_REGCONTEXT:
e0fa7e2b 1270 /* regexp must have croaked */
455ece5e 1271 case SAVEt_ALLOC:
1be36ce0 1272 PL_savestack_ix -= uv >> SAVE_TIGHT_SHIFT;
a0d0e21e 1273 break;
c9728782 1274
55497cff 1275 case SAVEt_STACK_POS: /* Position on Perl stack */
c9728782
DM
1276 a0 = ap[0];
1277 PL_stack_sp = PL_stack_base + a0.any_i32;
55497cff 1278 break;
c9728782 1279
161b7d16 1280 case SAVEt_AELEM: /* array element */
75ebea3c
DM
1281 {
1282 SV **svp;
c9728782
DM
1283 a0 = ap[0]; a1 = ap[1]; a2 = ap[2];
1284 svp = av_fetch(a0.any_av, a1.any_iv, 1);
1285 if (UNLIKELY(!AvREAL(a0.any_av) && AvREIFY(a0.any_av))) /* undo reify guard */
1286 SvREFCNT_dec(a2.any_sv);
5d9574c1 1287 if (LIKELY(svp)) {
03dba561 1288 SV * const sv = *svp;
5d9574c1 1289 if (LIKELY(sv && sv != &PL_sv_undef)) {
c9728782 1290 if (UNLIKELY(SvTIED_mg((const SV *)a0.any_av, PERL_MAGIC_tied)))
b37c2d43 1291 SvREFCNT_inc_void_NN(sv);
75ebea3c
DM
1292 a1.any_sv = a2.any_sv;
1293 a2.any_svp = svp;
4e4c362e
GS
1294 goto restore_sv;
1295 }
1296 }
c9728782
DM
1297 SvREFCNT_dec(a0.any_av);
1298 SvREFCNT_dec(a2.any_sv);
4e4c362e 1299 break;
75ebea3c 1300 }
c9728782 1301
161b7d16 1302 case SAVEt_HELEM: /* hash element */
03dba561 1303 {
9a2fefd6
DM
1304 HE *he;
1305
c9728782
DM
1306 a0 = ap[0]; a1 = ap[1]; a2 = ap[2];
1307 he = hv_fetch_ent(a0.any_hv, a1.any_sv, 1, 0);
1308 SvREFCNT_dec(a1.any_sv);
5d9574c1 1309 if (LIKELY(he)) {
03dba561 1310 const SV * const oval = HeVAL(he);
5d9574c1 1311 if (LIKELY(oval && oval != &PL_sv_undef)) {
75ebea3c 1312 SV **svp = &HeVAL(he);
c9728782 1313 if (UNLIKELY(SvTIED_mg((const SV *)a0.any_hv, PERL_MAGIC_tied)))
03dba561 1314 SvREFCNT_inc_void(*svp);
75ebea3c
DM
1315 a1.any_sv = a2.any_sv;
1316 a2.any_svp = svp;
4e4c362e
GS
1317 goto restore_sv;
1318 }
1319 }
c9728782
DM
1320 SvREFCNT_dec(a0.any_hv);
1321 SvREFCNT_dec(a2.any_sv);
4e4c362e 1322 break;
03dba561 1323 }
75ebea3c 1324
462e5cf6 1325 case SAVEt_OP:
c9728782
DM
1326 a0 = ap[0];
1327 PL_op = (OP*)a0.any_ptr;
462e5cf6 1328 break;
c9728782 1329
25eaa213 1330 case SAVEt_HINTS:
c9728782 1331 a0 = ap[0]; a1 = ap[1];
3607ca02
FC
1332 if ((PL_hints & HINT_LOCALIZE_HH)) {
1333 while (GvHV(PL_hintgv)) {
2653c1e3 1334 HV *hv = GvHV(PL_hintgv);
045ac317 1335 GvHV(PL_hintgv) = NULL;
2653c1e3 1336 SvREFCNT_dec(MUTABLE_SV(hv));
3607ca02 1337 }
045ac317 1338 }
20439bc7 1339 cophh_free(CopHINTHASH_get(&PL_compiling));
c9728782
DM
1340 CopHINTHASH_set(&PL_compiling, (COPHH*)a1.any_ptr);
1341 *(I32*)&PL_hints = a0.any_i32;
dfa41748 1342 if (PL_hints & HINT_LOCALIZE_HH) {
ad64d0ec 1343 SvREFCNT_dec(MUTABLE_SV(GvHV(PL_hintgv)));
85fbaab2 1344 GvHV(PL_hintgv) = MUTABLE_HV(SSPOPPTR);
2653c1e3
DM
1345 }
1346 if (!GvHV(PL_hintgv)) {
a3fb8386
FC
1347 /* Need to add a new one manually, else rv2hv can
1348 add one via GvHVn and it won't have the magic set. */
5b9c0671
NC
1349 HV *const hv = newHV();
1350 hv_magic(hv, NULL, PERL_MAGIC_hints);
1351 GvHV(PL_hintgv) = hv;
dfa41748 1352 }
5b9c0671 1353 assert(GvHV(PL_hintgv));
b3ac6de7 1354 break;
c9728782 1355
cb50131a 1356 case SAVEt_COMPPAD:
c9728782
DM
1357 a0 = ap[0];
1358 PL_comppad = (PAD*)a0.any_ptr;
5d9574c1 1359 if (LIKELY(PL_comppad))
cb50131a
CB
1360 PL_curpad = AvARRAY(PL_comppad);
1361 else
4608196e 1362 PL_curpad = NULL;
cb50131a 1363 break;
c9728782 1364
09edbca0 1365 case SAVEt_PADSV_AND_MORTALIZE:
c3564e5c 1366 {
09edbca0 1367 SV **svp;
9a2fefd6 1368
c9728782
DM
1369 a0 = ap[0]; a1 = ap[1]; a2 = ap[2];
1370 assert (a1.any_ptr);
1371 svp = AvARRAY((PAD*)a1.any_ptr) + (PADOFFSET)a2.any_uv;
b405d38b
DM
1372 /* This mortalizing used to be done by CX_POOPLOOP() via
1373 itersave. But as we have all the information here, we
1374 can do it here, save even having to have itersave in
1375 the struct.
1376 */
09edbca0 1377 sv_2mortal(*svp);
c9728782 1378 *svp = a0.any_sv;
c3564e5c
GS
1379 }
1380 break;
c9728782 1381
8b7059b1
DM
1382 case SAVEt_SAVESWITCHSTACK:
1383 {
1384 dSP;
9a2fefd6 1385
c9728782
DM
1386 a0 = ap[0]; a1 = ap[1];
1387 SWITCHSTACK(a1.any_av, a0.any_av);
1388 PL_curstackinfo->si_stack = a0.any_av;
8b7059b1
DM
1389 }
1390 break;
c9728782 1391
14f338dc 1392 case SAVEt_SET_SVFLAGS:
c9728782
DM
1393 a0 = ap[0]; a1 = ap[1]; a2 = ap[2];
1394 SvFLAGS(a0.any_sv) &= ~(a1.any_u32);
1395 SvFLAGS(a0.any_sv) |= a2.any_u32;
14f338dc 1396 break;
95e06916 1397
95e06916
NC
1398 /* These are only saved in mathoms.c */
1399 case SAVEt_NSTAB:
c9728782
DM
1400 a0 = ap[0];
1401 (void)sv_clear(a0.any_sv);
95e06916 1402 break;
c9728782 1403
2053acbf 1404 case SAVEt_LONG: /* long reference */
c9728782
DM
1405 a0 = ap[0]; a1 = ap[1];
1406 *(long*)a1.any_ptr = a0.any_long;
2053acbf 1407 break;
c9728782 1408
95e06916 1409 case SAVEt_IV: /* IV reference */
c9728782
DM
1410 a0 = ap[0]; a1 = ap[1];
1411 *(IV*)a1.any_ptr = a0.any_iv;
95e06916
NC
1412 break;
1413
2053acbf 1414 case SAVEt_I16: /* I16 reference */
c9728782
DM
1415 a0 = ap[0];
1416 *(I16*)a0.any_ptr = (I16)(uv >> 8);
2053acbf 1417 break;
c9728782 1418
2053acbf 1419 case SAVEt_I8: /* I8 reference */
c9728782
DM
1420 a0 = ap[0];
1421 *(I8*)a0.any_ptr = (I8)(uv >> 8);
2053acbf 1422 break;
c9728782 1423
2053acbf 1424 case SAVEt_DESTRUCTOR:
c9728782
DM
1425 a0 = ap[0]; a1 = ap[1];
1426 (*a0.any_dptr)(a1.any_ptr);
2053acbf 1427 break;
c9728782 1428
68da3b2f 1429 case SAVEt_COMPILE_WARNINGS:
c9728782 1430 a0 = ap[0];
68da3b2f
NC
1431 if (!specialWARN(PL_compiling.cop_warnings))
1432 PerlMemShared_free(PL_compiling.cop_warnings);
c9728782 1433 PL_compiling.cop_warnings = (STRLEN*)a0.any_ptr;
72dc9ed5 1434 break;
c9728782 1435
7c197c94 1436 case SAVEt_PARSER:
c9728782
DM
1437 a0 = ap[0];
1438 parser_free((yy_parser *)a0.any_ptr);
7c197c94 1439 break;
c9728782 1440
20d5dc23 1441 case SAVEt_READONLY_OFF:
c9728782
DM
1442 a0 = ap[0];
1443 SvREADONLY_off(a0.any_sv);
20d5dc23 1444 break;
c9728782 1445
79072805 1446 default:
75ebea3c
DM
1447 Perl_croak(aTHX_ "panic: leave_scope inconsistency %u",
1448 (U8)uv & SAVE_MASK);
79072805
LW
1449 }
1450 }
302c0c93 1451
284167a5 1452 TAINT_set(was);
79072805 1453}
8990e307 1454
8990e307 1455void
864dbfa3 1456Perl_cx_dump(pTHX_ PERL_CONTEXT *cx)
8990e307 1457{
7918f24d
NC
1458 PERL_ARGS_ASSERT_CX_DUMP;
1459
35ff7856 1460#ifdef DEBUGGING
22c35a8c 1461 PerlIO_printf(Perl_debug_log, "CX %ld = %s\n", (long)(cx - cxstack), PL_block_type[CxTYPE(cx)]);
6b35e009 1462 if (CxTYPE(cx) != CXt_SUBST) {
e8d9e9d0 1463 const char *gimme_text;
760ac839 1464 PerlIO_printf(Perl_debug_log, "BLK_OLDSP = %ld\n", (long)cx->blk_oldsp);
146174a9
CB
1465 PerlIO_printf(Perl_debug_log, "BLK_OLDCOP = 0x%"UVxf"\n",
1466 PTR2UV(cx->blk_oldcop));
760ac839
LW
1467 PerlIO_printf(Perl_debug_log, "BLK_OLDMARKSP = %ld\n", (long)cx->blk_oldmarksp);
1468 PerlIO_printf(Perl_debug_log, "BLK_OLDSCOPESP = %ld\n", (long)cx->blk_oldscopesp);
e992140c 1469 PerlIO_printf(Perl_debug_log, "BLK_OLDSAVEIX = %ld\n", (long)cx->blk_oldsaveix);
146174a9
CB
1470 PerlIO_printf(Perl_debug_log, "BLK_OLDPM = 0x%"UVxf"\n",
1471 PTR2UV(cx->blk_oldpm));
e8d9e9d0
VP
1472 switch (cx->blk_gimme) {
1473 case G_VOID:
1474 gimme_text = "VOID";
1475 break;
1476 case G_SCALAR:
1477 gimme_text = "SCALAR";
1478 break;
1479 case G_ARRAY:
1480 gimme_text = "LIST";
1481 break;
1482 default:
1483 gimme_text = "UNKNOWN";
1484 break;
1485 }
1486 PerlIO_printf(Perl_debug_log, "BLK_GIMME = %s\n", gimme_text);
8990e307 1487 }
6b35e009 1488 switch (CxTYPE(cx)) {
8990e307
LW
1489 case CXt_NULL:
1490 case CXt_BLOCK:
1491 break;
146174a9 1492 case CXt_FORMAT:
f9c764c5
NC
1493 PerlIO_printf(Perl_debug_log, "BLK_FORMAT.CV = 0x%"UVxf"\n",
1494 PTR2UV(cx->blk_format.cv));
1495 PerlIO_printf(Perl_debug_log, "BLK_FORMAT.GV = 0x%"UVxf"\n",
1496 PTR2UV(cx->blk_format.gv));
1497 PerlIO_printf(Perl_debug_log, "BLK_FORMAT.DFOUTGV = 0x%"UVxf"\n",
1498 PTR2UV(cx->blk_format.dfoutgv));
1499 PerlIO_printf(Perl_debug_log, "BLK_FORMAT.HASARGS = %d\n",
bafb2adc 1500 (int)CxHASARGS(cx));
f9c764c5
NC
1501 PerlIO_printf(Perl_debug_log, "BLK_FORMAT.RETOP = 0x%"UVxf"\n",
1502 PTR2UV(cx->blk_format.retop));
146174a9 1503 break;
8990e307 1504 case CXt_SUB:
146174a9
CB
1505 PerlIO_printf(Perl_debug_log, "BLK_SUB.CV = 0x%"UVxf"\n",
1506 PTR2UV(cx->blk_sub.cv));
760ac839 1507 PerlIO_printf(Perl_debug_log, "BLK_SUB.OLDDEPTH = %ld\n",
8990e307 1508 (long)cx->blk_sub.olddepth);
760ac839 1509 PerlIO_printf(Perl_debug_log, "BLK_SUB.HASARGS = %d\n",
bafb2adc
NC
1510 (int)CxHASARGS(cx));
1511 PerlIO_printf(Perl_debug_log, "BLK_SUB.LVAL = %d\n", (int)CxLVAL(cx));
f39bc417
DM
1512 PerlIO_printf(Perl_debug_log, "BLK_SUB.RETOP = 0x%"UVxf"\n",
1513 PTR2UV(cx->blk_sub.retop));
8990e307
LW
1514 break;
1515 case CXt_EVAL:
760ac839 1516 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_IN_EVAL = %ld\n",
85a64632 1517 (long)CxOLD_IN_EVAL(cx));
760ac839 1518 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_OP_TYPE = %s (%s)\n",
85a64632
NC
1519 PL_op_name[CxOLD_OP_TYPE(cx)],
1520 PL_op_desc[CxOLD_OP_TYPE(cx)]);
0f79a09d
GS
1521 if (cx->blk_eval.old_namesv)
1522 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_NAME = %s\n",
aa07b2f6 1523 SvPVX_const(cx->blk_eval.old_namesv));
146174a9
CB
1524 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_EVAL_ROOT = 0x%"UVxf"\n",
1525 PTR2UV(cx->blk_eval.old_eval_root));
f39bc417
DM
1526 PerlIO_printf(Perl_debug_log, "BLK_EVAL.RETOP = 0x%"UVxf"\n",
1527 PTR2UV(cx->blk_eval.retop));
8990e307
LW
1528 break;
1529
93661e56 1530 case CXt_LOOP_PLAIN:
c6fdafd0 1531 case CXt_LOOP_LAZYIV:
d01136d6 1532 case CXt_LOOP_LAZYSV:
93661e56
DM
1533 case CXt_LOOP_LIST:
1534 case CXt_LOOP_ARY:
0cbdab38 1535 PerlIO_printf(Perl_debug_log, "BLK_LOOP.LABEL = %s\n", CxLABEL(cx));
022eaa24
NC
1536 PerlIO_printf(Perl_debug_log, "BLK_LOOP.MY_OP = 0x%"UVxf"\n",
1537 PTR2UV(cx->blk_loop.my_op));
0925dc7f
DM
1538 if (CxTYPE(cx) != CXt_LOOP_PLAIN) {
1539 PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERVAR = 0x%"UVxf"\n",
1540 PTR2UV(CxITERVAR(cx)));
1541 PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERSAVE = 0x%"UVxf"\n",
1542 PTR2UV(cx->blk_loop.itersave));
1543 /* XXX: not accurate for LAZYSV/IV/LIST */
1544 PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERARY = 0x%"UVxf"\n",
1545 PTR2UV(cx->blk_loop.state_u.ary.ary));
1546 PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERIX = %ld\n",
1547 (long)cx->blk_loop.state_u.ary.ix);
1548 }
8990e307
LW
1549 break;
1550
1551 case CXt_SUBST:
760ac839 1552 PerlIO_printf(Perl_debug_log, "SB_ITERS = %ld\n",
8990e307 1553 (long)cx->sb_iters);
760ac839 1554 PerlIO_printf(Perl_debug_log, "SB_MAXITERS = %ld\n",
8990e307 1555 (long)cx->sb_maxiters);
35ef4773
GS
1556 PerlIO_printf(Perl_debug_log, "SB_RFLAGS = %ld\n",
1557 (long)cx->sb_rflags);
760ac839 1558 PerlIO_printf(Perl_debug_log, "SB_ONCE = %ld\n",
c5bed6a7 1559 (long)CxONCE(cx));
760ac839 1560 PerlIO_printf(Perl_debug_log, "SB_ORIG = %s\n",
8990e307 1561 cx->sb_orig);
146174a9
CB
1562 PerlIO_printf(Perl_debug_log, "SB_DSTR = 0x%"UVxf"\n",
1563 PTR2UV(cx->sb_dstr));
1564 PerlIO_printf(Perl_debug_log, "SB_TARG = 0x%"UVxf"\n",
1565 PTR2UV(cx->sb_targ));
1566 PerlIO_printf(Perl_debug_log, "SB_S = 0x%"UVxf"\n",
1567 PTR2UV(cx->sb_s));
1568 PerlIO_printf(Perl_debug_log, "SB_M = 0x%"UVxf"\n",
1569 PTR2UV(cx->sb_m));
1570 PerlIO_printf(Perl_debug_log, "SB_STREND = 0x%"UVxf"\n",
1571 PTR2UV(cx->sb_strend));
1572 PerlIO_printf(Perl_debug_log, "SB_RXRES = 0x%"UVxf"\n",
1573 PTR2UV(cx->sb_rxres));
8990e307
LW
1574 break;
1575 }
65e66c80 1576#else
96a5add6 1577 PERL_UNUSED_CONTEXT;
65e66c80 1578 PERL_UNUSED_ARG(cx);
17c3b450 1579#endif /* DEBUGGING */
35ff7856 1580}
241d1a3b
NC
1581
1582/*
14d04a33 1583 * ex: set ts=8 sts=4 sw=4 et:
37442d52 1584 */