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