This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Get PerlXxx_yyyy() macro stuff to _compile_ on Solaris.
[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;
fb73857a
PP
208 AV *oav, *av;
209
79072805
LW
210 SSCHECK(3);
211 SSPUSHPTR(gv);
fb73857a 212 SSPUSHPTR(oav = GvAVn(gv));
79072805
LW
213 SSPUSHINT(SAVEt_AV);
214
215 GvAV(gv) = Null(AV*);
fb73857a
PP
216 av = GvAVn(gv);
217 if (SvMAGIC(oav)) {
218 SvMAGIC(av) = SvMAGIC(oav);
219 SvFLAGS(av) |= SvMAGICAL(oav);
220 SvMAGICAL_off(oav);
221 SvMAGIC(oav) = 0;
222 localizing = 1;
223 SvSETMAGIC((SV*)av);
224 localizing = 0;
225 }
226 return av;
79072805
LW
227}
228
229HV *
8ac85365 230save_hash(GV *gv)
79072805 231{
11343788 232 dTHR;
fb73857a
PP
233 HV *ohv, *hv;
234
79072805
LW
235 SSCHECK(3);
236 SSPUSHPTR(gv);
fb73857a 237 SSPUSHPTR(ohv = GvHVn(gv));
79072805
LW
238 SSPUSHINT(SAVEt_HV);
239
240 GvHV(gv) = Null(HV*);
fb73857a
PP
241 hv = GvHVn(gv);
242 if (SvMAGIC(ohv)) {
243 SvMAGIC(hv) = SvMAGIC(ohv);
244 SvFLAGS(hv) |= SvMAGICAL(ohv);
245 SvMAGICAL_off(ohv);
246 SvMAGIC(ohv) = 0;
247 localizing = 1;
248 SvSETMAGIC((SV*)hv);
249 localizing = 0;
250 }
251 return hv;
79072805
LW
252}
253
254void
8ac85365 255save_item(register SV *item)
79072805 256{
11343788 257 dTHR;
79072805
LW
258 register SV *sv;
259
260 SSCHECK(3);
261 SSPUSHPTR(item); /* remember the pointer */
262 sv = NEWSV(0,0);
263 sv_setsv(sv,item);
264 SSPUSHPTR(sv); /* remember the value */
265 SSPUSHINT(SAVEt_ITEM);
266}
267
268void
8ac85365 269save_int(int *intp)
79072805 270{
11343788 271 dTHR;
79072805
LW
272 SSCHECK(3);
273 SSPUSHINT(*intp);
274 SSPUSHPTR(intp);
275 SSPUSHINT(SAVEt_INT);
276}
277
278void
8ac85365 279save_long(long int *longp)
85e6fe83 280{
11343788 281 dTHR;
85e6fe83
LW
282 SSCHECK(3);
283 SSPUSHLONG(*longp);
284 SSPUSHPTR(longp);
285 SSPUSHINT(SAVEt_LONG);
286}
287
288void
8ac85365 289save_I32(I32 *intp)
79072805 290{
11343788 291 dTHR;
79072805
LW
292 SSCHECK(3);
293 SSPUSHINT(*intp);
294 SSPUSHPTR(intp);
295 SSPUSHINT(SAVEt_I32);
296}
297
a0d0e21e 298void
8ac85365 299save_I16(I16 *intp)
55497cff 300{
e858de61 301 dTHR;
55497cff
PP
302 SSCHECK(3);
303 SSPUSHINT(*intp);
304 SSPUSHPTR(intp);
305 SSPUSHINT(SAVEt_I16);
306}
307
308void
8ac85365 309save_iv(IV *ivp)
a0d0e21e 310{
11343788 311 dTHR;
a0d0e21e 312 SSCHECK(3);
4aa0a1f7 313 SSPUSHIV(*ivp);
a0d0e21e
LW
314 SSPUSHPTR(ivp);
315 SSPUSHINT(SAVEt_IV);
316}
317
85e6fe83
LW
318/* Cannot use save_sptr() to store a char* since the SV** cast will
319 * force word-alignment and we'll miss the pointer.
320 */
321void
8ac85365 322save_pptr(char **pptr)
85e6fe83 323{
11343788 324 dTHR;
85e6fe83
LW
325 SSCHECK(3);
326 SSPUSHPTR(*pptr);
327 SSPUSHPTR(pptr);
328 SSPUSHINT(SAVEt_PPTR);
329}
330
79072805 331void
8ac85365 332save_sptr(SV **sptr)
79072805 333{
11343788 334 dTHR;
79072805
LW
335 SSCHECK(3);
336 SSPUSHPTR(*sptr);
337 SSPUSHPTR(sptr);
338 SSPUSHINT(SAVEt_SPTR);
339}
340
54b9620d
MB
341SV **
342save_threadsv(PADOFFSET i)
343{
344#ifdef USE_THREADS
345 dTHR;
346 SV **svp = av_fetch(thr->threadsv, i, FALSE);
347 DEBUG_L(PerlIO_printf(PerlIO_stderr(), "save_threadsv %u: %p %p:%s\n",
348 i, svp, *svp, SvPEEK(*svp)));
349 save_svref(svp);
350 return svp;
351#else
352 croak("panic: save_threadsv called in non-threaded perl");
353 return 0;
354#endif /* USE_THREADS */
355}
356
79072805 357void
8ac85365 358save_nogv(GV *gv)
79072805 359{
11343788 360 dTHR;
79072805
LW
361 SSCHECK(2);
362 SSPUSHPTR(gv);
363 SSPUSHINT(SAVEt_NSTAB);
364}
365
366void
8ac85365 367save_hptr(HV **hptr)
79072805 368{
11343788 369 dTHR;
79072805 370 SSCHECK(3);
85e6fe83 371 SSPUSHPTR(*hptr);
79072805
LW
372 SSPUSHPTR(hptr);
373 SSPUSHINT(SAVEt_HPTR);
374}
375
376void
8ac85365 377save_aptr(AV **aptr)
79072805 378{
11343788 379 dTHR;
79072805 380 SSCHECK(3);
85e6fe83 381 SSPUSHPTR(*aptr);
79072805
LW
382 SSPUSHPTR(aptr);
383 SSPUSHINT(SAVEt_APTR);
384}
385
386void
8ac85365 387save_freesv(SV *sv)
8990e307 388{
11343788 389 dTHR;
8990e307
LW
390 SSCHECK(2);
391 SSPUSHPTR(sv);
392 SSPUSHINT(SAVEt_FREESV);
393}
394
395void
8ac85365 396save_freeop(OP *o)
8990e307 397{
11343788 398 dTHR;
8990e307 399 SSCHECK(2);
11343788 400 SSPUSHPTR(o);
8990e307
LW
401 SSPUSHINT(SAVEt_FREEOP);
402}
403
404void
8ac85365 405save_freepv(char *pv)
8990e307 406{
11343788 407 dTHR;
8990e307
LW
408 SSCHECK(2);
409 SSPUSHPTR(pv);
410 SSPUSHINT(SAVEt_FREEPV);
411}
412
413void
8ac85365 414save_clearsv(SV **svp)
8990e307 415{
11343788 416 dTHR;
8990e307 417 SSCHECK(2);
4aa0a1f7 418 SSPUSHLONG((long)(svp-curpad));
8990e307
LW
419 SSPUSHINT(SAVEt_CLEARSV);
420}
421
422void
8ac85365 423save_delete(HV *hv, char *key, I32 klen)
8990e307 424{
11343788 425 dTHR;
8990e307
LW
426 SSCHECK(4);
427 SSPUSHINT(klen);
428 SSPUSHPTR(key);
429 SSPUSHPTR(hv);
430 SSPUSHINT(SAVEt_DELETE);
431}
432
433void
8ac85365 434save_list(register SV **sarg, I32 maxsarg)
79072805 435{
11343788 436 dTHR;
79072805
LW
437 register SV *sv;
438 register I32 i;
439
440 SSCHECK(3 * maxsarg);
441 for (i = 1; i <= maxsarg; i++) {
442 SSPUSHPTR(sarg[i]); /* remember the pointer */
443 sv = NEWSV(0,0);
444 sv_setsv(sv,sarg[i]);
445 SSPUSHPTR(sv); /* remember the value */
446 SSPUSHINT(SAVEt_ITEM);
447 }
448}
449
450void
8ac85365 451save_destructor(void (*f) (void *), void *p)
a0d0e21e 452{
11343788 453 dTHR;
a0d0e21e
LW
454 SSCHECK(3);
455 SSPUSHDPTR(f);
456 SSPUSHPTR(p);
457 SSPUSHINT(SAVEt_DESTRUCTOR);
458}
459
460void
8ac85365 461save_op(void)
462e5cf6
MB
462{
463 dTHR;
464 SSCHECK(2);
465 SSPUSHPTR(op);
466 SSPUSHINT(SAVEt_OP);
467}
468
469void
8ac85365 470leave_scope(I32 base)
79072805 471{
11343788 472 dTHR;
79072805
LW
473 register SV *sv;
474 register SV *value;
475 register GV *gv;
476 register AV *av;
477 register HV *hv;
478 register void* ptr;
479
480 if (base < -1)
463ee0b2 481 croak("panic: corrupt saved stack index");
79072805
LW
482 while (savestack_ix > base) {
483 switch (SSPOPINT) {
484 case SAVEt_ITEM: /* normal string */
485 value = (SV*)SSPOPPTR;
486 sv = (SV*)SSPOPPTR;
487 sv_replace(sv,value);
748a9306 488 localizing = 2;
79072805 489 SvSETMAGIC(sv);
748a9306 490 localizing = 0;
79072805
LW
491 break;
492 case SAVEt_SV: /* scalar reference */
493 value = (SV*)SSPOPPTR;
494 gv = (GV*)SSPOPPTR;
7a4c00b4
PP
495 ptr = &GvSV(gv);
496 goto restore_sv;
79072805 497 case SAVEt_SVREF: /* scalar reference */
7a4c00b4 498 value = (SV*)SSPOPPTR;
79072805 499 ptr = SSPOPPTR;
7a4c00b4 500 restore_sv:
79072805 501 sv = *(SV**)ptr;
54b9620d
MB
502 DEBUG_L(PerlIO_printf(PerlIO_stderr(),
503 "restore svref: %p %p:%s -> %p:%s\n",
504 ptr, sv, SvPEEK(sv), value, SvPEEK(value)));
748a9306
LW
505 if (SvTYPE(sv) >= SVt_PVMG && SvMAGIC(sv) &&
506 SvTYPE(sv) != SVt_PVGV)
507 {
a0d0e21e
LW
508 (void)SvUPGRADE(value, SvTYPE(sv));
509 SvMAGIC(value) = SvMAGIC(sv);
510 SvFLAGS(value) |= SvMAGICAL(sv);
511 SvMAGICAL_off(sv);
79072805 512 SvMAGIC(sv) = 0;
a0d0e21e 513 }
7a4c00b4
PP
514 else if (SvTYPE(value) >= SVt_PVMG && SvMAGIC(value) &&
515 SvTYPE(value) != SVt_PVGV)
516 {
517 SvFLAGS(value) |= (SvFLAGS(value) &
518 (SVp_IOK|SVp_NOK|SVp_POK)) >> PRIVSHIFT;
519 SvMAGICAL_off(value);
520 SvMAGIC(value) = 0;
521 }
8990e307 522 SvREFCNT_dec(sv);
a0d0e21e 523 *(SV**)ptr = value;
748a9306 524 localizing = 2;
a0d0e21e 525 SvSETMAGIC(value);
748a9306 526 localizing = 0;
79072805
LW
527 break;
528 case SAVEt_AV: /* array reference */
529 av = (AV*)SSPOPPTR;
530 gv = (GV*)SSPOPPTR;
fb73857a
PP
531 if (GvAV(gv)) {
532 AV *goner = GvAV(gv);
533 SvMAGIC(av) = SvMAGIC(goner);
534 SvFLAGS(av) |= SvMAGICAL(goner);
535 SvMAGICAL_off(goner);
536 SvMAGIC(goner) = 0;
537 SvREFCNT_dec(goner);
538 }
79072805 539 GvAV(gv) = av;
fb73857a
PP
540 if (SvMAGICAL(av)) {
541 localizing = 2;
542 SvSETMAGIC((SV*)av);
543 localizing = 0;
544 }
79072805
LW
545 break;
546 case SAVEt_HV: /* hash reference */
547 hv = (HV*)SSPOPPTR;
548 gv = (GV*)SSPOPPTR;
fb73857a
PP
549 if (GvHV(gv)) {
550 HV *goner = GvHV(gv);
551 SvMAGIC(hv) = SvMAGIC(goner);
552 SvFLAGS(hv) |= SvMAGICAL(goner);
553 SvMAGICAL_off(goner);
554 SvMAGIC(goner) = 0;
555 SvREFCNT_dec(goner);
556 }
79072805 557 GvHV(gv) = hv;
fb73857a
PP
558 if (SvMAGICAL(hv)) {
559 localizing = 2;
560 SvSETMAGIC((SV*)hv);
561 localizing = 0;
562 }
79072805
LW
563 break;
564 case SAVEt_INT: /* int reference */
565 ptr = SSPOPPTR;
566 *(int*)ptr = (int)SSPOPINT;
567 break;
85e6fe83
LW
568 case SAVEt_LONG: /* long reference */
569 ptr = SSPOPPTR;
570 *(long*)ptr = (long)SSPOPLONG;
571 break;
79072805
LW
572 case SAVEt_I32: /* I32 reference */
573 ptr = SSPOPPTR;
574 *(I32*)ptr = (I32)SSPOPINT;
575 break;
55497cff
PP
576 case SAVEt_I16: /* I16 reference */
577 ptr = SSPOPPTR;
578 *(I16*)ptr = (I16)SSPOPINT;
579 break;
a0d0e21e
LW
580 case SAVEt_IV: /* IV reference */
581 ptr = SSPOPPTR;
582 *(IV*)ptr = (IV)SSPOPIV;
583 break;
79072805
LW
584 case SAVEt_SPTR: /* SV* reference */
585 ptr = SSPOPPTR;
586 *(SV**)ptr = (SV*)SSPOPPTR;
587 break;
85e6fe83
LW
588 case SAVEt_PPTR: /* char* reference */
589 ptr = SSPOPPTR;
590 *(char**)ptr = (char*)SSPOPPTR;
591 break;
79072805
LW
592 case SAVEt_HPTR: /* HV* reference */
593 ptr = SSPOPPTR;
594 *(HV**)ptr = (HV*)SSPOPPTR;
595 break;
596 case SAVEt_APTR: /* AV* reference */
597 ptr = SSPOPPTR;
598 *(AV**)ptr = (AV*)SSPOPPTR;
599 break;
600 case SAVEt_NSTAB:
601 gv = (GV*)SSPOPPTR;
1f96a9ed 602 (void)sv_clear((SV*)gv);
79072805 603 break;
fb73857a 604 case SAVEt_GP: /* scalar reference */
79072805
LW
605 ptr = SSPOPPTR;
606 gv = (GV*)SSPOPPTR;
607 gp_free(gv);
608 GvGP(gv) = (GP*)ptr;
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;
4633a7c4 615 SvREFCNT_dec(gv);
79072805 616 break;
8990e307
LW
617 case SAVEt_FREESV:
618 ptr = SSPOPPTR;
619 SvREFCNT_dec((SV*)ptr);
620 break;
621 case SAVEt_FREEOP:
622 ptr = SSPOPPTR;
46fc3d4c
PP
623 if (comppad)
624 curpad = AvARRAY(comppad);
8990e307
LW
625 op_free((OP*)ptr);
626 break;
627 case SAVEt_FREEPV:
628 ptr = SSPOPPTR;
629 Safefree((char*)ptr);
630 break;
631 case SAVEt_CLEARSV:
4aa0a1f7 632 ptr = (void*)&curpad[SSPOPLONG];
8990e307 633 sv = *(SV**)ptr;
bc44cdaf
GS
634 /* Can clear pad variable in place? */
635 if (SvREFCNT(sv) <= 1 && !SvOBJECT(sv)) {
8990e307
LW
636 if (SvTHINKFIRST(sv)) {
637 if (SvREADONLY(sv))
638 croak("panic: leave_scope clearsv");
639 if (SvROK(sv))
640 sv_unref(sv);
641 }
a0d0e21e
LW
642 if (SvMAGICAL(sv))
643 mg_free(sv);
8990e307
LW
644
645 switch (SvTYPE(sv)) {
646 case SVt_NULL:
647 break;
648 case SVt_PVAV:
44a8e56a 649 av_clear((AV*)sv);
8990e307
LW
650 break;
651 case SVt_PVHV:
44a8e56a 652 hv_clear((HV*)sv);
8990e307
LW
653 break;
654 case SVt_PVCV:
5377b701
CS
655 croak("panic: leave_scope pad code");
656 case SVt_RV:
657 case SVt_IV:
658 case SVt_NV:
659 (void)SvOK_off(sv);
8990e307
LW
660 break;
661 default:
a0d0e21e 662 (void)SvOK_off(sv);
5377b701 663 (void)SvOOK_off(sv);
8990e307
LW
664 break;
665 }
666 }
667 else { /* Someone has a claim on this, so abandon it. */
4aa0a1f7 668 U32 padflags = SvFLAGS(sv) & (SVs_PADBUSY|SVs_PADMY|SVs_PADTMP);
8990e307
LW
669 switch (SvTYPE(sv)) { /* Console ourselves with a new value */
670 case SVt_PVAV: *(SV**)ptr = (SV*)newAV(); break;
671 case SVt_PVHV: *(SV**)ptr = (SV*)newHV(); break;
672 default: *(SV**)ptr = NEWSV(0,0); break;
673 }
53868620 674 SvREFCNT_dec(sv); /* Cast current value to the winds. */
4aa0a1f7 675 SvFLAGS(*(SV**)ptr) |= padflags; /* preserve pad nature */
8990e307
LW
676 }
677 break;
678 case SAVEt_DELETE:
679 ptr = SSPOPPTR;
680 hv = (HV*)ptr;
681 ptr = SSPOPPTR;
748a9306 682 (void)hv_delete(hv, (char*)ptr, (U32)SSPOPINT, G_DISCARD);
adbc6bb1 683 Safefree(ptr);
8990e307 684 break;
a0d0e21e
LW
685 case SAVEt_DESTRUCTOR:
686 ptr = SSPOPPTR;
687 (*SSPOPDPTR)(ptr);
688 break;
689 case SAVEt_REGCONTEXT:
8e07c86e
AD
690 {
691 I32 delta = SSPOPINT;
692 savestack_ix -= delta; /* regexp must have croaked */
693 }
a0d0e21e 694 break;
55497cff
PP
695 case SAVEt_STACK_POS: /* Position on Perl stack */
696 {
697 I32 delta = SSPOPINT;
698 stack_sp = stack_base + delta;
699 }
700 break;
462e5cf6
MB
701 case SAVEt_OP:
702 op = (OP*)SSPOPPTR;
703 break;
79072805 704 default:
463ee0b2 705 croak("panic: leave_scope inconsistency");
79072805
LW
706 }
707 }
708}
8990e307
LW
709
710#ifdef DEBUGGING
1f96a9ed 711
8990e307 712void
c09156bb 713cx_dump(PERL_CONTEXT *cx)
8990e307 714{
11343788 715 dTHR;
fb73857a 716 PerlIO_printf(Perl_debug_log, "CX %ld = %s\n", (long)(cx - cxstack), block_type[cx->cx_type]);
8990e307 717 if (cx->cx_type != CXt_SUBST) {
760ac839
LW
718 PerlIO_printf(Perl_debug_log, "BLK_OLDSP = %ld\n", (long)cx->blk_oldsp);
719 PerlIO_printf(Perl_debug_log, "BLK_OLDCOP = 0x%lx\n", (long)cx->blk_oldcop);
720 PerlIO_printf(Perl_debug_log, "BLK_OLDMARKSP = %ld\n", (long)cx->blk_oldmarksp);
721 PerlIO_printf(Perl_debug_log, "BLK_OLDSCOPESP = %ld\n", (long)cx->blk_oldscopesp);
722 PerlIO_printf(Perl_debug_log, "BLK_OLDRETSP = %ld\n", (long)cx->blk_oldretsp);
723 PerlIO_printf(Perl_debug_log, "BLK_OLDPM = 0x%lx\n", (long)cx->blk_oldpm);
724 PerlIO_printf(Perl_debug_log, "BLK_GIMME = %s\n", cx->blk_gimme ? "LIST" : "SCALAR");
8990e307
LW
725 }
726 switch (cx->cx_type) {
727 case CXt_NULL:
728 case CXt_BLOCK:
729 break;
730 case CXt_SUB:
760ac839 731 PerlIO_printf(Perl_debug_log, "BLK_SUB.CV = 0x%lx\n",
8990e307 732 (long)cx->blk_sub.cv);
760ac839 733 PerlIO_printf(Perl_debug_log, "BLK_SUB.GV = 0x%lx\n",
8990e307 734 (long)cx->blk_sub.gv);
760ac839 735 PerlIO_printf(Perl_debug_log, "BLK_SUB.DFOUTGV = 0x%lx\n",
8990e307 736 (long)cx->blk_sub.dfoutgv);
760ac839 737 PerlIO_printf(Perl_debug_log, "BLK_SUB.OLDDEPTH = %ld\n",
8990e307 738 (long)cx->blk_sub.olddepth);
760ac839 739 PerlIO_printf(Perl_debug_log, "BLK_SUB.HASARGS = %d\n",
8990e307
LW
740 (int)cx->blk_sub.hasargs);
741 break;
742 case CXt_EVAL:
760ac839 743 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_IN_EVAL = %ld\n",
8990e307 744 (long)cx->blk_eval.old_in_eval);
760ac839 745 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_OP_TYPE = %s (%s)\n",
c07a80fd
PP
746 op_name[cx->blk_eval.old_op_type],
747 op_desc[cx->blk_eval.old_op_type]);
760ac839 748 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_NAME = %s\n",
8990e307 749 cx->blk_eval.old_name);
760ac839 750 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_EVAL_ROOT = 0x%lx\n",
8990e307
LW
751 (long)cx->blk_eval.old_eval_root);
752 break;
753
754 case CXt_LOOP:
760ac839 755 PerlIO_printf(Perl_debug_log, "BLK_LOOP.LABEL = %s\n",
8990e307 756 cx->blk_loop.label);
760ac839 757 PerlIO_printf(Perl_debug_log, "BLK_LOOP.RESETSP = %ld\n",
8990e307 758 (long)cx->blk_loop.resetsp);
760ac839 759 PerlIO_printf(Perl_debug_log, "BLK_LOOP.REDO_OP = 0x%lx\n",
8990e307 760 (long)cx->blk_loop.redo_op);
760ac839 761 PerlIO_printf(Perl_debug_log, "BLK_LOOP.NEXT_OP = 0x%lx\n",
8990e307 762 (long)cx->blk_loop.next_op);
760ac839 763 PerlIO_printf(Perl_debug_log, "BLK_LOOP.LAST_OP = 0x%lx\n",
8990e307 764 (long)cx->blk_loop.last_op);
760ac839 765 PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERIX = %ld\n",
8990e307 766 (long)cx->blk_loop.iterix);
760ac839 767 PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERARY = 0x%lx\n",
8990e307 768 (long)cx->blk_loop.iterary);
760ac839 769 PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERVAR = 0x%lx\n",
8990e307
LW
770 (long)cx->blk_loop.itervar);
771 if (cx->blk_loop.itervar)
760ac839 772 PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERSAVE = 0x%lx\n",
8990e307 773 (long)cx->blk_loop.itersave);
7a4c00b4
PP
774 PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERLVAL = 0x%lx\n",
775 (long)cx->blk_loop.iterlval);
8990e307
LW
776 break;
777
778 case CXt_SUBST:
760ac839 779 PerlIO_printf(Perl_debug_log, "SB_ITERS = %ld\n",
8990e307 780 (long)cx->sb_iters);
760ac839 781 PerlIO_printf(Perl_debug_log, "SB_MAXITERS = %ld\n",
8990e307 782 (long)cx->sb_maxiters);
760ac839 783 PerlIO_printf(Perl_debug_log, "SB_SAFEBASE = %ld\n",
8990e307 784 (long)cx->sb_safebase);
760ac839 785 PerlIO_printf(Perl_debug_log, "SB_ONCE = %ld\n",
8990e307 786 (long)cx->sb_once);
760ac839 787 PerlIO_printf(Perl_debug_log, "SB_ORIG = %s\n",
8990e307 788 cx->sb_orig);
760ac839 789 PerlIO_printf(Perl_debug_log, "SB_DSTR = 0x%lx\n",
8990e307 790 (long)cx->sb_dstr);
760ac839 791 PerlIO_printf(Perl_debug_log, "SB_TARG = 0x%lx\n",
8990e307 792 (long)cx->sb_targ);
760ac839 793 PerlIO_printf(Perl_debug_log, "SB_S = 0x%lx\n",
8990e307 794 (long)cx->sb_s);
760ac839 795 PerlIO_printf(Perl_debug_log, "SB_M = 0x%lx\n",
8990e307 796 (long)cx->sb_m);
760ac839 797 PerlIO_printf(Perl_debug_log, "SB_STREND = 0x%lx\n",
8990e307 798 (long)cx->sb_strend);
c90c0ff4
PP
799 PerlIO_printf(Perl_debug_log, "SB_RXRES = 0x%lx\n",
800 (long)cx->sb_rxres);
8990e307
LW
801 break;
802 }
803}
804#endif