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