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