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