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