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