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