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