PATCH: untaint method for IO::Handle, 5.003_06 version
[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
83
84#define SVTYPEMASK 0xff
85#define SvTYPE(sv) ((sv)->sv_flags & SVTYPEMASK)
79072805 86
87#define SvUPGRADE(sv, mt) (SvTYPE(sv) >= mt || sv_upgrade(sv, mt))
88
8990e307 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 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 108#define SVf_THINKFIRST (SVf_READONLY|SVf_ROK)
109
8990e307 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 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 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
bf6bd887 132#define SVphv_SHAREKEYS 0x20000000 /* keys live on shared string table */
51594c39 133#define SVphv_LAZYDEL 0x40000000 /* entry in xhv_eiter must be deleted */
bf6bd887 134
a0d0e21e 135#ifdef OVERLOAD
136#define SVpgv_AM 0x40000000
137/* #define SVpgv_badAM 0x20000000 */
138#endif /* OVERLOAD */
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 */
a0d0e21e 154 IV xiv_iv; /* integer value or pv offset */
79072805 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 */
a0d0e21e 161 IV 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 */
a0d0e21e 169 IV 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 */
a0d0e21e 179 IV 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 */
a0d0e21e 194 IV 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;
a5f75d66 203 U8 xgv_flags;
79072805 204};
205
206struct xpvbm {
ed6116ce 207 char * xpv_pv; /* pointer to malloced string */
208 STRLEN xpv_cur; /* length of xpv_pv as a C string */
209 STRLEN xpv_len; /* allocated size */
a0d0e21e 210 IV xiv_iv; /* integer value or pv offset */
ed6116ce 211 double xnv_nv; /* numeric value, if any */
79072805 212 MAGIC* xmg_magic; /* linked list of magicalness */
213 HV* xmg_stash; /* class package */
8990e307 214
79072805 215 I32 xbm_useful; /* is this constant pattern being useful? */
216 U16 xbm_previous; /* how many characters in string before rare? */
217 U8 xbm_rare; /* rarest character in string */
218};
219
220struct xpvfm {
ed6116ce 221 char * xpv_pv; /* pointer to malloced string */
222 STRLEN xpv_cur; /* length of xpv_pv as a C string */
223 STRLEN xpv_len; /* allocated size */
a0d0e21e 224 IV xiv_iv; /* integer value or pv offset */
ed6116ce 225 double xnv_nv; /* numeric value, if any */
79072805 226 MAGIC* xmg_magic; /* linked list of magicalness */
227 HV* xmg_stash; /* class package */
8990e307 228
79072805 229 HV * xcv_stash;
230 OP * xcv_start;
231 OP * xcv_root;
a0d0e21e 232 void (*xcv_xsub)_((CV*));
233 ANY xcv_xsubany;
234 GV * xcv_gv;
79072805 235 GV * xcv_filegv;
236 long xcv_depth; /* >= 2 indicates recursive call */
237 AV * xcv_padlist;
748a9306 238 CV * xcv_outside;
79072805 239 I32 xfm_lines;
240};
241
8990e307 242struct xpvio {
243 char * xpv_pv; /* pointer to malloced string */
244 STRLEN xpv_cur; /* length of xpv_pv as a C string */
245 STRLEN xpv_len; /* allocated size */
a0d0e21e 246 IV xiv_iv; /* integer value or pv offset */
8990e307 247 double xnv_nv; /* numeric value, if any */
248 MAGIC* xmg_magic; /* linked list of magicalness */
249 HV* xmg_stash; /* class package */
250
760ac839 251 PerlIO * xio_ifp; /* ifp and ofp are normally the same */
252 PerlIO * xio_ofp; /* but sockets need separate streams */
8990e307 253 DIR * xio_dirp; /* for opendir, readdir, etc */
254 long xio_lines; /* $. */
255 long xio_page; /* $% */
256 long xio_page_len; /* $= */
257 long xio_lines_left; /* $- */
258 char * xio_top_name; /* $^ */
259 GV * xio_top_gv; /* $^ */
260 char * xio_fmt_name; /* $~ */
261 GV * xio_fmt_gv; /* $~ */
262 char * xio_bottom_name;/* $^B */
263 GV * xio_bottom_gv; /* $^B */
264 short xio_subprocess; /* -| or |- */
265 char xio_type;
266 char xio_flags;
267};
268
269#define IOf_ARGV 1 /* this fp iterates over ARGV */
270#define IOf_START 2 /* check for null ARGV and substitute '-' */
271#define IOf_FLUSH 4 /* this fp wants a flush after write op */
748a9306 272#define IOf_DIDTOP 8 /* just did top of form */
51594c39 273#define IOf_UNTAINT 16 /* consider this fp (and it's data) "safe" */
8990e307 274
ed6116ce 275/* The following macros define implementation-independent predicates on SVs. */
276
79072805 277#define SvNIOK(sv) (SvFLAGS(sv) & (SVf_IOK|SVf_NOK))
748a9306 278#define SvNIOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK))
a0d0e21e 279#define SvNIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK| \
280 SVp_IOK|SVp_NOK))
79072805 281
463ee0b2 282#define SvOK(sv) (SvFLAGS(sv) & SVf_OK)
a0d0e21e 283
284#ifdef OVERLOAD
285#define SvOK_off(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC), \
286 SvOOK_off(sv))
287#else
288#define SvOK_off(sv) (SvFLAGS(sv) &= ~SVf_OK, SvOOK_off(sv))
289#endif /* OVERLOAD */
79072805 290
8990e307 291#define SvOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK))
292#define SvIOKp(sv) (SvFLAGS(sv) & SVp_IOK)
293#define SvIOKp_on(sv) (SvOOK_off(sv), SvFLAGS(sv) |= SVp_IOK)
294#define SvNOKp(sv) (SvFLAGS(sv) & SVp_NOK)
295#define SvNOKp_on(sv) (SvFLAGS(sv) |= SVp_NOK)
296#define SvPOKp(sv) (SvFLAGS(sv) & SVp_POK)
297#define SvPOKp_on(sv) (SvFLAGS(sv) |= SVp_POK)
463ee0b2 298
79072805 299#define SvIOK(sv) (SvFLAGS(sv) & SVf_IOK)
8990e307 300#define SvIOK_on(sv) (SvOOK_off(sv), \
a0d0e21e 301 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
8990e307 302#define SvIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVp_IOK))
a5f75d66 303#define SvIOK_only(sv) (SvOOK_off(sv), SvOK_off(sv), \
a0d0e21e 304 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
79072805 305
306#define SvNOK(sv) (SvFLAGS(sv) & SVf_NOK)
a0d0e21e 307#define SvNOK_on(sv) (SvFLAGS(sv) |= (SVf_NOK|SVp_NOK))
8990e307 308#define SvNOK_off(sv) (SvFLAGS(sv) &= ~(SVf_NOK|SVp_NOK))
309#define SvNOK_only(sv) (SvOK_off(sv), \
a0d0e21e 310 SvFLAGS(sv) |= (SVf_NOK|SVp_NOK))
79072805 311
312#define SvPOK(sv) (SvFLAGS(sv) & SVf_POK)
a0d0e21e 313#define SvPOK_on(sv) (SvFLAGS(sv) |= (SVf_POK|SVp_POK))
8990e307 314#define SvPOK_off(sv) (SvFLAGS(sv) &= ~(SVf_POK|SVp_POK))
c07a80fd 315
316#ifdef OVERLOAD
317#define SvPOK_only(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC), \
a0d0e21e 318 SvFLAGS(sv) |= (SVf_POK|SVp_POK))
c07a80fd 319#else
320#define SvPOK_only(sv) (SvFLAGS(sv) &= ~SVf_OK, \
321 SvFLAGS(sv) |= (SVf_POK|SVp_POK))
322#endif /* OVERLOAD */
79072805 323
324#define SvOOK(sv) (SvFLAGS(sv) & SVf_OOK)
325#define SvOOK_on(sv) (SvIOK_off(sv), SvFLAGS(sv) |= SVf_OOK)
326#define SvOOK_off(sv) (SvOOK(sv) && sv_backoff(sv))
79072805 327
a0d0e21e 328#define SvFAKE(sv) (SvFLAGS(sv) & SVf_FAKE)
329#define SvFAKE_on(sv) (SvFLAGS(sv) |= SVf_FAKE)
330#define SvFAKE_off(sv) (SvFLAGS(sv) &= ~SVf_FAKE)
331
ed6116ce 332#define SvROK(sv) (SvFLAGS(sv) & SVf_ROK)
a0d0e21e 333#define SvROK_on(sv) (SvFLAGS(sv) |= SVf_ROK)
334
335#ifdef OVERLOAD
336#define SvROK_off(sv) (SvFLAGS(sv) &= ~(SVf_ROK|SVf_AMAGIC))
337#else
ed6116ce 338#define SvROK_off(sv) (SvFLAGS(sv) &= ~SVf_ROK)
a0d0e21e 339#endif /* OVERLOAD */
79072805 340
8990e307 341#define SvMAGICAL(sv) (SvFLAGS(sv) & (SVs_GMG|SVs_SMG|SVs_RMG))
342#define SvMAGICAL_on(sv) (SvFLAGS(sv) |= (SVs_GMG|SVs_SMG|SVs_RMG))
343#define SvMAGICAL_off(sv) (SvFLAGS(sv) &= ~(SVs_GMG|SVs_SMG|SVs_RMG))
79072805 344
8990e307 345#define SvGMAGICAL(sv) (SvFLAGS(sv) & SVs_GMG)
346#define SvGMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_GMG)
347#define SvGMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_GMG)
ed6116ce 348
8990e307 349#define SvSMAGICAL(sv) (SvFLAGS(sv) & SVs_SMG)
350#define SvSMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_SMG)
351#define SvSMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_SMG)
ed6116ce 352
8990e307 353#define SvRMAGICAL(sv) (SvFLAGS(sv) & SVs_RMG)
354#define SvRMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_RMG)
355#define SvRMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_RMG)
ed6116ce 356
a0d0e21e 357#ifdef OVERLOAD
358#define SvAMAGIC(sv) (SvFLAGS(sv) & SVf_AMAGIC)
359#define SvAMAGIC_on(sv) (SvFLAGS(sv) |= SVf_AMAGIC)
360#define SvAMAGIC_off(sv) (SvFLAGS(sv) &= ~SVf_AMAGIC)
361
362/*
363#define Gv_AMG(stash) \
364 (HV_AMAGICmb(stash) && \
365 ((!HV_AMAGICbad(stash) && HV_AMAGIC(stash)) || Gv_AMupdate(stash)))
366*/
367#define Gv_AMG(stash) (amagic_generation && Gv_AMupdate(stash))
368#endif /* OVERLOAD */
369
370#define SvTHINKFIRST(sv) (SvFLAGS(sv) & SVf_THINKFIRST)
ed6116ce 371
8990e307 372#define SvPADBUSY(sv) (SvFLAGS(sv) & SVs_PADBUSY)
ed6116ce 373
8990e307 374#define SvPADTMP(sv) (SvFLAGS(sv) & SVs_PADTMP)
375#define SvPADTMP_on(sv) (SvFLAGS(sv) |= SVs_PADTMP|SVs_PADBUSY)
376#define SvPADTMP_off(sv) (SvFLAGS(sv) &= ~SVs_PADTMP)
ed6116ce 377
8990e307 378#define SvPADMY(sv) (SvFLAGS(sv) & SVs_PADMY)
379#define SvPADMY_on(sv) (SvFLAGS(sv) |= SVs_PADMY|SVs_PADBUSY)
ed6116ce 380
8990e307 381#define SvTEMP(sv) (SvFLAGS(sv) & SVs_TEMP)
382#define SvTEMP_on(sv) (SvFLAGS(sv) |= SVs_TEMP)
383#define SvTEMP_off(sv) (SvFLAGS(sv) &= ~SVs_TEMP)
79072805 384
8990e307 385#define SvOBJECT(sv) (SvFLAGS(sv) & SVs_OBJECT)
386#define SvOBJECT_on(sv) (SvFLAGS(sv) |= SVs_OBJECT)
387#define SvOBJECT_off(sv) (SvFLAGS(sv) &= ~SVs_OBJECT)
79072805 388
8990e307 389#define SvREADONLY(sv) (SvFLAGS(sv) & SVf_READONLY)
390#define SvREADONLY_on(sv) (SvFLAGS(sv) |= SVf_READONLY)
391#define SvREADONLY_off(sv) (SvFLAGS(sv) &= ~SVf_READONLY)
79072805 392
8990e307 393#define SvSCREAM(sv) (SvFLAGS(sv) & SVp_SCREAM)
394#define SvSCREAM_on(sv) (SvFLAGS(sv) |= SVp_SCREAM)
395#define SvSCREAM_off(sv) (SvFLAGS(sv) &= ~SVp_SCREAM)
79072805 396
8990e307 397#define SvCOMPILED(sv) (SvFLAGS(sv) & SVpfm_COMPILED)
398#define SvCOMPILED_on(sv) (SvFLAGS(sv) |= SVpfm_COMPILED)
399#define SvCOMPILED_off(sv) (SvFLAGS(sv) &= ~SVpfm_COMPILED)
79072805 400
8990e307 401#define SvTAIL(sv) (SvFLAGS(sv) & SVpbm_TAIL)
402#define SvTAIL_on(sv) (SvFLAGS(sv) |= SVpbm_TAIL)
403#define SvTAIL_off(sv) (SvFLAGS(sv) &= ~SVpbm_TAIL)
404
405#define SvCASEFOLD(sv) (SvFLAGS(sv) & SVpbm_CASEFOLD)
406#define SvCASEFOLD_on(sv) (SvFLAGS(sv) |= SVpbm_CASEFOLD)
407#define SvCASEFOLD_off(sv) (SvFLAGS(sv) &= ~SVpbm_CASEFOLD)
408
409#define SvVALID(sv) (SvFLAGS(sv) & SVpbm_VALID)
410#define SvVALID_on(sv) (SvFLAGS(sv) |= SVpbm_VALID)
411#define SvVALID_off(sv) (SvFLAGS(sv) &= ~SVpbm_VALID)
412
ed6116ce 413#define SvRV(sv) ((XRV*) SvANY(sv))->xrv_rv
414#define SvRVx(sv) SvRV(sv)
415
463ee0b2 416#define SvIVX(sv) ((XPVIV*) SvANY(sv))->xiv_iv
417#define SvIVXx(sv) SvIVX(sv)
418#define SvNVX(sv) ((XPVNV*)SvANY(sv))->xnv_nv
419#define SvNVXx(sv) SvNVX(sv)
420#define SvPVX(sv) ((XPV*) SvANY(sv))->xpv_pv
421#define SvPVXx(sv) SvPVX(sv)
79072805 422#define SvCUR(sv) ((XPV*) SvANY(sv))->xpv_cur
79072805 423#define SvLEN(sv) ((XPV*) SvANY(sv))->xpv_len
424#define SvLENx(sv) SvLEN(sv)
425#define SvEND(sv)(((XPV*) SvANY(sv))->xpv_pv + ((XPV*)SvANY(sv))->xpv_cur)
8990e307 426#define SvENDx(sv) ((Sv = (sv)), SvEND(Sv))
79072805 427#define SvMAGIC(sv) ((XPVMG*) SvANY(sv))->xmg_magic
428#define SvSTASH(sv) ((XPVMG*) SvANY(sv))->xmg_stash
429
430#define SvIV_set(sv, val) \
80b92232 431 STMT_START { assert(SvTYPE(sv) == SVt_IV || SvTYPE(sv) >= SVt_PVIV); \
432 (((XPVIV*) SvANY(sv))->xiv_iv = val); } STMT_END
79072805 433#define SvNV_set(sv, val) \
80b92232 434 STMT_START { assert(SvTYPE(sv) == SVt_NV || SvTYPE(sv) >= SVt_PVNV); \
435 (((XPVNV*) SvANY(sv))->xnv_nv = val); } STMT_END
79072805 436#define SvPV_set(sv, val) \
80b92232 437 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
438 (((XPV*) SvANY(sv))->xpv_pv = val); } STMT_END
79072805 439#define SvCUR_set(sv, val) \
80b92232 440 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
441 (((XPV*) SvANY(sv))->xpv_cur = val); } STMT_END
79072805 442#define SvLEN_set(sv, val) \
80b92232 443 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
444 (((XPV*) SvANY(sv))->xpv_len = val); } STMT_END
79072805 445#define SvEND_set(sv, val) \
80b92232 446 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
447 (((XPV*) SvANY(sv))->xpv_cur = val - SvPVX(sv)); } STMT_END
79072805 448
449#define BmRARE(sv) ((XPVBM*) SvANY(sv))->xbm_rare
450#define BmUSEFUL(sv) ((XPVBM*) SvANY(sv))->xbm_useful
451#define BmPREVIOUS(sv) ((XPVBM*) SvANY(sv))->xbm_previous
452
453#define FmLINES(sv) ((XPVFM*) SvANY(sv))->xfm_lines
454
455#define LvTYPE(sv) ((XPVLV*) SvANY(sv))->xlv_type
456#define LvTARG(sv) ((XPVLV*) SvANY(sv))->xlv_targ
457#define LvTARGOFF(sv) ((XPVLV*) SvANY(sv))->xlv_targoff
458#define LvTARGLEN(sv) ((XPVLV*) SvANY(sv))->xlv_targlen
459
8990e307 460#define IoIFP(sv) ((XPVIO*) SvANY(sv))->xio_ifp
461#define IoOFP(sv) ((XPVIO*) SvANY(sv))->xio_ofp
462#define IoDIRP(sv) ((XPVIO*) SvANY(sv))->xio_dirp
463#define IoLINES(sv) ((XPVIO*) SvANY(sv))->xio_lines
464#define IoPAGE(sv) ((XPVIO*) SvANY(sv))->xio_page
465#define IoPAGE_LEN(sv) ((XPVIO*) SvANY(sv))->xio_page_len
466#define IoLINES_LEFT(sv)((XPVIO*) SvANY(sv))->xio_lines_left
467#define IoTOP_NAME(sv) ((XPVIO*) SvANY(sv))->xio_top_name
468#define IoTOP_GV(sv) ((XPVIO*) SvANY(sv))->xio_top_gv
469#define IoFMT_NAME(sv) ((XPVIO*) SvANY(sv))->xio_fmt_name
470#define IoFMT_GV(sv) ((XPVIO*) SvANY(sv))->xio_fmt_gv
471#define IoBOTTOM_NAME(sv)((XPVIO*) SvANY(sv))->xio_bottom_name
472#define IoBOTTOM_GV(sv) ((XPVIO*) SvANY(sv))->xio_bottom_gv
473#define IoSUBPROCESS(sv)((XPVIO*) SvANY(sv))->xio_subprocess
474#define IoTYPE(sv) ((XPVIO*) SvANY(sv))->xio_type
475#define IoFLAGS(sv) ((XPVIO*) SvANY(sv))->xio_flags
476
a0d0e21e 477#define SvTAINT(sv) if (tainting && tainted) sv_magic(sv, Nullsv, 't', Nullch, 0)
79072805 478
479#ifdef CRIPPLED_CC
480
a0d0e21e 481IV SvIV _((SV* sv));
482double SvNV _((SV* sv));
483#define SvPV_force(sv, lp) sv_pvn_force(sv, &lp)
463ee0b2 484#define SvPV(sv, lp) sv_pvn(sv, &lp)
a0d0e21e 485char *sv_pvn _((SV *, STRLEN *));
486I32 SvTRUE _((SV *));
79072805 487
463ee0b2 488#define SvIVx(sv) SvIV(sv)
489#define SvNVx(sv) SvNV(sv)
490#define SvPVx(sv, lp) sv_pvn(sv, &lp)
a0d0e21e 491#define SvPVx_force(sv, lp) sv_pvn_force(sv, &lp)
79072805 492#define SvTRUEx(sv) SvTRUE(sv)
493
494#else /* !CRIPPLED_CC */
495
463ee0b2 496#define SvIV(sv) (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv))
79072805 497
463ee0b2 498#define SvNV(sv) (SvNOK(sv) ? SvNVX(sv) : sv_2nv(sv))
79072805 499
463ee0b2 500#define SvPV(sv, lp) (SvPOK(sv) ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pv(sv, &lp))
79072805 501
a0d0e21e 502#define SvPV_force(sv, lp) ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvn_force(sv, &lp))
503
463ee0b2 504#define SvTRUE(sv) ( \
8990e307 505 !sv \
506 ? 0 \
507 : SvPOK(sv) \
79072805 508 ? ((Xpv = (XPV*)SvANY(sv)) && \
509 (*Xpv->xpv_pv > '0' || \
510 Xpv->xpv_cur > 1 || \
511 (Xpv->xpv_cur && *Xpv->xpv_pv != '0')) \
512 ? 1 \
513 : 0) \
514 : \
515 SvIOK(sv) \
463ee0b2 516 ? SvIVX(sv) != 0 \
79072805 517 : SvNOK(sv) \
463ee0b2 518 ? SvNVX(sv) != 0.0 \
519 : sv_2bool(sv) )
79072805 520
8990e307 521#define SvIVx(sv) ((Sv = (sv)), SvIV(Sv))
522#define SvNVx(sv) ((Sv = (sv)), SvNV(Sv))
523#define SvPVx(sv, lp) ((Sv = (sv)), SvPV(Sv, lp))
524#define SvTRUEx(sv) ((Sv = (sv)), SvTRUE(Sv))
79072805 525
526#endif /* CRIPPLED_CC */
527
528/* the following macro updates any magic values this sv is associated with */
529
8990e307 530#define SvSETMAGIC(x) if (SvSMAGICAL(x)) mg_set(x)
79072805 531
532#define SvSetSV(dst,src) if (dst != src) sv_setsv(dst,src)
533
534#define SvPEEK(sv) sv_peek(sv)
535
536#define isGV(sv) (SvTYPE(sv) == SVt_PVGV)
537
79072805 538#ifndef DOSISH
a0d0e21e 539# define SvGROW(sv,len) (SvLEN(sv) < (len) ? sv_grow(sv,len) : SvPVX(sv))
79072805 540# define Sv_Grow sv_grow
541#else
542 /* extra parentheses intentionally NOT placed around "len"! */
a0d0e21e 543# define SvGROW(sv,len) ((SvLEN(sv) < (unsigned long)len) \
544 ? sv_grow(sv,(unsigned long)len) : SvPVX(sv))
79072805 545# define Sv_Grow(sv,len) sv_grow(sv,(unsigned long)(len))
546#endif /* DOSISH */