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