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