perl 5.0 alpha 6
[p5sagit/p5-mst-13.2.git] / sv.h
CommitLineData
79072805 1/* $RCSfile: sv.h,v $$Revision: 4.1 $$Date: 92/08/07 18:26:57 $
2 *
3 * Copyright (c) 1991, Larry Wall
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 *
8 * $Log: sv.h,v $
9 * Revision 4.1 92/08/07 18:26:57 lwall
10 *
11 * Revision 4.0.1.4 92/06/08 15:41:45 lwall
12 * patch20: fixed confusion between a *var's real name and its effective name
13 * patch20: removed implicit int declarations on functions
14 *
15 * Revision 4.0.1.3 91/11/05 18:41:47 lwall
16 * patch11: random cleanup
17 * patch11: solitary subroutine references no longer trigger typo warnings
18 *
19 * Revision 4.0.1.2 91/06/07 11:58:33 lwall
20 * patch4: new copyright notice
21 *
22 * Revision 4.0.1.1 91/04/12 09:16:12 lwall
23 * patch1: you may now use "die" and "caller" in a signal handler
24 *
25 * Revision 4.0 91/03/20 01:40:04 lwall
26 * 4.0 baseline.
27 *
28 */
29
30typedef enum {
31 SVt_NULL,
79072805 32 SVt_IV,
33 SVt_NV,
ed6116ce 34 SVt_RV,
79072805 35 SVt_PV,
36 SVt_PVIV,
37 SVt_PVNV,
38 SVt_PVMG,
8990e307 39 SVt_PVBM,
79072805 40 SVt_PVLV,
41 SVt_PVAV,
42 SVt_PVHV,
43 SVt_PVCV,
44 SVt_PVGV,
79072805 45 SVt_PVFM,
8990e307 46 SVt_PVIO,
79072805 47} svtype;
48
79072805 49/* Using C's structural equivalence to help emulate C++ inheritance here... */
50
51struct sv {
463ee0b2 52 void* sv_any; /* pointer to something */
79072805 53 U32 sv_refcnt; /* how many references to us */
8990e307 54 U32 sv_flags; /* what we are */
79072805 55};
56
57struct gv {
463ee0b2 58 XPVGV* sv_any; /* pointer to something */
79072805 59 U32 sv_refcnt; /* how many references to us */
8990e307 60 U32 sv_flags; /* what we are */
79072805 61};
62
63struct cv {
463ee0b2 64 XPVGV* sv_any; /* pointer to something */
79072805 65 U32 sv_refcnt; /* how many references to us */
8990e307 66 U32 sv_flags; /* what we are */
79072805 67};
68
69struct av {
463ee0b2 70 XPVAV* sv_any; /* pointer to something */
79072805 71 U32 sv_refcnt; /* how many references to us */
8990e307 72 U32 sv_flags; /* what we are */
79072805 73};
74
75struct hv {
463ee0b2 76 XPVHV* sv_any; /* pointer to something */
79072805 77 U32 sv_refcnt; /* how many references to us */
8990e307 78 U32 sv_flags; /* what we are */
79};
80
81struct io {
82 XPVIO* sv_any; /* pointer to something */
83 U32 sv_refcnt; /* how many references to us */
84 U32 sv_flags; /* what we are */
79072805 85};
86
463ee0b2 87#define SvANY(sv) (sv)->sv_any
79072805 88#define SvFLAGS(sv) (sv)->sv_flags
8990e307 89
90#define SvREFCNT(sv) (sv)->sv_refcnt
91#ifdef CRIPPLED_CC
92#define SvREFCNT_inc(sv) sv_newref(sv)
93#define SvREFCNT_dec(sv) sv_free(sv)
94#else
95#define SvREFCNT_inc(sv) ((Sv = (SV*)(sv)), \
96 (Sv && ++SvREFCNT(Sv)), (SV*)Sv)
97#define SvREFCNT_dec(sv) sv_free(sv)
98#endif
99
100#define SVTYPEMASK 0xff
101#define SvTYPE(sv) ((sv)->sv_flags & SVTYPEMASK)
79072805 102
103#define SvUPGRADE(sv, mt) (SvTYPE(sv) >= mt || sv_upgrade(sv, mt))
104
8990e307 105#define SVs_PADBUSY 0x00000100 /* reserved for tmp or my already */
106#define SVs_PADTMP 0x00000200 /* in use as tmp */
107#define SVs_PADMY 0x00000400 /* in use a "my" variable */
108#define SVs_TEMP 0x00000800 /* string is stealable? */
109#define SVs_OBJECT 0x00001000 /* is "blessed" */
110#define SVs_GMG 0x00002000 /* has magical get method */
111#define SVs_SMG 0x00004000 /* has magical set method */
112#define SVs_RMG 0x00008000 /* has random magical methods */
113
114#define SVf_IOK 0x00010000 /* has valid public integer value */
115#define SVf_NOK 0x00020000 /* has valid public numeric value */
116#define SVf_POK 0x00040000 /* has valid public pointer value */
117#define SVf_ROK 0x00080000 /* has a valid reference pointer */
118#define SVf_OK 0x00100000 /* has defined value */
119#define SVf_OOK 0x00200000 /* has valid offset value */
120#define SVf_BREAK 0x00400000 /* refcnt is artificially low */
121#define SVf_READONLY 0x00800000 /* may not be modified */
122
123#define SVp_IOK 0x01000000 /* has valid non-public integer value */
124#define SVp_NOK 0x02000000 /* has valid non-public numeric value */
125#define SVp_POK 0x04000000 /* has valid non-public pointer value */
126#define SVp_SCREAM 0x08000000 /* has been studied? */
127
128#define PRIVSHIFT 8
129
130/* Some private flags. */
131
132#define SVpfm_COMPILED 0x80000000
133
134#define SVpbm_VALID 0x80000000
135#define SVpbm_CASEFOLD 0x40000000
136#define SVpbm_TAIL 0x20000000
137
138#define SVpgv_MULTI 0x80000000
79072805 139
ed6116ce 140struct xrv {
141 SV * xrv_rv; /* pointer to another SV */
142};
143
79072805 144struct xpv {
ed6116ce 145 char * xpv_pv; /* pointer to malloced string */
146 STRLEN xpv_cur; /* length of xpv_pv as a C string */
147 STRLEN xpv_len; /* allocated size */
79072805 148};
149
150struct xpviv {
ed6116ce 151 char * xpv_pv; /* pointer to malloced string */
152 STRLEN xpv_cur; /* length of xpv_pv as a C string */
153 STRLEN xpv_len; /* allocated size */
79072805 154 I32 xiv_iv; /* integer value or pv offset */
155};
156
157struct xpvnv {
ed6116ce 158 char * xpv_pv; /* pointer to malloced string */
159 STRLEN xpv_cur; /* length of xpv_pv as a C string */
160 STRLEN xpv_len; /* allocated size */
79072805 161 I32 xiv_iv; /* integer value or pv offset */
ed6116ce 162 double xnv_nv; /* numeric value, if any */
79072805 163};
164
165struct xpvmg {
ed6116ce 166 char * xpv_pv; /* pointer to malloced string */
167 STRLEN xpv_cur; /* length of xpv_pv as a C string */
168 STRLEN xpv_len; /* allocated size */
79072805 169 I32 xiv_iv; /* integer value or pv offset */
ed6116ce 170 double xnv_nv; /* numeric value, if any */
79072805 171 MAGIC* xmg_magic; /* linked list of magicalness */
172 HV* xmg_stash; /* class package */
173};
174
175struct xpvlv {
ed6116ce 176 char * xpv_pv; /* pointer to malloced string */
177 STRLEN xpv_cur; /* length of xpv_pv as a C string */
178 STRLEN xpv_len; /* allocated size */
79072805 179 I32 xiv_iv; /* integer value or pv offset */
ed6116ce 180 double xnv_nv; /* numeric value, if any */
79072805 181 MAGIC* xmg_magic; /* linked list of magicalness */
182 HV* xmg_stash; /* class package */
8990e307 183
79072805 184 STRLEN xlv_targoff;
185 STRLEN xlv_targlen;
186 SV* xlv_targ;
187 char xlv_type;
188};
189
190struct xpvgv {
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 */
79072805 194 I32 xiv_iv; /* integer value or pv offset */
ed6116ce 195 double xnv_nv; /* numeric value, if any */
79072805 196 MAGIC* xmg_magic; /* linked list of magicalness */
197 HV* xmg_stash; /* class package */
8990e307 198
79072805 199 GP* xgv_gp;
200 char* xgv_name;
201 STRLEN xgv_namelen;
202 HV* xgv_stash;
203};
204
205struct xpvbm {
ed6116ce 206 char * xpv_pv; /* pointer to malloced string */
207 STRLEN xpv_cur; /* length of xpv_pv as a C string */
208 STRLEN xpv_len; /* allocated size */
79072805 209 I32 xiv_iv; /* integer value or pv offset */
ed6116ce 210 double xnv_nv; /* numeric value, if any */
79072805 211 MAGIC* xmg_magic; /* linked list of magicalness */
212 HV* xmg_stash; /* class package */
8990e307 213
79072805 214 I32 xbm_useful; /* is this constant pattern being useful? */
215 U16 xbm_previous; /* how many characters in string before rare? */
216 U8 xbm_rare; /* rarest character in string */
217};
218
219struct xpvfm {
ed6116ce 220 char * xpv_pv; /* pointer to malloced string */
221 STRLEN xpv_cur; /* length of xpv_pv as a C string */
222 STRLEN xpv_len; /* allocated size */
79072805 223 I32 xiv_iv; /* integer value or pv offset */
ed6116ce 224 double xnv_nv; /* numeric value, if any */
79072805 225 MAGIC* xmg_magic; /* linked list of magicalness */
226 HV* xmg_stash; /* class package */
8990e307 227
79072805 228 HV * xcv_stash;
229 OP * xcv_start;
230 OP * xcv_root;
231 I32 (*xcv_usersub)();
232 I32 xcv_userindex;
233 GV * xcv_filegv;
234 long xcv_depth; /* >= 2 indicates recursive call */
235 AV * xcv_padlist;
236 bool xcv_deleted;
237 I32 xfm_lines;
238};
239
8990e307 240struct xpvio {
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 */
244 I32 xiv_iv; /* integer value or pv offset */
245 double xnv_nv; /* numeric value, if any */
246 MAGIC* xmg_magic; /* linked list of magicalness */
247 HV* xmg_stash; /* class package */
248
249 FILE * xio_ifp; /* ifp and ofp are normally the same */
250 FILE * xio_ofp; /* but sockets need separate streams */
251 DIR * xio_dirp; /* for opendir, readdir, etc */
252 long xio_lines; /* $. */
253 long xio_page; /* $% */
254 long xio_page_len; /* $= */
255 long xio_lines_left; /* $- */
256 char * xio_top_name; /* $^ */
257 GV * xio_top_gv; /* $^ */
258 char * xio_fmt_name; /* $~ */
259 GV * xio_fmt_gv; /* $~ */
260 char * xio_bottom_name;/* $^B */
261 GV * xio_bottom_gv; /* $^B */
262 short xio_subprocess; /* -| or |- */
263 char xio_type;
264 char xio_flags;
265};
266
267#define IOf_ARGV 1 /* this fp iterates over ARGV */
268#define IOf_START 2 /* check for null ARGV and substitute '-' */
269#define IOf_FLUSH 4 /* this fp wants a flush after write op */
270
ed6116ce 271/* The following macros define implementation-independent predicates on SVs. */
272
79072805 273#define SvNIOK(sv) (SvFLAGS(sv) & (SVf_IOK|SVf_NOK))
274
463ee0b2 275#define SvOK(sv) (SvFLAGS(sv) & SVf_OK)
276#define SvOK_on(sv) (SvFLAGS(sv) |= SVf_OK)
277#define SvOK_off(sv) (SvFLAGS(sv) &= \
8990e307 278 ~(SVf_IOK|SVf_NOK|SVf_POK|SVf_OK| \
279 SVp_IOK|SVp_NOK|SVp_POK|SVf_ROK),\
79072805 280 SvOOK_off(sv))
281
8990e307 282#define SvOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK))
283#define SvIOKp(sv) (SvFLAGS(sv) & SVp_IOK)
284#define SvIOKp_on(sv) (SvOOK_off(sv), SvFLAGS(sv) |= SVp_IOK)
285#define SvNOKp(sv) (SvFLAGS(sv) & SVp_NOK)
286#define SvNOKp_on(sv) (SvFLAGS(sv) |= SVp_NOK)
287#define SvPOKp(sv) (SvFLAGS(sv) & SVp_POK)
288#define SvPOKp_on(sv) (SvFLAGS(sv) |= SVp_POK)
463ee0b2 289
79072805 290#define SvIOK(sv) (SvFLAGS(sv) & SVf_IOK)
8990e307 291#define SvIOK_on(sv) (SvOOK_off(sv), \
292 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK|SVf_OK))
293#define SvIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVp_IOK))
294#define SvIOK_only(sv) (SvOK_off(sv), \
295 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK|SVf_OK))
79072805 296
297#define SvNOK(sv) (SvFLAGS(sv) & SVf_NOK)
8990e307 298#define SvNOK_on(sv) (SvFLAGS(sv) |= (SVf_NOK|SVp_NOK|SVf_OK))
299#define SvNOK_off(sv) (SvFLAGS(sv) &= ~(SVf_NOK|SVp_NOK))
300#define SvNOK_only(sv) (SvOK_off(sv), \
301 SvFLAGS(sv) |= (SVf_NOK|SVp_NOK|SVf_OK))
79072805 302
303#define SvPOK(sv) (SvFLAGS(sv) & SVf_POK)
8990e307 304#define SvPOK_on(sv) (SvFLAGS(sv) |= (SVf_POK|SVp_POK|SVf_OK))
305#define SvPOK_off(sv) (SvFLAGS(sv) &= ~(SVf_POK|SVp_POK))
306#define SvPOK_only(sv) (SvOK_off(sv), \
307 SvFLAGS(sv) |= (SVf_POK|SVp_POK|SVf_OK))
79072805 308
309#define SvOOK(sv) (SvFLAGS(sv) & SVf_OOK)
310#define SvOOK_on(sv) (SvIOK_off(sv), SvFLAGS(sv) |= SVf_OOK)
311#define SvOOK_off(sv) (SvOOK(sv) && sv_backoff(sv))
79072805 312
ed6116ce 313#define SvROK(sv) (SvFLAGS(sv) & SVf_ROK)
8990e307 314#define SvROK_on(sv) (SvFLAGS(sv) |= SVf_ROK|SVf_OK)
ed6116ce 315#define SvROK_off(sv) (SvFLAGS(sv) &= ~SVf_ROK)
79072805 316
8990e307 317#define SvMAGICAL(sv) (SvFLAGS(sv) & (SVs_GMG|SVs_SMG|SVs_RMG))
318#define SvMAGICAL_on(sv) (SvFLAGS(sv) |= (SVs_GMG|SVs_SMG|SVs_RMG))
319#define SvMAGICAL_off(sv) (SvFLAGS(sv) &= ~(SVs_GMG|SVs_SMG|SVs_RMG))
79072805 320
8990e307 321#define SvGMAGICAL(sv) (SvFLAGS(sv) & SVs_GMG)
322#define SvGMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_GMG)
323#define SvGMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_GMG)
ed6116ce 324
8990e307 325#define SvSMAGICAL(sv) (SvFLAGS(sv) & SVs_SMG)
326#define SvSMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_SMG)
327#define SvSMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_SMG)
ed6116ce 328
8990e307 329#define SvRMAGICAL(sv) (SvFLAGS(sv) & SVs_RMG)
330#define SvRMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_RMG)
331#define SvRMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_RMG)
ed6116ce 332
8990e307 333#define SvTHINKFIRST(sv) (SvFLAGS(sv) & (SVf_ROK|SVf_READONLY))
ed6116ce 334
8990e307 335#define SvPADBUSY(sv) (SvFLAGS(sv) & SVs_PADBUSY)
ed6116ce 336
8990e307 337#define SvPADTMP(sv) (SvFLAGS(sv) & SVs_PADTMP)
338#define SvPADTMP_on(sv) (SvFLAGS(sv) |= SVs_PADTMP|SVs_PADBUSY)
339#define SvPADTMP_off(sv) (SvFLAGS(sv) &= ~SVs_PADTMP)
ed6116ce 340
8990e307 341#define SvPADMY(sv) (SvFLAGS(sv) & SVs_PADMY)
342#define SvPADMY_on(sv) (SvFLAGS(sv) |= SVs_PADMY|SVs_PADBUSY)
ed6116ce 343
8990e307 344#define SvTEMP(sv) (SvFLAGS(sv) & SVs_TEMP)
345#define SvTEMP_on(sv) (SvFLAGS(sv) |= SVs_TEMP)
346#define SvTEMP_off(sv) (SvFLAGS(sv) &= ~SVs_TEMP)
79072805 347
8990e307 348#define SvOBJECT(sv) (SvFLAGS(sv) & SVs_OBJECT)
349#define SvOBJECT_on(sv) (SvFLAGS(sv) |= SVs_OBJECT)
350#define SvOBJECT_off(sv) (SvFLAGS(sv) &= ~SVs_OBJECT)
79072805 351
8990e307 352#define SvREADONLY(sv) (SvFLAGS(sv) & SVf_READONLY)
353#define SvREADONLY_on(sv) (SvFLAGS(sv) |= SVf_READONLY)
354#define SvREADONLY_off(sv) (SvFLAGS(sv) &= ~SVf_READONLY)
79072805 355
8990e307 356#define SvSCREAM(sv) (SvFLAGS(sv) & SVp_SCREAM)
357#define SvSCREAM_on(sv) (SvFLAGS(sv) |= SVp_SCREAM)
358#define SvSCREAM_off(sv) (SvFLAGS(sv) &= ~SVp_SCREAM)
79072805 359
8990e307 360#define SvCOMPILED(sv) (SvFLAGS(sv) & SVpfm_COMPILED)
361#define SvCOMPILED_on(sv) (SvFLAGS(sv) |= SVpfm_COMPILED)
362#define SvCOMPILED_off(sv) (SvFLAGS(sv) &= ~SVpfm_COMPILED)
79072805 363
8990e307 364#define SvTAIL(sv) (SvFLAGS(sv) & SVpbm_TAIL)
365#define SvTAIL_on(sv) (SvFLAGS(sv) |= SVpbm_TAIL)
366#define SvTAIL_off(sv) (SvFLAGS(sv) &= ~SVpbm_TAIL)
367
368#define SvCASEFOLD(sv) (SvFLAGS(sv) & SVpbm_CASEFOLD)
369#define SvCASEFOLD_on(sv) (SvFLAGS(sv) |= SVpbm_CASEFOLD)
370#define SvCASEFOLD_off(sv) (SvFLAGS(sv) &= ~SVpbm_CASEFOLD)
371
372#define SvVALID(sv) (SvFLAGS(sv) & SVpbm_VALID)
373#define SvVALID_on(sv) (SvFLAGS(sv) |= SVpbm_VALID)
374#define SvVALID_off(sv) (SvFLAGS(sv) &= ~SVpbm_VALID)
375
376#define SvMULTI(sv) (SvFLAGS(sv) & SVpgv_MULTI)
377#define SvMULTI_on(sv) (SvFLAGS(sv) |= SVpgv_MULTI)
378#define SvMULTI_off(sv) (SvFLAGS(sv) &= ~SVpgv_MULTI)
79072805 379
ed6116ce 380#define SvRV(sv) ((XRV*) SvANY(sv))->xrv_rv
381#define SvRVx(sv) SvRV(sv)
382
463ee0b2 383#define SvIVX(sv) ((XPVIV*) SvANY(sv))->xiv_iv
384#define SvIVXx(sv) SvIVX(sv)
385#define SvNVX(sv) ((XPVNV*)SvANY(sv))->xnv_nv
386#define SvNVXx(sv) SvNVX(sv)
387#define SvPVX(sv) ((XPV*) SvANY(sv))->xpv_pv
388#define SvPVXx(sv) SvPVX(sv)
79072805 389#define SvCUR(sv) ((XPV*) SvANY(sv))->xpv_cur
79072805 390#define SvLEN(sv) ((XPV*) SvANY(sv))->xpv_len
391#define SvLENx(sv) SvLEN(sv)
392#define SvEND(sv)(((XPV*) SvANY(sv))->xpv_pv + ((XPV*)SvANY(sv))->xpv_cur)
8990e307 393#define SvENDx(sv) ((Sv = (sv)), SvEND(Sv))
79072805 394#define SvMAGIC(sv) ((XPVMG*) SvANY(sv))->xmg_magic
395#define SvSTASH(sv) ((XPVMG*) SvANY(sv))->xmg_stash
396
397#define SvIV_set(sv, val) \
398 do { assert(SvTYPE(sv) == SVt_IV || SvTYPE(sv) >= SVt_PVIV); \
399 (((XPVIV*) SvANY(sv))->xiv_iv = val); } while (0)
400#define SvNV_set(sv, val) \
401 do { assert(SvTYPE(sv) == SVt_NV || SvTYPE(sv) >= SVt_PVNV); \
402 (((XPVNV*) SvANY(sv))->xnv_nv = val); } while (0)
403#define SvPV_set(sv, val) \
404 do { assert(SvTYPE(sv) >= SVt_PV); \
405 (((XPV*) SvANY(sv))->xpv_pv = val); } while (0)
406#define SvCUR_set(sv, val) \
407 do { assert(SvTYPE(sv) >= SVt_PV); \
408 (((XPV*) SvANY(sv))->xpv_cur = val); } while (0)
409#define SvLEN_set(sv, val) \
410 do { assert(SvTYPE(sv) >= SVt_PV); \
411 (((XPV*) SvANY(sv))->xpv_len = val); } while (0)
412#define SvEND_set(sv, val) \
413 do { assert(SvTYPE(sv) >= SVt_PV); \
463ee0b2 414 (((XPV*) SvANY(sv))->xpv_cur = val - SvPVX(sv)); } while (0)
79072805 415
93a17b20 416#define SvCUROK(sv) (SvPOK(sv) ? SvCUR(sv) : 0)
417
79072805 418#define BmRARE(sv) ((XPVBM*) SvANY(sv))->xbm_rare
419#define BmUSEFUL(sv) ((XPVBM*) SvANY(sv))->xbm_useful
420#define BmPREVIOUS(sv) ((XPVBM*) SvANY(sv))->xbm_previous
421
422#define FmLINES(sv) ((XPVFM*) SvANY(sv))->xfm_lines
423
424#define LvTYPE(sv) ((XPVLV*) SvANY(sv))->xlv_type
425#define LvTARG(sv) ((XPVLV*) SvANY(sv))->xlv_targ
426#define LvTARGOFF(sv) ((XPVLV*) SvANY(sv))->xlv_targoff
427#define LvTARGLEN(sv) ((XPVLV*) SvANY(sv))->xlv_targlen
428
8990e307 429#define IoIFP(sv) ((XPVIO*) SvANY(sv))->xio_ifp
430#define IoOFP(sv) ((XPVIO*) SvANY(sv))->xio_ofp
431#define IoDIRP(sv) ((XPVIO*) SvANY(sv))->xio_dirp
432#define IoLINES(sv) ((XPVIO*) SvANY(sv))->xio_lines
433#define IoPAGE(sv) ((XPVIO*) SvANY(sv))->xio_page
434#define IoPAGE_LEN(sv) ((XPVIO*) SvANY(sv))->xio_page_len
435#define IoLINES_LEFT(sv)((XPVIO*) SvANY(sv))->xio_lines_left
436#define IoTOP_NAME(sv) ((XPVIO*) SvANY(sv))->xio_top_name
437#define IoTOP_GV(sv) ((XPVIO*) SvANY(sv))->xio_top_gv
438#define IoFMT_NAME(sv) ((XPVIO*) SvANY(sv))->xio_fmt_name
439#define IoFMT_GV(sv) ((XPVIO*) SvANY(sv))->xio_fmt_gv
440#define IoBOTTOM_NAME(sv)((XPVIO*) SvANY(sv))->xio_bottom_name
441#define IoBOTTOM_GV(sv) ((XPVIO*) SvANY(sv))->xio_bottom_gv
442#define IoSUBPROCESS(sv)((XPVIO*) SvANY(sv))->xio_subprocess
443#define IoTYPE(sv) ((XPVIO*) SvANY(sv))->xio_type
444#define IoFLAGS(sv) ((XPVIO*) SvANY(sv))->xio_flags
445
463ee0b2 446#define SvTAINT(sv) if (tainting && tainted) sv_magic(sv, 0, 't', 0, 0)
79072805 447
448#ifdef CRIPPLED_CC
449
463ee0b2 450double SvIV();
451double SvNV();
452#define SvPV(sv, lp) sv_pvn(sv, &lp)
453char *sv_pvn();
79072805 454I32 SvTRUE();
455
463ee0b2 456#define SvIVx(sv) SvIV(sv)
457#define SvNVx(sv) SvNV(sv)
458#define SvPVx(sv, lp) sv_pvn(sv, &lp)
79072805 459#define SvTRUEx(sv) SvTRUE(sv)
460
461#else /* !CRIPPLED_CC */
462
463ee0b2 463#define SvIV(sv) (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv))
79072805 464
463ee0b2 465#define SvNV(sv) (SvNOK(sv) ? SvNVX(sv) : sv_2nv(sv))
79072805 466
463ee0b2 467#define SvPV(sv, lp) (SvPOK(sv) ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pv(sv, &lp))
79072805 468
463ee0b2 469#define SvTRUE(sv) ( \
8990e307 470 !sv \
471 ? 0 \
472 : SvPOK(sv) \
79072805 473 ? ((Xpv = (XPV*)SvANY(sv)) && \
474 (*Xpv->xpv_pv > '0' || \
475 Xpv->xpv_cur > 1 || \
476 (Xpv->xpv_cur && *Xpv->xpv_pv != '0')) \
477 ? 1 \
478 : 0) \
479 : \
480 SvIOK(sv) \
463ee0b2 481 ? SvIVX(sv) != 0 \
79072805 482 : SvNOK(sv) \
463ee0b2 483 ? SvNVX(sv) != 0.0 \
484 : sv_2bool(sv) )
79072805 485
8990e307 486#define SvIVx(sv) ((Sv = (sv)), SvIV(Sv))
487#define SvNVx(sv) ((Sv = (sv)), SvNV(Sv))
488#define SvPVx(sv, lp) ((Sv = (sv)), SvPV(Sv, lp))
489#define SvTRUEx(sv) ((Sv = (sv)), SvTRUE(Sv))
79072805 490
491#endif /* CRIPPLED_CC */
492
493/* the following macro updates any magic values this sv is associated with */
494
8990e307 495#define SvSETMAGIC(x) if (SvSMAGICAL(x)) mg_set(x)
79072805 496
497#define SvSetSV(dst,src) if (dst != src) sv_setsv(dst,src)
498
499#define SvPEEK(sv) sv_peek(sv)
500
501#define isGV(sv) (SvTYPE(sv) == SVt_PVGV)
502
79072805 503#ifndef DOSISH
504# define SvGROW(sv,len) if (SvLEN(sv) < (len)) sv_grow(sv,len)
505# define Sv_Grow sv_grow
506#else
507 /* extra parentheses intentionally NOT placed around "len"! */
508# define SvGROW(sv,len) if (SvLEN(sv) < (unsigned long)len) \
509 sv_grow(sv,(unsigned long)len)
510# define Sv_Grow(sv,len) sv_grow(sv,(unsigned long)(len))
511#endif /* DOSISH */