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