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