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