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