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