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