Commit | Line | Data |
---|---|---|
a0d0e21e | 1 | /* sv.h |
79072805 | 2 | * |
a0d0e21e | 3 | * Copyright (c) 1991-1994, Larry Wall |
79072805 LW |
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 LW |
8 | */ |
9 | ||
a0d0e21e LW |
10 | #ifdef sv_flags |
11 | #undef sv_flags /* Convex has this in <signal.h> for sigvec() */ | |
12 | #endif | |
13 | ||
79072805 | 14 | typedef enum { |
a0d0e21e LW |
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 LW |
31 | } svtype; |
32 | ||
79072805 LW |
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 LW |
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 LW |
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 LW |
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 LW |
57 | }; |
58 | ||
59 | struct hv { | |
463ee0b2 | 60 | XPVHV* sv_any; /* pointer to something */ |
79072805 | 61 | U32 sv_refcnt; /* how many references to us */ |
8990e307 LW |
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 LW |
69 | }; |
70 | ||
463ee0b2 | 71 | #define SvANY(sv) (sv)->sv_any |
79072805 | 72 | #define SvFLAGS(sv) (sv)->sv_flags |
8990e307 LW |
73 | |
74 | #define SvREFCNT(sv) (sv)->sv_refcnt | |
75 | #ifdef CRIPPLED_CC | |
2304df62 AD |
76 | #define SvREFCNT_inc(sv) sv_newref((SV*)sv) |
77 | #define SvREFCNT_dec(sv) sv_free((SV*)sv) | |
8990e307 LW |
78 | #else |
79 | #define SvREFCNT_inc(sv) ((Sv = (SV*)(sv)), \ | |
80 | (Sv && ++SvREFCNT(Sv)), (SV*)Sv) | |
2304df62 | 81 | #define SvREFCNT_dec(sv) sv_free((SV*)sv) |
8990e307 LW |
82 | #endif |
83 | ||
84 | #define SVTYPEMASK 0xff | |
85 | #define SvTYPE(sv) ((sv)->sv_flags & SVTYPEMASK) | |
79072805 LW |
86 | |
87 | #define SvUPGRADE(sv, mt) (SvTYPE(sv) >= mt || sv_upgrade(sv, mt)) | |
88 | ||
8990e307 LW |
89 | #define SVs_PADBUSY 0x00000100 /* reserved for tmp or my already */ |
90 | #define SVs_PADTMP 0x00000200 /* in use as tmp */ | |
91 | #define SVs_PADMY 0x00000400 /* in use a "my" variable */ | |
92 | #define SVs_TEMP 0x00000800 /* string is stealable? */ | |
93 | #define SVs_OBJECT 0x00001000 /* is "blessed" */ | |
94 | #define SVs_GMG 0x00002000 /* has magical get method */ | |
95 | #define SVs_SMG 0x00004000 /* has magical set method */ | |
96 | #define SVs_RMG 0x00008000 /* has random magical methods */ | |
97 | ||
98 | #define SVf_IOK 0x00010000 /* has valid public integer value */ | |
99 | #define SVf_NOK 0x00020000 /* has valid public numeric value */ | |
100 | #define SVf_POK 0x00040000 /* has valid public pointer value */ | |
101 | #define SVf_ROK 0x00080000 /* has a valid reference pointer */ | |
a0d0e21e | 102 | |
748a9306 | 103 | #define SVf_FAKE 0x00100000 /* glob or lexical is just a copy */ |
8990e307 LW |
104 | #define SVf_OOK 0x00200000 /* has valid offset value */ |
105 | #define SVf_BREAK 0x00400000 /* refcnt is artificially low */ | |
106 | #define SVf_READONLY 0x00800000 /* may not be modified */ | |
107 | ||
a0d0e21e LW |
108 | #define SVf_THINKFIRST (SVf_READONLY|SVf_ROK) |
109 | ||
8990e307 LW |
110 | #define SVp_IOK 0x01000000 /* has valid non-public integer value */ |
111 | #define SVp_NOK 0x02000000 /* has valid non-public numeric value */ | |
112 | #define SVp_POK 0x04000000 /* has valid non-public pointer value */ | |
113 | #define SVp_SCREAM 0x08000000 /* has been studied? */ | |
114 | ||
a0d0e21e LW |
115 | #define SVf_OK (SVf_IOK|SVf_NOK|SVf_POK|SVf_ROK| \ |
116 | SVp_IOK|SVp_NOK|SVp_POK) | |
117 | ||
118 | #ifdef OVERLOAD | |
119 | #define SVf_AMAGIC 0x10000000 /* has magical overloaded methods */ | |
120 | #endif /* OVERLOAD */ | |
121 | ||
8990e307 LW |
122 | #define PRIVSHIFT 8 |
123 | ||
124 | /* Some private flags. */ | |
125 | ||
126 | #define SVpfm_COMPILED 0x80000000 | |
127 | ||
128 | #define SVpbm_VALID 0x80000000 | |
129 | #define SVpbm_CASEFOLD 0x40000000 | |
130 | #define SVpbm_TAIL 0x20000000 | |
131 | ||
a0d0e21e LW |
132 | #ifdef OVERLOAD |
133 | #define SVpgv_AM 0x40000000 | |
134 | /* #define SVpgv_badAM 0x20000000 */ | |
135 | #endif /* OVERLOAD */ | |
136 | ||
ed6116ce LW |
137 | struct xrv { |
138 | SV * xrv_rv; /* pointer to another SV */ | |
139 | }; | |
140 | ||
79072805 | 141 | struct xpv { |
ed6116ce LW |
142 | char * xpv_pv; /* pointer to malloced string */ |
143 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ | |
144 | STRLEN xpv_len; /* allocated size */ | |
79072805 LW |
145 | }; |
146 | ||
147 | struct xpviv { | |
ed6116ce LW |
148 | char * xpv_pv; /* pointer to malloced string */ |
149 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ | |
150 | STRLEN xpv_len; /* allocated size */ | |
a0d0e21e | 151 | IV xiv_iv; /* integer value or pv offset */ |
79072805 LW |
152 | }; |
153 | ||
154 | struct xpvnv { | |
ed6116ce LW |
155 | char * xpv_pv; /* pointer to malloced string */ |
156 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ | |
157 | STRLEN xpv_len; /* allocated size */ | |
a0d0e21e | 158 | IV xiv_iv; /* integer value or pv offset */ |
ed6116ce | 159 | double xnv_nv; /* numeric value, if any */ |
79072805 LW |
160 | }; |
161 | ||
162 | struct xpvmg { | |
ed6116ce LW |
163 | char * xpv_pv; /* pointer to malloced string */ |
164 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ | |
165 | STRLEN xpv_len; /* allocated size */ | |
a0d0e21e | 166 | IV xiv_iv; /* integer value or pv offset */ |
ed6116ce | 167 | double xnv_nv; /* numeric value, if any */ |
79072805 LW |
168 | MAGIC* xmg_magic; /* linked list of magicalness */ |
169 | HV* xmg_stash; /* class package */ | |
170 | }; | |
171 | ||
172 | struct xpvlv { | |
ed6116ce LW |
173 | char * xpv_pv; /* pointer to malloced string */ |
174 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ | |
175 | STRLEN xpv_len; /* allocated size */ | |
a0d0e21e | 176 | IV xiv_iv; /* integer value or pv offset */ |
ed6116ce | 177 | double xnv_nv; /* numeric value, if any */ |
79072805 LW |
178 | MAGIC* xmg_magic; /* linked list of magicalness */ |
179 | HV* xmg_stash; /* class package */ | |
8990e307 | 180 | |
79072805 LW |
181 | STRLEN xlv_targoff; |
182 | STRLEN xlv_targlen; | |
183 | SV* xlv_targ; | |
184 | char xlv_type; | |
185 | }; | |
186 | ||
187 | struct xpvgv { | |
ed6116ce LW |
188 | char * xpv_pv; /* pointer to malloced string */ |
189 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ | |
190 | STRLEN xpv_len; /* allocated size */ | |
a0d0e21e | 191 | IV xiv_iv; /* integer value or pv offset */ |
ed6116ce | 192 | double xnv_nv; /* numeric value, if any */ |
79072805 LW |
193 | MAGIC* xmg_magic; /* linked list of magicalness */ |
194 | HV* xmg_stash; /* class package */ | |
8990e307 | 195 | |
79072805 LW |
196 | GP* xgv_gp; |
197 | char* xgv_name; | |
198 | STRLEN xgv_namelen; | |
199 | HV* xgv_stash; | |
a5f75d66 | 200 | U8 xgv_flags; |
79072805 LW |
201 | }; |
202 | ||
203 | struct xpvbm { | |
ed6116ce LW |
204 | char * xpv_pv; /* pointer to malloced string */ |
205 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ | |
206 | STRLEN xpv_len; /* allocated size */ | |
a0d0e21e | 207 | IV xiv_iv; /* integer value or pv offset */ |
ed6116ce | 208 | double xnv_nv; /* numeric value, if any */ |
79072805 LW |
209 | MAGIC* xmg_magic; /* linked list of magicalness */ |
210 | HV* xmg_stash; /* class package */ | |
8990e307 | 211 | |
79072805 LW |
212 | I32 xbm_useful; /* is this constant pattern being useful? */ |
213 | U16 xbm_previous; /* how many characters in string before rare? */ | |
214 | U8 xbm_rare; /* rarest character in string */ | |
215 | }; | |
216 | ||
217 | struct xpvfm { | |
ed6116ce LW |
218 | char * xpv_pv; /* pointer to malloced string */ |
219 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ | |
220 | STRLEN xpv_len; /* allocated size */ | |
a0d0e21e | 221 | IV xiv_iv; /* integer value or pv offset */ |
ed6116ce | 222 | double xnv_nv; /* numeric value, if any */ |
79072805 LW |
223 | MAGIC* xmg_magic; /* linked list of magicalness */ |
224 | HV* xmg_stash; /* class package */ | |
8990e307 | 225 | |
79072805 LW |
226 | HV * xcv_stash; |
227 | OP * xcv_start; | |
228 | OP * xcv_root; | |
a0d0e21e LW |
229 | void (*xcv_xsub)_((CV*)); |
230 | ANY xcv_xsubany; | |
231 | GV * xcv_gv; | |
79072805 LW |
232 | GV * xcv_filegv; |
233 | long xcv_depth; /* >= 2 indicates recursive call */ | |
234 | AV * xcv_padlist; | |
748a9306 | 235 | CV * xcv_outside; |
79072805 LW |
236 | I32 xfm_lines; |
237 | }; | |
238 | ||
8990e307 LW |
239 | struct xpvio { |
240 | char * xpv_pv; /* pointer to malloced string */ | |
241 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ | |
242 | STRLEN xpv_len; /* allocated size */ | |
a0d0e21e | 243 | IV xiv_iv; /* integer value or pv offset */ |
8990e307 LW |
244 | double xnv_nv; /* numeric value, if any */ |
245 | MAGIC* xmg_magic; /* linked list of magicalness */ | |
246 | HV* xmg_stash; /* class package */ | |
247 | ||
248 | FILE * xio_ifp; /* ifp and ofp are normally the same */ | |
249 | FILE * xio_ofp; /* but sockets need separate streams */ | |
250 | DIR * xio_dirp; /* for opendir, readdir, etc */ | |
251 | long xio_lines; /* $. */ | |
252 | long xio_page; /* $% */ | |
253 | long xio_page_len; /* $= */ | |
254 | long xio_lines_left; /* $- */ | |
255 | char * xio_top_name; /* $^ */ | |
256 | GV * xio_top_gv; /* $^ */ | |
257 | char * xio_fmt_name; /* $~ */ | |
258 | GV * xio_fmt_gv; /* $~ */ | |
259 | char * xio_bottom_name;/* $^B */ | |
260 | GV * xio_bottom_gv; /* $^B */ | |
261 | short xio_subprocess; /* -| or |- */ | |
262 | char xio_type; | |
263 | char xio_flags; | |
264 | }; | |
265 | ||
266 | #define IOf_ARGV 1 /* this fp iterates over ARGV */ | |
267 | #define IOf_START 2 /* check for null ARGV and substitute '-' */ | |
268 | #define IOf_FLUSH 4 /* this fp wants a flush after write op */ | |
748a9306 | 269 | #define IOf_DIDTOP 8 /* just did top of form */ |
8990e307 | 270 | |
ed6116ce LW |
271 | /* The following macros define implementation-independent predicates on SVs. */ |
272 | ||
79072805 | 273 | #define SvNIOK(sv) (SvFLAGS(sv) & (SVf_IOK|SVf_NOK)) |
748a9306 | 274 | #define SvNIOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK)) |
a0d0e21e LW |
275 | #define SvNIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK| \ |
276 | SVp_IOK|SVp_NOK)) | |
79072805 | 277 | |
463ee0b2 | 278 | #define SvOK(sv) (SvFLAGS(sv) & SVf_OK) |
a0d0e21e LW |
279 | |
280 | #ifdef OVERLOAD | |
281 | #define SvOK_off(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC), \ | |
282 | SvOOK_off(sv)) | |
283 | #else | |
284 | #define SvOK_off(sv) (SvFLAGS(sv) &= ~SVf_OK, SvOOK_off(sv)) | |
285 | #endif /* OVERLOAD */ | |
79072805 | 286 | |
8990e307 LW |
287 | #define SvOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK)) |
288 | #define SvIOKp(sv) (SvFLAGS(sv) & SVp_IOK) | |
289 | #define SvIOKp_on(sv) (SvOOK_off(sv), SvFLAGS(sv) |= SVp_IOK) | |
290 | #define SvNOKp(sv) (SvFLAGS(sv) & SVp_NOK) | |
291 | #define SvNOKp_on(sv) (SvFLAGS(sv) |= SVp_NOK) | |
292 | #define SvPOKp(sv) (SvFLAGS(sv) & SVp_POK) | |
293 | #define SvPOKp_on(sv) (SvFLAGS(sv) |= SVp_POK) | |
463ee0b2 | 294 | |
79072805 | 295 | #define SvIOK(sv) (SvFLAGS(sv) & SVf_IOK) |
8990e307 | 296 | #define SvIOK_on(sv) (SvOOK_off(sv), \ |
a0d0e21e | 297 | SvFLAGS(sv) |= (SVf_IOK|SVp_IOK)) |
8990e307 | 298 | #define SvIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVp_IOK)) |
a5f75d66 | 299 | #define SvIOK_only(sv) (SvOOK_off(sv), SvOK_off(sv), \ |
a0d0e21e | 300 | SvFLAGS(sv) |= (SVf_IOK|SVp_IOK)) |
79072805 LW |
301 | |
302 | #define SvNOK(sv) (SvFLAGS(sv) & SVf_NOK) | |
a0d0e21e | 303 | #define SvNOK_on(sv) (SvFLAGS(sv) |= (SVf_NOK|SVp_NOK)) |
8990e307 LW |
304 | #define SvNOK_off(sv) (SvFLAGS(sv) &= ~(SVf_NOK|SVp_NOK)) |
305 | #define SvNOK_only(sv) (SvOK_off(sv), \ | |
a0d0e21e | 306 | SvFLAGS(sv) |= (SVf_NOK|SVp_NOK)) |
79072805 LW |
307 | |
308 | #define SvPOK(sv) (SvFLAGS(sv) & SVf_POK) | |
a0d0e21e | 309 | #define SvPOK_on(sv) (SvFLAGS(sv) |= (SVf_POK|SVp_POK)) |
8990e307 | 310 | #define SvPOK_off(sv) (SvFLAGS(sv) &= ~(SVf_POK|SVp_POK)) |
c07a80fd | 311 | |
312 | #ifdef OVERLOAD | |
313 | #define SvPOK_only(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC), \ | |
a0d0e21e | 314 | SvFLAGS(sv) |= (SVf_POK|SVp_POK)) |
c07a80fd | 315 | #else |
316 | #define SvPOK_only(sv) (SvFLAGS(sv) &= ~SVf_OK, \ | |
317 | SvFLAGS(sv) |= (SVf_POK|SVp_POK)) | |
318 | #endif /* OVERLOAD */ | |
79072805 LW |
319 | |
320 | #define SvOOK(sv) (SvFLAGS(sv) & SVf_OOK) | |
321 | #define SvOOK_on(sv) (SvIOK_off(sv), SvFLAGS(sv) |= SVf_OOK) | |
322 | #define SvOOK_off(sv) (SvOOK(sv) && sv_backoff(sv)) | |
79072805 | 323 | |
a0d0e21e LW |
324 | #define SvFAKE(sv) (SvFLAGS(sv) & SVf_FAKE) |
325 | #define SvFAKE_on(sv) (SvFLAGS(sv) |= SVf_FAKE) | |
326 | #define SvFAKE_off(sv) (SvFLAGS(sv) &= ~SVf_FAKE) | |
327 | ||
ed6116ce | 328 | #define SvROK(sv) (SvFLAGS(sv) & SVf_ROK) |
a0d0e21e LW |
329 | #define SvROK_on(sv) (SvFLAGS(sv) |= SVf_ROK) |
330 | ||
331 | #ifdef OVERLOAD | |
332 | #define SvROK_off(sv) (SvFLAGS(sv) &= ~(SVf_ROK|SVf_AMAGIC)) | |
333 | #else | |
ed6116ce | 334 | #define SvROK_off(sv) (SvFLAGS(sv) &= ~SVf_ROK) |
a0d0e21e | 335 | #endif /* OVERLOAD */ |
79072805 | 336 | |
8990e307 LW |
337 | #define SvMAGICAL(sv) (SvFLAGS(sv) & (SVs_GMG|SVs_SMG|SVs_RMG)) |
338 | #define SvMAGICAL_on(sv) (SvFLAGS(sv) |= (SVs_GMG|SVs_SMG|SVs_RMG)) | |
339 | #define SvMAGICAL_off(sv) (SvFLAGS(sv) &= ~(SVs_GMG|SVs_SMG|SVs_RMG)) | |
79072805 | 340 | |
8990e307 LW |
341 | #define SvGMAGICAL(sv) (SvFLAGS(sv) & SVs_GMG) |
342 | #define SvGMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_GMG) | |
343 | #define SvGMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_GMG) | |
ed6116ce | 344 | |
8990e307 LW |
345 | #define SvSMAGICAL(sv) (SvFLAGS(sv) & SVs_SMG) |
346 | #define SvSMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_SMG) | |
347 | #define SvSMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_SMG) | |
ed6116ce | 348 | |
8990e307 LW |
349 | #define SvRMAGICAL(sv) (SvFLAGS(sv) & SVs_RMG) |
350 | #define SvRMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_RMG) | |
351 | #define SvRMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_RMG) | |
ed6116ce | 352 | |
a0d0e21e LW |
353 | #ifdef OVERLOAD |
354 | #define SvAMAGIC(sv) (SvFLAGS(sv) & SVf_AMAGIC) | |
355 | #define SvAMAGIC_on(sv) (SvFLAGS(sv) |= SVf_AMAGIC) | |
356 | #define SvAMAGIC_off(sv) (SvFLAGS(sv) &= ~SVf_AMAGIC) | |
357 | ||
358 | /* | |
359 | #define Gv_AMG(stash) \ | |
360 | (HV_AMAGICmb(stash) && \ | |
361 | ((!HV_AMAGICbad(stash) && HV_AMAGIC(stash)) || Gv_AMupdate(stash))) | |
362 | */ | |
363 | #define Gv_AMG(stash) (amagic_generation && Gv_AMupdate(stash)) | |
364 | #endif /* OVERLOAD */ | |
365 | ||
366 | #define SvTHINKFIRST(sv) (SvFLAGS(sv) & SVf_THINKFIRST) | |
ed6116ce | 367 | |
8990e307 | 368 | #define SvPADBUSY(sv) (SvFLAGS(sv) & SVs_PADBUSY) |
ed6116ce | 369 | |
8990e307 LW |
370 | #define SvPADTMP(sv) (SvFLAGS(sv) & SVs_PADTMP) |
371 | #define SvPADTMP_on(sv) (SvFLAGS(sv) |= SVs_PADTMP|SVs_PADBUSY) | |
372 | #define SvPADTMP_off(sv) (SvFLAGS(sv) &= ~SVs_PADTMP) | |
ed6116ce | 373 | |
8990e307 LW |
374 | #define SvPADMY(sv) (SvFLAGS(sv) & SVs_PADMY) |
375 | #define SvPADMY_on(sv) (SvFLAGS(sv) |= SVs_PADMY|SVs_PADBUSY) | |
ed6116ce | 376 | |
8990e307 LW |
377 | #define SvTEMP(sv) (SvFLAGS(sv) & SVs_TEMP) |
378 | #define SvTEMP_on(sv) (SvFLAGS(sv) |= SVs_TEMP) | |
379 | #define SvTEMP_off(sv) (SvFLAGS(sv) &= ~SVs_TEMP) | |
79072805 | 380 | |
8990e307 LW |
381 | #define SvOBJECT(sv) (SvFLAGS(sv) & SVs_OBJECT) |
382 | #define SvOBJECT_on(sv) (SvFLAGS(sv) |= SVs_OBJECT) | |
383 | #define SvOBJECT_off(sv) (SvFLAGS(sv) &= ~SVs_OBJECT) | |
79072805 | 384 | |
8990e307 LW |
385 | #define SvREADONLY(sv) (SvFLAGS(sv) & SVf_READONLY) |
386 | #define SvREADONLY_on(sv) (SvFLAGS(sv) |= SVf_READONLY) | |
387 | #define SvREADONLY_off(sv) (SvFLAGS(sv) &= ~SVf_READONLY) | |
79072805 | 388 | |
8990e307 LW |
389 | #define SvSCREAM(sv) (SvFLAGS(sv) & SVp_SCREAM) |
390 | #define SvSCREAM_on(sv) (SvFLAGS(sv) |= SVp_SCREAM) | |
391 | #define SvSCREAM_off(sv) (SvFLAGS(sv) &= ~SVp_SCREAM) | |
79072805 | 392 | |
8990e307 LW |
393 | #define SvCOMPILED(sv) (SvFLAGS(sv) & SVpfm_COMPILED) |
394 | #define SvCOMPILED_on(sv) (SvFLAGS(sv) |= SVpfm_COMPILED) | |
395 | #define SvCOMPILED_off(sv) (SvFLAGS(sv) &= ~SVpfm_COMPILED) | |
79072805 | 396 | |
8990e307 LW |
397 | #define SvTAIL(sv) (SvFLAGS(sv) & SVpbm_TAIL) |
398 | #define SvTAIL_on(sv) (SvFLAGS(sv) |= SVpbm_TAIL) | |
399 | #define SvTAIL_off(sv) (SvFLAGS(sv) &= ~SVpbm_TAIL) | |
400 | ||
401 | #define SvCASEFOLD(sv) (SvFLAGS(sv) & SVpbm_CASEFOLD) | |
402 | #define SvCASEFOLD_on(sv) (SvFLAGS(sv) |= SVpbm_CASEFOLD) | |
403 | #define SvCASEFOLD_off(sv) (SvFLAGS(sv) &= ~SVpbm_CASEFOLD) | |
404 | ||
405 | #define SvVALID(sv) (SvFLAGS(sv) & SVpbm_VALID) | |
406 | #define SvVALID_on(sv) (SvFLAGS(sv) |= SVpbm_VALID) | |
407 | #define SvVALID_off(sv) (SvFLAGS(sv) &= ~SVpbm_VALID) | |
408 | ||
ed6116ce LW |
409 | #define SvRV(sv) ((XRV*) SvANY(sv))->xrv_rv |
410 | #define SvRVx(sv) SvRV(sv) | |
411 | ||
463ee0b2 LW |
412 | #define SvIVX(sv) ((XPVIV*) SvANY(sv))->xiv_iv |
413 | #define SvIVXx(sv) SvIVX(sv) | |
414 | #define SvNVX(sv) ((XPVNV*)SvANY(sv))->xnv_nv | |
415 | #define SvNVXx(sv) SvNVX(sv) | |
416 | #define SvPVX(sv) ((XPV*) SvANY(sv))->xpv_pv | |
417 | #define SvPVXx(sv) SvPVX(sv) | |
79072805 | 418 | #define SvCUR(sv) ((XPV*) SvANY(sv))->xpv_cur |
79072805 LW |
419 | #define SvLEN(sv) ((XPV*) SvANY(sv))->xpv_len |
420 | #define SvLENx(sv) SvLEN(sv) | |
421 | #define SvEND(sv)(((XPV*) SvANY(sv))->xpv_pv + ((XPV*)SvANY(sv))->xpv_cur) | |
8990e307 | 422 | #define SvENDx(sv) ((Sv = (sv)), SvEND(Sv)) |
79072805 LW |
423 | #define SvMAGIC(sv) ((XPVMG*) SvANY(sv))->xmg_magic |
424 | #define SvSTASH(sv) ((XPVMG*) SvANY(sv))->xmg_stash | |
425 | ||
426 | #define SvIV_set(sv, val) \ | |
427 | do { assert(SvTYPE(sv) == SVt_IV || SvTYPE(sv) >= SVt_PVIV); \ | |
428 | (((XPVIV*) SvANY(sv))->xiv_iv = val); } while (0) | |
429 | #define SvNV_set(sv, val) \ | |
430 | do { assert(SvTYPE(sv) == SVt_NV || SvTYPE(sv) >= SVt_PVNV); \ | |
431 | (((XPVNV*) SvANY(sv))->xnv_nv = val); } while (0) | |
432 | #define SvPV_set(sv, val) \ | |
433 | do { assert(SvTYPE(sv) >= SVt_PV); \ | |
434 | (((XPV*) SvANY(sv))->xpv_pv = val); } while (0) | |
435 | #define SvCUR_set(sv, val) \ | |
436 | do { assert(SvTYPE(sv) >= SVt_PV); \ | |
437 | (((XPV*) SvANY(sv))->xpv_cur = val); } while (0) | |
438 | #define SvLEN_set(sv, val) \ | |
439 | do { assert(SvTYPE(sv) >= SVt_PV); \ | |
440 | (((XPV*) SvANY(sv))->xpv_len = val); } while (0) | |
441 | #define SvEND_set(sv, val) \ | |
442 | do { assert(SvTYPE(sv) >= SVt_PV); \ | |
463ee0b2 | 443 | (((XPV*) SvANY(sv))->xpv_cur = val - SvPVX(sv)); } while (0) |
79072805 LW |
444 | |
445 | #define BmRARE(sv) ((XPVBM*) SvANY(sv))->xbm_rare | |
446 | #define BmUSEFUL(sv) ((XPVBM*) SvANY(sv))->xbm_useful | |
447 | #define BmPREVIOUS(sv) ((XPVBM*) SvANY(sv))->xbm_previous | |
448 | ||
449 | #define FmLINES(sv) ((XPVFM*) SvANY(sv))->xfm_lines | |
450 | ||
451 | #define LvTYPE(sv) ((XPVLV*) SvANY(sv))->xlv_type | |
452 | #define LvTARG(sv) ((XPVLV*) SvANY(sv))->xlv_targ | |
453 | #define LvTARGOFF(sv) ((XPVLV*) SvANY(sv))->xlv_targoff | |
454 | #define LvTARGLEN(sv) ((XPVLV*) SvANY(sv))->xlv_targlen | |
455 | ||
8990e307 LW |
456 | #define IoIFP(sv) ((XPVIO*) SvANY(sv))->xio_ifp |
457 | #define IoOFP(sv) ((XPVIO*) SvANY(sv))->xio_ofp | |
458 | #define IoDIRP(sv) ((XPVIO*) SvANY(sv))->xio_dirp | |
459 | #define IoLINES(sv) ((XPVIO*) SvANY(sv))->xio_lines | |
460 | #define IoPAGE(sv) ((XPVIO*) SvANY(sv))->xio_page | |
461 | #define IoPAGE_LEN(sv) ((XPVIO*) SvANY(sv))->xio_page_len | |
462 | #define IoLINES_LEFT(sv)((XPVIO*) SvANY(sv))->xio_lines_left | |
463 | #define IoTOP_NAME(sv) ((XPVIO*) SvANY(sv))->xio_top_name | |
464 | #define IoTOP_GV(sv) ((XPVIO*) SvANY(sv))->xio_top_gv | |
465 | #define IoFMT_NAME(sv) ((XPVIO*) SvANY(sv))->xio_fmt_name | |
466 | #define IoFMT_GV(sv) ((XPVIO*) SvANY(sv))->xio_fmt_gv | |
467 | #define IoBOTTOM_NAME(sv)((XPVIO*) SvANY(sv))->xio_bottom_name | |
468 | #define IoBOTTOM_GV(sv) ((XPVIO*) SvANY(sv))->xio_bottom_gv | |
469 | #define IoSUBPROCESS(sv)((XPVIO*) SvANY(sv))->xio_subprocess | |
470 | #define IoTYPE(sv) ((XPVIO*) SvANY(sv))->xio_type | |
471 | #define IoFLAGS(sv) ((XPVIO*) SvANY(sv))->xio_flags | |
472 | ||
a0d0e21e | 473 | #define SvTAINT(sv) if (tainting && tainted) sv_magic(sv, Nullsv, 't', Nullch, 0) |
79072805 LW |
474 | |
475 | #ifdef CRIPPLED_CC | |
476 | ||
a0d0e21e LW |
477 | IV SvIV _((SV* sv)); |
478 | double SvNV _((SV* sv)); | |
479 | #define SvPV_force(sv, lp) sv_pvn_force(sv, &lp) | |
463ee0b2 | 480 | #define SvPV(sv, lp) sv_pvn(sv, &lp) |
a0d0e21e LW |
481 | char *sv_pvn _((SV *, STRLEN *)); |
482 | I32 SvTRUE _((SV *)); | |
79072805 | 483 | |
463ee0b2 LW |
484 | #define SvIVx(sv) SvIV(sv) |
485 | #define SvNVx(sv) SvNV(sv) | |
486 | #define SvPVx(sv, lp) sv_pvn(sv, &lp) | |
a0d0e21e | 487 | #define SvPVx_force(sv, lp) sv_pvn_force(sv, &lp) |
79072805 LW |
488 | #define SvTRUEx(sv) SvTRUE(sv) |
489 | ||
490 | #else /* !CRIPPLED_CC */ | |
491 | ||
463ee0b2 | 492 | #define SvIV(sv) (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)) |
79072805 | 493 | |
463ee0b2 | 494 | #define SvNV(sv) (SvNOK(sv) ? SvNVX(sv) : sv_2nv(sv)) |
79072805 | 495 | |
463ee0b2 | 496 | #define SvPV(sv, lp) (SvPOK(sv) ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pv(sv, &lp)) |
79072805 | 497 | |
a0d0e21e LW |
498 | #define SvPV_force(sv, lp) ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvn_force(sv, &lp)) |
499 | ||
463ee0b2 | 500 | #define SvTRUE(sv) ( \ |
8990e307 LW |
501 | !sv \ |
502 | ? 0 \ | |
503 | : SvPOK(sv) \ | |
79072805 LW |
504 | ? ((Xpv = (XPV*)SvANY(sv)) && \ |
505 | (*Xpv->xpv_pv > '0' || \ | |
506 | Xpv->xpv_cur > 1 || \ | |
507 | (Xpv->xpv_cur && *Xpv->xpv_pv != '0')) \ | |
508 | ? 1 \ | |
509 | : 0) \ | |
510 | : \ | |
511 | SvIOK(sv) \ | |
463ee0b2 | 512 | ? SvIVX(sv) != 0 \ |
79072805 | 513 | : SvNOK(sv) \ |
463ee0b2 LW |
514 | ? SvNVX(sv) != 0.0 \ |
515 | : sv_2bool(sv) ) | |
79072805 | 516 | |
8990e307 LW |
517 | #define SvIVx(sv) ((Sv = (sv)), SvIV(Sv)) |
518 | #define SvNVx(sv) ((Sv = (sv)), SvNV(Sv)) | |
519 | #define SvPVx(sv, lp) ((Sv = (sv)), SvPV(Sv, lp)) | |
520 | #define SvTRUEx(sv) ((Sv = (sv)), SvTRUE(Sv)) | |
79072805 LW |
521 | |
522 | #endif /* CRIPPLED_CC */ | |
523 | ||
524 | /* the following macro updates any magic values this sv is associated with */ | |
525 | ||
8990e307 | 526 | #define SvSETMAGIC(x) if (SvSMAGICAL(x)) mg_set(x) |
79072805 LW |
527 | |
528 | #define SvSetSV(dst,src) if (dst != src) sv_setsv(dst,src) | |
529 | ||
530 | #define SvPEEK(sv) sv_peek(sv) | |
531 | ||
532 | #define isGV(sv) (SvTYPE(sv) == SVt_PVGV) | |
533 | ||
79072805 | 534 | #ifndef DOSISH |
a0d0e21e | 535 | # define SvGROW(sv,len) (SvLEN(sv) < (len) ? sv_grow(sv,len) : SvPVX(sv)) |
79072805 LW |
536 | # define Sv_Grow sv_grow |
537 | #else | |
538 | /* extra parentheses intentionally NOT placed around "len"! */ | |
a0d0e21e LW |
539 | # define SvGROW(sv,len) ((SvLEN(sv) < (unsigned long)len) \ |
540 | ? sv_grow(sv,(unsigned long)len) : SvPVX(sv)) | |
79072805 LW |
541 | # define Sv_Grow(sv,len) sv_grow(sv,(unsigned long)(len)) |
542 | #endif /* DOSISH */ |