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 { \ |
79 | MUTEX_LOCK(&svref_mutex); \ |
80 | ++count; \ |
81 | MUTEX_UNLOCK(&svref_mutex); \ |
82 | } STMT_END |
0bfcb09d |
83 | # define ATOMIC_DEC_AND_TEST(res,count) STMT_START { \ |
84 | MUTEX_LOCK(&svref_mutex); \ |
85 | res = (--count == 0); \ |
86 | MUTEX_UNLOCK(&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) \ |
110 | ((Sv=(SV*)(sv)), (Sv && ATOMIC_INC(SvREFCNT(Sv))), (SV*)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 | |
150 | #ifdef OVERLOAD |
151 | #define SVf_AMAGIC 0x10000000 /* has magical overloaded methods */ |
152 | #endif /* OVERLOAD */ |
153 | |
8990e307 |
154 | #define PRIVSHIFT 8 |
155 | |
156 | /* Some private flags. */ |
157 | |
158 | #define SVpfm_COMPILED 0x80000000 |
159 | |
160 | #define SVpbm_VALID 0x80000000 |
bbce6d69 |
161 | #define SVpbm_TAIL 0x40000000 |
8990e307 |
162 | |
bf6bd887 |
163 | #define SVphv_SHAREKEYS 0x20000000 /* keys live on shared string table */ |
51594c39 |
164 | #define SVphv_LAZYDEL 0x40000000 /* entry in xhv_eiter must be deleted */ |
bf6bd887 |
165 | |
ed6116ce |
166 | struct xrv { |
167 | SV * xrv_rv; /* pointer to another SV */ |
168 | }; |
169 | |
79072805 |
170 | struct xpv { |
ed6116ce |
171 | char * xpv_pv; /* pointer to malloced string */ |
172 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ |
173 | STRLEN xpv_len; /* allocated size */ |
79072805 |
174 | }; |
175 | |
176 | struct xpviv { |
ed6116ce |
177 | char * xpv_pv; /* pointer to malloced string */ |
178 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ |
179 | STRLEN xpv_len; /* allocated size */ |
a0d0e21e |
180 | IV xiv_iv; /* integer value or pv offset */ |
79072805 |
181 | }; |
182 | |
ff68c719 |
183 | struct xpvuv { |
184 | char * xpv_pv; /* pointer to malloced string */ |
185 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ |
186 | STRLEN xpv_len; /* allocated size */ |
187 | UV xuv_uv; /* unsigned value or pv offset */ |
188 | }; |
189 | |
79072805 |
190 | struct xpvnv { |
ed6116ce |
191 | char * xpv_pv; /* pointer to malloced string */ |
192 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ |
193 | STRLEN xpv_len; /* allocated size */ |
a0d0e21e |
194 | IV xiv_iv; /* integer value or pv offset */ |
ed6116ce |
195 | double xnv_nv; /* numeric value, if any */ |
79072805 |
196 | }; |
197 | |
6ee623d5 |
198 | /* These structure must match the beginning of struct xpvhv in hv.h. */ |
79072805 |
199 | struct xpvmg { |
ed6116ce |
200 | char * xpv_pv; /* pointer to malloced string */ |
201 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ |
202 | STRLEN xpv_len; /* allocated size */ |
a0d0e21e |
203 | IV xiv_iv; /* integer value or pv offset */ |
ed6116ce |
204 | double xnv_nv; /* numeric value, if any */ |
79072805 |
205 | MAGIC* xmg_magic; /* linked list of magicalness */ |
206 | HV* xmg_stash; /* class package */ |
207 | }; |
208 | |
209 | struct xpvlv { |
ed6116ce |
210 | char * xpv_pv; /* pointer to malloced string */ |
211 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ |
212 | STRLEN xpv_len; /* allocated size */ |
a0d0e21e |
213 | IV xiv_iv; /* integer value or pv offset */ |
ed6116ce |
214 | double xnv_nv; /* numeric value, if any */ |
79072805 |
215 | MAGIC* xmg_magic; /* linked list of magicalness */ |
216 | HV* xmg_stash; /* class package */ |
8990e307 |
217 | |
79072805 |
218 | STRLEN xlv_targoff; |
219 | STRLEN xlv_targlen; |
220 | SV* xlv_targ; |
221 | char xlv_type; |
222 | }; |
223 | |
224 | struct xpvgv { |
ed6116ce |
225 | char * xpv_pv; /* pointer to malloced string */ |
226 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ |
227 | STRLEN xpv_len; /* allocated size */ |
a0d0e21e |
228 | IV xiv_iv; /* integer value or pv offset */ |
ed6116ce |
229 | double xnv_nv; /* numeric value, if any */ |
79072805 |
230 | MAGIC* xmg_magic; /* linked list of magicalness */ |
231 | HV* xmg_stash; /* class package */ |
8990e307 |
232 | |
79072805 |
233 | GP* xgv_gp; |
234 | char* xgv_name; |
235 | STRLEN xgv_namelen; |
236 | HV* xgv_stash; |
a5f75d66 |
237 | U8 xgv_flags; |
79072805 |
238 | }; |
239 | |
240 | struct xpvbm { |
ed6116ce |
241 | char * xpv_pv; /* pointer to malloced string */ |
242 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ |
243 | STRLEN xpv_len; /* allocated size */ |
a0d0e21e |
244 | IV xiv_iv; /* integer value or pv offset */ |
ed6116ce |
245 | double xnv_nv; /* numeric value, if any */ |
79072805 |
246 | MAGIC* xmg_magic; /* linked list of magicalness */ |
247 | HV* xmg_stash; /* class package */ |
8990e307 |
248 | |
79072805 |
249 | I32 xbm_useful; /* is this constant pattern being useful? */ |
250 | U16 xbm_previous; /* how many characters in string before rare? */ |
251 | U8 xbm_rare; /* rarest character in string */ |
252 | }; |
253 | |
44a8e56a |
254 | /* This structure much match XPVCV */ |
255 | |
77a005ab |
256 | typedef U16 cv_flags_t; |
257 | |
79072805 |
258 | struct xpvfm { |
ed6116ce |
259 | char * xpv_pv; /* pointer to malloced string */ |
260 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ |
261 | STRLEN xpv_len; /* allocated size */ |
a0d0e21e |
262 | IV xiv_iv; /* integer value or pv offset */ |
ed6116ce |
263 | double xnv_nv; /* numeric value, if any */ |
79072805 |
264 | MAGIC* xmg_magic; /* linked list of magicalness */ |
265 | HV* xmg_stash; /* class package */ |
8990e307 |
266 | |
79072805 |
267 | HV * xcv_stash; |
268 | OP * xcv_start; |
269 | OP * xcv_root; |
e3b8966e |
270 | void (*xcv_xsub)_((CV* _CPERLproto)); |
a0d0e21e |
271 | ANY xcv_xsubany; |
272 | GV * xcv_gv; |
79072805 |
273 | GV * xcv_filegv; |
274 | long xcv_depth; /* >= 2 indicates recursive call */ |
275 | AV * xcv_padlist; |
748a9306 |
276 | CV * xcv_outside; |
e858de61 |
277 | #ifdef USE_THREADS |
f6d98b14 |
278 | perl_mutex *xcv_mutexp; /* protects xcv_owner */ |
52e1cb5e |
279 | struct perl_thread *xcv_owner; /* current owner thread */ |
e858de61 |
280 | #endif /* USE_THREADS */ |
77a005ab |
281 | cv_flags_t xcv_flags; |
44a8e56a |
282 | |
79072805 |
283 | I32 xfm_lines; |
284 | }; |
285 | |
8990e307 |
286 | struct xpvio { |
287 | char * xpv_pv; /* pointer to malloced string */ |
288 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ |
289 | STRLEN xpv_len; /* allocated size */ |
a0d0e21e |
290 | IV xiv_iv; /* integer value or pv offset */ |
8990e307 |
291 | double xnv_nv; /* numeric value, if any */ |
292 | MAGIC* xmg_magic; /* linked list of magicalness */ |
293 | HV* xmg_stash; /* class package */ |
294 | |
760ac839 |
295 | PerlIO * xio_ifp; /* ifp and ofp are normally the same */ |
296 | PerlIO * xio_ofp; /* but sockets need separate streams */ |
8990e307 |
297 | DIR * xio_dirp; /* for opendir, readdir, etc */ |
298 | long xio_lines; /* $. */ |
299 | long xio_page; /* $% */ |
300 | long xio_page_len; /* $= */ |
301 | long xio_lines_left; /* $- */ |
302 | char * xio_top_name; /* $^ */ |
303 | GV * xio_top_gv; /* $^ */ |
304 | char * xio_fmt_name; /* $~ */ |
305 | GV * xio_fmt_gv; /* $~ */ |
306 | char * xio_bottom_name;/* $^B */ |
307 | GV * xio_bottom_gv; /* $^B */ |
308 | short xio_subprocess; /* -| or |- */ |
309 | char xio_type; |
310 | char xio_flags; |
311 | }; |
312 | |
313 | #define IOf_ARGV 1 /* this fp iterates over ARGV */ |
314 | #define IOf_START 2 /* check for null ARGV and substitute '-' */ |
315 | #define IOf_FLUSH 4 /* this fp wants a flush after write op */ |
748a9306 |
316 | #define IOf_DIDTOP 8 /* just did top of form */ |
51594c39 |
317 | #define IOf_UNTAINT 16 /* consider this fp (and it's data) "safe" */ |
8990e307 |
318 | |
ed6116ce |
319 | /* The following macros define implementation-independent predicates on SVs. */ |
320 | |
79072805 |
321 | #define SvNIOK(sv) (SvFLAGS(sv) & (SVf_IOK|SVf_NOK)) |
748a9306 |
322 | #define SvNIOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK)) |
a0d0e21e |
323 | #define SvNIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK| \ |
324 | SVp_IOK|SVp_NOK)) |
79072805 |
325 | |
463ee0b2 |
326 | #define SvOK(sv) (SvFLAGS(sv) & SVf_OK) |
a0d0e21e |
327 | |
328 | #ifdef OVERLOAD |
329 | #define SvOK_off(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC), \ |
330 | SvOOK_off(sv)) |
331 | #else |
332 | #define SvOK_off(sv) (SvFLAGS(sv) &= ~SVf_OK, SvOOK_off(sv)) |
333 | #endif /* OVERLOAD */ |
79072805 |
334 | |
8990e307 |
335 | #define SvOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK)) |
336 | #define SvIOKp(sv) (SvFLAGS(sv) & SVp_IOK) |
337 | #define SvIOKp_on(sv) (SvOOK_off(sv), SvFLAGS(sv) |= SVp_IOK) |
338 | #define SvNOKp(sv) (SvFLAGS(sv) & SVp_NOK) |
339 | #define SvNOKp_on(sv) (SvFLAGS(sv) |= SVp_NOK) |
340 | #define SvPOKp(sv) (SvFLAGS(sv) & SVp_POK) |
341 | #define SvPOKp_on(sv) (SvFLAGS(sv) |= SVp_POK) |
463ee0b2 |
342 | |
79072805 |
343 | #define SvIOK(sv) (SvFLAGS(sv) & SVf_IOK) |
8990e307 |
344 | #define SvIOK_on(sv) (SvOOK_off(sv), \ |
a0d0e21e |
345 | SvFLAGS(sv) |= (SVf_IOK|SVp_IOK)) |
8990e307 |
346 | #define SvIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVp_IOK)) |
a5f75d66 |
347 | #define SvIOK_only(sv) (SvOOK_off(sv), SvOK_off(sv), \ |
a0d0e21e |
348 | SvFLAGS(sv) |= (SVf_IOK|SVp_IOK)) |
79072805 |
349 | |
350 | #define SvNOK(sv) (SvFLAGS(sv) & SVf_NOK) |
a0d0e21e |
351 | #define SvNOK_on(sv) (SvFLAGS(sv) |= (SVf_NOK|SVp_NOK)) |
8990e307 |
352 | #define SvNOK_off(sv) (SvFLAGS(sv) &= ~(SVf_NOK|SVp_NOK)) |
353 | #define SvNOK_only(sv) (SvOK_off(sv), \ |
a0d0e21e |
354 | SvFLAGS(sv) |= (SVf_NOK|SVp_NOK)) |
79072805 |
355 | |
356 | #define SvPOK(sv) (SvFLAGS(sv) & SVf_POK) |
a0d0e21e |
357 | #define SvPOK_on(sv) (SvFLAGS(sv) |= (SVf_POK|SVp_POK)) |
8990e307 |
358 | #define SvPOK_off(sv) (SvFLAGS(sv) &= ~(SVf_POK|SVp_POK)) |
c07a80fd |
359 | |
360 | #ifdef OVERLOAD |
361 | #define SvPOK_only(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC), \ |
a0d0e21e |
362 | SvFLAGS(sv) |= (SVf_POK|SVp_POK)) |
c07a80fd |
363 | #else |
364 | #define SvPOK_only(sv) (SvFLAGS(sv) &= ~SVf_OK, \ |
365 | SvFLAGS(sv) |= (SVf_POK|SVp_POK)) |
366 | #endif /* OVERLOAD */ |
79072805 |
367 | |
368 | #define SvOOK(sv) (SvFLAGS(sv) & SVf_OOK) |
369 | #define SvOOK_on(sv) (SvIOK_off(sv), SvFLAGS(sv) |= SVf_OOK) |
370 | #define SvOOK_off(sv) (SvOOK(sv) && sv_backoff(sv)) |
79072805 |
371 | |
a0d0e21e |
372 | #define SvFAKE(sv) (SvFLAGS(sv) & SVf_FAKE) |
373 | #define SvFAKE_on(sv) (SvFLAGS(sv) |= SVf_FAKE) |
374 | #define SvFAKE_off(sv) (SvFLAGS(sv) &= ~SVf_FAKE) |
375 | |
ed6116ce |
376 | #define SvROK(sv) (SvFLAGS(sv) & SVf_ROK) |
a0d0e21e |
377 | #define SvROK_on(sv) (SvFLAGS(sv) |= SVf_ROK) |
378 | |
379 | #ifdef OVERLOAD |
380 | #define SvROK_off(sv) (SvFLAGS(sv) &= ~(SVf_ROK|SVf_AMAGIC)) |
381 | #else |
ed6116ce |
382 | #define SvROK_off(sv) (SvFLAGS(sv) &= ~SVf_ROK) |
a0d0e21e |
383 | #endif /* OVERLOAD */ |
79072805 |
384 | |
8990e307 |
385 | #define SvMAGICAL(sv) (SvFLAGS(sv) & (SVs_GMG|SVs_SMG|SVs_RMG)) |
386 | #define SvMAGICAL_on(sv) (SvFLAGS(sv) |= (SVs_GMG|SVs_SMG|SVs_RMG)) |
387 | #define SvMAGICAL_off(sv) (SvFLAGS(sv) &= ~(SVs_GMG|SVs_SMG|SVs_RMG)) |
79072805 |
388 | |
8990e307 |
389 | #define SvGMAGICAL(sv) (SvFLAGS(sv) & SVs_GMG) |
390 | #define SvGMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_GMG) |
391 | #define SvGMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_GMG) |
ed6116ce |
392 | |
8990e307 |
393 | #define SvSMAGICAL(sv) (SvFLAGS(sv) & SVs_SMG) |
394 | #define SvSMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_SMG) |
395 | #define SvSMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_SMG) |
ed6116ce |
396 | |
8990e307 |
397 | #define SvRMAGICAL(sv) (SvFLAGS(sv) & SVs_RMG) |
398 | #define SvRMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_RMG) |
399 | #define SvRMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_RMG) |
ed6116ce |
400 | |
a0d0e21e |
401 | #ifdef OVERLOAD |
402 | #define SvAMAGIC(sv) (SvFLAGS(sv) & SVf_AMAGIC) |
403 | #define SvAMAGIC_on(sv) (SvFLAGS(sv) |= SVf_AMAGIC) |
404 | #define SvAMAGIC_off(sv) (SvFLAGS(sv) &= ~SVf_AMAGIC) |
405 | |
406 | /* |
407 | #define Gv_AMG(stash) \ |
408 | (HV_AMAGICmb(stash) && \ |
409 | ((!HV_AMAGICbad(stash) && HV_AMAGIC(stash)) || Gv_AMupdate(stash))) |
410 | */ |
411 | #define Gv_AMG(stash) (amagic_generation && Gv_AMupdate(stash)) |
412 | #endif /* OVERLOAD */ |
413 | |
414 | #define SvTHINKFIRST(sv) (SvFLAGS(sv) & SVf_THINKFIRST) |
ed6116ce |
415 | |
8990e307 |
416 | #define SvPADBUSY(sv) (SvFLAGS(sv) & SVs_PADBUSY) |
ed6116ce |
417 | |
8990e307 |
418 | #define SvPADTMP(sv) (SvFLAGS(sv) & SVs_PADTMP) |
419 | #define SvPADTMP_on(sv) (SvFLAGS(sv) |= SVs_PADTMP|SVs_PADBUSY) |
420 | #define SvPADTMP_off(sv) (SvFLAGS(sv) &= ~SVs_PADTMP) |
ed6116ce |
421 | |
8990e307 |
422 | #define SvPADMY(sv) (SvFLAGS(sv) & SVs_PADMY) |
423 | #define SvPADMY_on(sv) (SvFLAGS(sv) |= SVs_PADMY|SVs_PADBUSY) |
ed6116ce |
424 | |
8990e307 |
425 | #define SvTEMP(sv) (SvFLAGS(sv) & SVs_TEMP) |
426 | #define SvTEMP_on(sv) (SvFLAGS(sv) |= SVs_TEMP) |
427 | #define SvTEMP_off(sv) (SvFLAGS(sv) &= ~SVs_TEMP) |
79072805 |
428 | |
8990e307 |
429 | #define SvOBJECT(sv) (SvFLAGS(sv) & SVs_OBJECT) |
430 | #define SvOBJECT_on(sv) (SvFLAGS(sv) |= SVs_OBJECT) |
431 | #define SvOBJECT_off(sv) (SvFLAGS(sv) &= ~SVs_OBJECT) |
79072805 |
432 | |
8990e307 |
433 | #define SvREADONLY(sv) (SvFLAGS(sv) & SVf_READONLY) |
434 | #define SvREADONLY_on(sv) (SvFLAGS(sv) |= SVf_READONLY) |
435 | #define SvREADONLY_off(sv) (SvFLAGS(sv) &= ~SVf_READONLY) |
79072805 |
436 | |
8990e307 |
437 | #define SvSCREAM(sv) (SvFLAGS(sv) & SVp_SCREAM) |
438 | #define SvSCREAM_on(sv) (SvFLAGS(sv) |= SVp_SCREAM) |
439 | #define SvSCREAM_off(sv) (SvFLAGS(sv) &= ~SVp_SCREAM) |
79072805 |
440 | |
8990e307 |
441 | #define SvCOMPILED(sv) (SvFLAGS(sv) & SVpfm_COMPILED) |
442 | #define SvCOMPILED_on(sv) (SvFLAGS(sv) |= SVpfm_COMPILED) |
443 | #define SvCOMPILED_off(sv) (SvFLAGS(sv) &= ~SVpfm_COMPILED) |
79072805 |
444 | |
8990e307 |
445 | #define SvTAIL(sv) (SvFLAGS(sv) & SVpbm_TAIL) |
446 | #define SvTAIL_on(sv) (SvFLAGS(sv) |= SVpbm_TAIL) |
447 | #define SvTAIL_off(sv) (SvFLAGS(sv) &= ~SVpbm_TAIL) |
448 | |
8990e307 |
449 | #define SvVALID(sv) (SvFLAGS(sv) & SVpbm_VALID) |
450 | #define SvVALID_on(sv) (SvFLAGS(sv) |= SVpbm_VALID) |
451 | #define SvVALID_off(sv) (SvFLAGS(sv) &= ~SVpbm_VALID) |
452 | |
ed6116ce |
453 | #define SvRV(sv) ((XRV*) SvANY(sv))->xrv_rv |
454 | #define SvRVx(sv) SvRV(sv) |
455 | |
463ee0b2 |
456 | #define SvIVX(sv) ((XPVIV*) SvANY(sv))->xiv_iv |
457 | #define SvIVXx(sv) SvIVX(sv) |
ff68c719 |
458 | #define SvUVX(sv) ((XPVUV*) SvANY(sv))->xuv_uv |
459 | #define SvUVXx(sv) SvUVX(sv) |
463ee0b2 |
460 | #define SvNVX(sv) ((XPVNV*)SvANY(sv))->xnv_nv |
461 | #define SvNVXx(sv) SvNVX(sv) |
462 | #define SvPVX(sv) ((XPV*) SvANY(sv))->xpv_pv |
463 | #define SvPVXx(sv) SvPVX(sv) |
79072805 |
464 | #define SvCUR(sv) ((XPV*) SvANY(sv))->xpv_cur |
79072805 |
465 | #define SvLEN(sv) ((XPV*) SvANY(sv))->xpv_len |
466 | #define SvLENx(sv) SvLEN(sv) |
467 | #define SvEND(sv)(((XPV*) SvANY(sv))->xpv_pv + ((XPV*)SvANY(sv))->xpv_cur) |
8990e307 |
468 | #define SvENDx(sv) ((Sv = (sv)), SvEND(Sv)) |
79072805 |
469 | #define SvMAGIC(sv) ((XPVMG*) SvANY(sv))->xmg_magic |
470 | #define SvSTASH(sv) ((XPVMG*) SvANY(sv))->xmg_stash |
471 | |
472 | #define SvIV_set(sv, val) \ |
80b92232 |
473 | STMT_START { assert(SvTYPE(sv) == SVt_IV || SvTYPE(sv) >= SVt_PVIV); \ |
474 | (((XPVIV*) SvANY(sv))->xiv_iv = val); } STMT_END |
79072805 |
475 | #define SvNV_set(sv, val) \ |
80b92232 |
476 | STMT_START { assert(SvTYPE(sv) == SVt_NV || SvTYPE(sv) >= SVt_PVNV); \ |
477 | (((XPVNV*) SvANY(sv))->xnv_nv = val); } STMT_END |
79072805 |
478 | #define SvPV_set(sv, val) \ |
80b92232 |
479 | STMT_START { assert(SvTYPE(sv) >= SVt_PV); \ |
480 | (((XPV*) SvANY(sv))->xpv_pv = val); } STMT_END |
79072805 |
481 | #define SvCUR_set(sv, val) \ |
80b92232 |
482 | STMT_START { assert(SvTYPE(sv) >= SVt_PV); \ |
483 | (((XPV*) SvANY(sv))->xpv_cur = val); } STMT_END |
79072805 |
484 | #define SvLEN_set(sv, val) \ |
80b92232 |
485 | STMT_START { assert(SvTYPE(sv) >= SVt_PV); \ |
486 | (((XPV*) SvANY(sv))->xpv_len = val); } STMT_END |
79072805 |
487 | #define SvEND_set(sv, val) \ |
80b92232 |
488 | STMT_START { assert(SvTYPE(sv) >= SVt_PV); \ |
489 | (((XPV*) SvANY(sv))->xpv_cur = val - SvPVX(sv)); } STMT_END |
79072805 |
490 | |
491 | #define BmRARE(sv) ((XPVBM*) SvANY(sv))->xbm_rare |
492 | #define BmUSEFUL(sv) ((XPVBM*) SvANY(sv))->xbm_useful |
493 | #define BmPREVIOUS(sv) ((XPVBM*) SvANY(sv))->xbm_previous |
494 | |
495 | #define FmLINES(sv) ((XPVFM*) SvANY(sv))->xfm_lines |
496 | |
497 | #define LvTYPE(sv) ((XPVLV*) SvANY(sv))->xlv_type |
498 | #define LvTARG(sv) ((XPVLV*) SvANY(sv))->xlv_targ |
499 | #define LvTARGOFF(sv) ((XPVLV*) SvANY(sv))->xlv_targoff |
500 | #define LvTARGLEN(sv) ((XPVLV*) SvANY(sv))->xlv_targlen |
501 | |
8990e307 |
502 | #define IoIFP(sv) ((XPVIO*) SvANY(sv))->xio_ifp |
503 | #define IoOFP(sv) ((XPVIO*) SvANY(sv))->xio_ofp |
504 | #define IoDIRP(sv) ((XPVIO*) SvANY(sv))->xio_dirp |
505 | #define IoLINES(sv) ((XPVIO*) SvANY(sv))->xio_lines |
506 | #define IoPAGE(sv) ((XPVIO*) SvANY(sv))->xio_page |
507 | #define IoPAGE_LEN(sv) ((XPVIO*) SvANY(sv))->xio_page_len |
508 | #define IoLINES_LEFT(sv)((XPVIO*) SvANY(sv))->xio_lines_left |
509 | #define IoTOP_NAME(sv) ((XPVIO*) SvANY(sv))->xio_top_name |
510 | #define IoTOP_GV(sv) ((XPVIO*) SvANY(sv))->xio_top_gv |
511 | #define IoFMT_NAME(sv) ((XPVIO*) SvANY(sv))->xio_fmt_name |
512 | #define IoFMT_GV(sv) ((XPVIO*) SvANY(sv))->xio_fmt_gv |
513 | #define IoBOTTOM_NAME(sv)((XPVIO*) SvANY(sv))->xio_bottom_name |
514 | #define IoBOTTOM_GV(sv) ((XPVIO*) SvANY(sv))->xio_bottom_gv |
515 | #define IoSUBPROCESS(sv)((XPVIO*) SvANY(sv))->xio_subprocess |
516 | #define IoTYPE(sv) ((XPVIO*) SvANY(sv))->xio_type |
517 | #define IoFLAGS(sv) ((XPVIO*) SvANY(sv))->xio_flags |
518 | |
bbce6d69 |
519 | #define SvTAINTED(sv) (SvMAGICAL(sv) && sv_tainted(sv)) |
520 | #define SvTAINTED_on(sv) STMT_START{ if(tainting){sv_taint(sv);} }STMT_END |
521 | #define SvTAINTED_off(sv) STMT_START{ if(tainting){sv_untaint(sv);} }STMT_END |
522 | |
c6ee37c5 |
523 | #define SvTAINT(sv) \ |
524 | STMT_START { \ |
525 | if (tainting) { \ |
526 | dTHR; \ |
527 | if (tainted) \ |
528 | SvTAINTED_on(sv); \ |
529 | } \ |
530 | } STMT_END |
79072805 |
531 | |
a0d0e21e |
532 | #define SvPV_force(sv, lp) sv_pvn_force(sv, &lp) |
463ee0b2 |
533 | #define SvPV(sv, lp) sv_pvn(sv, &lp) |
4e35701f |
534 | #define SvIVx(sv) sv_iv(sv) |
535 | #define SvUVx(sv) sv_uv(sv) |
536 | #define SvNVx(sv) sv_nv(sv) |
463ee0b2 |
537 | #define SvPVx(sv, lp) sv_pvn(sv, &lp) |
a0d0e21e |
538 | #define SvPVx_force(sv, lp) sv_pvn_force(sv, &lp) |
4e35701f |
539 | #define SvTRUEx(sv) sv_true(sv) |
540 | |
541 | #define SvIV(sv) SvIVx(sv) |
542 | #define SvNV(sv) SvNVx(sv) |
543 | #define SvUV(sv) SvIVx(sv) |
544 | #define SvTRUE(sv) SvTRUEx(sv) |
79072805 |
545 | |
a80f87c4 |
546 | #ifndef CRIPPLED_CC |
547 | /* redefine some things to more efficient inlined versions */ |
79072805 |
548 | |
ff68c719 |
549 | #undef SvIV |
463ee0b2 |
550 | #define SvIV(sv) (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)) |
79072805 |
551 | |
ff68c719 |
552 | #undef SvUV |
553 | #define SvUV(sv) (SvIOK(sv) ? SvUVX(sv) : sv_2uv(sv)) |
554 | |
555 | #undef SvNV |
463ee0b2 |
556 | #define SvNV(sv) (SvNOK(sv) ? SvNVX(sv) : sv_2nv(sv)) |
79072805 |
557 | |
ff68c719 |
558 | #undef SvPV |
559 | #define SvPV(sv, lp) \ |
560 | (SvPOK(sv) ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pv(sv, &lp)) |
79072805 |
561 | |
ff68c719 |
562 | #undef SvPV_force |
563 | #define SvPV_force(sv, lp) \ |
564 | ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \ |
565 | ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvn_force(sv, &lp)) |
a0d0e21e |
566 | |
a80f87c4 |
567 | #ifdef __GNUC__ |
568 | # undef SvIVx |
569 | # undef SvUVx |
570 | # undef SvNVx |
571 | # undef SvPVx |
572 | # undef SvTRUE |
573 | # undef SvTRUEx |
574 | # define SvIVx(sv) ({SV *nsv = (SV*)(sv); SvIV(nsv); }) |
575 | # define SvUVx(sv) ({SV *nsv = (SV*)(sv); SvUV(nsv); }) |
576 | # define SvNVx(sv) ({SV *nsv = (SV*)(sv); SvNV(nsv); }) |
577 | # define SvPVx(sv, lp) ({SV *nsv = (sv); SvPV(nsv, lp); }) |
578 | # define SvTRUE(sv) ( \ |
8990e307 |
579 | !sv \ |
580 | ? 0 \ |
581 | : SvPOK(sv) \ |
a80f87c4 |
582 | ? (({XPV *nxpv = (XPV*)SvANY(sv); \ |
583 | nxpv && \ |
584 | (*nxpv->xpv_pv > '0' || \ |
585 | nxpv->xpv_cur > 1 || \ |
586 | (nxpv->xpv_cur && *nxpv->xpv_pv != '0')); }) \ |
79072805 |
587 | ? 1 \ |
588 | : 0) \ |
589 | : \ |
590 | SvIOK(sv) \ |
463ee0b2 |
591 | ? SvIVX(sv) != 0 \ |
79072805 |
592 | : SvNOK(sv) \ |
463ee0b2 |
593 | ? SvNVX(sv) != 0.0 \ |
594 | : sv_2bool(sv) ) |
a80f87c4 |
595 | # define SvTRUEx(sv) ({SV *nsv = (sv); SvTRUE(nsv); }) |
596 | #else /* __GNUC__ */ |
597 | #ifndef USE_THREADS |
598 | /* These inlined macros use globals, which will require a thread |
599 | * declaration in user code, so we avoid them under threads */ |
600 | |
601 | # undef SvIVx |
602 | # undef SvUVx |
603 | # undef SvNVx |
604 | # undef SvPVx |
605 | # undef SvTRUE |
606 | # undef SvTRUEx |
aeea060c |
607 | # define SvIVx(sv) ((Sv = (sv)), SvIV(Sv)) |
608 | # define SvUVx(sv) ((Sv = (sv)), SvUV(Sv)) |
609 | # define SvNVx(sv) ((Sv = (sv)), SvNV(Sv)) |
610 | # define SvPVx(sv, lp) ((Sv = (sv)), SvPV(Sv, lp)) |
a80f87c4 |
611 | # define SvTRUE(sv) ( \ |
612 | !sv \ |
613 | ? 0 \ |
614 | : SvPOK(sv) \ |
615 | ? ((Xpv = (XPV*)SvANY(sv)) && \ |
616 | (*Xpv->xpv_pv > '0' || \ |
617 | Xpv->xpv_cur > 1 || \ |
618 | (Xpv->xpv_cur && *Xpv->xpv_pv != '0')) \ |
619 | ? 1 \ |
620 | : 0) \ |
621 | : \ |
622 | SvIOK(sv) \ |
623 | ? SvIVX(sv) != 0 \ |
624 | : SvNOK(sv) \ |
625 | ? SvNVX(sv) != 0.0 \ |
626 | : sv_2bool(sv) ) |
627 | # define SvTRUEx(sv) ((Sv = (sv)), SvTRUE(Sv)) |
628 | #endif /* !USE_THREADS */ |
629 | #endif /* !__GNU__ */ |
630 | #endif /* !CRIPPLED_CC */ |
79072805 |
631 | |
5f05dabc |
632 | #define newRV_inc(sv) newRV(sv) |
aeea060c |
633 | #ifdef __GNUC__ |
634 | # undef newRV_noinc |
635 | # define newRV_noinc(sv) ({SV *nsv=newRV((sv)); --SvREFCNT(SvRV(nsv)); nsv;}) |
636 | #else |
76e3520e |
637 | # if defined(CRIPPLED_CC) || defined(USE_THREADS) || defined(PERL_OBJECT) |
aeea060c |
638 | # else |
639 | # undef newRV_noinc |
640 | # define newRV_noinc(sv) ((Sv = newRV(sv)), --SvREFCNT(SvRV(Sv)), Sv) |
641 | # endif |
642 | #endif /* __GNUC__ */ |
5f05dabc |
643 | |
ef50df4b |
644 | /* the following macros update any magic values this sv is associated with */ |
79072805 |
645 | |
189b2af5 |
646 | #define SvGETMAGIC(x) STMT_START { if (SvGMAGICAL(x)) mg_get(x); } STMT_END |
647 | #define SvSETMAGIC(x) STMT_START { if (SvSMAGICAL(x)) mg_set(x); } STMT_END |
79072805 |
648 | |
54310121 |
649 | #define SvSetSV_and(dst,src,finally) \ |
189b2af5 |
650 | STMT_START { \ |
54310121 |
651 | if ((dst) != (src)) { \ |
652 | sv_setsv(dst, src); \ |
653 | finally; \ |
189b2af5 |
654 | } \ |
655 | } STMT_END |
54310121 |
656 | #define SvSetSV_nosteal_and(dst,src,finally) \ |
189b2af5 |
657 | STMT_START { \ |
8ebc5c01 |
658 | if ((dst) != (src)) { \ |
659 | U32 tMpF = SvFLAGS(src) & SVs_TEMP; \ |
660 | SvTEMP_off(src); \ |
661 | sv_setsv(dst, src); \ |
662 | SvFLAGS(src) |= tMpF; \ |
54310121 |
663 | finally; \ |
189b2af5 |
664 | } \ |
665 | } STMT_END |
79072805 |
666 | |
54310121 |
667 | #define SvSetSV(dst,src) \ |
c9d716f7 |
668 | SvSetSV_and(dst,src,/*nothing*/;) |
54310121 |
669 | #define SvSetSV_nosteal(dst,src) \ |
c9d716f7 |
670 | SvSetSV_nosteal_and(dst,src,/*nothing*/;) |
54310121 |
671 | |
672 | #define SvSetMagicSV(dst,src) \ |
673 | SvSetSV_and(dst,src,SvSETMAGIC(dst)) |
674 | #define SvSetMagicSV_nosteal(dst,src) \ |
675 | SvSetSV_nosteal_and(dst,src,SvSETMAGIC(dst)) |
676 | |
79072805 |
677 | #define SvPEEK(sv) sv_peek(sv) |
678 | |
36477c24 |
679 | #define SvIMMORTAL(sv) ((sv)==&sv_undef || (sv)==&sv_yes || (sv)==&sv_no) |
680 | |
54310121 |
681 | #define boolSV(b) ((b) ? &sv_yes : &sv_no) |
682 | |
79072805 |
683 | #define isGV(sv) (SvTYPE(sv) == SVt_PVGV) |
684 | |
79072805 |
685 | #ifndef DOSISH |
a0d0e21e |
686 | # define SvGROW(sv,len) (SvLEN(sv) < (len) ? sv_grow(sv,len) : SvPVX(sv)) |
79072805 |
687 | # define Sv_Grow sv_grow |
688 | #else |
689 | /* extra parentheses intentionally NOT placed around "len"! */ |
a0d0e21e |
690 | # define SvGROW(sv,len) ((SvLEN(sv) < (unsigned long)len) \ |
691 | ? sv_grow(sv,(unsigned long)len) : SvPVX(sv)) |
79072805 |
692 | # define Sv_Grow(sv,len) sv_grow(sv,(unsigned long)(len)) |
693 | #endif /* DOSISH */ |