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 /* *** these are ordered by number of of auto-popped args */
16 #define SAVEt_CLEARPADRANGE 1
17 #define SAVEt_CLEARSV 2
18 #define SAVEt_REGCONTEXT 3
20 #define SAVEt_ARG0_MAX 3
24 #define SAVEt_GP_ALIASED_SV 4
26 #define SAVEt_COMPILE_WARNINGS 6
27 #define SAVEt_COMPPAD 7
28 #define SAVEt_FREECOPHH 8
29 #define SAVEt_FREEOP 9
30 #define SAVEt_FREEPV 10
31 #define SAVEt_FREESV 11
33 #define SAVEt_I32_SMALL 13
35 #define SAVEt_INT_SMALL 15
36 #define SAVEt_MORTALIZESV 16
37 #define SAVEt_NSTAB 17
39 #define SAVEt_PARSER 19
40 #define SAVEt_STACK_POS 20
41 #define SAVEt_READONLY_OFF 21
42 #define SAVEt_FREEPADNAME 22
44 #define SAVEt_ARG1_MAX 22
49 #define SAVEt_DESTRUCTOR 24
50 #define SAVEt_DESTRUCTOR_X 25
51 #define SAVEt_GENERIC_PVREF 26
52 #define SAVEt_GENERIC_SVREF 27
55 #define SAVEt_HINTS 30
64 #define SAVEt_SAVESWITCHSTACK 39
65 #define SAVEt_SHARED_PVREF 40
67 #define SAVEt_STRLEN 42
69 #define SAVEt_SVREF 44
71 #define SAVEt_ADELETE 46
74 #define SAVEt_ARG2_MAX 47
78 #define SAVEt_HELEM 48
79 #define SAVEt_PADSV_AND_MORTALIZE 49
80 #define SAVEt_SET_SVFLAGS 50
81 #define SAVEt_GVSLOT 51
82 #define SAVEt_AELEM 52
83 #define SAVEt_DELETE 53
86 #define SAVEf_SETMAGIC 1
87 #define SAVEf_KEEPOLDELEM 2
89 #define SAVE_TIGHT_SHIFT 6
90 #define SAVE_MASK 0x3F
92 #define save_aelem(av,idx,sptr) save_aelem_flags(av,idx,sptr,SAVEf_SETMAGIC)
93 #define save_helem(hv,key,sptr) save_helem_flags(hv,key,sptr,SAVEf_SETMAGIC)
95 #ifndef SCOPE_SAVES_SIGNAL_MASK
96 #define SCOPE_SAVES_SIGNAL_MASK 0
99 /* the maximum number of entries that might be pushed using the SS_ADD*
103 #define SSCHECK(need) if (UNLIKELY(PL_savestack_ix + (I32)(need) + SS_MAXPUSH > PL_savestack_max)) savestack_grow()
104 #define SSGROW(need) if (UNLIKELY(PL_savestack_ix + (I32)(need) + SS_MAXPUSH > PL_savestack_max)) savestack_grow_cnt(need + SS_MAXPUSH)
105 #define SSPUSHINT(i) (PL_savestack[PL_savestack_ix++].any_i32 = (I32)(i))
106 #define SSPUSHLONG(i) (PL_savestack[PL_savestack_ix++].any_long = (long)(i))
107 #define SSPUSHBOOL(p) (PL_savestack[PL_savestack_ix++].any_bool = (p))
108 #define SSPUSHIV(i) (PL_savestack[PL_savestack_ix++].any_iv = (IV)(i))
109 #define SSPUSHUV(u) (PL_savestack[PL_savestack_ix++].any_uv = (UV)(u))
110 #define SSPUSHPTR(p) (PL_savestack[PL_savestack_ix++].any_ptr = (void*)(p))
111 #define SSPUSHDPTR(p) (PL_savestack[PL_savestack_ix++].any_dptr = (p))
112 #define SSPUSHDXPTR(p) (PL_savestack[PL_savestack_ix++].any_dxptr = (p))
114 /* SS_ADD*: newer, faster versions of the above. Don't mix the two sets of
115 * macros. These are fast because they save reduce accesses to the PL_
116 * vars and move the size check to the end. Doing the check last means
117 * that values in registers will have been pushed and no longer needed, so
118 * don't need saving around the call to grow. Also, tail-call elimination
119 * of the grow() can be done. These changes reduce the code of something
120 * like save_pushptrptr() to half its former size.
121 * Of course, doing the size check *after* pushing means we must always
122 * ensure there are SS_MAXPUSH free slots on the savestack
124 * These are for internal core use only and are subject to change */
127 I32 ix = PL_savestack_ix; \
128 ANY *ssp = &PL_savestack[ix]
130 #define SS_ADD_END(need) \
131 assert((need) <= SS_MAXPUSH); \
133 PL_savestack_ix = ix; \
134 assert(ix <= PL_savestack_max); \
135 if (UNLIKELY((ix + SS_MAXPUSH) > PL_savestack_max)) savestack_grow(); \
136 assert(PL_savestack_ix + SS_MAXPUSH <= PL_savestack_max);
138 #define SS_ADD_INT(i) ((ssp++)->any_i32 = (I32)(i))
139 #define SS_ADD_LONG(i) ((ssp++)->any_long = (long)(i))
140 #define SS_ADD_BOOL(p) ((ssp++)->any_bool = (p))
141 #define SS_ADD_IV(i) ((ssp++)->any_iv = (IV)(i))
142 #define SS_ADD_UV(u) ((ssp++)->any_uv = (UV)(u))
143 #define SS_ADD_PTR(p) ((ssp++)->any_ptr = (void*)(p))
144 #define SS_ADD_DPTR(p) ((ssp++)->any_dptr = (p))
145 #define SS_ADD_DXPTR(p) ((ssp++)->any_dxptr = (p))
147 #define SSPOPINT (PL_savestack[--PL_savestack_ix].any_i32)
148 #define SSPOPLONG (PL_savestack[--PL_savestack_ix].any_long)
149 #define SSPOPBOOL (PL_savestack[--PL_savestack_ix].any_bool)
150 #define SSPOPIV (PL_savestack[--PL_savestack_ix].any_iv)
151 #define SSPOPUV (PL_savestack[--PL_savestack_ix].any_uv)
152 #define SSPOPPTR (PL_savestack[--PL_savestack_ix].any_ptr)
153 #define SSPOPDPTR (PL_savestack[--PL_savestack_ix].any_dptr)
154 #define SSPOPDXPTR (PL_savestack[--PL_savestack_ix].any_dxptr)
158 =head1 Callback Functions
160 =for apidoc Ams||SAVETMPS
161 Opening bracket for temporaries on a callback. See C<FREETMPS> and
164 =for apidoc Ams||FREETMPS
165 Closing bracket for temporaries on a callback. See C<SAVETMPS> and
168 =for apidoc Ams||ENTER
169 Opening bracket on a callback. See C<LEAVE> and L<perlcall>.
171 =for apidoc Ams||LEAVE
172 Closing bracket on a callback. See C<ENTER> and L<perlcall>.
176 =item ENTER_with_name(name)
178 Same as C<ENTER>, but when debugging is enabled it also associates the
179 given literal string with the new scope.
181 =item LEAVE_with_name(name)
183 Same as C<LEAVE>, but when debugging is enabled it first checks that the
184 scope has the given name. Name must be a literal string.
191 #define SAVETMPS Perl_save_strlen(aTHX_ (STRLEN *)&PL_tmps_floor), \
192 PL_tmps_floor = PL_tmps_ix
193 #define FREETMPS if (PL_tmps_ix > PL_tmps_floor) free_tmps()
199 DEBUG_SCOPE("ENTER") \
203 DEBUG_SCOPE("LEAVE") \
206 #define ENTER_with_name(name) \
209 if (PL_scopestack_name) \
210 PL_scopestack_name[PL_scopestack_ix-1] = name; \
211 DEBUG_SCOPE("ENTER \"" name "\"") \
213 #define LEAVE_with_name(name) \
215 DEBUG_SCOPE("LEAVE \"" name "\"") \
216 if (PL_scopestack_name) { \
217 assert(((char*)PL_scopestack_name[PL_scopestack_ix-1] \
219 || strEQ(PL_scopestack_name[PL_scopestack_ix-1], name)); \
224 #define ENTER push_scope()
225 #define LEAVE pop_scope()
226 #define ENTER_with_name(name) ENTER
227 #define LEAVE_with_name(name) LEAVE
229 #define LEAVE_SCOPE(old) STMT_START { \
230 if (PL_savestack_ix > old) leave_scope(old); \
233 #define SAVEI8(i) save_I8((I8*)&(i))
234 #define SAVEI16(i) save_I16((I16*)&(i))
235 #define SAVEI32(i) save_I32((I32*)&(i))
236 #define SAVEINT(i) save_int((int*)&(i))
237 #define SAVEIV(i) save_iv((IV*)&(i))
238 #define SAVELONG(l) save_long((long*)&(l))
239 #define SAVEBOOL(b) save_bool(&(b))
240 #define SAVESPTR(s) save_sptr((SV**)&(s))
241 #define SAVEPPTR(s) save_pptr((char**)&(s))
242 #define SAVEVPTR(s) save_vptr((void*)&(s))
243 #define SAVEPADSVANDMORTALIZE(s) save_padsv_and_mortalize(s)
244 #define SAVEFREESV(s) save_freesv(MUTABLE_SV(s))
245 #define SAVEFREEPADNAME(s) save_pushptr((void *)(s), SAVEt_FREEPADNAME)
246 #define SAVEMORTALIZESV(s) save_mortalizesv(MUTABLE_SV(s))
247 #define SAVEFREEOP(o) save_freeop((OP*)(o))
248 #define SAVEFREEPV(p) save_freepv((char*)(p))
249 #define SAVECLEARSV(sv) save_clearsv((SV**)&(sv))
250 #define SAVEGENERICSV(s) save_generic_svref((SV**)&(s))
251 #define SAVEGENERICPV(s) save_generic_pvref((char**)&(s))
252 #define SAVESHAREDPV(s) save_shared_pvref((char**)&(s))
253 #define SAVESETSVFLAGS(sv,mask,val) save_set_svflags(sv,mask,val)
254 #define SAVEFREECOPHH(h) save_pushptr((void *)(h), SAVEt_FREECOPHH)
255 #define SAVEDELETE(h,k,l) \
256 save_delete(MUTABLE_HV(h), (char*)(k), (I32)(l))
257 #define SAVEHDELETE(h,s) \
258 save_hdelete(MUTABLE_HV(h), (s))
259 #define SAVEADELETE(a,k) \
260 save_adelete(MUTABLE_AV(a), (SSize_t)(k))
261 #define SAVEDESTRUCTOR(f,p) \
262 save_destructor((DESTRUCTORFUNC_NOCONTEXT_t)(f), (void*)(p))
264 #define SAVEDESTRUCTOR_X(f,p) \
265 save_destructor_x((DESTRUCTORFUNC_t)(f), (void*)(p))
267 #define SAVESTACK_POS() \
270 SS_ADD_INT(PL_stack_sp - PL_stack_base); \
271 SS_ADD_UV(SAVEt_STACK_POS); \
275 #define SAVEOP() save_op()
277 #define SAVEHINTS() save_hints()
279 #define SAVECOMPPAD() save_pushptr(MUTABLE_SV(PL_comppad), SAVEt_COMPPAD)
281 #define SAVESWITCHSTACK(f,t) \
283 save_pushptrptr(MUTABLE_SV(f), MUTABLE_SV(t), SAVEt_SAVESWITCHSTACK); \
284 SWITCHSTACK((f),(t)); \
285 PL_curstackinfo->si_stack = (t); \
288 /* Need to do the cop warnings like this, rather than a "SAVEFREESHAREDPV",
289 because realloc() means that the value can actually change. Possibly
290 could have done savefreesharedpvREF, but this way actually seems cleaner,
291 as it simplifies the code that does the saves, and reduces the load on the
293 #define SAVECOMPILEWARNINGS() save_pushptr(PL_compiling.cop_warnings, SAVEt_COMPILE_WARNINGS)
295 #define SAVEPARSER(p) save_pushptr((p), SAVEt_PARSER)
298 # define SAVECOPSTASH_FREE(c) SAVEIV((c)->cop_stashoff)
299 # define SAVECOPFILE(c) SAVEPPTR(CopFILE(c))
300 # define SAVECOPFILE_FREE(c) SAVESHAREDPV(CopFILE(c))
302 # /* XXX not refcounted */
303 # define SAVECOPSTASH_FREE(c) SAVESPTR(CopSTASH(c))
304 # define SAVECOPFILE(c) SAVESPTR(CopFILEGV(c))
305 # define SAVECOPFILE_FREE(c) SAVEGENERICSV(CopFILEGV(c))
308 #define SAVECOPLINE(c) SAVEI32(CopLINE(c))
310 /* SSNEW() temporarily allocates a specified number of bytes of data on the
311 * savestack. It returns an integer index into the savestack, because a
312 * pointer would get broken if the savestack is moved on reallocation.
313 * SSNEWa() works like SSNEW(), but also aligns the data to the specified
314 * number of bytes. MEM_ALIGNBYTES is perhaps the most useful. The
315 * alignment will be preserved through savestack reallocation *only* if
316 * realloc returns data aligned to a size divisible by "align"!
318 * SSPTR() converts the index returned by SSNEW/SSNEWa() into a pointer.
321 #define SSNEW(size) Perl_save_alloc(aTHX_ (size), 0)
322 #define SSNEWt(n,t) SSNEW((n)*sizeof(t))
323 #define SSNEWa(size,align) Perl_save_alloc(aTHX_ (size), \
324 (I32)(align - ((size_t)((caddr_t)&PL_savestack[PL_savestack_ix]) % align)) % align)
325 #define SSNEWat(n,t,align) SSNEWa((n)*sizeof(t), align)
327 #define SSPTR(off,type) ((type) ((char*)PL_savestack + off))
328 #define SSPTRt(off,type) ((type*) ((char*)PL_savestack + off))
330 #define save_freesv(op) save_pushptr((void *)(op), SAVEt_FREESV)
331 #define save_mortalizesv(op) save_pushptr((void *)(op), SAVEt_MORTALIZESV)
333 # define save_freeop(op) \
335 OP * const _o = (OP *)(op); \
336 assert(!_o->op_savefree); \
337 _o->op_savefree = 1; \
338 save_pushptr((void *)(_o), SAVEt_FREEOP); \
340 #define save_freepv(pv) save_pushptr((void *)(pv), SAVEt_FREEPV)
341 #define save_op() save_pushptr((void *)(PL_op), SAVEt_OP)
344 * ex: set ts=8 sts=4 sw=4 et: