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