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