Commit | Line | Data |
a0d0e21e |
1 | /* sv.h |
79072805 |
2 | * |
9607fc9c |
3 | * Copyright (c) 1991-1997, Larry Wall |
79072805 |
4 | * |
5 | * You may distribute under the terms of either the GNU General Public |
6 | * License or the Artistic License, as specified in the README file. |
7 | * |
79072805 |
8 | */ |
9 | |
a0d0e21e |
10 | #ifdef sv_flags |
11 | #undef sv_flags /* Convex has this in <signal.h> for sigvec() */ |
12 | #endif |
13 | |
79072805 |
14 | typedef enum { |
a0d0e21e |
15 | SVt_NULL, /* 0 */ |
16 | SVt_IV, /* 1 */ |
17 | SVt_NV, /* 2 */ |
18 | SVt_RV, /* 3 */ |
19 | SVt_PV, /* 4 */ |
20 | SVt_PVIV, /* 5 */ |
21 | SVt_PVNV, /* 6 */ |
22 | SVt_PVMG, /* 7 */ |
23 | SVt_PVBM, /* 8 */ |
24 | SVt_PVLV, /* 9 */ |
25 | SVt_PVAV, /* 10 */ |
26 | SVt_PVHV, /* 11 */ |
27 | SVt_PVCV, /* 12 */ |
28 | SVt_PVGV, /* 13 */ |
29 | SVt_PVFM, /* 14 */ |
30 | SVt_PVIO /* 15 */ |
79072805 |
31 | } svtype; |
32 | |
79072805 |
33 | /* Using C's structural equivalence to help emulate C++ inheritance here... */ |
34 | |
35 | struct sv { |
463ee0b2 |
36 | void* sv_any; /* pointer to something */ |
79072805 |
37 | U32 sv_refcnt; /* how many references to us */ |
8990e307 |
38 | U32 sv_flags; /* what we are */ |
79072805 |
39 | }; |
40 | |
41 | struct gv { |
463ee0b2 |
42 | XPVGV* sv_any; /* pointer to something */ |
79072805 |
43 | U32 sv_refcnt; /* how many references to us */ |
8990e307 |
44 | U32 sv_flags; /* what we are */ |
79072805 |
45 | }; |
46 | |
47 | struct cv { |
232e078e |
48 | XPVCV* sv_any; /* pointer to something */ |
79072805 |
49 | U32 sv_refcnt; /* how many references to us */ |
8990e307 |
50 | U32 sv_flags; /* what we are */ |
79072805 |
51 | }; |
52 | |
53 | struct av { |
463ee0b2 |
54 | XPVAV* sv_any; /* pointer to something */ |
79072805 |
55 | U32 sv_refcnt; /* how many references to us */ |
8990e307 |
56 | U32 sv_flags; /* what we are */ |
79072805 |
57 | }; |
58 | |
59 | struct hv { |
463ee0b2 |
60 | XPVHV* sv_any; /* pointer to something */ |
79072805 |
61 | U32 sv_refcnt; /* how many references to us */ |
8990e307 |
62 | U32 sv_flags; /* what we are */ |
63 | }; |
64 | |
65 | struct io { |
66 | XPVIO* sv_any; /* pointer to something */ |
67 | U32 sv_refcnt; /* how many references to us */ |
68 | U32 sv_flags; /* what we are */ |
79072805 |
69 | }; |
70 | |
463ee0b2 |
71 | #define SvANY(sv) (sv)->sv_any |
79072805 |
72 | #define SvFLAGS(sv) (sv)->sv_flags |
aeea060c |
73 | #define SvREFCNT(sv) (sv)->sv_refcnt |
a863c7d1 |
74 | |
dce16143 |
75 | #ifdef USE_THREADS |
76 | |
dce16143 |
77 | # ifdef EMULATE_ATOMIC_REFCOUNTS |
78 | # define ATOMIC_INC(count) STMT_START { \ |
533c011a |
79 | MUTEX_LOCK(&PL_svref_mutex); \ |
dce16143 |
80 | ++count; \ |
533c011a |
81 | MUTEX_UNLOCK(&PL_svref_mutex); \ |
dce16143 |
82 | } STMT_END |
0bfcb09d |
83 | # define ATOMIC_DEC_AND_TEST(res,count) STMT_START { \ |
533c011a |
84 | MUTEX_LOCK(&PL_svref_mutex); \ |
0bfcb09d |
85 | res = (--count == 0); \ |
533c011a |
86 | MUTEX_UNLOCK(&PL_svref_mutex); \ |
dce16143 |
87 | } STMT_END |
88 | # else |
89 | # define ATOMIC_INC(count) atomic_inc(&count) |
90 | # define ATOMIC_DEC_AND_TEST(res,count) (res = atomic_dec_and_test(&count)) |
91 | # endif /* EMULATE_ATOMIC_REFCOUNTS */ |
92 | #else |
93 | # define ATOMIC_INC(count) (++count) |
83b0a010 |
94 | # define ATOMIC_DEC_AND_TEST(res, count) (res = (--count == 0)) |
dce16143 |
95 | #endif /* USE_THREADS */ |
96 | |
a863c7d1 |
97 | #ifdef __GNUC__ |
dce16143 |
98 | # define SvREFCNT_inc(sv) \ |
99 | ({ \ |
100 | SV *nsv = (SV*)(sv); \ |
101 | if (nsv) \ |
102 | ATOMIC_INC(SvREFCNT(nsv)); \ |
103 | nsv; \ |
104 | }) |
8990e307 |
105 | #else |
a863c7d1 |
106 | # if defined(CRIPPLED_CC) || defined(USE_THREADS) |
199100c8 |
107 | # define SvREFCNT_inc(sv) sv_newref((SV*)sv) |
a863c7d1 |
108 | # else |
dce16143 |
109 | # define SvREFCNT_inc(sv) \ |
6b88bc9c |
110 | ((PL_Sv=(SV*)(sv)), (PL_Sv && ATOMIC_INC(SvREFCNT(PL_Sv))), (SV*)PL_Sv) |
a863c7d1 |
111 | # endif |
8990e307 |
112 | #endif |
113 | |
a863c7d1 |
114 | #define SvREFCNT_dec(sv) sv_free((SV*)sv) |
115 | |
8990e307 |
116 | #define SVTYPEMASK 0xff |
117 | #define SvTYPE(sv) ((sv)->sv_flags & SVTYPEMASK) |
79072805 |
118 | |
119 | #define SvUPGRADE(sv, mt) (SvTYPE(sv) >= mt || sv_upgrade(sv, mt)) |
120 | |
8990e307 |
121 | #define SVs_PADBUSY 0x00000100 /* reserved for tmp or my already */ |
122 | #define SVs_PADTMP 0x00000200 /* in use as tmp */ |
123 | #define SVs_PADMY 0x00000400 /* in use a "my" variable */ |
124 | #define SVs_TEMP 0x00000800 /* string is stealable? */ |
125 | #define SVs_OBJECT 0x00001000 /* is "blessed" */ |
126 | #define SVs_GMG 0x00002000 /* has magical get method */ |
127 | #define SVs_SMG 0x00004000 /* has magical set method */ |
128 | #define SVs_RMG 0x00008000 /* has random magical methods */ |
129 | |
130 | #define SVf_IOK 0x00010000 /* has valid public integer value */ |
131 | #define SVf_NOK 0x00020000 /* has valid public numeric value */ |
132 | #define SVf_POK 0x00040000 /* has valid public pointer value */ |
133 | #define SVf_ROK 0x00080000 /* has a valid reference pointer */ |
a0d0e21e |
134 | |
748a9306 |
135 | #define SVf_FAKE 0x00100000 /* glob or lexical is just a copy */ |
8990e307 |
136 | #define SVf_OOK 0x00200000 /* has valid offset value */ |
137 | #define SVf_BREAK 0x00400000 /* refcnt is artificially low */ |
138 | #define SVf_READONLY 0x00800000 /* may not be modified */ |
139 | |
a0d0e21e |
140 | #define SVf_THINKFIRST (SVf_READONLY|SVf_ROK) |
141 | |
8990e307 |
142 | #define SVp_IOK 0x01000000 /* has valid non-public integer value */ |
143 | #define SVp_NOK 0x02000000 /* has valid non-public numeric value */ |
144 | #define SVp_POK 0x04000000 /* has valid non-public pointer value */ |
145 | #define SVp_SCREAM 0x08000000 /* has been studied? */ |
146 | |
a0d0e21e |
147 | #define SVf_OK (SVf_IOK|SVf_NOK|SVf_POK|SVf_ROK| \ |
148 | SVp_IOK|SVp_NOK|SVp_POK) |
149 | |
9e7bc3e8 |
150 | #define SVf_AMAGIC 0x10000000 /* has magical overloaded methods */ |
a0d0e21e |
151 | |
8990e307 |
152 | #define PRIVSHIFT 8 |
153 | |
154 | /* Some private flags. */ |
155 | |
156 | #define SVpfm_COMPILED 0x80000000 |
157 | |
158 | #define SVpbm_VALID 0x80000000 |
bbce6d69 |
159 | #define SVpbm_TAIL 0x40000000 |
8990e307 |
160 | |
bf6bd887 |
161 | #define SVphv_SHAREKEYS 0x20000000 /* keys live on shared string table */ |
51594c39 |
162 | #define SVphv_LAZYDEL 0x40000000 /* entry in xhv_eiter must be deleted */ |
bf6bd887 |
163 | |
ed6116ce |
164 | struct xrv { |
165 | SV * xrv_rv; /* pointer to another SV */ |
166 | }; |
167 | |
79072805 |
168 | struct xpv { |
ed6116ce |
169 | char * xpv_pv; /* pointer to malloced string */ |
170 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ |
171 | STRLEN xpv_len; /* allocated size */ |
79072805 |
172 | }; |
173 | |
174 | struct xpviv { |
ed6116ce |
175 | char * xpv_pv; /* pointer to malloced string */ |
176 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ |
177 | STRLEN xpv_len; /* allocated size */ |
a0d0e21e |
178 | IV xiv_iv; /* integer value or pv offset */ |
79072805 |
179 | }; |
180 | |
ff68c719 |
181 | struct xpvuv { |
182 | char * xpv_pv; /* pointer to malloced string */ |
183 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ |
184 | STRLEN xpv_len; /* allocated size */ |
185 | UV xuv_uv; /* unsigned value or pv offset */ |
186 | }; |
187 | |
79072805 |
188 | struct xpvnv { |
ed6116ce |
189 | char * xpv_pv; /* pointer to malloced string */ |
190 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ |
191 | STRLEN xpv_len; /* allocated size */ |
a0d0e21e |
192 | IV xiv_iv; /* integer value or pv offset */ |
ed6116ce |
193 | double xnv_nv; /* numeric value, if any */ |
79072805 |
194 | }; |
195 | |
6ee623d5 |
196 | /* These structure must match the beginning of struct xpvhv in hv.h. */ |
79072805 |
197 | struct xpvmg { |
ed6116ce |
198 | char * xpv_pv; /* pointer to malloced string */ |
199 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ |
200 | STRLEN xpv_len; /* allocated size */ |
a0d0e21e |
201 | IV xiv_iv; /* integer value or pv offset */ |
ed6116ce |
202 | double xnv_nv; /* numeric value, if any */ |
79072805 |
203 | MAGIC* xmg_magic; /* linked list of magicalness */ |
204 | HV* xmg_stash; /* class package */ |
205 | }; |
206 | |
207 | struct xpvlv { |
ed6116ce |
208 | char * xpv_pv; /* pointer to malloced string */ |
209 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ |
210 | STRLEN xpv_len; /* allocated size */ |
a0d0e21e |
211 | IV xiv_iv; /* integer value or pv offset */ |
ed6116ce |
212 | double xnv_nv; /* numeric value, if any */ |
79072805 |
213 | MAGIC* xmg_magic; /* linked list of magicalness */ |
214 | HV* xmg_stash; /* class package */ |
8990e307 |
215 | |
79072805 |
216 | STRLEN xlv_targoff; |
217 | STRLEN xlv_targlen; |
218 | SV* xlv_targ; |
219 | char xlv_type; |
220 | }; |
221 | |
222 | struct xpvgv { |
ed6116ce |
223 | char * xpv_pv; /* pointer to malloced string */ |
224 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ |
225 | STRLEN xpv_len; /* allocated size */ |
a0d0e21e |
226 | IV xiv_iv; /* integer value or pv offset */ |
ed6116ce |
227 | double xnv_nv; /* numeric value, if any */ |
79072805 |
228 | MAGIC* xmg_magic; /* linked list of magicalness */ |
229 | HV* xmg_stash; /* class package */ |
8990e307 |
230 | |
79072805 |
231 | GP* xgv_gp; |
232 | char* xgv_name; |
233 | STRLEN xgv_namelen; |
234 | HV* xgv_stash; |
a5f75d66 |
235 | U8 xgv_flags; |
79072805 |
236 | }; |
237 | |
238 | struct xpvbm { |
ed6116ce |
239 | char * xpv_pv; /* pointer to malloced string */ |
240 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ |
241 | STRLEN xpv_len; /* allocated size */ |
a0d0e21e |
242 | IV xiv_iv; /* integer value or pv offset */ |
ed6116ce |
243 | double xnv_nv; /* numeric value, if any */ |
79072805 |
244 | MAGIC* xmg_magic; /* linked list of magicalness */ |
245 | HV* xmg_stash; /* class package */ |
8990e307 |
246 | |
79072805 |
247 | I32 xbm_useful; /* is this constant pattern being useful? */ |
248 | U16 xbm_previous; /* how many characters in string before rare? */ |
249 | U8 xbm_rare; /* rarest character in string */ |
250 | }; |
251 | |
44a8e56a |
252 | /* This structure much match XPVCV */ |
253 | |
77a005ab |
254 | typedef U16 cv_flags_t; |
255 | |
79072805 |
256 | struct xpvfm { |
ed6116ce |
257 | char * xpv_pv; /* pointer to malloced string */ |
258 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ |
259 | STRLEN xpv_len; /* allocated size */ |
a0d0e21e |
260 | IV xiv_iv; /* integer value or pv offset */ |
ed6116ce |
261 | double xnv_nv; /* numeric value, if any */ |
79072805 |
262 | MAGIC* xmg_magic; /* linked list of magicalness */ |
263 | HV* xmg_stash; /* class package */ |
8990e307 |
264 | |
79072805 |
265 | HV * xcv_stash; |
266 | OP * xcv_start; |
267 | OP * xcv_root; |
e3b8966e |
268 | void (*xcv_xsub)_((CV* _CPERLproto)); |
a0d0e21e |
269 | ANY xcv_xsubany; |
270 | GV * xcv_gv; |
79072805 |
271 | GV * xcv_filegv; |
272 | long xcv_depth; /* >= 2 indicates recursive call */ |
273 | AV * xcv_padlist; |
748a9306 |
274 | CV * xcv_outside; |
e858de61 |
275 | #ifdef USE_THREADS |
f6d98b14 |
276 | perl_mutex *xcv_mutexp; /* protects xcv_owner */ |
52e1cb5e |
277 | struct perl_thread *xcv_owner; /* current owner thread */ |
e858de61 |
278 | #endif /* USE_THREADS */ |
77a005ab |
279 | cv_flags_t xcv_flags; |
44a8e56a |
280 | |
79072805 |
281 | I32 xfm_lines; |
282 | }; |
283 | |
8990e307 |
284 | struct xpvio { |
285 | char * xpv_pv; /* pointer to malloced string */ |
286 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ |
287 | STRLEN xpv_len; /* allocated size */ |
a0d0e21e |
288 | IV xiv_iv; /* integer value or pv offset */ |
8990e307 |
289 | double xnv_nv; /* numeric value, if any */ |
290 | MAGIC* xmg_magic; /* linked list of magicalness */ |
291 | HV* xmg_stash; /* class package */ |
292 | |
760ac839 |
293 | PerlIO * xio_ifp; /* ifp and ofp are normally the same */ |
294 | PerlIO * xio_ofp; /* but sockets need separate streams */ |
8990e307 |
295 | DIR * xio_dirp; /* for opendir, readdir, etc */ |
296 | long xio_lines; /* $. */ |
297 | long xio_page; /* $% */ |
298 | long xio_page_len; /* $= */ |
299 | long xio_lines_left; /* $- */ |
300 | char * xio_top_name; /* $^ */ |
301 | GV * xio_top_gv; /* $^ */ |
302 | char * xio_fmt_name; /* $~ */ |
303 | GV * xio_fmt_gv; /* $~ */ |
304 | char * xio_bottom_name;/* $^B */ |
305 | GV * xio_bottom_gv; /* $^B */ |
306 | short xio_subprocess; /* -| or |- */ |
307 | char xio_type; |
308 | char xio_flags; |
309 | }; |
310 | |
311 | #define IOf_ARGV 1 /* this fp iterates over ARGV */ |
312 | #define IOf_START 2 /* check for null ARGV and substitute '-' */ |
313 | #define IOf_FLUSH 4 /* this fp wants a flush after write op */ |
748a9306 |
314 | #define IOf_DIDTOP 8 /* just did top of form */ |
003e7f14 |
315 | #define IOf_UNTAINT 16 /* consider this fp (and its data) "safe" */ |
fbad3eb5 |
316 | #define IOf_NOLINE 32 /* slurped a pseudo-line from empty file */ |
8990e307 |
317 | |
ed6116ce |
318 | /* The following macros define implementation-independent predicates on SVs. */ |
319 | |
79072805 |
320 | #define SvNIOK(sv) (SvFLAGS(sv) & (SVf_IOK|SVf_NOK)) |
748a9306 |
321 | #define SvNIOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK)) |
a0d0e21e |
322 | #define SvNIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK| \ |
323 | SVp_IOK|SVp_NOK)) |
79072805 |
324 | |
463ee0b2 |
325 | #define SvOK(sv) (SvFLAGS(sv) & SVf_OK) |
a0d0e21e |
326 | #define SvOK_off(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC), \ |
327 | SvOOK_off(sv)) |
79072805 |
328 | |
8990e307 |
329 | #define SvOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK)) |
330 | #define SvIOKp(sv) (SvFLAGS(sv) & SVp_IOK) |
331 | #define SvIOKp_on(sv) (SvOOK_off(sv), SvFLAGS(sv) |= SVp_IOK) |
332 | #define SvNOKp(sv) (SvFLAGS(sv) & SVp_NOK) |
333 | #define SvNOKp_on(sv) (SvFLAGS(sv) |= SVp_NOK) |
334 | #define SvPOKp(sv) (SvFLAGS(sv) & SVp_POK) |
335 | #define SvPOKp_on(sv) (SvFLAGS(sv) |= SVp_POK) |
463ee0b2 |
336 | |
79072805 |
337 | #define SvIOK(sv) (SvFLAGS(sv) & SVf_IOK) |
8990e307 |
338 | #define SvIOK_on(sv) (SvOOK_off(sv), \ |
a0d0e21e |
339 | SvFLAGS(sv) |= (SVf_IOK|SVp_IOK)) |
8990e307 |
340 | #define SvIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVp_IOK)) |
827b7e14 |
341 | #define SvIOK_only(sv) (SvOK_off(sv), \ |
a0d0e21e |
342 | SvFLAGS(sv) |= (SVf_IOK|SVp_IOK)) |
79072805 |
343 | |
344 | #define SvNOK(sv) (SvFLAGS(sv) & SVf_NOK) |
a0d0e21e |
345 | #define SvNOK_on(sv) (SvFLAGS(sv) |= (SVf_NOK|SVp_NOK)) |
8990e307 |
346 | #define SvNOK_off(sv) (SvFLAGS(sv) &= ~(SVf_NOK|SVp_NOK)) |
347 | #define SvNOK_only(sv) (SvOK_off(sv), \ |
a0d0e21e |
348 | SvFLAGS(sv) |= (SVf_NOK|SVp_NOK)) |
79072805 |
349 | |
350 | #define SvPOK(sv) (SvFLAGS(sv) & SVf_POK) |
a0d0e21e |
351 | #define SvPOK_on(sv) (SvFLAGS(sv) |= (SVf_POK|SVp_POK)) |
8990e307 |
352 | #define SvPOK_off(sv) (SvFLAGS(sv) &= ~(SVf_POK|SVp_POK)) |
827b7e14 |
353 | #define SvPOK_only(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC), \ |
a0d0e21e |
354 | SvFLAGS(sv) |= (SVf_POK|SVp_POK)) |
79072805 |
355 | |
356 | #define SvOOK(sv) (SvFLAGS(sv) & SVf_OOK) |
357 | #define SvOOK_on(sv) (SvIOK_off(sv), SvFLAGS(sv) |= SVf_OOK) |
358 | #define SvOOK_off(sv) (SvOOK(sv) && sv_backoff(sv)) |
79072805 |
359 | |
a0d0e21e |
360 | #define SvFAKE(sv) (SvFLAGS(sv) & SVf_FAKE) |
361 | #define SvFAKE_on(sv) (SvFLAGS(sv) |= SVf_FAKE) |
362 | #define SvFAKE_off(sv) (SvFLAGS(sv) &= ~SVf_FAKE) |
363 | |
ed6116ce |
364 | #define SvROK(sv) (SvFLAGS(sv) & SVf_ROK) |
a0d0e21e |
365 | #define SvROK_on(sv) (SvFLAGS(sv) |= SVf_ROK) |
a0d0e21e |
366 | #define SvROK_off(sv) (SvFLAGS(sv) &= ~(SVf_ROK|SVf_AMAGIC)) |
79072805 |
367 | |
8990e307 |
368 | #define SvMAGICAL(sv) (SvFLAGS(sv) & (SVs_GMG|SVs_SMG|SVs_RMG)) |
369 | #define SvMAGICAL_on(sv) (SvFLAGS(sv) |= (SVs_GMG|SVs_SMG|SVs_RMG)) |
370 | #define SvMAGICAL_off(sv) (SvFLAGS(sv) &= ~(SVs_GMG|SVs_SMG|SVs_RMG)) |
79072805 |
371 | |
8990e307 |
372 | #define SvGMAGICAL(sv) (SvFLAGS(sv) & SVs_GMG) |
373 | #define SvGMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_GMG) |
374 | #define SvGMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_GMG) |
ed6116ce |
375 | |
8990e307 |
376 | #define SvSMAGICAL(sv) (SvFLAGS(sv) & SVs_SMG) |
377 | #define SvSMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_SMG) |
378 | #define SvSMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_SMG) |
ed6116ce |
379 | |
8990e307 |
380 | #define SvRMAGICAL(sv) (SvFLAGS(sv) & SVs_RMG) |
381 | #define SvRMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_RMG) |
382 | #define SvRMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_RMG) |
ed6116ce |
383 | |
9e7bc3e8 |
384 | #define SvAMAGIC(sv) (SvFLAGS(sv) & SVf_AMAGIC) |
385 | #define SvAMAGIC_on(sv) (SvFLAGS(sv) |= SVf_AMAGIC) |
386 | #define SvAMAGIC_off(sv) (SvFLAGS(sv) &= ~SVf_AMAGIC) |
a0d0e21e |
387 | |
388 | /* |
389 | #define Gv_AMG(stash) \ |
390 | (HV_AMAGICmb(stash) && \ |
391 | ((!HV_AMAGICbad(stash) && HV_AMAGIC(stash)) || Gv_AMupdate(stash))) |
392 | */ |
3280af22 |
393 | #define Gv_AMG(stash) (PL_amagic_generation && Gv_AMupdate(stash)) |
a0d0e21e |
394 | |
395 | #define SvTHINKFIRST(sv) (SvFLAGS(sv) & SVf_THINKFIRST) |
ed6116ce |
396 | |
8990e307 |
397 | #define SvPADBUSY(sv) (SvFLAGS(sv) & SVs_PADBUSY) |
ed6116ce |
398 | |
8990e307 |
399 | #define SvPADTMP(sv) (SvFLAGS(sv) & SVs_PADTMP) |
400 | #define SvPADTMP_on(sv) (SvFLAGS(sv) |= SVs_PADTMP|SVs_PADBUSY) |
401 | #define SvPADTMP_off(sv) (SvFLAGS(sv) &= ~SVs_PADTMP) |
ed6116ce |
402 | |
8990e307 |
403 | #define SvPADMY(sv) (SvFLAGS(sv) & SVs_PADMY) |
404 | #define SvPADMY_on(sv) (SvFLAGS(sv) |= SVs_PADMY|SVs_PADBUSY) |
ed6116ce |
405 | |
8990e307 |
406 | #define SvTEMP(sv) (SvFLAGS(sv) & SVs_TEMP) |
407 | #define SvTEMP_on(sv) (SvFLAGS(sv) |= SVs_TEMP) |
408 | #define SvTEMP_off(sv) (SvFLAGS(sv) &= ~SVs_TEMP) |
79072805 |
409 | |
8990e307 |
410 | #define SvOBJECT(sv) (SvFLAGS(sv) & SVs_OBJECT) |
411 | #define SvOBJECT_on(sv) (SvFLAGS(sv) |= SVs_OBJECT) |
412 | #define SvOBJECT_off(sv) (SvFLAGS(sv) &= ~SVs_OBJECT) |
79072805 |
413 | |
8990e307 |
414 | #define SvREADONLY(sv) (SvFLAGS(sv) & SVf_READONLY) |
415 | #define SvREADONLY_on(sv) (SvFLAGS(sv) |= SVf_READONLY) |
416 | #define SvREADONLY_off(sv) (SvFLAGS(sv) &= ~SVf_READONLY) |
79072805 |
417 | |
8990e307 |
418 | #define SvSCREAM(sv) (SvFLAGS(sv) & SVp_SCREAM) |
419 | #define SvSCREAM_on(sv) (SvFLAGS(sv) |= SVp_SCREAM) |
420 | #define SvSCREAM_off(sv) (SvFLAGS(sv) &= ~SVp_SCREAM) |
79072805 |
421 | |
8990e307 |
422 | #define SvCOMPILED(sv) (SvFLAGS(sv) & SVpfm_COMPILED) |
423 | #define SvCOMPILED_on(sv) (SvFLAGS(sv) |= SVpfm_COMPILED) |
424 | #define SvCOMPILED_off(sv) (SvFLAGS(sv) &= ~SVpfm_COMPILED) |
79072805 |
425 | |
8990e307 |
426 | #define SvTAIL(sv) (SvFLAGS(sv) & SVpbm_TAIL) |
427 | #define SvTAIL_on(sv) (SvFLAGS(sv) |= SVpbm_TAIL) |
428 | #define SvTAIL_off(sv) (SvFLAGS(sv) &= ~SVpbm_TAIL) |
429 | |
8990e307 |
430 | #define SvVALID(sv) (SvFLAGS(sv) & SVpbm_VALID) |
431 | #define SvVALID_on(sv) (SvFLAGS(sv) |= SVpbm_VALID) |
432 | #define SvVALID_off(sv) (SvFLAGS(sv) &= ~SVpbm_VALID) |
433 | |
ed6116ce |
434 | #define SvRV(sv) ((XRV*) SvANY(sv))->xrv_rv |
435 | #define SvRVx(sv) SvRV(sv) |
436 | |
463ee0b2 |
437 | #define SvIVX(sv) ((XPVIV*) SvANY(sv))->xiv_iv |
438 | #define SvIVXx(sv) SvIVX(sv) |
ff68c719 |
439 | #define SvUVX(sv) ((XPVUV*) SvANY(sv))->xuv_uv |
440 | #define SvUVXx(sv) SvUVX(sv) |
463ee0b2 |
441 | #define SvNVX(sv) ((XPVNV*)SvANY(sv))->xnv_nv |
442 | #define SvNVXx(sv) SvNVX(sv) |
443 | #define SvPVX(sv) ((XPV*) SvANY(sv))->xpv_pv |
444 | #define SvPVXx(sv) SvPVX(sv) |
79072805 |
445 | #define SvCUR(sv) ((XPV*) SvANY(sv))->xpv_cur |
79072805 |
446 | #define SvLEN(sv) ((XPV*) SvANY(sv))->xpv_len |
447 | #define SvLENx(sv) SvLEN(sv) |
448 | #define SvEND(sv)(((XPV*) SvANY(sv))->xpv_pv + ((XPV*)SvANY(sv))->xpv_cur) |
6b88bc9c |
449 | #define SvENDx(sv) ((PL_Sv = (sv)), SvEND(PL_Sv)) |
79072805 |
450 | #define SvMAGIC(sv) ((XPVMG*) SvANY(sv))->xmg_magic |
451 | #define SvSTASH(sv) ((XPVMG*) SvANY(sv))->xmg_stash |
452 | |
453 | #define SvIV_set(sv, val) \ |
80b92232 |
454 | STMT_START { assert(SvTYPE(sv) == SVt_IV || SvTYPE(sv) >= SVt_PVIV); \ |
455 | (((XPVIV*) SvANY(sv))->xiv_iv = val); } STMT_END |
79072805 |
456 | #define SvNV_set(sv, val) \ |
80b92232 |
457 | STMT_START { assert(SvTYPE(sv) == SVt_NV || SvTYPE(sv) >= SVt_PVNV); \ |
458 | (((XPVNV*) SvANY(sv))->xnv_nv = val); } STMT_END |
79072805 |
459 | #define SvPV_set(sv, val) \ |
80b92232 |
460 | STMT_START { assert(SvTYPE(sv) >= SVt_PV); \ |
461 | (((XPV*) SvANY(sv))->xpv_pv = val); } STMT_END |
79072805 |
462 | #define SvCUR_set(sv, val) \ |
80b92232 |
463 | STMT_START { assert(SvTYPE(sv) >= SVt_PV); \ |
464 | (((XPV*) SvANY(sv))->xpv_cur = val); } STMT_END |
79072805 |
465 | #define SvLEN_set(sv, val) \ |
80b92232 |
466 | STMT_START { assert(SvTYPE(sv) >= SVt_PV); \ |
467 | (((XPV*) SvANY(sv))->xpv_len = val); } STMT_END |
79072805 |
468 | #define SvEND_set(sv, val) \ |
80b92232 |
469 | STMT_START { assert(SvTYPE(sv) >= SVt_PV); \ |
470 | (((XPV*) SvANY(sv))->xpv_cur = val - SvPVX(sv)); } STMT_END |
79072805 |
471 | |
472 | #define BmRARE(sv) ((XPVBM*) SvANY(sv))->xbm_rare |
473 | #define BmUSEFUL(sv) ((XPVBM*) SvANY(sv))->xbm_useful |
474 | #define BmPREVIOUS(sv) ((XPVBM*) SvANY(sv))->xbm_previous |
475 | |
476 | #define FmLINES(sv) ((XPVFM*) SvANY(sv))->xfm_lines |
477 | |
478 | #define LvTYPE(sv) ((XPVLV*) SvANY(sv))->xlv_type |
479 | #define LvTARG(sv) ((XPVLV*) SvANY(sv))->xlv_targ |
480 | #define LvTARGOFF(sv) ((XPVLV*) SvANY(sv))->xlv_targoff |
481 | #define LvTARGLEN(sv) ((XPVLV*) SvANY(sv))->xlv_targlen |
482 | |
8990e307 |
483 | #define IoIFP(sv) ((XPVIO*) SvANY(sv))->xio_ifp |
484 | #define IoOFP(sv) ((XPVIO*) SvANY(sv))->xio_ofp |
485 | #define IoDIRP(sv) ((XPVIO*) SvANY(sv))->xio_dirp |
486 | #define IoLINES(sv) ((XPVIO*) SvANY(sv))->xio_lines |
487 | #define IoPAGE(sv) ((XPVIO*) SvANY(sv))->xio_page |
488 | #define IoPAGE_LEN(sv) ((XPVIO*) SvANY(sv))->xio_page_len |
489 | #define IoLINES_LEFT(sv)((XPVIO*) SvANY(sv))->xio_lines_left |
490 | #define IoTOP_NAME(sv) ((XPVIO*) SvANY(sv))->xio_top_name |
491 | #define IoTOP_GV(sv) ((XPVIO*) SvANY(sv))->xio_top_gv |
492 | #define IoFMT_NAME(sv) ((XPVIO*) SvANY(sv))->xio_fmt_name |
493 | #define IoFMT_GV(sv) ((XPVIO*) SvANY(sv))->xio_fmt_gv |
494 | #define IoBOTTOM_NAME(sv)((XPVIO*) SvANY(sv))->xio_bottom_name |
495 | #define IoBOTTOM_GV(sv) ((XPVIO*) SvANY(sv))->xio_bottom_gv |
496 | #define IoSUBPROCESS(sv)((XPVIO*) SvANY(sv))->xio_subprocess |
497 | #define IoTYPE(sv) ((XPVIO*) SvANY(sv))->xio_type |
498 | #define IoFLAGS(sv) ((XPVIO*) SvANY(sv))->xio_flags |
499 | |
bbce6d69 |
500 | #define SvTAINTED(sv) (SvMAGICAL(sv) && sv_tainted(sv)) |
3280af22 |
501 | #define SvTAINTED_on(sv) STMT_START{ if(PL_tainting){sv_taint(sv);} }STMT_END |
502 | #define SvTAINTED_off(sv) STMT_START{ if(PL_tainting){sv_untaint(sv);} }STMT_END |
bbce6d69 |
503 | |
c6ee37c5 |
504 | #define SvTAINT(sv) \ |
505 | STMT_START { \ |
3280af22 |
506 | if (PL_tainting) { \ |
c6ee37c5 |
507 | dTHR; \ |
3280af22 |
508 | if (PL_tainted) \ |
c6ee37c5 |
509 | SvTAINTED_on(sv); \ |
510 | } \ |
511 | } STMT_END |
79072805 |
512 | |
a0d0e21e |
513 | #define SvPV_force(sv, lp) sv_pvn_force(sv, &lp) |
463ee0b2 |
514 | #define SvPV(sv, lp) sv_pvn(sv, &lp) |
1fa8b10d |
515 | #define SvPV_nolen(sv) sv_pv(sv) |
4e35701f |
516 | #define SvIVx(sv) sv_iv(sv) |
517 | #define SvUVx(sv) sv_uv(sv) |
518 | #define SvNVx(sv) sv_nv(sv) |
463ee0b2 |
519 | #define SvPVx(sv, lp) sv_pvn(sv, &lp) |
a0d0e21e |
520 | #define SvPVx_force(sv, lp) sv_pvn_force(sv, &lp) |
4e35701f |
521 | #define SvTRUEx(sv) sv_true(sv) |
522 | |
523 | #define SvIV(sv) SvIVx(sv) |
524 | #define SvNV(sv) SvNVx(sv) |
525 | #define SvUV(sv) SvIVx(sv) |
526 | #define SvTRUE(sv) SvTRUEx(sv) |
79072805 |
527 | |
a80f87c4 |
528 | #ifndef CRIPPLED_CC |
529 | /* redefine some things to more efficient inlined versions */ |
79072805 |
530 | |
ff68c719 |
531 | #undef SvIV |
463ee0b2 |
532 | #define SvIV(sv) (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)) |
79072805 |
533 | |
ff68c719 |
534 | #undef SvUV |
535 | #define SvUV(sv) (SvIOK(sv) ? SvUVX(sv) : sv_2uv(sv)) |
536 | |
537 | #undef SvNV |
463ee0b2 |
538 | #define SvNV(sv) (SvNOK(sv) ? SvNVX(sv) : sv_2nv(sv)) |
79072805 |
539 | |
ff68c719 |
540 | #undef SvPV |
541 | #define SvPV(sv, lp) \ |
542 | (SvPOK(sv) ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pv(sv, &lp)) |
79072805 |
543 | |
ff68c719 |
544 | #undef SvPV_force |
545 | #define SvPV_force(sv, lp) \ |
546 | ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \ |
547 | ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvn_force(sv, &lp)) |
a0d0e21e |
548 | |
1fa8b10d |
549 | #undef SvPV_nolen |
550 | #define SvPV_nolen(sv) \ |
551 | (SvPOK(sv) ? SvPVX(sv) : sv_2pv_nolen(sv)) |
552 | |
a80f87c4 |
553 | #ifdef __GNUC__ |
554 | # undef SvIVx |
555 | # undef SvUVx |
556 | # undef SvNVx |
557 | # undef SvPVx |
558 | # undef SvTRUE |
559 | # undef SvTRUEx |
560 | # define SvIVx(sv) ({SV *nsv = (SV*)(sv); SvIV(nsv); }) |
561 | # define SvUVx(sv) ({SV *nsv = (SV*)(sv); SvUV(nsv); }) |
562 | # define SvNVx(sv) ({SV *nsv = (SV*)(sv); SvNV(nsv); }) |
563 | # define SvPVx(sv, lp) ({SV *nsv = (sv); SvPV(nsv, lp); }) |
564 | # define SvTRUE(sv) ( \ |
8990e307 |
565 | !sv \ |
566 | ? 0 \ |
567 | : SvPOK(sv) \ |
a80f87c4 |
568 | ? (({XPV *nxpv = (XPV*)SvANY(sv); \ |
569 | nxpv && \ |
570 | (*nxpv->xpv_pv > '0' || \ |
571 | nxpv->xpv_cur > 1 || \ |
572 | (nxpv->xpv_cur && *nxpv->xpv_pv != '0')); }) \ |
79072805 |
573 | ? 1 \ |
574 | : 0) \ |
575 | : \ |
576 | SvIOK(sv) \ |
463ee0b2 |
577 | ? SvIVX(sv) != 0 \ |
79072805 |
578 | : SvNOK(sv) \ |
463ee0b2 |
579 | ? SvNVX(sv) != 0.0 \ |
580 | : sv_2bool(sv) ) |
a80f87c4 |
581 | # define SvTRUEx(sv) ({SV *nsv = (sv); SvTRUE(nsv); }) |
582 | #else /* __GNUC__ */ |
583 | #ifndef USE_THREADS |
584 | /* These inlined macros use globals, which will require a thread |
585 | * declaration in user code, so we avoid them under threads */ |
586 | |
587 | # undef SvIVx |
588 | # undef SvUVx |
589 | # undef SvNVx |
590 | # undef SvPVx |
591 | # undef SvTRUE |
592 | # undef SvTRUEx |
6b88bc9c |
593 | # define SvIVx(sv) ((PL_Sv = (sv)), SvIV(PL_Sv)) |
594 | # define SvUVx(sv) ((PL_Sv = (sv)), SvUV(PL_Sv)) |
595 | # define SvNVx(sv) ((PL_Sv = (sv)), SvNV(PL_Sv)) |
596 | # define SvPVx(sv, lp) ((PL_Sv = (sv)), SvPV(PL_Sv, lp)) |
a80f87c4 |
597 | # define SvTRUE(sv) ( \ |
598 | !sv \ |
599 | ? 0 \ |
600 | : SvPOK(sv) \ |
6b88bc9c |
601 | ? ((PL_Xpv = (XPV*)SvANY(sv)) && \ |
602 | (*PL_Xpv->xpv_pv > '0' || \ |
603 | PL_Xpv->xpv_cur > 1 || \ |
604 | (PL_Xpv->xpv_cur && *PL_Xpv->xpv_pv != '0')) \ |
a80f87c4 |
605 | ? 1 \ |
606 | : 0) \ |
607 | : \ |
608 | SvIOK(sv) \ |
609 | ? SvIVX(sv) != 0 \ |
610 | : SvNOK(sv) \ |
611 | ? SvNVX(sv) != 0.0 \ |
612 | : sv_2bool(sv) ) |
6b88bc9c |
613 | # define SvTRUEx(sv) ((PL_Sv = (sv)), SvTRUE(PL_Sv)) |
a80f87c4 |
614 | #endif /* !USE_THREADS */ |
615 | #endif /* !__GNU__ */ |
616 | #endif /* !CRIPPLED_CC */ |
79072805 |
617 | |
5f05dabc |
618 | #define newRV_inc(sv) newRV(sv) |
5f05dabc |
619 | |
ef50df4b |
620 | /* the following macros update any magic values this sv is associated with */ |
79072805 |
621 | |
189b2af5 |
622 | #define SvGETMAGIC(x) STMT_START { if (SvGMAGICAL(x)) mg_get(x); } STMT_END |
623 | #define SvSETMAGIC(x) STMT_START { if (SvSMAGICAL(x)) mg_set(x); } STMT_END |
79072805 |
624 | |
54310121 |
625 | #define SvSetSV_and(dst,src,finally) \ |
189b2af5 |
626 | STMT_START { \ |
54310121 |
627 | if ((dst) != (src)) { \ |
628 | sv_setsv(dst, src); \ |
629 | finally; \ |
189b2af5 |
630 | } \ |
631 | } STMT_END |
54310121 |
632 | #define SvSetSV_nosteal_and(dst,src,finally) \ |
189b2af5 |
633 | STMT_START { \ |
8ebc5c01 |
634 | if ((dst) != (src)) { \ |
635 | U32 tMpF = SvFLAGS(src) & SVs_TEMP; \ |
636 | SvTEMP_off(src); \ |
637 | sv_setsv(dst, src); \ |
638 | SvFLAGS(src) |= tMpF; \ |
54310121 |
639 | finally; \ |
189b2af5 |
640 | } \ |
641 | } STMT_END |
79072805 |
642 | |
54310121 |
643 | #define SvSetSV(dst,src) \ |
c9d716f7 |
644 | SvSetSV_and(dst,src,/*nothing*/;) |
54310121 |
645 | #define SvSetSV_nosteal(dst,src) \ |
c9d716f7 |
646 | SvSetSV_nosteal_and(dst,src,/*nothing*/;) |
54310121 |
647 | |
648 | #define SvSetMagicSV(dst,src) \ |
649 | SvSetSV_and(dst,src,SvSETMAGIC(dst)) |
650 | #define SvSetMagicSV_nosteal(dst,src) \ |
651 | SvSetSV_nosteal_and(dst,src,SvSETMAGIC(dst)) |
652 | |
3967c732 |
653 | #ifdef DEBUGGING |
79072805 |
654 | #define SvPEEK(sv) sv_peek(sv) |
3967c732 |
655 | #else |
656 | #define SvPEEK(sv) "" |
657 | #endif |
79072805 |
658 | |
3280af22 |
659 | #define SvIMMORTAL(sv) ((sv)==&PL_sv_undef || (sv)==&PL_sv_yes || (sv)==&PL_sv_no) |
36477c24 |
660 | |
3280af22 |
661 | #define boolSV(b) ((b) ? &PL_sv_yes : &PL_sv_no) |
54310121 |
662 | |
79072805 |
663 | #define isGV(sv) (SvTYPE(sv) == SVt_PVGV) |
664 | |
79072805 |
665 | #ifndef DOSISH |
a0d0e21e |
666 | # define SvGROW(sv,len) (SvLEN(sv) < (len) ? sv_grow(sv,len) : SvPVX(sv)) |
79072805 |
667 | # define Sv_Grow sv_grow |
668 | #else |
669 | /* extra parentheses intentionally NOT placed around "len"! */ |
a0d0e21e |
670 | # define SvGROW(sv,len) ((SvLEN(sv) < (unsigned long)len) \ |
671 | ? sv_grow(sv,(unsigned long)len) : SvPVX(sv)) |
79072805 |
672 | # define Sv_Grow(sv,len) sv_grow(sv,(unsigned long)(len)) |
673 | #endif /* DOSISH */ |