3 * Copyright (C) 1993, 1994, 1996, 1997, 1998, 1999, 2000, 2001,
4 * 2002, 2004, 2005, 2006, 2007, 2008 by Larry Wall and others
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.
11 /* *** Update arg_counts[] in scope.c if you modify these */
16 #define SAVEt_CLEARPADRANGE 1
17 #define SAVEt_CLEARSV 2
18 #define SAVEt_REGCONTEXT 3
22 #define SAVEt_TMPSFLOOR 4
24 #define SAVEt_COMPILE_WARNINGS 6
25 #define SAVEt_COMPPAD 7
26 #define SAVEt_FREECOPHH 8
27 #define SAVEt_FREEOP 9
28 #define SAVEt_FREEPV 10
29 #define SAVEt_FREESV 11
31 #define SAVEt_I32_SMALL 13
33 #define SAVEt_INT_SMALL 15
34 #define SAVEt_MORTALIZESV 16
35 #define SAVEt_NSTAB 17
37 #define SAVEt_PARSER 19
38 #define SAVEt_STACK_POS 20
39 #define SAVEt_READONLY_OFF 21
40 #define SAVEt_FREEPADNAME 22
41 #define SAVEt_STRLEN_SMALL 23
46 #define SAVEt_DESTRUCTOR 25
47 #define SAVEt_DESTRUCTOR_X 26
48 #define SAVEt_GENERIC_PVREF 27
49 #define SAVEt_GENERIC_SVREF 28
52 #define SAVEt_HINTS 31
61 #define SAVEt_SAVESWITCHSTACK 40
62 #define SAVEt_SHARED_PVREF 41
64 #define SAVEt_STRLEN 43
66 #define SAVEt_SVREF 45
68 #define SAVEt_ADELETE 47
73 #define SAVEt_HELEM 49
74 #define SAVEt_PADSV_AND_MORTALIZE 50
75 #define SAVEt_SET_SVFLAGS 51
76 #define SAVEt_GVSLOT 52
77 #define SAVEt_AELEM 53
78 #define SAVEt_DELETE 54
79 #define SAVEt_HINTS_HH 55
82 #define SAVEf_SETMAGIC 1
83 #define SAVEf_KEEPOLDELEM 2
85 #define SAVE_TIGHT_SHIFT 6
86 #define SAVE_MASK 0x3F
88 #define save_aelem(av,idx,sptr) save_aelem_flags(av,idx,sptr,SAVEf_SETMAGIC)
89 #define save_helem(hv,key,sptr) save_helem_flags(hv,key,sptr,SAVEf_SETMAGIC)
91 #ifndef SCOPE_SAVES_SIGNAL_MASK
92 #define SCOPE_SAVES_SIGNAL_MASK 0
95 /* the maximum number of entries that might be pushed using the SS_ADD*
99 #define SSCHECK(need) if (UNLIKELY(PL_savestack_ix + (I32)(need) > PL_savestack_max)) savestack_grow()
100 #define SSGROW(need) if (UNLIKELY(PL_savestack_ix + (I32)(need) > PL_savestack_max)) savestack_grow_cnt(need)
101 #define SSPUSHINT(i) (PL_savestack[PL_savestack_ix++].any_i32 = (I32)(i))
102 #define SSPUSHLONG(i) (PL_savestack[PL_savestack_ix++].any_long = (long)(i))
103 #define SSPUSHBOOL(p) (PL_savestack[PL_savestack_ix++].any_bool = (p))
104 #define SSPUSHIV(i) (PL_savestack[PL_savestack_ix++].any_iv = (IV)(i))
105 #define SSPUSHUV(u) (PL_savestack[PL_savestack_ix++].any_uv = (UV)(u))
106 #define SSPUSHPTR(p) (PL_savestack[PL_savestack_ix++].any_ptr = (void*)(p))
107 #define SSPUSHDPTR(p) (PL_savestack[PL_savestack_ix++].any_dptr = (p))
108 #define SSPUSHDXPTR(p) (PL_savestack[PL_savestack_ix++].any_dxptr = (p))
110 /* SS_ADD*: newer, faster versions of the above. Don't mix the two sets of
111 * macros. These are fast because they save reduce accesses to the PL_
112 * vars and move the size check to the end. Doing the check last means
113 * that values in registers will have been pushed and no longer needed, so
114 * don't need saving around the call to grow. Also, tail-call elimination
115 * of the grow() can be done. These changes reduce the code of something
116 * like save_pushptrptr() to half its former size.
117 * Of course, doing the size check *after* pushing means we must always
118 * ensure there are SS_MAXPUSH free slots on the savestack. This ensured
119 * bt savestack_grow() and savestack_grow_cnt always allocating SS_MAXPUSH
120 * slots more than asked for, or that it sets PL_savestack_max to
122 * These are for internal core use only and are subject to change */
125 I32 ix = PL_savestack_ix; \
126 ANY *ssp = &PL_savestack[ix]
128 #define SS_ADD_END(need) \
129 assert((need) <= SS_MAXPUSH); \
131 PL_savestack_ix = ix; \
132 assert(ix <= PL_savestack_max + SS_MAXPUSH); \
133 if (UNLIKELY(ix > PL_savestack_max)) savestack_grow(); \
134 assert(PL_savestack_ix <= PL_savestack_max);
136 #define SS_ADD_INT(i) ((ssp++)->any_i32 = (I32)(i))
137 #define SS_ADD_LONG(i) ((ssp++)->any_long = (long)(i))
138 #define SS_ADD_BOOL(p) ((ssp++)->any_bool = (p))
139 #define SS_ADD_IV(i) ((ssp++)->any_iv = (IV)(i))
140 #define SS_ADD_UV(u) ((ssp++)->any_uv = (UV)(u))
141 #define SS_ADD_PTR(p) ((ssp++)->any_ptr = (void*)(p))
142 #define SS_ADD_DPTR(p) ((ssp++)->any_dptr = (p))
143 #define SS_ADD_DXPTR(p) ((ssp++)->any_dxptr = (p))
145 #define SSPOPINT (PL_savestack[--PL_savestack_ix].any_i32)
146 #define SSPOPLONG (PL_savestack[--PL_savestack_ix].any_long)
147 #define SSPOPBOOL (PL_savestack[--PL_savestack_ix].any_bool)
148 #define SSPOPIV (PL_savestack[--PL_savestack_ix].any_iv)
149 #define SSPOPUV (PL_savestack[--PL_savestack_ix].any_uv)
150 #define SSPOPPTR (PL_savestack[--PL_savestack_ix].any_ptr)
151 #define SSPOPDPTR (PL_savestack[--PL_savestack_ix].any_dptr)
152 #define SSPOPDXPTR (PL_savestack[--PL_savestack_ix].any_dxptr)
156 =for apidoc_section $callback
158 =for apidoc Amns||SAVETMPS
159 Opening bracket for temporaries on a callback. See C<L</FREETMPS>> and
162 =for apidoc Amns||FREETMPS
163 Closing bracket for temporaries on a callback. See C<L</SAVETMPS>> and
166 =for apidoc Amns||ENTER
167 Opening bracket on a callback. See C<L</LEAVE>> and L<perlcall>.
169 =for apidoc Amns||LEAVE
170 Closing bracket on a callback. See C<L</ENTER>> and L<perlcall>.
172 =for apidoc Ams||ENTER_with_name|"name"
174 Same as C<L</ENTER>>, but when debugging is enabled it also associates the
175 given literal string with the new scope.
177 =for apidoc Ams||LEAVE_with_name|"name"
179 Same as C<L</LEAVE>>, but when debugging is enabled it first checks that the
180 scope has the given name. C<name> must be a literal string.
185 #define SAVETMPS Perl_savetmps(aTHX)
187 #define FREETMPS if (PL_tmps_ix > PL_tmps_floor) free_tmps()
193 DEBUG_SCOPE("ENTER") \
197 DEBUG_SCOPE("LEAVE") \
200 #define ENTER_with_name(name) \
203 if (PL_scopestack_name) \
204 PL_scopestack_name[PL_scopestack_ix-1] = name; \
205 DEBUG_SCOPE("ENTER \"" name "\"") \
207 #define LEAVE_with_name(name) \
209 DEBUG_SCOPE("LEAVE \"" name "\"") \
210 if (PL_scopestack_name) { \
211 assert(((char*)PL_scopestack_name[PL_scopestack_ix-1] \
213 || strEQ(PL_scopestack_name[PL_scopestack_ix-1], name)); \
218 #define ENTER push_scope()
219 #define LEAVE pop_scope()
220 #define ENTER_with_name(name) ENTER
221 #define LEAVE_with_name(name) LEAVE
223 #define LEAVE_SCOPE(old) STMT_START { \
224 if (PL_savestack_ix > old) leave_scope(old); \
227 #define SAVEI8(i) save_I8((I8*)&(i))
228 #define SAVEI16(i) save_I16((I16*)&(i))
229 #define SAVEI32(i) save_I32((I32*)&(i))
230 #define SAVEINT(i) save_int((int*)&(i))
231 #define SAVEIV(i) save_iv((IV*)&(i))
232 #define SAVELONG(l) save_long((long*)&(l))
233 #define SAVEBOOL(b) save_bool(&(b))
234 #define SAVESPTR(s) save_sptr((SV**)&(s))
235 #define SAVEPPTR(s) save_pptr((char**)&(s))
236 #define SAVEVPTR(s) save_vptr((void*)&(s))
237 #define SAVEPADSVANDMORTALIZE(s) save_padsv_and_mortalize(s)
238 #define SAVEFREESV(s) save_freesv(MUTABLE_SV(s))
239 #define SAVEFREEPADNAME(s) save_pushptr((void *)(s), SAVEt_FREEPADNAME)
240 #define SAVEMORTALIZESV(s) save_mortalizesv(MUTABLE_SV(s))
241 #define SAVEFREEOP(o) save_freeop((OP*)(o))
242 #define SAVEFREEPV(p) save_freepv((char*)(p))
243 #define SAVECLEARSV(sv) save_clearsv((SV**)&(sv))
244 #define SAVEGENERICSV(s) save_generic_svref((SV**)&(s))
245 #define SAVEGENERICPV(s) save_generic_pvref((char**)&(s))
246 #define SAVESHAREDPV(s) save_shared_pvref((char**)&(s))
247 #define SAVESETSVFLAGS(sv,mask,val) save_set_svflags(sv,mask,val)
248 #define SAVEFREECOPHH(h) save_pushptr((void *)(h), SAVEt_FREECOPHH)
249 #define SAVEDELETE(h,k,l) \
250 save_delete(MUTABLE_HV(h), (char*)(k), (I32)(l))
251 #define SAVEHDELETE(h,s) \
252 save_hdelete(MUTABLE_HV(h), (s))
253 #define SAVEADELETE(a,k) \
254 save_adelete(MUTABLE_AV(a), (SSize_t)(k))
255 #define SAVEDESTRUCTOR(f,p) \
256 save_destructor((DESTRUCTORFUNC_NOCONTEXT_t)(f), (void*)(p))
258 #define SAVEDESTRUCTOR_X(f,p) \
259 save_destructor_x((DESTRUCTORFUNC_t)(f), (void*)(p))
261 #define SAVESTACK_POS() \
264 SS_ADD_INT(PL_stack_sp - PL_stack_base); \
265 SS_ADD_UV(SAVEt_STACK_POS); \
269 #define SAVEOP() save_op()
271 #define SAVEHINTS() save_hints()
273 #define SAVECOMPPAD() save_pushptr(MUTABLE_SV(PL_comppad), SAVEt_COMPPAD)
275 #define SAVESWITCHSTACK(f,t) \
277 save_pushptrptr(MUTABLE_SV(f), MUTABLE_SV(t), SAVEt_SAVESWITCHSTACK); \
278 SWITCHSTACK((f),(t)); \
279 PL_curstackinfo->si_stack = (t); \
282 /* Need to do the cop warnings like this, rather than a "SAVEFREESHAREDPV",
283 because realloc() means that the value can actually change. Possibly
284 could have done savefreesharedpvREF, but this way actually seems cleaner,
285 as it simplifies the code that does the saves, and reduces the load on the
287 #define SAVECOMPILEWARNINGS() save_pushptr(PL_compiling.cop_warnings, SAVEt_COMPILE_WARNINGS)
289 #define SAVEPARSER(p) save_pushptr((p), SAVEt_PARSER)
292 # define SAVECOPSTASH_FREE(c) SAVEIV((c)->cop_stashoff)
293 # define SAVECOPFILE(c) SAVEPPTR(CopFILE(c))
294 # define SAVECOPFILE_FREE(c) SAVESHAREDPV(CopFILE(c))
296 # /* XXX not refcounted */
297 # define SAVECOPSTASH_FREE(c) SAVESPTR(CopSTASH(c))
298 # define SAVECOPFILE(c) SAVESPTR(CopFILEGV(c))
299 # define SAVECOPFILE_FREE(c) SAVEGENERICSV(CopFILEGV(c))
302 #define SAVECOPLINE(c) SAVEI32(CopLINE(c))
304 /* SSNEW() temporarily allocates a specified number of bytes of data on the
305 * savestack. It returns an I32 index into the savestack, because a
306 * pointer would get broken if the savestack is moved on reallocation.
307 * SSNEWa() works like SSNEW(), but also aligns the data to the specified
308 * number of bytes. MEM_ALIGNBYTES is perhaps the most useful. The
309 * alignment will be preserved through savestack reallocation *only* if
310 * realloc returns data aligned to a size divisible by "align"!
312 * SSPTR() converts the index returned by SSNEW/SSNEWa() into a pointer.
315 #define SSNEW(size) Perl_save_alloc(aTHX_ (size), 0)
316 #define SSNEWt(n,t) SSNEW((n)*sizeof(t))
317 #define SSNEWa(size,align) Perl_save_alloc(aTHX_ (size), \
318 (I32)(align - ((size_t)((caddr_t)&PL_savestack[PL_savestack_ix]) % align)) % align)
319 #define SSNEWat(n,t,align) SSNEWa((n)*sizeof(t), align)
321 #define SSPTR(off,type) ((type) ((char*)PL_savestack + off))
322 #define SSPTRt(off,type) ((type*) ((char*)PL_savestack + off))
324 #define save_freesv(op) save_pushptr((void *)(op), SAVEt_FREESV)
325 #define save_mortalizesv(op) save_pushptr((void *)(op), SAVEt_MORTALIZESV)
327 # define save_freeop(op) \
329 OP * const _o = (OP *)(op); \
330 assert(!_o->op_savefree); \
331 _o->op_savefree = 1; \
332 save_pushptr((void *)(_o), SAVEt_FREEOP); \
334 #define save_freepv(pv) save_pushptr((void *)(pv), SAVEt_FREEPV)
335 #define save_op() save_pushptr((void *)(PL_op), SAVEt_OP)
338 * ex: set ts=8 sts=4 sw=4 et: