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