This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[win32] fix extra LEAVE when require fails
[perl5.git] / scope.c
CommitLineData
a0d0e21e 1/* scope.c
79072805 2 *
9607fc9c 3 * Copyright (c) 1991-1997, Larry Wall
79072805
LW
4 *
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
7 *
a0d0e21e
LW
8 */
9
10/*
11 * "For the fashion of Minas Tirith was such that it was built on seven
12 * levels..."
79072805
LW
13 */
14
15#include "EXTERN.h"
16#include "perl.h"
17
a0d0e21e 18SV**
8ac85365 19stack_grow(SV **sp, SV **p, int n)
a0d0e21e 20{
11343788 21 dTHR;
a60c0954
NIS
22#if defined(DEBUGGING) && !defined(USE_THREADS)
23 static int growing = 0;
24 if (growing++)
25 abort();
26#endif
a0d0e21e 27 stack_sp = sp;
1f96a9ed 28 av_extend(curstack, (p - stack_base) + (n) + 128);
a60c0954
NIS
29#if defined(DEBUGGING) && !defined(USE_THREADS)
30 growing--;
31#endif
a0d0e21e
LW
32 return stack_sp;
33}
34
79072805 35I32
8ac85365 36cxinc(void)
79072805 37{
11343788 38 dTHR;
79072805 39 cxstack_max = cxstack_max * 3 / 2;
c09156bb 40 Renew(cxstack, cxstack_max + 1, PERL_CONTEXT); /* XXX should fix CXINC macro */
79072805
LW
41 return cxstack_ix + 1;
42}
43
44void
8ac85365 45push_return(OP *retop)
79072805 46{
11343788 47 dTHR;
79072805
LW
48 if (retstack_ix == retstack_max) {
49 retstack_max = retstack_max * 3 / 2;
50 Renew(retstack, retstack_max, OP*);
51 }
52 retstack[retstack_ix++] = retop;
53}
54
55OP *
8ac85365 56pop_return(void)
79072805 57{
11343788 58 dTHR;
79072805
LW
59 if (retstack_ix > 0)
60 return retstack[--retstack_ix];
61 else
62 return Nullop;
63}
64
65void
8ac85365 66push_scope(void)
79072805 67{
11343788 68 dTHR;
79072805
LW
69 if (scopestack_ix == scopestack_max) {
70 scopestack_max = scopestack_max * 3 / 2;
71 Renew(scopestack, scopestack_max, I32);
72 }
73 scopestack[scopestack_ix++] = savestack_ix;
74
75}
76
77void
8ac85365 78pop_scope(void)
79072805 79{
11343788 80 dTHR;
79072805 81 I32 oldsave = scopestack[--scopestack_ix];
8990e307 82 LEAVE_SCOPE(oldsave);
79072805
LW
83}
84
85void
8ac85365 86markstack_grow(void)
a0d0e21e 87{
11343788 88 dTHR;
a0d0e21e
LW
89 I32 oldmax = markstack_max - markstack;
90 I32 newmax = oldmax * 3 / 2;
91
92 Renew(markstack, newmax, I32);
93 markstack_ptr = markstack + oldmax;
94 markstack_max = markstack + newmax;
95}
96
97void
8ac85365 98savestack_grow(void)
79072805 99{
11343788 100 dTHR;
79072805
LW
101 savestack_max = savestack_max * 3 / 2;
102 Renew(savestack, savestack_max, ANY);
103}
104
105void
8ac85365 106free_tmps(void)
79072805 107{
11343788 108 dTHR;
79072805
LW
109 /* XXX should tmps_floor live in cxstack? */
110 I32 myfloor = tmps_floor;
111 while (tmps_ix > myfloor) { /* clean up after last statement */
112 SV* sv = tmps_stack[tmps_ix];
113 tmps_stack[tmps_ix--] = Nullsv;
463ee0b2
LW
114 if (sv) {
115#ifdef DEBUGGING
116 SvTEMP_off(sv);
117#endif
8990e307 118 SvREFCNT_dec(sv); /* note, can modify tmps_ix!!! */
463ee0b2 119 }
79072805
LW
120 }
121}
122
7a4c00b4 123static SV *
8ac85365 124save_scalar_at(SV **sptr)
79072805 125{
11343788 126 dTHR;
79072805 127 register SV *sv;
7a4c00b4 128 SV *osv = *sptr;
79072805 129
7a4c00b4 130 sv = *sptr = NEWSV(0,0);
a0d0e21e 131 if (SvTYPE(osv) >= SVt_PVMG && SvMAGIC(osv) && SvTYPE(osv) != SVt_PVGV) {
79072805 132 sv_upgrade(sv, SvTYPE(osv));
a0d0e21e 133 if (SvGMAGICAL(osv)) {
748a9306
LW
134 MAGIC* mg;
135 bool oldtainted = tainted;
a0d0e21e 136 mg_get(osv);
748a9306
LW
137 if (tainting && tainted && (mg = mg_find(osv, 't'))) {
138 SAVESPTR(mg->mg_obj);
139 mg->mg_obj = osv;
140 }
a0d0e21e
LW
141 SvFLAGS(osv) |= (SvFLAGS(osv) &
142 (SVp_IOK|SVp_NOK|SVp_POK)) >> PRIVSHIFT;
748a9306 143 tainted = oldtainted;
a0d0e21e 144 }
79072805 145 SvMAGIC(sv) = SvMAGIC(osv);
a0d0e21e 146 SvFLAGS(sv) |= SvMAGICAL(osv);
748a9306 147 localizing = 1;
79072805 148 SvSETMAGIC(sv);
748a9306 149 localizing = 0;
79072805
LW
150 }
151 return sv;
152}
153
7a4c00b4 154SV *
8ac85365 155save_scalar(GV *gv)
7a4c00b4 156{
11343788 157 dTHR;
7a4c00b4
PP
158 SSCHECK(3);
159 SSPUSHPTR(gv);
160 SSPUSHPTR(GvSV(gv));
161 SSPUSHINT(SAVEt_SV);
162 return save_scalar_at(&GvSV(gv));
163}
164
165SV*
8ac85365 166save_svref(SV **sptr)
7a4c00b4 167{
11343788 168 dTHR;
7a4c00b4
PP
169 SSCHECK(3);
170 SSPUSHPTR(sptr);
171 SSPUSHPTR(*sptr);
172 SSPUSHINT(SAVEt_SVREF);
173 return save_scalar_at(sptr);
174}
175
79072805 176void
8ac85365 177save_gp(GV *gv, I32 empty)
79072805 178{
e858de61 179 dTHR;
fb73857a
PP
180 SSCHECK(6);
181 SSPUSHIV((IV)SvLEN(gv));
182 SvLEN(gv) = 0; /* forget that anything was allocated here */
183 SSPUSHIV((IV)SvCUR(gv));
184 SSPUSHPTR(SvPVX(gv));
185 SvPOK_off(gv);
4633a7c4 186 SSPUSHPTR(SvREFCNT_inc(gv));
5f05dabc 187 SSPUSHPTR(GvGP(gv));
79072805
LW
188 SSPUSHINT(SAVEt_GP);
189
5f05dabc
PP
190 if (empty) {
191 register GP *gp;
192 Newz(602, gp, 1, GP);
44a8e56a 193 GvGP(gv) = gp_ref(gp);
5f05dabc
PP
194 GvSV(gv) = NEWSV(72,0);
195 GvLINE(gv) = curcop->cop_line;
196 GvEGV(gv) = gv;
197 }
198 else {
44a8e56a 199 gp_ref(GvGP(gv));
5f05dabc
PP
200 GvINTRO_on(gv);
201 }
79072805 202}
79072805 203
79072805 204AV *
8ac85365 205save_ary(GV *gv)
79072805 206{
11343788 207 dTHR;
67a38de0
NIS
208 AV *oav = GvAVn(gv);
209 AV *av;
fb73857a 210
67a38de0
NIS
211 if (!AvREAL(oav) && AvREIFY(oav))
212 av_reify(oav);
79072805
LW
213 SSCHECK(3);
214 SSPUSHPTR(gv);
67a38de0 215 SSPUSHPTR(oav);
79072805
LW
216 SSPUSHINT(SAVEt_AV);
217
218 GvAV(gv) = Null(AV*);
fb73857a
PP
219 av = GvAVn(gv);
220 if (SvMAGIC(oav)) {
221 SvMAGIC(av) = SvMAGIC(oav);
222 SvFLAGS(av) |= SvMAGICAL(oav);
223 SvMAGICAL_off(oav);
224 SvMAGIC(oav) = 0;
225 localizing = 1;
226 SvSETMAGIC((SV*)av);
227 localizing = 0;
228 }
229 return av;
79072805
LW
230}
231
232HV *
8ac85365 233save_hash(GV *gv)
79072805 234{
11343788 235 dTHR;
fb73857a
PP
236 HV *ohv, *hv;
237
79072805
LW
238 SSCHECK(3);
239 SSPUSHPTR(gv);
fb73857a 240 SSPUSHPTR(ohv = GvHVn(gv));
79072805
LW
241 SSPUSHINT(SAVEt_HV);
242
243 GvHV(gv) = Null(HV*);
fb73857a
PP
244 hv = GvHVn(gv);
245 if (SvMAGIC(ohv)) {
246 SvMAGIC(hv) = SvMAGIC(ohv);
247 SvFLAGS(hv) |= SvMAGICAL(ohv);
248 SvMAGICAL_off(ohv);
249 SvMAGIC(ohv) = 0;
250 localizing = 1;
251 SvSETMAGIC((SV*)hv);
252 localizing = 0;
253 }
254 return hv;
79072805
LW
255}
256
257void
8ac85365 258save_item(register SV *item)
79072805 259{
11343788 260 dTHR;
f46d017c 261 register SV *sv = NEWSV(0,0);
79072805 262
f46d017c 263 sv_setsv(sv,item);
79072805
LW
264 SSCHECK(3);
265 SSPUSHPTR(item); /* remember the pointer */
79072805
LW
266 SSPUSHPTR(sv); /* remember the value */
267 SSPUSHINT(SAVEt_ITEM);
268}
269
270void
8ac85365 271save_int(int *intp)
79072805 272{
11343788 273 dTHR;
79072805
LW
274 SSCHECK(3);
275 SSPUSHINT(*intp);
276 SSPUSHPTR(intp);
277 SSPUSHINT(SAVEt_INT);
278}
279
280void
8ac85365 281save_long(long int *longp)
85e6fe83 282{
11343788 283 dTHR;
85e6fe83
LW
284 SSCHECK(3);
285 SSPUSHLONG(*longp);
286 SSPUSHPTR(longp);
287 SSPUSHINT(SAVEt_LONG);
288}
289
290void
8ac85365 291save_I32(I32 *intp)
79072805 292{
11343788 293 dTHR;
79072805
LW
294 SSCHECK(3);
295 SSPUSHINT(*intp);
296 SSPUSHPTR(intp);
297 SSPUSHINT(SAVEt_I32);
298}
299
a0d0e21e 300void
8ac85365 301save_I16(I16 *intp)
55497cff 302{
e858de61 303 dTHR;
55497cff
PP
304 SSCHECK(3);
305 SSPUSHINT(*intp);
306 SSPUSHPTR(intp);
307 SSPUSHINT(SAVEt_I16);
308}
309
310void
8ac85365 311save_iv(IV *ivp)
a0d0e21e 312{
11343788 313 dTHR;
a0d0e21e 314 SSCHECK(3);
4aa0a1f7 315 SSPUSHIV(*ivp);
a0d0e21e
LW
316 SSPUSHPTR(ivp);
317 SSPUSHINT(SAVEt_IV);
318}
319
85e6fe83
LW
320/* Cannot use save_sptr() to store a char* since the SV** cast will
321 * force word-alignment and we'll miss the pointer.
322 */
323void
8ac85365 324save_pptr(char **pptr)
85e6fe83 325{
11343788 326 dTHR;
85e6fe83
LW
327 SSCHECK(3);
328 SSPUSHPTR(*pptr);
329 SSPUSHPTR(pptr);
330 SSPUSHINT(SAVEt_PPTR);
331}
332
79072805 333void
8ac85365 334save_sptr(SV **sptr)
79072805 335{
11343788 336 dTHR;
79072805
LW
337 SSCHECK(3);
338 SSPUSHPTR(*sptr);
339 SSPUSHPTR(sptr);
340 SSPUSHINT(SAVEt_SPTR);
341}
342
54b9620d
MB
343SV **
344save_threadsv(PADOFFSET i)
345{
346#ifdef USE_THREADS
347 dTHR;
940cb80d 348 SV **svp = &THREADSV(i); /* XXX Change to save by offset */
54b9620d
MB
349 DEBUG_L(PerlIO_printf(PerlIO_stderr(), "save_threadsv %u: %p %p:%s\n",
350 i, svp, *svp, SvPEEK(*svp)));
351 save_svref(svp);
352 return svp;
353#else
354 croak("panic: save_threadsv called in non-threaded perl");
355 return 0;
356#endif /* USE_THREADS */
357}
358
79072805 359void
8ac85365 360save_nogv(GV *gv)
79072805 361{
11343788 362 dTHR;
79072805
LW
363 SSCHECK(2);
364 SSPUSHPTR(gv);
365 SSPUSHINT(SAVEt_NSTAB);
366}
367
368void
8ac85365 369save_hptr(HV **hptr)
79072805 370{
11343788 371 dTHR;
79072805 372 SSCHECK(3);
85e6fe83 373 SSPUSHPTR(*hptr);
79072805
LW
374 SSPUSHPTR(hptr);
375 SSPUSHINT(SAVEt_HPTR);
376}
377
378void
8ac85365 379save_aptr(AV **aptr)
79072805 380{
11343788 381 dTHR;
79072805 382 SSCHECK(3);
85e6fe83 383 SSPUSHPTR(*aptr);
79072805
LW
384 SSPUSHPTR(aptr);
385 SSPUSHINT(SAVEt_APTR);
386}
387
388void
8ac85365 389save_freesv(SV *sv)
8990e307 390{
11343788 391 dTHR;
8990e307
LW
392 SSCHECK(2);
393 SSPUSHPTR(sv);
394 SSPUSHINT(SAVEt_FREESV);
395}
396
397void
8ac85365 398save_freeop(OP *o)
8990e307 399{
11343788 400 dTHR;
8990e307 401 SSCHECK(2);
11343788 402 SSPUSHPTR(o);
8990e307
LW
403 SSPUSHINT(SAVEt_FREEOP);
404}
405
406void
8ac85365 407save_freepv(char *pv)
8990e307 408{
11343788 409 dTHR;
8990e307
LW
410 SSCHECK(2);
411 SSPUSHPTR(pv);
412 SSPUSHINT(SAVEt_FREEPV);
413}
414
415void
8ac85365 416save_clearsv(SV **svp)
8990e307 417{
11343788 418 dTHR;
8990e307 419 SSCHECK(2);
4aa0a1f7 420 SSPUSHLONG((long)(svp-curpad));
8990e307
LW
421 SSPUSHINT(SAVEt_CLEARSV);
422}
423
424void
8ac85365 425save_delete(HV *hv, char *key, I32 klen)
8990e307 426{
11343788 427 dTHR;
8990e307
LW
428 SSCHECK(4);
429 SSPUSHINT(klen);
430 SSPUSHPTR(key);
431 SSPUSHPTR(hv);
432 SSPUSHINT(SAVEt_DELETE);
433}
434
435void
8ac85365 436save_list(register SV **sarg, I32 maxsarg)
79072805 437{
11343788 438 dTHR;
79072805
LW
439 register SV *sv;
440 register I32 i;
441
79072805 442 for (i = 1; i <= maxsarg; i++) {
79072805
LW
443 sv = NEWSV(0,0);
444 sv_setsv(sv,sarg[i]);
f46d017c
GS
445 SSCHECK(3);
446 SSPUSHPTR(sarg[i]); /* remember the pointer */
79072805
LW
447 SSPUSHPTR(sv); /* remember the value */
448 SSPUSHINT(SAVEt_ITEM);
449 }
450}
451
452void
8ac85365 453save_destructor(void (*f) (void *), void *p)
a0d0e21e 454{
11343788 455 dTHR;
a0d0e21e
LW
456 SSCHECK(3);
457 SSPUSHDPTR(f);
458 SSPUSHPTR(p);
459 SSPUSHINT(SAVEt_DESTRUCTOR);
460}
461
462void
8ac85365 463save_op(void)
462e5cf6
MB
464{
465 dTHR;
466 SSCHECK(2);
467 SSPUSHPTR(op);
468 SSPUSHINT(SAVEt_OP);
469}
470
471void
8ac85365 472leave_scope(I32 base)
79072805 473{
11343788 474 dTHR;
79072805
LW
475 register SV *sv;
476 register SV *value;
477 register GV *gv;
478 register AV *av;
479 register HV *hv;
480 register void* ptr;
481
482 if (base < -1)
463ee0b2 483 croak("panic: corrupt saved stack index");
79072805
LW
484 while (savestack_ix > base) {
485 switch (SSPOPINT) {
486 case SAVEt_ITEM: /* normal string */
487 value = (SV*)SSPOPPTR;
488 sv = (SV*)SSPOPPTR;
489 sv_replace(sv,value);
748a9306 490 localizing = 2;
79072805 491 SvSETMAGIC(sv);
748a9306 492 localizing = 0;
79072805
LW
493 break;
494 case SAVEt_SV: /* scalar reference */
495 value = (SV*)SSPOPPTR;
496 gv = (GV*)SSPOPPTR;
7a4c00b4
PP
497 ptr = &GvSV(gv);
498 goto restore_sv;
79072805 499 case SAVEt_SVREF: /* scalar reference */
7a4c00b4 500 value = (SV*)SSPOPPTR;
79072805 501 ptr = SSPOPPTR;
7a4c00b4 502 restore_sv:
79072805 503 sv = *(SV**)ptr;
54b9620d
MB
504 DEBUG_L(PerlIO_printf(PerlIO_stderr(),
505 "restore svref: %p %p:%s -> %p:%s\n",
506 ptr, sv, SvPEEK(sv), value, SvPEEK(value)));
748a9306
LW
507 if (SvTYPE(sv) >= SVt_PVMG && SvMAGIC(sv) &&
508 SvTYPE(sv) != SVt_PVGV)
509 {
a0d0e21e
LW
510 (void)SvUPGRADE(value, SvTYPE(sv));
511 SvMAGIC(value) = SvMAGIC(sv);
512 SvFLAGS(value) |= SvMAGICAL(sv);
513 SvMAGICAL_off(sv);
79072805 514 SvMAGIC(sv) = 0;
a0d0e21e 515 }
7a4c00b4
PP
516 else if (SvTYPE(value) >= SVt_PVMG && SvMAGIC(value) &&
517 SvTYPE(value) != SVt_PVGV)
518 {
519 SvFLAGS(value) |= (SvFLAGS(value) &
520 (SVp_IOK|SVp_NOK|SVp_POK)) >> PRIVSHIFT;
521 SvMAGICAL_off(value);
522 SvMAGIC(value) = 0;
523 }
8990e307 524 SvREFCNT_dec(sv);
a0d0e21e 525 *(SV**)ptr = value;
748a9306 526 localizing = 2;
a0d0e21e 527 SvSETMAGIC(value);
748a9306 528 localizing = 0;
79072805
LW
529 break;
530 case SAVEt_AV: /* array reference */
531 av = (AV*)SSPOPPTR;
532 gv = (GV*)SSPOPPTR;
fb73857a
PP
533 if (GvAV(gv)) {
534 AV *goner = GvAV(gv);
535 SvMAGIC(av) = SvMAGIC(goner);
536 SvFLAGS(av) |= SvMAGICAL(goner);
537 SvMAGICAL_off(goner);
538 SvMAGIC(goner) = 0;
539 SvREFCNT_dec(goner);
540 }
79072805 541 GvAV(gv) = av;
fb73857a
PP
542 if (SvMAGICAL(av)) {
543 localizing = 2;
544 SvSETMAGIC((SV*)av);
545 localizing = 0;
546 }
79072805
LW
547 break;
548 case SAVEt_HV: /* hash reference */
549 hv = (HV*)SSPOPPTR;
550 gv = (GV*)SSPOPPTR;
fb73857a
PP
551 if (GvHV(gv)) {
552 HV *goner = GvHV(gv);
553 SvMAGIC(hv) = SvMAGIC(goner);
554 SvFLAGS(hv) |= SvMAGICAL(goner);
555 SvMAGICAL_off(goner);
556 SvMAGIC(goner) = 0;
557 SvREFCNT_dec(goner);
558 }
79072805 559 GvHV(gv) = hv;
fb73857a
PP
560 if (SvMAGICAL(hv)) {
561 localizing = 2;
562 SvSETMAGIC((SV*)hv);
563 localizing = 0;
564 }
79072805
LW
565 break;
566 case SAVEt_INT: /* int reference */
567 ptr = SSPOPPTR;
568 *(int*)ptr = (int)SSPOPINT;
569 break;
85e6fe83
LW
570 case SAVEt_LONG: /* long reference */
571 ptr = SSPOPPTR;
572 *(long*)ptr = (long)SSPOPLONG;
573 break;
79072805
LW
574 case SAVEt_I32: /* I32 reference */
575 ptr = SSPOPPTR;
576 *(I32*)ptr = (I32)SSPOPINT;
577 break;
55497cff
PP
578 case SAVEt_I16: /* I16 reference */
579 ptr = SSPOPPTR;
580 *(I16*)ptr = (I16)SSPOPINT;
581 break;
a0d0e21e
LW
582 case SAVEt_IV: /* IV reference */
583 ptr = SSPOPPTR;
584 *(IV*)ptr = (IV)SSPOPIV;
585 break;
79072805
LW
586 case SAVEt_SPTR: /* SV* reference */
587 ptr = SSPOPPTR;
588 *(SV**)ptr = (SV*)SSPOPPTR;
589 break;
85e6fe83
LW
590 case SAVEt_PPTR: /* char* reference */
591 ptr = SSPOPPTR;
592 *(char**)ptr = (char*)SSPOPPTR;
593 break;
79072805
LW
594 case SAVEt_HPTR: /* HV* reference */
595 ptr = SSPOPPTR;
596 *(HV**)ptr = (HV*)SSPOPPTR;
597 break;
598 case SAVEt_APTR: /* AV* reference */
599 ptr = SSPOPPTR;
600 *(AV**)ptr = (AV*)SSPOPPTR;
601 break;
602 case SAVEt_NSTAB:
603 gv = (GV*)SSPOPPTR;
1f96a9ed 604 (void)sv_clear((SV*)gv);
79072805 605 break;
fb73857a 606 case SAVEt_GP: /* scalar reference */
79072805
LW
607 ptr = SSPOPPTR;
608 gv = (GV*)SSPOPPTR;
fb73857a
PP
609 if (SvPOK(gv) && SvLEN(gv) > 0) {
610 Safefree(SvPVX(gv));
611 }
612 SvPVX(gv) = (char *)SSPOPPTR;
613 SvCUR(gv) = (STRLEN)SSPOPIV;
614 SvLEN(gv) = (STRLEN)SSPOPIV;
f46d017c
GS
615 gp_free(gv);
616 GvGP(gv) = (GP*)ptr;
4633a7c4 617 SvREFCNT_dec(gv);
79072805 618 break;
8990e307
LW
619 case SAVEt_FREESV:
620 ptr = SSPOPPTR;
621 SvREFCNT_dec((SV*)ptr);
622 break;
623 case SAVEt_FREEOP:
624 ptr = SSPOPPTR;
46fc3d4c
PP
625 if (comppad)
626 curpad = AvARRAY(comppad);
8990e307
LW
627 op_free((OP*)ptr);
628 break;
629 case SAVEt_FREEPV:
630 ptr = SSPOPPTR;
631 Safefree((char*)ptr);
632 break;
633 case SAVEt_CLEARSV:
4aa0a1f7 634 ptr = (void*)&curpad[SSPOPLONG];
8990e307 635 sv = *(SV**)ptr;
bc44cdaf
GS
636 /* Can clear pad variable in place? */
637 if (SvREFCNT(sv) <= 1 && !SvOBJECT(sv)) {
8990e307
LW
638 if (SvTHINKFIRST(sv)) {
639 if (SvREADONLY(sv))
640 croak("panic: leave_scope clearsv");
641 if (SvROK(sv))
642 sv_unref(sv);
643 }
a0d0e21e
LW
644 if (SvMAGICAL(sv))
645 mg_free(sv);
8990e307
LW
646
647 switch (SvTYPE(sv)) {
648 case SVt_NULL:
649 break;
650 case SVt_PVAV:
44a8e56a 651 av_clear((AV*)sv);
8990e307
LW
652 break;
653 case SVt_PVHV:
44a8e56a 654 hv_clear((HV*)sv);
8990e307
LW
655 break;
656 case SVt_PVCV:
5377b701
CS
657 croak("panic: leave_scope pad code");
658 case SVt_RV:
659 case SVt_IV:
660 case SVt_NV:
661 (void)SvOK_off(sv);
8990e307
LW
662 break;
663 default:
a0d0e21e 664 (void)SvOK_off(sv);
5377b701 665 (void)SvOOK_off(sv);
8990e307
LW
666 break;
667 }
668 }
669 else { /* Someone has a claim on this, so abandon it. */
4aa0a1f7 670 U32 padflags = SvFLAGS(sv) & (SVs_PADBUSY|SVs_PADMY|SVs_PADTMP);
8990e307
LW
671 switch (SvTYPE(sv)) { /* Console ourselves with a new value */
672 case SVt_PVAV: *(SV**)ptr = (SV*)newAV(); break;
673 case SVt_PVHV: *(SV**)ptr = (SV*)newHV(); break;
674 default: *(SV**)ptr = NEWSV(0,0); break;
675 }
53868620 676 SvREFCNT_dec(sv); /* Cast current value to the winds. */
4aa0a1f7 677 SvFLAGS(*(SV**)ptr) |= padflags; /* preserve pad nature */
8990e307
LW
678 }
679 break;
680 case SAVEt_DELETE:
681 ptr = SSPOPPTR;
682 hv = (HV*)ptr;
683 ptr = SSPOPPTR;
748a9306 684 (void)hv_delete(hv, (char*)ptr, (U32)SSPOPINT, G_DISCARD);
adbc6bb1 685 Safefree(ptr);
8990e307 686 break;
a0d0e21e
LW
687 case SAVEt_DESTRUCTOR:
688 ptr = SSPOPPTR;
689 (*SSPOPDPTR)(ptr);
690 break;
691 case SAVEt_REGCONTEXT:
8e07c86e
AD
692 {
693 I32 delta = SSPOPINT;
694 savestack_ix -= delta; /* regexp must have croaked */
695 }
a0d0e21e 696 break;
55497cff
PP
697 case SAVEt_STACK_POS: /* Position on Perl stack */
698 {
699 I32 delta = SSPOPINT;
700 stack_sp = stack_base + delta;
701 }
702 break;
462e5cf6
MB
703 case SAVEt_OP:
704 op = (OP*)SSPOPPTR;
705 break;
79072805 706 default:
463ee0b2 707 croak("panic: leave_scope inconsistency");
79072805
LW
708 }
709 }
710}
8990e307
LW
711
712#ifdef DEBUGGING
1f96a9ed 713
8990e307 714void
c09156bb 715cx_dump(PERL_CONTEXT *cx)
8990e307 716{
11343788 717 dTHR;
fb73857a 718 PerlIO_printf(Perl_debug_log, "CX %ld = %s\n", (long)(cx - cxstack), block_type[cx->cx_type]);
8990e307 719 if (cx->cx_type != CXt_SUBST) {
760ac839
LW
720 PerlIO_printf(Perl_debug_log, "BLK_OLDSP = %ld\n", (long)cx->blk_oldsp);
721 PerlIO_printf(Perl_debug_log, "BLK_OLDCOP = 0x%lx\n", (long)cx->blk_oldcop);
722 PerlIO_printf(Perl_debug_log, "BLK_OLDMARKSP = %ld\n", (long)cx->blk_oldmarksp);
723 PerlIO_printf(Perl_debug_log, "BLK_OLDSCOPESP = %ld\n", (long)cx->blk_oldscopesp);
724 PerlIO_printf(Perl_debug_log, "BLK_OLDRETSP = %ld\n", (long)cx->blk_oldretsp);
725 PerlIO_printf(Perl_debug_log, "BLK_OLDPM = 0x%lx\n", (long)cx->blk_oldpm);
726 PerlIO_printf(Perl_debug_log, "BLK_GIMME = %s\n", cx->blk_gimme ? "LIST" : "SCALAR");
8990e307
LW
727 }
728 switch (cx->cx_type) {
729 case CXt_NULL:
730 case CXt_BLOCK:
731 break;
732 case CXt_SUB:
760ac839 733 PerlIO_printf(Perl_debug_log, "BLK_SUB.CV = 0x%lx\n",
8990e307 734 (long)cx->blk_sub.cv);
760ac839 735 PerlIO_printf(Perl_debug_log, "BLK_SUB.GV = 0x%lx\n",
8990e307 736 (long)cx->blk_sub.gv);
760ac839 737 PerlIO_printf(Perl_debug_log, "BLK_SUB.DFOUTGV = 0x%lx\n",
8990e307 738 (long)cx->blk_sub.dfoutgv);
760ac839 739 PerlIO_printf(Perl_debug_log, "BLK_SUB.OLDDEPTH = %ld\n",
8990e307 740 (long)cx->blk_sub.olddepth);
760ac839 741 PerlIO_printf(Perl_debug_log, "BLK_SUB.HASARGS = %d\n",
8990e307
LW
742 (int)cx->blk_sub.hasargs);
743 break;
744 case CXt_EVAL:
760ac839 745 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_IN_EVAL = %ld\n",
8990e307 746 (long)cx->blk_eval.old_in_eval);
760ac839 747 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_OP_TYPE = %s (%s)\n",
c07a80fd
PP
748 op_name[cx->blk_eval.old_op_type],
749 op_desc[cx->blk_eval.old_op_type]);
760ac839 750 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_NAME = %s\n",
8990e307 751 cx->blk_eval.old_name);
760ac839 752 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_EVAL_ROOT = 0x%lx\n",
8990e307
LW
753 (long)cx->blk_eval.old_eval_root);
754 break;
755
756 case CXt_LOOP:
760ac839 757 PerlIO_printf(Perl_debug_log, "BLK_LOOP.LABEL = %s\n",
8990e307 758 cx->blk_loop.label);
760ac839 759 PerlIO_printf(Perl_debug_log, "BLK_LOOP.RESETSP = %ld\n",
8990e307 760 (long)cx->blk_loop.resetsp);
760ac839 761 PerlIO_printf(Perl_debug_log, "BLK_LOOP.REDO_OP = 0x%lx\n",
8990e307 762 (long)cx->blk_loop.redo_op);
760ac839 763 PerlIO_printf(Perl_debug_log, "BLK_LOOP.NEXT_OP = 0x%lx\n",
8990e307 764 (long)cx->blk_loop.next_op);
760ac839 765 PerlIO_printf(Perl_debug_log, "BLK_LOOP.LAST_OP = 0x%lx\n",
8990e307 766 (long)cx->blk_loop.last_op);
760ac839 767 PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERIX = %ld\n",
8990e307 768 (long)cx->blk_loop.iterix);
760ac839 769 PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERARY = 0x%lx\n",
8990e307 770 (long)cx->blk_loop.iterary);
760ac839 771 PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERVAR = 0x%lx\n",
8990e307
LW
772 (long)cx->blk_loop.itervar);
773 if (cx->blk_loop.itervar)
760ac839 774 PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERSAVE = 0x%lx\n",
8990e307 775 (long)cx->blk_loop.itersave);
7a4c00b4
PP
776 PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERLVAL = 0x%lx\n",
777 (long)cx->blk_loop.iterlval);
8990e307
LW
778 break;
779
780 case CXt_SUBST:
760ac839 781 PerlIO_printf(Perl_debug_log, "SB_ITERS = %ld\n",
8990e307 782 (long)cx->sb_iters);
760ac839 783 PerlIO_printf(Perl_debug_log, "SB_MAXITERS = %ld\n",
8990e307 784 (long)cx->sb_maxiters);
760ac839 785 PerlIO_printf(Perl_debug_log, "SB_SAFEBASE = %ld\n",
8990e307 786 (long)cx->sb_safebase);
760ac839 787 PerlIO_printf(Perl_debug_log, "SB_ONCE = %ld\n",
8990e307 788 (long)cx->sb_once);
760ac839 789 PerlIO_printf(Perl_debug_log, "SB_ORIG = %s\n",
8990e307 790 cx->sb_orig);
760ac839 791 PerlIO_printf(Perl_debug_log, "SB_DSTR = 0x%lx\n",
8990e307 792 (long)cx->sb_dstr);
760ac839 793 PerlIO_printf(Perl_debug_log, "SB_TARG = 0x%lx\n",
8990e307 794 (long)cx->sb_targ);
760ac839 795 PerlIO_printf(Perl_debug_log, "SB_S = 0x%lx\n",
8990e307 796 (long)cx->sb_s);
760ac839 797 PerlIO_printf(Perl_debug_log, "SB_M = 0x%lx\n",
8990e307 798 (long)cx->sb_m);
760ac839 799 PerlIO_printf(Perl_debug_log, "SB_STREND = 0x%lx\n",
8990e307 800 (long)cx->sb_strend);
c90c0ff4
PP
801 PerlIO_printf(Perl_debug_log, "SB_RXRES = 0x%lx\n",
802 (long)cx->sb_rxres);
8990e307
LW
803 break;
804 }
805}
806#endif