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