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