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