Commit | Line | Data |
a0d0e21e |
1 | /* scope.c |
79072805 |
2 | * |
4bb101f2 |
3 | * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, |
54ca4ee7 |
4 | * 2000, 2001, 2002, 2003, 2004, 2005, 2006, 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. */ |
65 | Poison(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. */ |
78 | Poison(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 | |
a0d0e21e |
168 | if (SvTYPE(osv) >= SVt_PVMG && SvMAGIC(osv) && SvTYPE(osv) != SVt_PVGV) { |
a0d0e21e |
169 | if (SvGMAGICAL(osv)) { |
35a4481c |
170 | const bool oldtainted = PL_tainted; |
a0d0e21e |
171 | SvFLAGS(osv) |= (SvFLAGS(osv) & |
c268c2a6 |
172 | (SVp_IOK|SVp_NOK|SVp_POK)) >> PRIVSHIFT; |
3280af22 |
173 | PL_tainted = oldtainted; |
a0d0e21e |
174 | } |
0cbee0a4 |
175 | mg_localize(osv, sv); |
79072805 |
176 | } |
177 | return sv; |
178 | } |
179 | |
7a4c00b4 |
180 | SV * |
864dbfa3 |
181 | Perl_save_scalar(pTHX_ GV *gv) |
7a4c00b4 |
182 | { |
97aff369 |
183 | dVAR; |
7452cf6a |
184 | SV ** const sptr = &GvSV(gv); |
27cc343c |
185 | PL_localizing = 1; |
0cbee0a4 |
186 | SvGETMAGIC(*sptr); |
27cc343c |
187 | PL_localizing = 0; |
7a4c00b4 |
188 | SSCHECK(3); |
4e4c362e |
189 | SSPUSHPTR(SvREFCNT_inc(gv)); |
190 | SSPUSHPTR(SvREFCNT_inc(*sptr)); |
7a4c00b4 |
191 | SSPUSHINT(SAVEt_SV); |
4e4c362e |
192 | return save_scalar_at(sptr); |
7a4c00b4 |
193 | } |
194 | |
f4dd75d9 |
195 | /* Like save_sptr(), but also SvREFCNT_dec()s the new value. Can be used to |
b9d12d37 |
196 | * restore a global SV to its prior contents, freeing new value. */ |
197 | void |
864dbfa3 |
198 | Perl_save_generic_svref(pTHX_ SV **sptr) |
b9d12d37 |
199 | { |
97aff369 |
200 | dVAR; |
b9d12d37 |
201 | SSCHECK(3); |
202 | SSPUSHPTR(sptr); |
203 | SSPUSHPTR(SvREFCNT_inc(*sptr)); |
204 | SSPUSHINT(SAVEt_GENERIC_SVREF); |
205 | } |
206 | |
f4dd75d9 |
207 | /* Like save_pptr(), but also Safefree()s the new value if it is different |
208 | * from the old one. Can be used to restore a global char* to its prior |
209 | * contents, freeing new value. */ |
210 | void |
211 | Perl_save_generic_pvref(pTHX_ char **str) |
212 | { |
97aff369 |
213 | dVAR; |
f4dd75d9 |
214 | SSCHECK(3); |
215 | SSPUSHPTR(str); |
216 | SSPUSHPTR(*str); |
217 | SSPUSHINT(SAVEt_GENERIC_PVREF); |
218 | } |
219 | |
05ec9bb3 |
220 | /* Like save_generic_pvref(), but uses PerlMemShared_free() rather than Safefree(). |
221 | * Can be used to restore a shared global char* to its prior |
222 | * contents, freeing new value. */ |
223 | void |
224 | Perl_save_shared_pvref(pTHX_ char **str) |
225 | { |
97aff369 |
226 | dVAR; |
05ec9bb3 |
227 | SSCHECK(3); |
228 | SSPUSHPTR(str); |
229 | SSPUSHPTR(*str); |
230 | SSPUSHINT(SAVEt_SHARED_PVREF); |
231 | } |
232 | |
14f338dc |
233 | /* set the SvFLAGS specified by mask to the values in val */ |
234 | |
235 | void |
236 | Perl_save_set_svflags(pTHX_ SV* sv, U32 mask, U32 val) |
237 | { |
97aff369 |
238 | dVAR; |
14f338dc |
239 | SSCHECK(4); |
240 | SSPUSHPTR(sv); |
241 | SSPUSHINT(mask); |
242 | SSPUSHINT(val); |
243 | SSPUSHINT(SAVEt_SET_SVFLAGS); |
244 | } |
245 | |
79072805 |
246 | void |
864dbfa3 |
247 | Perl_save_gp(pTHX_ GV *gv, I32 empty) |
79072805 |
248 | { |
97aff369 |
249 | dVAR; |
4b3c1a47 |
250 | SSGROW(6); |
fb73857a |
251 | SSPUSHIV((IV)SvLEN(gv)); |
b162af07 |
252 | SvLEN_set(gv, 0); /* forget that anything was allocated here */ |
fb73857a |
253 | SSPUSHIV((IV)SvCUR(gv)); |
aa07b2f6 |
254 | SSPUSHPTR(SvPVX_const(gv)); |
fb73857a |
255 | SvPOK_off(gv); |
4633a7c4 |
256 | SSPUSHPTR(SvREFCNT_inc(gv)); |
5f05dabc |
257 | SSPUSHPTR(GvGP(gv)); |
79072805 |
258 | SSPUSHINT(SAVEt_GP); |
259 | |
5f05dabc |
260 | if (empty) { |
261 | register GP *gp; |
fae75791 |
262 | |
a02a5408 |
263 | Newxz(gp, 1, GP); |
146174a9 |
264 | |
fae75791 |
265 | if (GvCVu(gv)) |
3280af22 |
266 | PL_sub_generation++; /* taking a method out of circulation */ |
146174a9 |
267 | if (GvIOp(gv) && (IoFLAGS(GvIOp(gv)) & IOf_ARGV)) { |
268 | gp->gp_io = newIO(); |
269 | IoFLAGS(gp->gp_io) |= IOf_ARGV|IOf_START; |
270 | } |
44a8e56a |
271 | GvGP(gv) = gp_ref(gp); |
561b68a9 |
272 | GvSV(gv) = newSV(0); |
146174a9 |
273 | GvLINE(gv) = CopLINE(PL_curcop); |
07409e01 |
274 | /* XXX Ideally this cast would be replaced with a change to const char* |
275 | in the struct. */ |
276 | GvFILE(gv) = CopFILE(PL_curcop) ? CopFILE(PL_curcop) : (char *) ""; |
5f05dabc |
277 | GvEGV(gv) = gv; |
278 | } |
279 | else { |
44a8e56a |
280 | gp_ref(GvGP(gv)); |
5f05dabc |
281 | GvINTRO_on(gv); |
282 | } |
79072805 |
283 | } |
79072805 |
284 | |
79072805 |
285 | AV * |
864dbfa3 |
286 | Perl_save_ary(pTHX_ GV *gv) |
79072805 |
287 | { |
97aff369 |
288 | dVAR; |
901017d6 |
289 | AV * const oav = GvAVn(gv); |
67a38de0 |
290 | AV *av; |
fb73857a |
291 | |
67a38de0 |
292 | if (!AvREAL(oav) && AvREIFY(oav)) |
293 | av_reify(oav); |
79072805 |
294 | SSCHECK(3); |
295 | SSPUSHPTR(gv); |
67a38de0 |
296 | SSPUSHPTR(oav); |
79072805 |
297 | SSPUSHINT(SAVEt_AV); |
298 | |
4608196e |
299 | GvAV(gv) = NULL; |
fb73857a |
300 | av = GvAVn(gv); |
0cbee0a4 |
301 | if (SvMAGIC(oav)) |
302 | mg_localize((SV*)oav, (SV*)av); |
fb73857a |
303 | return av; |
79072805 |
304 | } |
305 | |
306 | HV * |
864dbfa3 |
307 | Perl_save_hash(pTHX_ GV *gv) |
79072805 |
308 | { |
97aff369 |
309 | dVAR; |
fb73857a |
310 | HV *ohv, *hv; |
311 | |
79072805 |
312 | SSCHECK(3); |
313 | SSPUSHPTR(gv); |
fb73857a |
314 | SSPUSHPTR(ohv = GvHVn(gv)); |
79072805 |
315 | SSPUSHINT(SAVEt_HV); |
316 | |
4608196e |
317 | GvHV(gv) = NULL; |
fb73857a |
318 | hv = GvHVn(gv); |
0cbee0a4 |
319 | if (SvMAGIC(ohv)) |
320 | mg_localize((SV*)ohv, (SV*)hv); |
fb73857a |
321 | return hv; |
79072805 |
322 | } |
323 | |
324 | void |
864dbfa3 |
325 | Perl_save_item(pTHX_ register SV *item) |
79072805 |
326 | { |
97aff369 |
327 | dVAR; |
901017d6 |
328 | register SV * const sv = newSVsv(item); |
79072805 |
329 | |
330 | SSCHECK(3); |
331 | SSPUSHPTR(item); /* remember the pointer */ |
79072805 |
332 | SSPUSHPTR(sv); /* remember the value */ |
333 | SSPUSHINT(SAVEt_ITEM); |
334 | } |
335 | |
336 | void |
864dbfa3 |
337 | Perl_save_int(pTHX_ int *intp) |
79072805 |
338 | { |
97aff369 |
339 | dVAR; |
79072805 |
340 | SSCHECK(3); |
341 | SSPUSHINT(*intp); |
342 | SSPUSHPTR(intp); |
343 | SSPUSHINT(SAVEt_INT); |
344 | } |
345 | |
346 | void |
9febdf04 |
347 | Perl_save_bool(pTHX_ bool *boolp) |
348 | { |
97aff369 |
349 | dVAR; |
9febdf04 |
350 | SSCHECK(3); |
351 | SSPUSHBOOL(*boolp); |
352 | SSPUSHPTR(boolp); |
353 | SSPUSHINT(SAVEt_BOOL); |
354 | } |
355 | |
356 | void |
864dbfa3 |
357 | Perl_save_I32(pTHX_ I32 *intp) |
79072805 |
358 | { |
97aff369 |
359 | dVAR; |
79072805 |
360 | SSCHECK(3); |
361 | SSPUSHINT(*intp); |
362 | SSPUSHPTR(intp); |
363 | SSPUSHINT(SAVEt_I32); |
364 | } |
365 | |
85e6fe83 |
366 | /* Cannot use save_sptr() to store a char* since the SV** cast will |
367 | * force word-alignment and we'll miss the pointer. |
368 | */ |
369 | void |
864dbfa3 |
370 | Perl_save_pptr(pTHX_ char **pptr) |
85e6fe83 |
371 | { |
97aff369 |
372 | dVAR; |
85e6fe83 |
373 | SSCHECK(3); |
374 | SSPUSHPTR(*pptr); |
375 | SSPUSHPTR(pptr); |
376 | SSPUSHINT(SAVEt_PPTR); |
377 | } |
378 | |
79072805 |
379 | void |
146174a9 |
380 | Perl_save_vptr(pTHX_ void *ptr) |
381 | { |
97aff369 |
382 | dVAR; |
146174a9 |
383 | SSCHECK(3); |
384 | SSPUSHPTR(*(char**)ptr); |
385 | SSPUSHPTR(ptr); |
386 | SSPUSHINT(SAVEt_VPTR); |
387 | } |
388 | |
389 | void |
864dbfa3 |
390 | Perl_save_sptr(pTHX_ SV **sptr) |
79072805 |
391 | { |
97aff369 |
392 | dVAR; |
79072805 |
393 | SSCHECK(3); |
394 | SSPUSHPTR(*sptr); |
395 | SSPUSHPTR(sptr); |
396 | SSPUSHINT(SAVEt_SPTR); |
397 | } |
398 | |
c3564e5c |
399 | void |
400 | Perl_save_padsv(pTHX_ PADOFFSET off) |
401 | { |
97aff369 |
402 | dVAR; |
c3564e5c |
403 | SSCHECK(4); |
f3548bdc |
404 | ASSERT_CURPAD_ACTIVE("save_padsv"); |
c3564e5c |
405 | SSPUSHPTR(PL_curpad[off]); |
f3548bdc |
406 | SSPUSHPTR(PL_comppad); |
c3564e5c |
407 | SSPUSHLONG((long)off); |
408 | SSPUSHINT(SAVEt_PADSV); |
409 | } |
410 | |
79072805 |
411 | void |
864dbfa3 |
412 | Perl_save_hptr(pTHX_ HV **hptr) |
79072805 |
413 | { |
97aff369 |
414 | dVAR; |
79072805 |
415 | SSCHECK(3); |
85e6fe83 |
416 | SSPUSHPTR(*hptr); |
79072805 |
417 | SSPUSHPTR(hptr); |
418 | SSPUSHINT(SAVEt_HPTR); |
419 | } |
420 | |
421 | void |
864dbfa3 |
422 | Perl_save_aptr(pTHX_ AV **aptr) |
79072805 |
423 | { |
97aff369 |
424 | dVAR; |
79072805 |
425 | SSCHECK(3); |
85e6fe83 |
426 | SSPUSHPTR(*aptr); |
79072805 |
427 | SSPUSHPTR(aptr); |
428 | SSPUSHINT(SAVEt_APTR); |
429 | } |
430 | |
431 | void |
864dbfa3 |
432 | Perl_save_freesv(pTHX_ SV *sv) |
8990e307 |
433 | { |
97aff369 |
434 | dVAR; |
8990e307 |
435 | SSCHECK(2); |
436 | SSPUSHPTR(sv); |
437 | SSPUSHINT(SAVEt_FREESV); |
438 | } |
439 | |
440 | void |
26d9b02f |
441 | Perl_save_mortalizesv(pTHX_ SV *sv) |
442 | { |
97aff369 |
443 | dVAR; |
26d9b02f |
444 | SSCHECK(2); |
445 | SSPUSHPTR(sv); |
446 | SSPUSHINT(SAVEt_MORTALIZESV); |
447 | } |
448 | |
449 | void |
864dbfa3 |
450 | Perl_save_freeop(pTHX_ OP *o) |
8990e307 |
451 | { |
97aff369 |
452 | dVAR; |
8990e307 |
453 | SSCHECK(2); |
11343788 |
454 | SSPUSHPTR(o); |
8990e307 |
455 | SSPUSHINT(SAVEt_FREEOP); |
456 | } |
457 | |
458 | void |
864dbfa3 |
459 | Perl_save_freepv(pTHX_ char *pv) |
8990e307 |
460 | { |
97aff369 |
461 | dVAR; |
8990e307 |
462 | SSCHECK(2); |
463 | SSPUSHPTR(pv); |
464 | SSPUSHINT(SAVEt_FREEPV); |
465 | } |
466 | |
467 | void |
864dbfa3 |
468 | Perl_save_clearsv(pTHX_ SV **svp) |
8990e307 |
469 | { |
97aff369 |
470 | dVAR; |
f3548bdc |
471 | ASSERT_CURPAD_ACTIVE("save_clearsv"); |
8990e307 |
472 | SSCHECK(2); |
3280af22 |
473 | SSPUSHLONG((long)(svp-PL_curpad)); |
8990e307 |
474 | SSPUSHINT(SAVEt_CLEARSV); |
d9d18af6 |
475 | SvPADSTALE_off(*svp); /* mark lexical as active */ |
8990e307 |
476 | } |
477 | |
478 | void |
864dbfa3 |
479 | Perl_save_delete(pTHX_ HV *hv, char *key, I32 klen) |
8990e307 |
480 | { |
97aff369 |
481 | dVAR; |
8990e307 |
482 | SSCHECK(4); |
483 | SSPUSHINT(klen); |
484 | SSPUSHPTR(key); |
4e4c362e |
485 | SSPUSHPTR(SvREFCNT_inc(hv)); |
8990e307 |
486 | SSPUSHINT(SAVEt_DELETE); |
487 | } |
488 | |
489 | void |
146174a9 |
490 | Perl_save_destructor_x(pTHX_ DESTRUCTORFUNC_t f, void* p) |
491 | { |
97aff369 |
492 | dVAR; |
146174a9 |
493 | SSCHECK(3); |
494 | SSPUSHDXPTR(f); |
495 | SSPUSHPTR(p); |
496 | SSPUSHINT(SAVEt_DESTRUCTOR_X); |
497 | } |
498 | |
499 | void |
35a4481c |
500 | Perl_save_aelem(pTHX_ const AV *av, I32 idx, SV **sptr) |
4e4c362e |
501 | { |
97aff369 |
502 | dVAR; |
bfc4de9f |
503 | SV *sv; |
0cbee0a4 |
504 | SvGETMAGIC(*sptr); |
4e4c362e |
505 | SSCHECK(4); |
506 | SSPUSHPTR(SvREFCNT_inc(av)); |
507 | SSPUSHINT(idx); |
508 | SSPUSHPTR(SvREFCNT_inc(*sptr)); |
509 | SSPUSHINT(SAVEt_AELEM); |
5dd42e15 |
510 | /* if it gets reified later, the restore will have the wrong refcnt */ |
511 | if (!AvREAL(av) && AvREIFY(av)) |
7fc63493 |
512 | (void)SvREFCNT_inc(*sptr); |
4e4c362e |
513 | save_scalar_at(sptr); |
bfc4de9f |
514 | sv = *sptr; |
515 | /* If we're localizing a tied array element, this new sv |
516 | * won't actually be stored in the array - so it won't get |
517 | * reaped when the localize ends. Ensure it gets reaped by |
518 | * mortifying it instead. DAPM */ |
519 | if (SvTIED_mg(sv, PERL_MAGIC_tiedelem)) |
520 | sv_2mortal(sv); |
4e4c362e |
521 | } |
522 | |
523 | void |
e1ec3a88 |
524 | Perl_save_helem(pTHX_ HV *hv, SV *key, SV **sptr) |
4e4c362e |
525 | { |
97aff369 |
526 | dVAR; |
bfc4de9f |
527 | SV *sv; |
0cbee0a4 |
528 | SvGETMAGIC(*sptr); |
4e4c362e |
529 | SSCHECK(4); |
530 | SSPUSHPTR(SvREFCNT_inc(hv)); |
531 | SSPUSHPTR(SvREFCNT_inc(key)); |
532 | SSPUSHPTR(SvREFCNT_inc(*sptr)); |
533 | SSPUSHINT(SAVEt_HELEM); |
534 | save_scalar_at(sptr); |
bfc4de9f |
535 | sv = *sptr; |
536 | /* If we're localizing a tied hash element, this new sv |
537 | * won't actually be stored in the hash - so it won't get |
538 | * reaped when the localize ends. Ensure it gets reaped by |
539 | * mortifying it instead. DAPM */ |
540 | if (SvTIED_mg(sv, PERL_MAGIC_tiedelem)) |
541 | sv_2mortal(sv); |
4e4c362e |
542 | } |
543 | |
2053acbf |
544 | SV* |
545 | Perl_save_svref(pTHX_ SV **sptr) |
546 | { |
547 | dVAR; |
548 | SvGETMAGIC(*sptr); |
549 | SSCHECK(3); |
550 | SSPUSHPTR(sptr); |
551 | SSPUSHPTR(SvREFCNT_inc(*sptr)); |
552 | SSPUSHINT(SAVEt_SVREF); |
553 | return save_scalar_at(sptr); |
554 | } |
555 | |
4e4c362e |
556 | void |
864dbfa3 |
557 | Perl_save_op(pTHX) |
462e5cf6 |
558 | { |
97aff369 |
559 | dVAR; |
462e5cf6 |
560 | SSCHECK(2); |
533c011a |
561 | SSPUSHPTR(PL_op); |
462e5cf6 |
562 | SSPUSHINT(SAVEt_OP); |
563 | } |
564 | |
455ece5e |
565 | I32 |
864dbfa3 |
566 | Perl_save_alloc(pTHX_ I32 size, I32 pad) |
455ece5e |
567 | { |
97aff369 |
568 | dVAR; |
35a4481c |
569 | register const I32 start = pad + ((char*)&PL_savestack[PL_savestack_ix] |
8aacddc1 |
570 | - (char*)PL_savestack); |
35a4481c |
571 | register const I32 elems = 1 + ((size + pad - 1) / sizeof(*PL_savestack)); |
455ece5e |
572 | |
573 | /* SSCHECK may not be good enough */ |
574 | while (PL_savestack_ix + elems + 2 > PL_savestack_max) |
8aacddc1 |
575 | savestack_grow(); |
455ece5e |
576 | |
577 | PL_savestack_ix += elems; |
578 | SSPUSHINT(elems); |
579 | SSPUSHINT(SAVEt_ALLOC); |
580 | return start; |
581 | } |
582 | |
462e5cf6 |
583 | void |
864dbfa3 |
584 | Perl_leave_scope(pTHX_ I32 base) |
79072805 |
585 | { |
97aff369 |
586 | dVAR; |
79072805 |
587 | register SV *sv; |
588 | register SV *value; |
589 | register GV *gv; |
590 | register AV *av; |
591 | register HV *hv; |
20454177 |
592 | void* ptr; |
f4dd75d9 |
593 | register char* str; |
161b7d16 |
594 | I32 i; |
79072805 |
595 | |
596 | if (base < -1) |
cea2e8a9 |
597 | Perl_croak(aTHX_ "panic: corrupt saved stack index"); |
3280af22 |
598 | while (PL_savestack_ix > base) { |
79072805 |
599 | switch (SSPOPINT) { |
600 | case SAVEt_ITEM: /* normal string */ |
601 | value = (SV*)SSPOPPTR; |
602 | sv = (SV*)SSPOPPTR; |
603 | sv_replace(sv,value); |
3280af22 |
604 | PL_localizing = 2; |
79072805 |
605 | SvSETMAGIC(sv); |
3280af22 |
606 | PL_localizing = 0; |
79072805 |
607 | break; |
8aacddc1 |
608 | case SAVEt_SV: /* scalar reference */ |
79072805 |
609 | value = (SV*)SSPOPPTR; |
610 | gv = (GV*)SSPOPPTR; |
7a4c00b4 |
611 | ptr = &GvSV(gv); |
5dd42e15 |
612 | av = (AV*)gv; /* what to refcnt_dec */ |
2053acbf |
613 | restore_sv: |
614 | sv = *(SV**)ptr; |
615 | DEBUG_S(PerlIO_printf(Perl_debug_log, |
616 | "restore svref: %p %p:%s -> %p:%s\n", |
617 | ptr, sv, SvPEEK(sv), value, SvPEEK(value))); |
618 | *(SV**)ptr = value; |
619 | SvREFCNT_dec(sv); |
620 | PL_localizing = 2; |
621 | SvSETMAGIC(value); |
622 | PL_localizing = 0; |
623 | SvREFCNT_dec(value); |
624 | if (av) /* actually an av, hv or gv */ |
625 | SvREFCNT_dec(av); |
626 | break; |
8aacddc1 |
627 | case SAVEt_GENERIC_PVREF: /* generic pv */ |
f4dd75d9 |
628 | str = (char*)SSPOPPTR; |
629 | ptr = SSPOPPTR; |
630 | if (*(char**)ptr != str) { |
631 | Safefree(*(char**)ptr); |
632 | *(char**)ptr = str; |
633 | } |
634 | break; |
05ec9bb3 |
635 | case SAVEt_SHARED_PVREF: /* shared pv */ |
636 | str = (char*)SSPOPPTR; |
637 | ptr = SSPOPPTR; |
638 | if (*(char**)ptr != str) { |
5e54c26f |
639 | #ifdef NETWARE |
9ecbcc42 |
640 | PerlMem_free(*(char**)ptr); |
5e54c26f |
641 | #else |
05ec9bb3 |
642 | PerlMemShared_free(*(char**)ptr); |
5e54c26f |
643 | #endif |
05ec9bb3 |
644 | *(char**)ptr = str; |
645 | } |
646 | break; |
8aacddc1 |
647 | case SAVEt_GENERIC_SVREF: /* generic sv */ |
b9d12d37 |
648 | value = (SV*)SSPOPPTR; |
649 | ptr = SSPOPPTR; |
f4dd75d9 |
650 | sv = *(SV**)ptr; |
651 | *(SV**)ptr = value; |
652 | SvREFCNT_dec(sv); |
b9d12d37 |
653 | SvREFCNT_dec(value); |
654 | break; |
8aacddc1 |
655 | case SAVEt_AV: /* array reference */ |
79072805 |
656 | av = (AV*)SSPOPPTR; |
657 | gv = (GV*)SSPOPPTR; |
fb73857a |
658 | if (GvAV(gv)) { |
35a4481c |
659 | AV * const goner = GvAV(gv); |
404a4710 |
660 | /* FIXME - this is a temporary hack until we work out what |
661 | the correct behaviour for magic should be. */ |
662 | sv_unmagic((SV*)goner, PERL_MAGIC_arylen_p); |
b162af07 |
663 | SvMAGIC_set(av, SvMAGIC(goner)); |
32da55ab |
664 | SvFLAGS((SV*)av) |= SvMAGICAL(goner); |
fb73857a |
665 | SvMAGICAL_off(goner); |
b162af07 |
666 | SvMAGIC_set(goner, NULL); |
fb73857a |
667 | SvREFCNT_dec(goner); |
668 | } |
8aacddc1 |
669 | GvAV(gv) = av; |
fb73857a |
670 | if (SvMAGICAL(av)) { |
3280af22 |
671 | PL_localizing = 2; |
fb73857a |
672 | SvSETMAGIC((SV*)av); |
3280af22 |
673 | PL_localizing = 0; |
fb73857a |
674 | } |
8aacddc1 |
675 | break; |
676 | case SAVEt_HV: /* hash reference */ |
79072805 |
677 | hv = (HV*)SSPOPPTR; |
678 | gv = (GV*)SSPOPPTR; |
fb73857a |
679 | if (GvHV(gv)) { |
35a4481c |
680 | HV * const goner = GvHV(gv); |
b162af07 |
681 | SvMAGIC_set(hv, SvMAGIC(goner)); |
fb73857a |
682 | SvFLAGS(hv) |= SvMAGICAL(goner); |
683 | SvMAGICAL_off(goner); |
b162af07 |
684 | SvMAGIC_set(goner, NULL); |
fb73857a |
685 | SvREFCNT_dec(goner); |
686 | } |
8aacddc1 |
687 | GvHV(gv) = hv; |
fb73857a |
688 | if (SvMAGICAL(hv)) { |
3280af22 |
689 | PL_localizing = 2; |
fb73857a |
690 | SvSETMAGIC((SV*)hv); |
3280af22 |
691 | PL_localizing = 0; |
fb73857a |
692 | } |
8aacddc1 |
693 | break; |
79072805 |
694 | case SAVEt_INT: /* int reference */ |
695 | ptr = SSPOPPTR; |
696 | *(int*)ptr = (int)SSPOPINT; |
697 | break; |
9febdf04 |
698 | case SAVEt_BOOL: /* bool reference */ |
699 | ptr = SSPOPPTR; |
700 | *(bool*)ptr = (bool)SSPOPBOOL; |
701 | break; |
79072805 |
702 | case SAVEt_I32: /* I32 reference */ |
703 | ptr = SSPOPPTR; |
704 | *(I32*)ptr = (I32)SSPOPINT; |
705 | break; |
706 | case SAVEt_SPTR: /* SV* reference */ |
707 | ptr = SSPOPPTR; |
708 | *(SV**)ptr = (SV*)SSPOPPTR; |
709 | break; |
146174a9 |
710 | case SAVEt_VPTR: /* random* reference */ |
85e6fe83 |
711 | case SAVEt_PPTR: /* char* reference */ |
712 | ptr = SSPOPPTR; |
713 | *(char**)ptr = (char*)SSPOPPTR; |
714 | break; |
79072805 |
715 | case SAVEt_HPTR: /* HV* reference */ |
716 | ptr = SSPOPPTR; |
717 | *(HV**)ptr = (HV*)SSPOPPTR; |
718 | break; |
719 | case SAVEt_APTR: /* AV* reference */ |
720 | ptr = SSPOPPTR; |
721 | *(AV**)ptr = (AV*)SSPOPPTR; |
722 | break; |
fb73857a |
723 | case SAVEt_GP: /* scalar reference */ |
79072805 |
724 | ptr = SSPOPPTR; |
725 | gv = (GV*)SSPOPPTR; |
aa07b2f6 |
726 | if (SvPVX_const(gv) && SvLEN(gv) > 0) { |
94010e71 |
727 | Safefree(SvPVX_mutable(gv)); |
8aacddc1 |
728 | } |
f880fe2f |
729 | SvPV_set(gv, (char *)SSPOPPTR); |
b162af07 |
730 | SvCUR_set(gv, (STRLEN)SSPOPIV); |
731 | SvLEN_set(gv, (STRLEN)SSPOPIV); |
8aacddc1 |
732 | gp_free(gv); |
733 | GvGP(gv) = (GP*)ptr; |
fae75791 |
734 | if (GvCVu(gv)) |
3280af22 |
735 | PL_sub_generation++; /* putting a method back into circulation */ |
4633a7c4 |
736 | SvREFCNT_dec(gv); |
8aacddc1 |
737 | break; |
8990e307 |
738 | case SAVEt_FREESV: |
739 | ptr = SSPOPPTR; |
740 | SvREFCNT_dec((SV*)ptr); |
741 | break; |
26d9b02f |
742 | case SAVEt_MORTALIZESV: |
743 | ptr = SSPOPPTR; |
744 | sv_2mortal((SV*)ptr); |
745 | break; |
8990e307 |
746 | case SAVEt_FREEOP: |
747 | ptr = SSPOPPTR; |
f3548bdc |
748 | ASSERT_CURPAD_LEGAL("SAVEt_FREEOP"); /* XXX DAPM tmp */ |
8990e307 |
749 | op_free((OP*)ptr); |
750 | break; |
751 | case SAVEt_FREEPV: |
752 | ptr = SSPOPPTR; |
1df70142 |
753 | Safefree(ptr); |
8990e307 |
754 | break; |
755 | case SAVEt_CLEARSV: |
3280af22 |
756 | ptr = (void*)&PL_curpad[SSPOPLONG]; |
8990e307 |
757 | sv = *(SV**)ptr; |
dd2155a4 |
758 | |
759 | DEBUG_Xv(PerlIO_printf(Perl_debug_log, |
f3548bdc |
760 | "Pad 0x%"UVxf"[0x%"UVxf"] clearsv: %ld sv=0x%"UVxf"<%"IVdf"> %s\n", |
761 | PTR2UV(PL_comppad), PTR2UV(PL_curpad), |
762 | (long)((SV **)ptr-PL_curpad), PTR2UV(sv), (IV)SvREFCNT(sv), |
dd2155a4 |
763 | (SvREFCNT(sv) <= 1 && !SvOBJECT(sv)) ? "clear" : "abandon" |
764 | )); |
765 | |
bc44cdaf |
766 | /* Can clear pad variable in place? */ |
767 | if (SvREFCNT(sv) <= 1 && !SvOBJECT(sv)) { |
8aacddc1 |
768 | /* |
769 | * if a my variable that was made readonly is going out of |
770 | * scope, we want to remove the readonlyness so that it can |
771 | * go out of scope quietly |
8aacddc1 |
772 | */ |
a26e96df |
773 | if (SvPADMY(sv) && !SvFAKE(sv)) |
8aacddc1 |
774 | SvREADONLY_off(sv); |
775 | |
6fc92669 |
776 | if (SvTHINKFIRST(sv)) |
840a7b70 |
777 | sv_force_normal_flags(sv, SV_IMMEDIATE_UNREF); |
a0d0e21e |
778 | if (SvMAGICAL(sv)) |
779 | mg_free(sv); |
8990e307 |
780 | |
781 | switch (SvTYPE(sv)) { |
782 | case SVt_NULL: |
783 | break; |
784 | case SVt_PVAV: |
44a8e56a |
785 | av_clear((AV*)sv); |
8990e307 |
786 | break; |
787 | case SVt_PVHV: |
44a8e56a |
788 | hv_clear((HV*)sv); |
8990e307 |
789 | break; |
790 | case SVt_PVCV: |
cea2e8a9 |
791 | Perl_croak(aTHX_ "panic: leave_scope pad code"); |
8990e307 |
792 | default: |
0c34ef67 |
793 | SvOK_off(sv); |
8990e307 |
794 | break; |
795 | } |
d9d18af6 |
796 | SvPADSTALE_on(sv); /* mark as no longer live */ |
8990e307 |
797 | } |
798 | else { /* Someone has a claim on this, so abandon it. */ |
35a4481c |
799 | const U32 padflags = SvFLAGS(sv) & (SVs_PADMY|SVs_PADTMP); |
8990e307 |
800 | switch (SvTYPE(sv)) { /* Console ourselves with a new value */ |
801 | case SVt_PVAV: *(SV**)ptr = (SV*)newAV(); break; |
802 | case SVt_PVHV: *(SV**)ptr = (SV*)newHV(); break; |
561b68a9 |
803 | default: *(SV**)ptr = newSV(0); break; |
8990e307 |
804 | } |
53868620 |
805 | SvREFCNT_dec(sv); /* Cast current value to the winds. */ |
d9d18af6 |
806 | /* preserve pad nature, but also mark as not live |
807 | * for any closure capturing */ |
2740392c |
808 | SvFLAGS(*(SV**)ptr) |= padflags | SVs_PADSTALE; |
8990e307 |
809 | } |
810 | break; |
811 | case SAVEt_DELETE: |
812 | ptr = SSPOPPTR; |
813 | hv = (HV*)ptr; |
814 | ptr = SSPOPPTR; |
748a9306 |
815 | (void)hv_delete(hv, (char*)ptr, (U32)SSPOPINT, G_DISCARD); |
4e4c362e |
816 | SvREFCNT_dec(hv); |
8aacddc1 |
817 | Safefree(ptr); |
8990e307 |
818 | break; |
146174a9 |
819 | case SAVEt_DESTRUCTOR_X: |
820 | ptr = SSPOPPTR; |
acfe0abc |
821 | (*SSPOPDXPTR)(aTHX_ ptr); |
a0d0e21e |
822 | break; |
823 | case SAVEt_REGCONTEXT: |
455ece5e |
824 | case SAVEt_ALLOC: |
161b7d16 |
825 | i = SSPOPINT; |
3280af22 |
826 | PL_savestack_ix -= i; /* regexp must have croaked */ |
a0d0e21e |
827 | break; |
55497cff |
828 | case SAVEt_STACK_POS: /* Position on Perl stack */ |
161b7d16 |
829 | i = SSPOPINT; |
3280af22 |
830 | PL_stack_sp = PL_stack_base + i; |
55497cff |
831 | break; |
161b7d16 |
832 | case SAVEt_AELEM: /* array element */ |
833 | value = (SV*)SSPOPPTR; |
834 | i = SSPOPINT; |
835 | av = (AV*)SSPOPPTR; |
5dd42e15 |
836 | if (!AvREAL(av) && AvREIFY(av)) /* undo reify guard */ |
837 | SvREFCNT_dec(value); |
161b7d16 |
838 | ptr = av_fetch(av,i,1); |
4e4c362e |
839 | if (ptr) { |
840 | sv = *(SV**)ptr; |
3280af22 |
841 | if (sv && sv != &PL_sv_undef) { |
14befaf4 |
842 | if (SvTIED_mg((SV*)av, PERL_MAGIC_tied)) |
4e4c362e |
843 | (void)SvREFCNT_inc(sv); |
4e4c362e |
844 | goto restore_sv; |
845 | } |
846 | } |
847 | SvREFCNT_dec(av); |
848 | SvREFCNT_dec(value); |
849 | break; |
161b7d16 |
850 | case SAVEt_HELEM: /* hash element */ |
851 | value = (SV*)SSPOPPTR; |
9002cb76 |
852 | sv = (SV*)SSPOPPTR; |
161b7d16 |
853 | hv = (HV*)SSPOPPTR; |
854 | ptr = hv_fetch_ent(hv, sv, 1, 0); |
4e4c362e |
855 | if (ptr) { |
35a4481c |
856 | const SV * const oval = HeVAL((HE*)ptr); |
3280af22 |
857 | if (oval && oval != &PL_sv_undef) { |
4e4c362e |
858 | ptr = &HeVAL((HE*)ptr); |
14befaf4 |
859 | if (SvTIED_mg((SV*)hv, PERL_MAGIC_tied)) |
4e4c362e |
860 | (void)SvREFCNT_inc(*(SV**)ptr); |
4e4c362e |
861 | SvREFCNT_dec(sv); |
5dd42e15 |
862 | av = (AV*)hv; /* what to refcnt_dec */ |
4e4c362e |
863 | goto restore_sv; |
864 | } |
865 | } |
866 | SvREFCNT_dec(hv); |
867 | SvREFCNT_dec(sv); |
868 | SvREFCNT_dec(value); |
869 | break; |
462e5cf6 |
870 | case SAVEt_OP: |
533c011a |
871 | PL_op = (OP*)SSPOPPTR; |
462e5cf6 |
872 | break; |
25eaa213 |
873 | case SAVEt_HINTS: |
045ac317 |
874 | if ((PL_hints & HINT_LOCALIZE_HH) && GvHV(PL_hintgv)) { |
875 | SvREFCNT_dec((SV*)GvHV(PL_hintgv)); |
876 | GvHV(PL_hintgv) = NULL; |
877 | } |
3280af22 |
878 | *(I32*)&PL_hints = (I32)SSPOPINT; |
dfa41748 |
879 | if (PL_hints & HINT_LOCALIZE_HH) { |
880 | SvREFCNT_dec((SV*)GvHV(PL_hintgv)); |
881 | GvHV(PL_hintgv) = (HV*)SSPOPPTR; |
882 | } |
883 | |
b3ac6de7 |
884 | break; |
cb50131a |
885 | case SAVEt_COMPPAD: |
f3548bdc |
886 | PL_comppad = (PAD*)SSPOPPTR; |
58ed4fbe |
887 | if (PL_comppad) |
cb50131a |
888 | PL_curpad = AvARRAY(PL_comppad); |
889 | else |
4608196e |
890 | PL_curpad = NULL; |
cb50131a |
891 | break; |
c3564e5c |
892 | case SAVEt_PADSV: |
893 | { |
35a4481c |
894 | const PADOFFSET off = (PADOFFSET)SSPOPLONG; |
c3564e5c |
895 | ptr = SSPOPPTR; |
896 | if (ptr) |
f3548bdc |
897 | AvARRAY((PAD*)ptr)[off] = (SV*)SSPOPPTR; |
c3564e5c |
898 | } |
899 | break; |
8b7059b1 |
900 | case SAVEt_SAVESWITCHSTACK: |
901 | { |
902 | dSP; |
7452cf6a |
903 | AV* const t = (AV*)SSPOPPTR; |
904 | AV* const f = (AV*)SSPOPPTR; |
8b7059b1 |
905 | SWITCHSTACK(t,f); |
906 | PL_curstackinfo->si_stack = f; |
907 | } |
908 | break; |
14f338dc |
909 | case SAVEt_SET_SVFLAGS: |
910 | { |
35a4481c |
911 | const U32 val = (U32)SSPOPINT; |
912 | const U32 mask = (U32)SSPOPINT; |
14f338dc |
913 | sv = (SV*)SSPOPPTR; |
914 | SvFLAGS(sv) &= ~mask; |
915 | SvFLAGS(sv) |= val; |
916 | } |
917 | break; |
2053acbf |
918 | /* These are only saved in mathoms.c */ |
919 | case SAVEt_SVREF: /* scalar reference */ |
920 | value = (SV*)SSPOPPTR; |
921 | ptr = SSPOPPTR; |
922 | av = NULL; /* what to refcnt_dec */ |
923 | goto restore_sv; |
924 | case SAVEt_LONG: /* long reference */ |
925 | ptr = SSPOPPTR; |
926 | *(long*)ptr = (long)SSPOPLONG; |
927 | break; |
928 | case SAVEt_I16: /* I16 reference */ |
929 | ptr = SSPOPPTR; |
930 | *(I16*)ptr = (I16)SSPOPINT; |
931 | break; |
932 | case SAVEt_I8: /* I8 reference */ |
933 | ptr = SSPOPPTR; |
934 | *(I8*)ptr = (I8)SSPOPINT; |
935 | break; |
936 | case SAVEt_IV: /* IV reference */ |
937 | ptr = SSPOPPTR; |
938 | *(IV*)ptr = (IV)SSPOPIV; |
939 | break; |
940 | case SAVEt_NSTAB: |
941 | gv = (GV*)SSPOPPTR; |
942 | (void)sv_clear((SV*)gv); |
943 | break; |
944 | case SAVEt_DESTRUCTOR: |
945 | ptr = SSPOPPTR; |
946 | (*SSPOPDPTR)(ptr); |
947 | break; |
79072805 |
948 | default: |
cea2e8a9 |
949 | Perl_croak(aTHX_ "panic: leave_scope inconsistency"); |
79072805 |
950 | } |
951 | } |
952 | } |
8990e307 |
953 | |
8990e307 |
954 | void |
864dbfa3 |
955 | Perl_cx_dump(pTHX_ PERL_CONTEXT *cx) |
8990e307 |
956 | { |
97aff369 |
957 | dVAR; |
35ff7856 |
958 | #ifdef DEBUGGING |
22c35a8c |
959 | PerlIO_printf(Perl_debug_log, "CX %ld = %s\n", (long)(cx - cxstack), PL_block_type[CxTYPE(cx)]); |
6b35e009 |
960 | if (CxTYPE(cx) != CXt_SUBST) { |
760ac839 |
961 | PerlIO_printf(Perl_debug_log, "BLK_OLDSP = %ld\n", (long)cx->blk_oldsp); |
146174a9 |
962 | PerlIO_printf(Perl_debug_log, "BLK_OLDCOP = 0x%"UVxf"\n", |
963 | PTR2UV(cx->blk_oldcop)); |
760ac839 |
964 | PerlIO_printf(Perl_debug_log, "BLK_OLDMARKSP = %ld\n", (long)cx->blk_oldmarksp); |
965 | PerlIO_printf(Perl_debug_log, "BLK_OLDSCOPESP = %ld\n", (long)cx->blk_oldscopesp); |
146174a9 |
966 | PerlIO_printf(Perl_debug_log, "BLK_OLDPM = 0x%"UVxf"\n", |
967 | PTR2UV(cx->blk_oldpm)); |
760ac839 |
968 | PerlIO_printf(Perl_debug_log, "BLK_GIMME = %s\n", cx->blk_gimme ? "LIST" : "SCALAR"); |
8990e307 |
969 | } |
6b35e009 |
970 | switch (CxTYPE(cx)) { |
8990e307 |
971 | case CXt_NULL: |
972 | case CXt_BLOCK: |
973 | break; |
146174a9 |
974 | case CXt_FORMAT: |
975 | PerlIO_printf(Perl_debug_log, "BLK_SUB.CV = 0x%"UVxf"\n", |
976 | PTR2UV(cx->blk_sub.cv)); |
977 | PerlIO_printf(Perl_debug_log, "BLK_SUB.GV = 0x%"UVxf"\n", |
978 | PTR2UV(cx->blk_sub.gv)); |
979 | PerlIO_printf(Perl_debug_log, "BLK_SUB.DFOUTGV = 0x%"UVxf"\n", |
980 | PTR2UV(cx->blk_sub.dfoutgv)); |
981 | PerlIO_printf(Perl_debug_log, "BLK_SUB.HASARGS = %d\n", |
982 | (int)cx->blk_sub.hasargs); |
f39bc417 |
983 | PerlIO_printf(Perl_debug_log, "BLK_SUB.RETOP = 0x%"UVxf"\n", |
984 | PTR2UV(cx->blk_sub.retop)); |
146174a9 |
985 | break; |
8990e307 |
986 | case CXt_SUB: |
146174a9 |
987 | PerlIO_printf(Perl_debug_log, "BLK_SUB.CV = 0x%"UVxf"\n", |
988 | PTR2UV(cx->blk_sub.cv)); |
760ac839 |
989 | PerlIO_printf(Perl_debug_log, "BLK_SUB.OLDDEPTH = %ld\n", |
8990e307 |
990 | (long)cx->blk_sub.olddepth); |
760ac839 |
991 | PerlIO_printf(Perl_debug_log, "BLK_SUB.HASARGS = %d\n", |
8990e307 |
992 | (int)cx->blk_sub.hasargs); |
146174a9 |
993 | PerlIO_printf(Perl_debug_log, "BLK_SUB.LVAL = %d\n", |
994 | (int)cx->blk_sub.lval); |
f39bc417 |
995 | PerlIO_printf(Perl_debug_log, "BLK_SUB.RETOP = 0x%"UVxf"\n", |
996 | PTR2UV(cx->blk_sub.retop)); |
8990e307 |
997 | break; |
998 | case CXt_EVAL: |
760ac839 |
999 | PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_IN_EVAL = %ld\n", |
8990e307 |
1000 | (long)cx->blk_eval.old_in_eval); |
760ac839 |
1001 | PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_OP_TYPE = %s (%s)\n", |
22c35a8c |
1002 | PL_op_name[cx->blk_eval.old_op_type], |
1003 | PL_op_desc[cx->blk_eval.old_op_type]); |
0f79a09d |
1004 | if (cx->blk_eval.old_namesv) |
1005 | PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_NAME = %s\n", |
aa07b2f6 |
1006 | SvPVX_const(cx->blk_eval.old_namesv)); |
146174a9 |
1007 | PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_EVAL_ROOT = 0x%"UVxf"\n", |
1008 | PTR2UV(cx->blk_eval.old_eval_root)); |
f39bc417 |
1009 | PerlIO_printf(Perl_debug_log, "BLK_EVAL.RETOP = 0x%"UVxf"\n", |
1010 | PTR2UV(cx->blk_eval.retop)); |
8990e307 |
1011 | break; |
1012 | |
1013 | case CXt_LOOP: |
760ac839 |
1014 | PerlIO_printf(Perl_debug_log, "BLK_LOOP.LABEL = %s\n", |
8990e307 |
1015 | cx->blk_loop.label); |
760ac839 |
1016 | PerlIO_printf(Perl_debug_log, "BLK_LOOP.RESETSP = %ld\n", |
8990e307 |
1017 | (long)cx->blk_loop.resetsp); |
146174a9 |
1018 | PerlIO_printf(Perl_debug_log, "BLK_LOOP.REDO_OP = 0x%"UVxf"\n", |
1019 | PTR2UV(cx->blk_loop.redo_op)); |
1020 | PerlIO_printf(Perl_debug_log, "BLK_LOOP.NEXT_OP = 0x%"UVxf"\n", |
1021 | PTR2UV(cx->blk_loop.next_op)); |
1022 | PerlIO_printf(Perl_debug_log, "BLK_LOOP.LAST_OP = 0x%"UVxf"\n", |
1023 | PTR2UV(cx->blk_loop.last_op)); |
760ac839 |
1024 | PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERIX = %ld\n", |
8990e307 |
1025 | (long)cx->blk_loop.iterix); |
146174a9 |
1026 | PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERARY = 0x%"UVxf"\n", |
1027 | PTR2UV(cx->blk_loop.iterary)); |
1028 | PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERVAR = 0x%"UVxf"\n", |
1029 | PTR2UV(CxITERVAR(cx))); |
1030 | if (CxITERVAR(cx)) |
1031 | PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERSAVE = 0x%"UVxf"\n", |
1032 | PTR2UV(cx->blk_loop.itersave)); |
1033 | PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERLVAL = 0x%"UVxf"\n", |
1034 | PTR2UV(cx->blk_loop.iterlval)); |
8990e307 |
1035 | break; |
1036 | |
1037 | case CXt_SUBST: |
760ac839 |
1038 | PerlIO_printf(Perl_debug_log, "SB_ITERS = %ld\n", |
8990e307 |
1039 | (long)cx->sb_iters); |
760ac839 |
1040 | PerlIO_printf(Perl_debug_log, "SB_MAXITERS = %ld\n", |
8990e307 |
1041 | (long)cx->sb_maxiters); |
35ef4773 |
1042 | PerlIO_printf(Perl_debug_log, "SB_RFLAGS = %ld\n", |
1043 | (long)cx->sb_rflags); |
760ac839 |
1044 | PerlIO_printf(Perl_debug_log, "SB_ONCE = %ld\n", |
8990e307 |
1045 | (long)cx->sb_once); |
760ac839 |
1046 | PerlIO_printf(Perl_debug_log, "SB_ORIG = %s\n", |
8990e307 |
1047 | cx->sb_orig); |
146174a9 |
1048 | PerlIO_printf(Perl_debug_log, "SB_DSTR = 0x%"UVxf"\n", |
1049 | PTR2UV(cx->sb_dstr)); |
1050 | PerlIO_printf(Perl_debug_log, "SB_TARG = 0x%"UVxf"\n", |
1051 | PTR2UV(cx->sb_targ)); |
1052 | PerlIO_printf(Perl_debug_log, "SB_S = 0x%"UVxf"\n", |
1053 | PTR2UV(cx->sb_s)); |
1054 | PerlIO_printf(Perl_debug_log, "SB_M = 0x%"UVxf"\n", |
1055 | PTR2UV(cx->sb_m)); |
1056 | PerlIO_printf(Perl_debug_log, "SB_STREND = 0x%"UVxf"\n", |
1057 | PTR2UV(cx->sb_strend)); |
1058 | PerlIO_printf(Perl_debug_log, "SB_RXRES = 0x%"UVxf"\n", |
1059 | PTR2UV(cx->sb_rxres)); |
8990e307 |
1060 | break; |
1061 | } |
65e66c80 |
1062 | #else |
1063 | PERL_UNUSED_ARG(cx); |
17c3b450 |
1064 | #endif /* DEBUGGING */ |
35ff7856 |
1065 | } |
241d1a3b |
1066 | |
1067 | /* |
1068 | * Local variables: |
1069 | * c-indentation-style: bsd |
1070 | * c-basic-offset: 4 |
1071 | * indent-tabs-mode: t |
1072 | * End: |
1073 | * |
37442d52 |
1074 | * ex: set ts=8 sts=4 sw=4 noet: |
1075 | */ |