This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Re-implement the macros SAVECOMPPAD(), SAVECOMPILEWARNINGS(),
[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**
864dbfa3 30Perl_stack_grow(pTHX_ SV **sp, SV **p, int n)
a0d0e21e 31{
97aff369 32 dVAR;
7918f24d
NC
33
34 PERL_ARGS_ASSERT_STACK_GROW;
35
3280af22 36 PL_stack_sp = sp;
2ce36478 37#ifndef STRESS_REALLOC
3280af22 38 av_extend(PL_curstack, (p - PL_stack_base) + (n) + 128);
2ce36478 39#else
6b88bc9c 40 av_extend(PL_curstack, (p - PL_stack_base) + (n) + 1);
2ce36478 41#endif
3280af22 42 return PL_stack_sp;
a0d0e21e
LW
43}
44
2ce36478
SM
45#ifndef STRESS_REALLOC
46#define GROW(old) ((old) * 3 / 2)
47#else
48#define GROW(old) ((old) + 1)
49#endif
50
e336de0d 51PERL_SI *
864dbfa3 52Perl_new_stackinfo(pTHX_ I32 stitems, I32 cxitems)
e336de0d 53{
97aff369 54 dVAR;
e336de0d 55 PERL_SI *si;
a02a5408 56 Newx(si, 1, PERL_SI);
e336de0d
GS
57 si->si_stack = newAV();
58 AvREAL_off(si->si_stack);
59 av_extend(si->si_stack, stitems > 0 ? stitems-1 : 0);
3280af22 60 AvALLOC(si->si_stack)[0] = &PL_sv_undef;
e336de0d
GS
61 AvFILLp(si->si_stack) = 0;
62 si->si_prev = 0;
63 si->si_next = 0;
64 si->si_cxmax = cxitems - 1;
65 si->si_cxix = -1;
e788e7d3 66 si->si_type = PERLSI_UNDEF;
a02a5408 67 Newx(si->si_cxstack, cxitems, PERL_CONTEXT);
9965345d
JH
68 /* Without any kind of initialising PUSHSUBST()
69 * in pp_subst() will read uninitialised heap. */
7e337ee0 70 PoisonNew(si->si_cxstack, cxitems, PERL_CONTEXT);
e336de0d
GS
71 return si;
72}
73
79072805 74I32
864dbfa3 75Perl_cxinc(pTHX)
79072805 76{
97aff369 77 dVAR;
a3b680e6 78 const IV old_max = cxstack_max;
2ce36478 79 cxstack_max = GROW(cxstack_max);
c09156bb 80 Renew(cxstack, cxstack_max + 1, PERL_CONTEXT); /* XXX should fix CXINC macro */
9965345d
JH
81 /* Without any kind of initialising deep enough recursion
82 * will end up reading uninitialised PERL_CONTEXTs. */
7e337ee0 83 PoisonNew(cxstack + old_max + 1, cxstack_max - old_max, PERL_CONTEXT);
79072805
LW
84 return cxstack_ix + 1;
85}
86
79072805 87void
864dbfa3 88Perl_push_scope(pTHX)
79072805 89{
97aff369 90 dVAR;
3280af22
NIS
91 if (PL_scopestack_ix == PL_scopestack_max) {
92 PL_scopestack_max = GROW(PL_scopestack_max);
93 Renew(PL_scopestack, PL_scopestack_max, I32);
79072805 94 }
3280af22 95 PL_scopestack[PL_scopestack_ix++] = PL_savestack_ix;
79072805
LW
96
97}
98
99void
864dbfa3 100Perl_pop_scope(pTHX)
79072805 101{
97aff369 102 dVAR;
35a4481c 103 const I32 oldsave = PL_scopestack[--PL_scopestack_ix];
8990e307 104 LEAVE_SCOPE(oldsave);
79072805
LW
105}
106
107void
864dbfa3 108Perl_markstack_grow(pTHX)
a0d0e21e 109{
97aff369 110 dVAR;
35a4481c
AL
111 const I32 oldmax = PL_markstack_max - PL_markstack;
112 const I32 newmax = GROW(oldmax);
a0d0e21e 113
3280af22
NIS
114 Renew(PL_markstack, newmax, I32);
115 PL_markstack_ptr = PL_markstack + oldmax;
116 PL_markstack_max = PL_markstack + newmax;
a0d0e21e
LW
117}
118
119void
864dbfa3 120Perl_savestack_grow(pTHX)
79072805 121{
97aff369 122 dVAR;
8aacddc1 123 PL_savestack_max = GROW(PL_savestack_max) + 4;
3280af22 124 Renew(PL_savestack, PL_savestack_max, ANY);
79072805
LW
125}
126
4b3c1a47
AE
127void
128Perl_savestack_grow_cnt(pTHX_ I32 need)
129{
97aff369 130 dVAR;
4b3c1a47
AE
131 PL_savestack_max = PL_savestack_ix + need;
132 Renew(PL_savestack, PL_savestack_max, ANY);
133}
134
2ce36478
SM
135#undef GROW
136
79072805 137void
864dbfa3 138Perl_tmps_grow(pTHX_ I32 n)
677b06e3 139{
97aff369 140 dVAR;
677b06e3
GS
141#ifndef STRESS_REALLOC
142 if (n < 128)
143 n = (PL_tmps_max < 512) ? 128 : 512;
144#endif
145 PL_tmps_max = PL_tmps_ix + n + 1;
146 Renew(PL_tmps_stack, PL_tmps_max, SV*);
147}
148
149
150void
864dbfa3 151Perl_free_tmps(pTHX)
79072805 152{
97aff369 153 dVAR;
79072805 154 /* XXX should tmps_floor live in cxstack? */
35a4481c 155 const I32 myfloor = PL_tmps_floor;
3280af22 156 while (PL_tmps_ix > myfloor) { /* clean up after last statement */
901017d6 157 SV* const sv = PL_tmps_stack[PL_tmps_ix];
a0714e2c 158 PL_tmps_stack[PL_tmps_ix--] = NULL;
8aacddc1 159 if (sv && sv != &PL_sv_undef) {
463ee0b2 160 SvTEMP_off(sv);
8990e307 161 SvREFCNT_dec(sv); /* note, can modify tmps_ix!!! */
463ee0b2 162 }
79072805
LW
163 }
164}
165
76e3520e 166STATIC SV *
af7df257 167S_save_scalar_at(pTHX_ SV **sptr, const U32 flags)
79072805 168{
97aff369 169 dVAR;
901017d6 170 SV * const osv = *sptr;
561b68a9 171 register SV * const sv = *sptr = newSV(0);
79072805 172
7918f24d
NC
173 PERL_ARGS_ASSERT_SAVE_SCALAR_AT;
174
a0d0e21e 175 if (SvTYPE(osv) >= SVt_PVMG && SvMAGIC(osv) && SvTYPE(osv) != SVt_PVGV) {
a0d0e21e 176 if (SvGMAGICAL(osv)) {
35a4481c 177 const bool oldtainted = PL_tainted;
a0d0e21e 178 SvFLAGS(osv) |= (SvFLAGS(osv) &
c268c2a6 179 (SVp_IOK|SVp_NOK|SVp_POK)) >> PRIVSHIFT;
3280af22 180 PL_tainted = oldtainted;
a0d0e21e 181 }
af7df257 182 mg_localize(osv, sv, (flags & SAVEf_SETMAGIC) != 0);
79072805
LW
183 }
184 return sv;
185}
186
e22024d3
NC
187static void
188S_save_pushptrptr(pTHX_ void *const ptr1, void *const ptr2, const int type)
189{
190 dVAR;
191 SSCHECK(3);
192 SSPUSHPTR(ptr1);
193 SSPUSHPTR(ptr2);
194 SSPUSHINT(type);
195}
196
7a4c00b4 197SV *
864dbfa3 198Perl_save_scalar(pTHX_ GV *gv)
7a4c00b4 199{
97aff369 200 dVAR;
fb4fc1fa 201 SV ** const sptr = &GvSVn(gv);
7918f24d
NC
202
203 PERL_ARGS_ASSERT_SAVE_SCALAR;
204
27cc343c 205 PL_localizing = 1;
0cbee0a4 206 SvGETMAGIC(*sptr);
27cc343c 207 PL_localizing = 0;
e22024d3 208 save_pushptrptr(SvREFCNT_inc_simple(gv), SvREFCNT_inc(*sptr), SAVEt_SV);
af7df257 209 return save_scalar_at(sptr, SAVEf_SETMAGIC); /* XXX - FIXME - see #60360 */
7a4c00b4
PP
210}
211
f4dd75d9 212/* Like save_sptr(), but also SvREFCNT_dec()s the new value. Can be used to
b9d12d37
GS
213 * restore a global SV to its prior contents, freeing new value. */
214void
864dbfa3 215Perl_save_generic_svref(pTHX_ SV **sptr)
b9d12d37 216{
97aff369 217 dVAR;
7918f24d
NC
218
219 PERL_ARGS_ASSERT_SAVE_GENERIC_SVREF;
220
e22024d3 221 save_pushptrptr(sptr, SvREFCNT_inc(*sptr), SAVEt_GENERIC_SVREF);
b9d12d37
GS
222}
223
f4dd75d9
GS
224/* Like save_pptr(), but also Safefree()s the new value if it is different
225 * from the old one. Can be used to restore a global char* to its prior
226 * contents, freeing new value. */
227void
228Perl_save_generic_pvref(pTHX_ char **str)
229{
97aff369 230 dVAR;
7918f24d
NC
231
232 PERL_ARGS_ASSERT_SAVE_GENERIC_PVREF;
233
e22024d3 234 save_pushptrptr(*str, str, SAVEt_GENERIC_PVREF);
f4dd75d9
GS
235}
236
05ec9bb3
NIS
237/* Like save_generic_pvref(), but uses PerlMemShared_free() rather than Safefree().
238 * Can be used to restore a shared global char* to its prior
239 * contents, freeing new value. */
240void
241Perl_save_shared_pvref(pTHX_ char **str)
242{
97aff369 243 dVAR;
7918f24d
NC
244
245 PERL_ARGS_ASSERT_SAVE_SHARED_PVREF;
246
e22024d3 247 save_pushptrptr(str, *str, SAVEt_SHARED_PVREF);
05ec9bb3
NIS
248}
249
14f338dc
DM
250/* set the SvFLAGS specified by mask to the values in val */
251
252void
253Perl_save_set_svflags(pTHX_ SV* sv, U32 mask, U32 val)
254{
97aff369 255 dVAR;
7918f24d
NC
256
257 PERL_ARGS_ASSERT_SAVE_SET_SVFLAGS;
258
14f338dc
DM
259 SSCHECK(4);
260 SSPUSHPTR(sv);
261 SSPUSHINT(mask);
262 SSPUSHINT(val);
263 SSPUSHINT(SAVEt_SET_SVFLAGS);
264}
265
79072805 266void
864dbfa3 267Perl_save_gp(pTHX_ GV *gv, I32 empty)
79072805 268{
97aff369 269 dVAR;
7918f24d
NC
270
271 PERL_ARGS_ASSERT_SAVE_GP;
272
e22024d3 273 save_pushptrptr(SvREFCNT_inc(gv), GvGP(gv), SAVEt_GP);
79072805 274
5f05dabc 275 if (empty) {
12816592 276 GP *gp = Perl_newGP(aTHX_ gv);
146174a9 277
fae75791 278 if (GvCVu(gv))
e1a479c5 279 mro_method_changed_in(GvSTASH(gv)); /* taking a method out of circulation ("local")*/
146174a9
CB
280 if (GvIOp(gv) && (IoFLAGS(GvIOp(gv)) & IOf_ARGV)) {
281 gp->gp_io = newIO();
282 IoFLAGS(gp->gp_io) |= IOf_ARGV|IOf_START;
283 }
72651472
NC
284#ifdef PERL_DONT_CREATE_GVSV
285 if (gv == PL_errgv) {
286 /* We could scatter this logic everywhere by changing the
287 definition of ERRSV from GvSV() to GvSVn(), but it seems more
288 efficient to do this check once here. */
289 gp->gp_sv = newSV(0);
290 }
291#endif
12816592 292 GvGP(gv) = gp;
5f05dabc
PP
293 }
294 else {
44a8e56a 295 gp_ref(GvGP(gv));
5f05dabc
PP
296 GvINTRO_on(gv);
297 }
79072805 298}
79072805 299
79072805 300AV *
864dbfa3 301Perl_save_ary(pTHX_ GV *gv)
79072805 302{
97aff369 303 dVAR;
901017d6 304 AV * const oav = GvAVn(gv);
67a38de0 305 AV *av;
fb73857a 306
7918f24d
NC
307 PERL_ARGS_ASSERT_SAVE_ARY;
308
67a38de0
NIS
309 if (!AvREAL(oav) && AvREIFY(oav))
310 av_reify(oav);
e22024d3 311 save_pushptrptr(gv, oav, SAVEt_AV);
79072805 312
4608196e 313 GvAV(gv) = NULL;
fb73857a 314 av = GvAVn(gv);
0cbee0a4 315 if (SvMAGIC(oav))
9711599e 316 mg_localize(MUTABLE_SV(oav), MUTABLE_SV(av), TRUE);
fb73857a 317 return av;
79072805
LW
318}
319
320HV *
864dbfa3 321Perl_save_hash(pTHX_ GV *gv)
79072805 322{
97aff369 323 dVAR;
fb73857a
PP
324 HV *ohv, *hv;
325
7918f24d
NC
326 PERL_ARGS_ASSERT_SAVE_HASH;
327
e22024d3 328 save_pushptrptr(gv, (ohv = GvHVn(gv)), SAVEt_HV);
79072805 329
4608196e 330 GvHV(gv) = NULL;
fb73857a 331 hv = GvHVn(gv);
0cbee0a4 332 if (SvMAGIC(ohv))
9711599e 333 mg_localize(MUTABLE_SV(ohv), MUTABLE_SV(hv), TRUE);
fb73857a 334 return hv;
79072805
LW
335}
336
337void
864dbfa3 338Perl_save_item(pTHX_ register SV *item)
79072805 339{
97aff369 340 dVAR;
901017d6 341 register SV * const sv = newSVsv(item);
79072805 342
7918f24d
NC
343 PERL_ARGS_ASSERT_SAVE_ITEM;
344
e22024d3
NC
345 save_pushptrptr(item, /* remember the pointer */
346 sv, /* remember the value */
347 SAVEt_ITEM);
79072805
LW
348}
349
350void
864dbfa3 351Perl_save_int(pTHX_ int *intp)
79072805 352{
97aff369 353 dVAR;
7918f24d
NC
354
355 PERL_ARGS_ASSERT_SAVE_INT;
356
79072805
LW
357 SSCHECK(3);
358 SSPUSHINT(*intp);
359 SSPUSHPTR(intp);
360 SSPUSHINT(SAVEt_INT);
361}
362
363void
9febdf04
RH
364Perl_save_bool(pTHX_ bool *boolp)
365{
97aff369 366 dVAR;
7918f24d
NC
367
368 PERL_ARGS_ASSERT_SAVE_BOOL;
369
9febdf04
RH
370 SSCHECK(3);
371 SSPUSHBOOL(*boolp);
372 SSPUSHPTR(boolp);
373 SSPUSHINT(SAVEt_BOOL);
374}
375
376void
58188858
RGS
377Perl_save_I8(pTHX_ I8 *bytep)
378{
379 dVAR;
7918f24d
NC
380
381 PERL_ARGS_ASSERT_SAVE_I8;
382
58188858
RGS
383 SSCHECK(3);
384 SSPUSHINT(*bytep);
385 SSPUSHPTR(bytep);
386 SSPUSHINT(SAVEt_I8);
387}
388
389void
87a84751
JH
390Perl_save_I16(pTHX_ I16 *intp)
391{
392 dVAR;
7918f24d
NC
393
394 PERL_ARGS_ASSERT_SAVE_I16;
395
87a84751
JH
396 SSCHECK(3);
397 SSPUSHINT(*intp);
398 SSPUSHPTR(intp);
399 SSPUSHINT(SAVEt_I16);
400}
401
402void
864dbfa3 403Perl_save_I32(pTHX_ I32 *intp)
79072805 404{
97aff369 405 dVAR;
7918f24d
NC
406
407 PERL_ARGS_ASSERT_SAVE_I32;
408
79072805
LW
409 SSCHECK(3);
410 SSPUSHINT(*intp);
411 SSPUSHPTR(intp);
412 SSPUSHINT(SAVEt_I32);
413}
414
85e6fe83
LW
415/* Cannot use save_sptr() to store a char* since the SV** cast will
416 * force word-alignment and we'll miss the pointer.
417 */
418void
864dbfa3 419Perl_save_pptr(pTHX_ char **pptr)
85e6fe83 420{
97aff369 421 dVAR;
7918f24d
NC
422
423 PERL_ARGS_ASSERT_SAVE_PPTR;
424
e22024d3 425 save_pushptrptr(*pptr, pptr, SAVEt_PPTR);
85e6fe83
LW
426}
427
79072805 428void
146174a9
CB
429Perl_save_vptr(pTHX_ void *ptr)
430{
97aff369 431 dVAR;
7918f24d
NC
432
433 PERL_ARGS_ASSERT_SAVE_VPTR;
434
e22024d3 435 save_pushptrptr(*(char**)ptr, ptr, SAVEt_VPTR);
146174a9
CB
436}
437
438void
864dbfa3 439Perl_save_sptr(pTHX_ SV **sptr)
79072805 440{
97aff369 441 dVAR;
7918f24d
NC
442
443 PERL_ARGS_ASSERT_SAVE_SPTR;
444
e22024d3 445 save_pushptrptr(*sptr, sptr, SAVEt_SPTR);
79072805
LW
446}
447
c3564e5c 448void
09edbca0 449Perl_save_padsv_and_mortalize(pTHX_ PADOFFSET off)
c3564e5c 450{
97aff369 451 dVAR;
c3564e5c 452 SSCHECK(4);
f3548bdc 453 ASSERT_CURPAD_ACTIVE("save_padsv");
09edbca0 454 SSPUSHPTR(SvREFCNT_inc_simple_NN(PL_curpad[off]));
f3548bdc 455 SSPUSHPTR(PL_comppad);
c3564e5c 456 SSPUSHLONG((long)off);
09edbca0 457 SSPUSHINT(SAVEt_PADSV_AND_MORTALIZE);
c3564e5c
GS
458}
459
79072805 460void
864dbfa3 461Perl_save_hptr(pTHX_ HV **hptr)
79072805 462{
97aff369 463 dVAR;
7918f24d
NC
464
465 PERL_ARGS_ASSERT_SAVE_HPTR;
466
e22024d3 467 save_pushptrptr(*hptr, hptr, SAVEt_HPTR);
79072805
LW
468}
469
470void
864dbfa3 471Perl_save_aptr(pTHX_ AV **aptr)
79072805 472{
97aff369 473 dVAR;
7918f24d
NC
474
475 PERL_ARGS_ASSERT_SAVE_APTR;
476
e22024d3 477 save_pushptrptr(*aptr, aptr, SAVEt_APTR);
79072805
LW
478}
479
480void
2fd8beea 481Perl_save_pushptr(pTHX_ void *const ptr, const int type)
8990e307 482{
97aff369 483 dVAR;
8990e307 484 SSCHECK(2);
2fd8beea
NC
485 SSPUSHPTR(ptr);
486 SSPUSHINT(type);
8990e307
LW
487}
488
489void
864dbfa3 490Perl_save_clearsv(pTHX_ SV **svp)
8990e307 491{
97aff369 492 dVAR;
7918f24d
NC
493
494 PERL_ARGS_ASSERT_SAVE_CLEARSV;
495
f3548bdc 496 ASSERT_CURPAD_ACTIVE("save_clearsv");
8990e307 497 SSCHECK(2);
3280af22 498 SSPUSHLONG((long)(svp-PL_curpad));
8990e307 499 SSPUSHINT(SAVEt_CLEARSV);
d9d18af6 500 SvPADSTALE_off(*svp); /* mark lexical as active */
8990e307
LW
501}
502
503void
864dbfa3 504Perl_save_delete(pTHX_ HV *hv, char *key, I32 klen)
8990e307 505{
97aff369 506 dVAR;
7918f24d
NC
507
508 PERL_ARGS_ASSERT_SAVE_DELETE;
509
8990e307
LW
510 SSCHECK(4);
511 SSPUSHINT(klen);
512 SSPUSHPTR(key);
b37c2d43 513 SSPUSHPTR(SvREFCNT_inc_simple(hv));
8990e307
LW
514 SSPUSHINT(SAVEt_DELETE);
515}
516
517void
12ab1f58
JH
518Perl_save_destructor(pTHX_ DESTRUCTORFUNC_NOCONTEXT_t f, void* p)
519{
520 dVAR;
7918f24d
NC
521
522 PERL_ARGS_ASSERT_SAVE_DESTRUCTOR;
523
12ab1f58
JH
524 SSCHECK(3);
525 SSPUSHDPTR(f);
526 SSPUSHPTR(p);
527 SSPUSHINT(SAVEt_DESTRUCTOR);
528}
529
530void
146174a9
CB
531Perl_save_destructor_x(pTHX_ DESTRUCTORFUNC_t f, void* p)
532{
97aff369 533 dVAR;
146174a9
CB
534 SSCHECK(3);
535 SSPUSHDXPTR(f);
536 SSPUSHPTR(p);
537 SSPUSHINT(SAVEt_DESTRUCTOR_X);
538}
539
540void
59413342 541Perl_save_aelem(pTHX_ AV *av, I32 idx, SV **sptr)
4e4c362e 542{
97aff369 543 dVAR;
bfc4de9f 544 SV *sv;
7918f24d
NC
545
546 PERL_ARGS_ASSERT_SAVE_AELEM;
547
0cbee0a4 548 SvGETMAGIC(*sptr);
4e4c362e 549 SSCHECK(4);
b37c2d43 550 SSPUSHPTR(SvREFCNT_inc_simple(av));
4e4c362e
GS
551 SSPUSHINT(idx);
552 SSPUSHPTR(SvREFCNT_inc(*sptr));
553 SSPUSHINT(SAVEt_AELEM);
5dd42e15
DM
554 /* if it gets reified later, the restore will have the wrong refcnt */
555 if (!AvREAL(av) && AvREIFY(av))
b37c2d43 556 SvREFCNT_inc_void(*sptr);
af7df257 557 save_scalar_at(sptr, SAVEf_SETMAGIC); /* XXX - FIXME - see #60360 */
bfc4de9f
DM
558 sv = *sptr;
559 /* If we're localizing a tied array element, this new sv
560 * won't actually be stored in the array - so it won't get
561 * reaped when the localize ends. Ensure it gets reaped by
562 * mortifying it instead. DAPM */
563 if (SvTIED_mg(sv, PERL_MAGIC_tiedelem))
564 sv_2mortal(sv);
4e4c362e
GS
565}
566
567void
af7df257 568Perl_save_helem_flags(pTHX_ HV *hv, SV *key, SV **sptr, const U32 flags)
4e4c362e 569{
97aff369 570 dVAR;
bfc4de9f 571 SV *sv;
7918f24d 572
af7df257 573 PERL_ARGS_ASSERT_SAVE_HELEM_FLAGS;
7918f24d 574
0cbee0a4 575 SvGETMAGIC(*sptr);
4e4c362e 576 SSCHECK(4);
b37c2d43 577 SSPUSHPTR(SvREFCNT_inc_simple(hv));
b2096149 578 SSPUSHPTR(newSVsv(key));
4e4c362e
GS
579 SSPUSHPTR(SvREFCNT_inc(*sptr));
580 SSPUSHINT(SAVEt_HELEM);
af7df257 581 save_scalar_at(sptr, flags);
bfc4de9f
DM
582 sv = *sptr;
583 /* If we're localizing a tied hash element, this new sv
584 * won't actually be stored in the hash - so it won't get
585 * reaped when the localize ends. Ensure it gets reaped by
586 * mortifying it instead. DAPM */
587 if (SvTIED_mg(sv, PERL_MAGIC_tiedelem))
588 sv_2mortal(sv);
4e4c362e
GS
589}
590
2053acbf
NC
591SV*
592Perl_save_svref(pTHX_ SV **sptr)
593{
594 dVAR;
7918f24d
NC
595
596 PERL_ARGS_ASSERT_SAVE_SVREF;
597
2053acbf 598 SvGETMAGIC(*sptr);
e22024d3 599 save_pushptrptr(sptr, SvREFCNT_inc(*sptr), SAVEt_SVREF);
af7df257 600 return save_scalar_at(sptr, SAVEf_SETMAGIC); /* XXX - FIXME - see #60360 */
2053acbf
NC
601}
602
455ece5e 603I32
864dbfa3 604Perl_save_alloc(pTHX_ I32 size, I32 pad)
455ece5e 605{
97aff369 606 dVAR;
35a4481c 607 register const I32 start = pad + ((char*)&PL_savestack[PL_savestack_ix]
8aacddc1 608 - (char*)PL_savestack);
35a4481c 609 register const I32 elems = 1 + ((size + pad - 1) / sizeof(*PL_savestack));
455ece5e 610
1bb4c835 611 SSGROW(elems + 2);
455ece5e
AD
612
613 PL_savestack_ix += elems;
614 SSPUSHINT(elems);
615 SSPUSHINT(SAVEt_ALLOC);
616 return start;
617}
618
462e5cf6 619void
864dbfa3 620Perl_leave_scope(pTHX_ I32 base)
79072805 621{
97aff369 622 dVAR;
79072805
LW
623 register SV *sv;
624 register SV *value;
625 register GV *gv;
626 register AV *av;
627 register HV *hv;
20454177 628 void* ptr;
f4dd75d9 629 register char* str;
161b7d16 630 I32 i;
79072805
LW
631
632 if (base < -1)
cea2e8a9 633 Perl_croak(aTHX_ "panic: corrupt saved stack index");
3280af22 634 while (PL_savestack_ix > base) {
c6ae7647
NC
635 TAINT_NOT;
636
79072805
LW
637 switch (SSPOPINT) {
638 case SAVEt_ITEM: /* normal string */
ad64d0ec
NC
639 value = MUTABLE_SV(SSPOPPTR);
640 sv = MUTABLE_SV(SSPOPPTR);
79072805 641 sv_replace(sv,value);
3280af22 642 PL_localizing = 2;
79072805 643 SvSETMAGIC(sv);
3280af22 644 PL_localizing = 0;
79072805 645 break;
8aacddc1 646 case SAVEt_SV: /* scalar reference */
ad64d0ec 647 value = MUTABLE_SV(SSPOPPTR);
159b6efe 648 gv = MUTABLE_GV(SSPOPPTR);
7a4c00b4 649 ptr = &GvSV(gv);
502c6561 650 av = MUTABLE_AV(gv); /* what to refcnt_dec */
2053acbf
NC
651 restore_sv:
652 sv = *(SV**)ptr;
2053acbf
NC
653 *(SV**)ptr = value;
654 SvREFCNT_dec(sv);
655 PL_localizing = 2;
656 SvSETMAGIC(value);
657 PL_localizing = 0;
658 SvREFCNT_dec(value);
659 if (av) /* actually an av, hv or gv */
660 SvREFCNT_dec(av);
661 break;
8aacddc1 662 case SAVEt_GENERIC_PVREF: /* generic pv */
f4dd75d9 663 ptr = SSPOPPTR;
b03d03b0 664 str = (char*)SSPOPPTR;
f4dd75d9
GS
665 if (*(char**)ptr != str) {
666 Safefree(*(char**)ptr);
667 *(char**)ptr = str;
668 }
669 break;
05ec9bb3
NIS
670 case SAVEt_SHARED_PVREF: /* shared pv */
671 str = (char*)SSPOPPTR;
672 ptr = SSPOPPTR;
673 if (*(char**)ptr != str) {
5e54c26f 674#ifdef NETWARE
9ecbcc42 675 PerlMem_free(*(char**)ptr);
5e54c26f 676#else
05ec9bb3 677 PerlMemShared_free(*(char**)ptr);
5e54c26f 678#endif
05ec9bb3
NIS
679 *(char**)ptr = str;
680 }
681 break;
8aacddc1 682 case SAVEt_GENERIC_SVREF: /* generic sv */
ad64d0ec 683 value = MUTABLE_SV(SSPOPPTR);
b9d12d37 684 ptr = SSPOPPTR;
f4dd75d9
GS
685 sv = *(SV**)ptr;
686 *(SV**)ptr = value;
687 SvREFCNT_dec(sv);
b9d12d37
GS
688 SvREFCNT_dec(value);
689 break;
8aacddc1 690 case SAVEt_AV: /* array reference */
502c6561 691 av = MUTABLE_AV(SSPOPPTR);
159b6efe 692 gv = MUTABLE_GV(SSPOPPTR);
fb73857a 693 if (GvAV(gv)) {
c4a7531d 694 SvREFCNT_dec(GvAV(gv));
fb73857a 695 }
8aacddc1 696 GvAV(gv) = av;
fb73857a 697 if (SvMAGICAL(av)) {
3280af22 698 PL_localizing = 2;
ad64d0ec 699 SvSETMAGIC(MUTABLE_SV(av));
3280af22 700 PL_localizing = 0;
fb73857a 701 }
8aacddc1
NIS
702 break;
703 case SAVEt_HV: /* hash reference */
85fbaab2 704 hv = MUTABLE_HV(SSPOPPTR);
159b6efe 705 gv = MUTABLE_GV(SSPOPPTR);
fb73857a 706 if (GvHV(gv)) {
c4a7531d 707 SvREFCNT_dec(GvHV(gv));
fb73857a 708 }
8aacddc1 709 GvHV(gv) = hv;
fb73857a 710 if (SvMAGICAL(hv)) {
3280af22 711 PL_localizing = 2;
ad64d0ec 712 SvSETMAGIC(MUTABLE_SV(hv));
3280af22 713 PL_localizing = 0;
fb73857a 714 }
8aacddc1 715 break;
79072805
LW
716 case SAVEt_INT: /* int reference */
717 ptr = SSPOPPTR;
718 *(int*)ptr = (int)SSPOPINT;
719 break;
9febdf04
RH
720 case SAVEt_BOOL: /* bool reference */
721 ptr = SSPOPPTR;
722 *(bool*)ptr = (bool)SSPOPBOOL;
723 break;
79072805
LW
724 case SAVEt_I32: /* I32 reference */
725 ptr = SSPOPPTR;
3235b7a3
NC
726#ifdef PERL_DEBUG_READONLY_OPS
727 {
728 const I32 val = SSPOPINT;
729 if (*(I32*)ptr != val)
730 *(I32*)ptr = val;
731 }
732#else
79072805 733 *(I32*)ptr = (I32)SSPOPINT;
3235b7a3 734#endif
79072805
LW
735 break;
736 case SAVEt_SPTR: /* SV* reference */
737 ptr = SSPOPPTR;
ad64d0ec 738 *(SV**)ptr = MUTABLE_SV(SSPOPPTR);
79072805 739 break;
146174a9 740 case SAVEt_VPTR: /* random* reference */
85e6fe83
LW
741 case SAVEt_PPTR: /* char* reference */
742 ptr = SSPOPPTR;
743 *(char**)ptr = (char*)SSPOPPTR;
744 break;
79072805
LW
745 case SAVEt_HPTR: /* HV* reference */
746 ptr = SSPOPPTR;
85fbaab2 747 *(HV**)ptr = MUTABLE_HV(SSPOPPTR);
79072805
LW
748 break;
749 case SAVEt_APTR: /* AV* reference */
750 ptr = SSPOPPTR;
502c6561 751 *(AV**)ptr = MUTABLE_AV(SSPOPPTR);
79072805 752 break;
fb73857a 753 case SAVEt_GP: /* scalar reference */
79072805 754 ptr = SSPOPPTR;
159b6efe 755 gv = MUTABLE_GV(SSPOPPTR);
8aacddc1
NIS
756 gp_free(gv);
757 GvGP(gv) = (GP*)ptr;
dd69841b
BB
758 /* putting a method back into circulation ("local")*/
759 if (GvCVu(gv) && (hv=GvSTASH(gv)) && HvNAME_get(hv))
760 mro_method_changed_in(hv);
4633a7c4 761 SvREFCNT_dec(gv);
8aacddc1 762 break;
8990e307
LW
763 case SAVEt_FREESV:
764 ptr = SSPOPPTR;
ad64d0ec 765 SvREFCNT_dec(MUTABLE_SV(ptr));
8990e307 766 break;
26d9b02f
JH
767 case SAVEt_MORTALIZESV:
768 ptr = SSPOPPTR;
ad64d0ec 769 sv_2mortal(MUTABLE_SV(ptr));
26d9b02f 770 break;
8990e307
LW
771 case SAVEt_FREEOP:
772 ptr = SSPOPPTR;
f3548bdc 773 ASSERT_CURPAD_LEGAL("SAVEt_FREEOP"); /* XXX DAPM tmp */
8990e307
LW
774 op_free((OP*)ptr);
775 break;
776 case SAVEt_FREEPV:
777 ptr = SSPOPPTR;
1df70142 778 Safefree(ptr);
8990e307
LW
779 break;
780 case SAVEt_CLEARSV:
3280af22 781 ptr = (void*)&PL_curpad[SSPOPLONG];
8990e307 782 sv = *(SV**)ptr;
dd2155a4
DM
783
784 DEBUG_Xv(PerlIO_printf(Perl_debug_log,
f3548bdc
DM
785 "Pad 0x%"UVxf"[0x%"UVxf"] clearsv: %ld sv=0x%"UVxf"<%"IVdf"> %s\n",
786 PTR2UV(PL_comppad), PTR2UV(PL_curpad),
787 (long)((SV **)ptr-PL_curpad), PTR2UV(sv), (IV)SvREFCNT(sv),
dd2155a4
DM
788 (SvREFCNT(sv) <= 1 && !SvOBJECT(sv)) ? "clear" : "abandon"
789 ));
790
bc44cdaf
GS
791 /* Can clear pad variable in place? */
792 if (SvREFCNT(sv) <= 1 && !SvOBJECT(sv)) {
8aacddc1
NIS
793 /*
794 * if a my variable that was made readonly is going out of
795 * scope, we want to remove the readonlyness so that it can
796 * go out of scope quietly
8aacddc1 797 */
a26e96df 798 if (SvPADMY(sv) && !SvFAKE(sv))
8aacddc1
NIS
799 SvREADONLY_off(sv);
800
6fc92669 801 if (SvTHINKFIRST(sv))
840a7b70 802 sv_force_normal_flags(sv, SV_IMMEDIATE_UNREF);
a0d0e21e
LW
803 if (SvMAGICAL(sv))
804 mg_free(sv);
8990e307
LW
805
806 switch (SvTYPE(sv)) {
807 case SVt_NULL:
808 break;
809 case SVt_PVAV:
502c6561 810 av_clear(MUTABLE_AV(sv));
8990e307
LW
811 break;
812 case SVt_PVHV:
85fbaab2 813 hv_clear(MUTABLE_HV(sv));
8990e307
LW
814 break;
815 case SVt_PVCV:
cea2e8a9 816 Perl_croak(aTHX_ "panic: leave_scope pad code");
8990e307 817 default:
0c34ef67 818 SvOK_off(sv);
8990e307
LW
819 break;
820 }
d9d18af6 821 SvPADSTALE_on(sv); /* mark as no longer live */
8990e307
LW
822 }
823 else { /* Someone has a claim on this, so abandon it. */
35a4481c 824 const U32 padflags = SvFLAGS(sv) & (SVs_PADMY|SVs_PADTMP);
8990e307 825 switch (SvTYPE(sv)) { /* Console ourselves with a new value */
ad64d0ec
NC
826 case SVt_PVAV: *(SV**)ptr = MUTABLE_SV(newAV()); break;
827 case SVt_PVHV: *(SV**)ptr = MUTABLE_SV(newHV()); break;
561b68a9 828 default: *(SV**)ptr = newSV(0); break;
8990e307 829 }
53868620 830 SvREFCNT_dec(sv); /* Cast current value to the winds. */
d9d18af6
DM
831 /* preserve pad nature, but also mark as not live
832 * for any closure capturing */
2740392c 833 SvFLAGS(*(SV**)ptr) |= padflags | SVs_PADSTALE;
8990e307
LW
834 }
835 break;
836 case SAVEt_DELETE:
837 ptr = SSPOPPTR;
85fbaab2 838 hv = MUTABLE_HV(ptr);
8990e307 839 ptr = SSPOPPTR;
7d654f43 840 (void)hv_delete(hv, (char*)ptr, (I32)SSPOPINT, G_DISCARD);
4e4c362e 841 SvREFCNT_dec(hv);
8aacddc1 842 Safefree(ptr);
8990e307 843 break;
146174a9
CB
844 case SAVEt_DESTRUCTOR_X:
845 ptr = SSPOPPTR;
acfe0abc 846 (*SSPOPDXPTR)(aTHX_ ptr);
a0d0e21e
LW
847 break;
848 case SAVEt_REGCONTEXT:
455ece5e 849 case SAVEt_ALLOC:
161b7d16 850 i = SSPOPINT;
3280af22 851 PL_savestack_ix -= i; /* regexp must have croaked */
a0d0e21e 852 break;
55497cff 853 case SAVEt_STACK_POS: /* Position on Perl stack */
161b7d16 854 i = SSPOPINT;
3280af22 855 PL_stack_sp = PL_stack_base + i;
55497cff 856 break;
ea8d6ae1
DB
857 case SAVEt_STACK_CXPOS: /* blk_oldsp on context stack */
858 i = SSPOPINT;
859 cxstack[i].blk_oldsp = SSPOPINT;
860 break;
161b7d16 861 case SAVEt_AELEM: /* array element */
ad64d0ec 862 value = MUTABLE_SV(SSPOPPTR);
161b7d16 863 i = SSPOPINT;
502c6561 864 av = MUTABLE_AV(SSPOPPTR);
658aef79 865 ptr = av_fetch(av,i,1);
5dd42e15
DM
866 if (!AvREAL(av) && AvREIFY(av)) /* undo reify guard */
867 SvREFCNT_dec(value);
4e4c362e
GS
868 if (ptr) {
869 sv = *(SV**)ptr;
3280af22 870 if (sv && sv != &PL_sv_undef) {
ad64d0ec 871 if (SvTIED_mg((const SV *)av, PERL_MAGIC_tied))
b37c2d43 872 SvREFCNT_inc_void_NN(sv);
4e4c362e
GS
873 goto restore_sv;
874 }
875 }
876 SvREFCNT_dec(av);
877 SvREFCNT_dec(value);
878 break;
161b7d16 879 case SAVEt_HELEM: /* hash element */
ad64d0ec
NC
880 value = MUTABLE_SV(SSPOPPTR);
881 sv = MUTABLE_SV(SSPOPPTR);
85fbaab2 882 hv = MUTABLE_HV(SSPOPPTR);
161b7d16 883 ptr = hv_fetch_ent(hv, sv, 1, 0);
4e4c362e 884 if (ptr) {
35a4481c 885 const SV * const oval = HeVAL((HE*)ptr);
3280af22 886 if (oval && oval != &PL_sv_undef) {
4e4c362e 887 ptr = &HeVAL((HE*)ptr);
ad64d0ec 888 if (SvTIED_mg((const SV *)hv, PERL_MAGIC_tied))
b37c2d43 889 SvREFCNT_inc_void(*(SV**)ptr);
4e4c362e 890 SvREFCNT_dec(sv);
502c6561 891 av = MUTABLE_AV(hv); /* what to refcnt_dec */
4e4c362e
GS
892 goto restore_sv;
893 }
894 }
895 SvREFCNT_dec(hv);
896 SvREFCNT_dec(sv);
897 SvREFCNT_dec(value);
898 break;
462e5cf6 899 case SAVEt_OP:
533c011a 900 PL_op = (OP*)SSPOPPTR;
462e5cf6 901 break;
25eaa213 902 case SAVEt_HINTS:
045ac317 903 if ((PL_hints & HINT_LOCALIZE_HH) && GvHV(PL_hintgv)) {
ad64d0ec 904 SvREFCNT_dec(MUTABLE_SV(GvHV(PL_hintgv)));
045ac317
RGS
905 GvHV(PL_hintgv) = NULL;
906 }
3280af22 907 *(I32*)&PL_hints = (I32)SSPOPINT;
c28fe1ec
NC
908 Perl_refcounted_he_free(aTHX_ PL_compiling.cop_hints_hash);
909 PL_compiling.cop_hints_hash = (struct refcounted_he *) SSPOPPTR;
dfa41748 910 if (PL_hints & HINT_LOCALIZE_HH) {
ad64d0ec 911 SvREFCNT_dec(MUTABLE_SV(GvHV(PL_hintgv)));
85fbaab2 912 GvHV(PL_hintgv) = MUTABLE_HV(SSPOPPTR);
5b9c0671
NC
913 assert(GvHV(PL_hintgv));
914 } else if (!GvHV(PL_hintgv)) {
915 /* Need to add a new one manually, else gv_fetchpv() can
916 add one in this code:
917
918 if (SvTYPE(gv) == SVt_PVGV) {
919 if (add) {
920 GvMULTI_on(gv);
921 gv_init_sv(gv, sv_type);
922 if (*name=='!' && sv_type == SVt_PVHV && len==1)
923 require_errno(gv);
924 }
925 return gv;
926 }
927
928 and it won't have the magic set. */
929
930 HV *const hv = newHV();
931 hv_magic(hv, NULL, PERL_MAGIC_hints);
932 GvHV(PL_hintgv) = hv;
dfa41748 933 }
5b9c0671 934 assert(GvHV(PL_hintgv));
b3ac6de7 935 break;
cb50131a 936 case SAVEt_COMPPAD:
f3548bdc 937 PL_comppad = (PAD*)SSPOPPTR;
58ed4fbe 938 if (PL_comppad)
cb50131a
CB
939 PL_curpad = AvARRAY(PL_comppad);
940 else
4608196e 941 PL_curpad = NULL;
cb50131a 942 break;
09edbca0 943 case SAVEt_PADSV_AND_MORTALIZE:
c3564e5c 944 {
35a4481c 945 const PADOFFSET off = (PADOFFSET)SSPOPLONG;
09edbca0 946 SV **svp;
c3564e5c 947 ptr = SSPOPPTR;
09edbca0
NC
948 assert (ptr);
949 svp = AvARRAY((PAD*)ptr) + off;
950 /* This mortalizing used to be done by POPLOOP() via itersave.
951 But as we have all the information here, we can do it here,
952 save even having to have itersave in the struct. */
953 sv_2mortal(*svp);
ad64d0ec 954 *svp = MUTABLE_SV(SSPOPPTR);
c3564e5c
GS
955 }
956 break;
8b7059b1
DM
957 case SAVEt_SAVESWITCHSTACK:
958 {
959 dSP;
502c6561
NC
960 AV *const t = MUTABLE_AV(SSPOPPTR);
961 AV *const f = MUTABLE_AV(SSPOPPTR);
8b7059b1
DM
962 SWITCHSTACK(t,f);
963 PL_curstackinfo->si_stack = f;
964 }
965 break;
14f338dc
DM
966 case SAVEt_SET_SVFLAGS:
967 {
35a4481c
AL
968 const U32 val = (U32)SSPOPINT;
969 const U32 mask = (U32)SSPOPINT;
ad64d0ec 970 sv = MUTABLE_SV(SSPOPPTR);
14f338dc
DM
971 SvFLAGS(sv) &= ~mask;
972 SvFLAGS(sv) |= val;
973 }
974 break;
95e06916
NC
975
976 /* This would be a mathom, but Perl_save_svref() calls a static
977 function, S_save_scalar_at(), so has to stay in this file. */
2053acbf 978 case SAVEt_SVREF: /* scalar reference */
ad64d0ec 979 value = MUTABLE_SV(SSPOPPTR);
2053acbf
NC
980 ptr = SSPOPPTR;
981 av = NULL; /* what to refcnt_dec */
982 goto restore_sv;
95e06916
NC
983
984 /* These are only saved in mathoms.c */
985 case SAVEt_NSTAB:
159b6efe 986 gv = MUTABLE_GV(SSPOPPTR);
ad64d0ec 987 (void)sv_clear(MUTABLE_SV(gv));
95e06916 988 break;
2053acbf
NC
989 case SAVEt_LONG: /* long reference */
990 ptr = SSPOPPTR;
991 *(long*)ptr = (long)SSPOPLONG;
992 break;
95e06916
NC
993 case SAVEt_IV: /* IV reference */
994 ptr = SSPOPPTR;
995 *(IV*)ptr = (IV)SSPOPIV;
996 break;
997
2053acbf
NC
998 case SAVEt_I16: /* I16 reference */
999 ptr = SSPOPPTR;
1000 *(I16*)ptr = (I16)SSPOPINT;
1001 break;
1002 case SAVEt_I8: /* I8 reference */
1003 ptr = SSPOPPTR;
1004 *(I8*)ptr = (I8)SSPOPINT;
1005 break;
2053acbf
NC
1006 case SAVEt_DESTRUCTOR:
1007 ptr = SSPOPPTR;
1008 (*SSPOPDPTR)(ptr);
1009 break;
fc15ae8f
NC
1010 case SAVEt_COP_ARYBASE:
1011 ptr = SSPOPPTR;
1012 i = SSPOPINT;
1013 CopARYBASE_set((COP *)ptr, i);
1014 break;
68da3b2f
NC
1015 case SAVEt_COMPILE_WARNINGS:
1016 ptr = SSPOPPTR;
72dc9ed5 1017
68da3b2f
NC
1018 if (!specialWARN(PL_compiling.cop_warnings))
1019 PerlMemShared_free(PL_compiling.cop_warnings);
72dc9ed5 1020
10edeb5d 1021 PL_compiling.cop_warnings = (STRLEN*)ptr;
72dc9ed5 1022 break;
1ade1aa1
NC
1023 case SAVEt_RE_STATE:
1024 {
1025 const struct re_save_state *const state
1026 = (struct re_save_state *)
1027 (PL_savestack + PL_savestack_ix
1028 - SAVESTACK_ALLOC_FOR_RE_SAVE_STATE);
1029 PL_savestack_ix -= SAVESTACK_ALLOC_FOR_RE_SAVE_STATE;
1030
1ade1aa1
NC
1031 if (PL_reg_start_tmp != state->re_state_reg_start_tmp) {
1032 Safefree(PL_reg_start_tmp);
1ade1aa1 1033 }
1ade1aa1
NC
1034 if (PL_reg_poscache != state->re_state_reg_poscache) {
1035 Safefree(PL_reg_poscache);
1ade1aa1 1036 }
46ab3289 1037 Copy(state, &PL_reg_state, 1, struct re_save_state);
1ade1aa1
NC
1038 }
1039 break;
7c197c94
DM
1040 case SAVEt_PARSER:
1041 ptr = SSPOPPTR;
1042 parser_free((yy_parser *) ptr);
1043 break;
79072805 1044 default:
cea2e8a9 1045 Perl_croak(aTHX_ "panic: leave_scope inconsistency");
79072805
LW
1046 }
1047 }
1048}
8990e307 1049
8990e307 1050void
864dbfa3 1051Perl_cx_dump(pTHX_ PERL_CONTEXT *cx)
8990e307 1052{
97aff369 1053 dVAR;
7918f24d
NC
1054
1055 PERL_ARGS_ASSERT_CX_DUMP;
1056
35ff7856 1057#ifdef DEBUGGING
22c35a8c 1058 PerlIO_printf(Perl_debug_log, "CX %ld = %s\n", (long)(cx - cxstack), PL_block_type[CxTYPE(cx)]);
6b35e009 1059 if (CxTYPE(cx) != CXt_SUBST) {
760ac839 1060 PerlIO_printf(Perl_debug_log, "BLK_OLDSP = %ld\n", (long)cx->blk_oldsp);
146174a9
CB
1061 PerlIO_printf(Perl_debug_log, "BLK_OLDCOP = 0x%"UVxf"\n",
1062 PTR2UV(cx->blk_oldcop));
760ac839
LW
1063 PerlIO_printf(Perl_debug_log, "BLK_OLDMARKSP = %ld\n", (long)cx->blk_oldmarksp);
1064 PerlIO_printf(Perl_debug_log, "BLK_OLDSCOPESP = %ld\n", (long)cx->blk_oldscopesp);
146174a9
CB
1065 PerlIO_printf(Perl_debug_log, "BLK_OLDPM = 0x%"UVxf"\n",
1066 PTR2UV(cx->blk_oldpm));
760ac839 1067 PerlIO_printf(Perl_debug_log, "BLK_GIMME = %s\n", cx->blk_gimme ? "LIST" : "SCALAR");
8990e307 1068 }
6b35e009 1069 switch (CxTYPE(cx)) {
8990e307
LW
1070 case CXt_NULL:
1071 case CXt_BLOCK:
1072 break;
146174a9 1073 case CXt_FORMAT:
f9c764c5
NC
1074 PerlIO_printf(Perl_debug_log, "BLK_FORMAT.CV = 0x%"UVxf"\n",
1075 PTR2UV(cx->blk_format.cv));
1076 PerlIO_printf(Perl_debug_log, "BLK_FORMAT.GV = 0x%"UVxf"\n",
1077 PTR2UV(cx->blk_format.gv));
1078 PerlIO_printf(Perl_debug_log, "BLK_FORMAT.DFOUTGV = 0x%"UVxf"\n",
1079 PTR2UV(cx->blk_format.dfoutgv));
1080 PerlIO_printf(Perl_debug_log, "BLK_FORMAT.HASARGS = %d\n",
bafb2adc 1081 (int)CxHASARGS(cx));
f9c764c5
NC
1082 PerlIO_printf(Perl_debug_log, "BLK_FORMAT.RETOP = 0x%"UVxf"\n",
1083 PTR2UV(cx->blk_format.retop));
146174a9 1084 break;
8990e307 1085 case CXt_SUB:
146174a9
CB
1086 PerlIO_printf(Perl_debug_log, "BLK_SUB.CV = 0x%"UVxf"\n",
1087 PTR2UV(cx->blk_sub.cv));
760ac839 1088 PerlIO_printf(Perl_debug_log, "BLK_SUB.OLDDEPTH = %ld\n",
8990e307 1089 (long)cx->blk_sub.olddepth);
760ac839 1090 PerlIO_printf(Perl_debug_log, "BLK_SUB.HASARGS = %d\n",
bafb2adc
NC
1091 (int)CxHASARGS(cx));
1092 PerlIO_printf(Perl_debug_log, "BLK_SUB.LVAL = %d\n", (int)CxLVAL(cx));
f39bc417
DM
1093 PerlIO_printf(Perl_debug_log, "BLK_SUB.RETOP = 0x%"UVxf"\n",
1094 PTR2UV(cx->blk_sub.retop));
8990e307
LW
1095 break;
1096 case CXt_EVAL:
760ac839 1097 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_IN_EVAL = %ld\n",
85a64632 1098 (long)CxOLD_IN_EVAL(cx));
760ac839 1099 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_OP_TYPE = %s (%s)\n",
85a64632
NC
1100 PL_op_name[CxOLD_OP_TYPE(cx)],
1101 PL_op_desc[CxOLD_OP_TYPE(cx)]);
0f79a09d
GS
1102 if (cx->blk_eval.old_namesv)
1103 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_NAME = %s\n",
aa07b2f6 1104 SvPVX_const(cx->blk_eval.old_namesv));
146174a9
CB
1105 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_EVAL_ROOT = 0x%"UVxf"\n",
1106 PTR2UV(cx->blk_eval.old_eval_root));
f39bc417
DM
1107 PerlIO_printf(Perl_debug_log, "BLK_EVAL.RETOP = 0x%"UVxf"\n",
1108 PTR2UV(cx->blk_eval.retop));
8990e307
LW
1109 break;
1110
c6fdafd0 1111 case CXt_LOOP_LAZYIV:
d01136d6 1112 case CXt_LOOP_LAZYSV:
3b719c58
NC
1113 case CXt_LOOP_FOR:
1114 case CXt_LOOP_PLAIN:
0cbdab38 1115 PerlIO_printf(Perl_debug_log, "BLK_LOOP.LABEL = %s\n", CxLABEL(cx));
760ac839 1116 PerlIO_printf(Perl_debug_log, "BLK_LOOP.RESETSP = %ld\n",
8990e307 1117 (long)cx->blk_loop.resetsp);
022eaa24
NC
1118 PerlIO_printf(Perl_debug_log, "BLK_LOOP.MY_OP = 0x%"UVxf"\n",
1119 PTR2UV(cx->blk_loop.my_op));
146174a9 1120 PerlIO_printf(Perl_debug_log, "BLK_LOOP.NEXT_OP = 0x%"UVxf"\n",
022eaa24 1121 PTR2UV(CX_LOOP_NEXTOP_GET(cx)));
d01136d6 1122 /* XXX: not accurate for LAZYSV/IV */
146174a9 1123 PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERARY = 0x%"UVxf"\n",
d01136d6
BS
1124 PTR2UV(cx->blk_loop.state_u.ary.ary));
1125 PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERIX = %ld\n",
1126 (long)cx->blk_loop.state_u.ary.ix);
146174a9
CB
1127 PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERVAR = 0x%"UVxf"\n",
1128 PTR2UV(CxITERVAR(cx)));
8990e307
LW
1129 break;
1130
1131 case CXt_SUBST:
760ac839 1132 PerlIO_printf(Perl_debug_log, "SB_ITERS = %ld\n",
8990e307 1133 (long)cx->sb_iters);
760ac839 1134 PerlIO_printf(Perl_debug_log, "SB_MAXITERS = %ld\n",
8990e307 1135 (long)cx->sb_maxiters);
35ef4773
GS
1136 PerlIO_printf(Perl_debug_log, "SB_RFLAGS = %ld\n",
1137 (long)cx->sb_rflags);
760ac839 1138 PerlIO_printf(Perl_debug_log, "SB_ONCE = %ld\n",
c5bed6a7 1139 (long)CxONCE(cx));
760ac839 1140 PerlIO_printf(Perl_debug_log, "SB_ORIG = %s\n",
8990e307 1141 cx->sb_orig);
146174a9
CB
1142 PerlIO_printf(Perl_debug_log, "SB_DSTR = 0x%"UVxf"\n",
1143 PTR2UV(cx->sb_dstr));
1144 PerlIO_printf(Perl_debug_log, "SB_TARG = 0x%"UVxf"\n",
1145 PTR2UV(cx->sb_targ));
1146 PerlIO_printf(Perl_debug_log, "SB_S = 0x%"UVxf"\n",
1147 PTR2UV(cx->sb_s));
1148 PerlIO_printf(Perl_debug_log, "SB_M = 0x%"UVxf"\n",
1149 PTR2UV(cx->sb_m));
1150 PerlIO_printf(Perl_debug_log, "SB_STREND = 0x%"UVxf"\n",
1151 PTR2UV(cx->sb_strend));
1152 PerlIO_printf(Perl_debug_log, "SB_RXRES = 0x%"UVxf"\n",
1153 PTR2UV(cx->sb_rxres));
8990e307
LW
1154 break;
1155 }
65e66c80 1156#else
96a5add6 1157 PERL_UNUSED_CONTEXT;
65e66c80 1158 PERL_UNUSED_ARG(cx);
17c3b450 1159#endif /* DEBUGGING */
35ff7856 1160}
241d1a3b
NC
1161
1162/*
1163 * Local variables:
1164 * c-indentation-style: bsd
1165 * c-basic-offset: 4
1166 * indent-tabs-mode: t
1167 * End:
1168 *
37442d52
RGS
1169 * ex: set ts=8 sts=4 sw=4 noet:
1170 */