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