Compiling with OP_IN_REGISTER
[p5sagit/p5-mst-13.2.git] / sv.h
CommitLineData
a0d0e21e 1/* sv.h
79072805 2 *
9607fc9c 3 * Copyright (c) 1991-1997, 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
aeea060c 73#define SvREFCNT(sv) (sv)->sv_refcnt
a863c7d1 74
dce16143 75#ifdef USE_THREADS
76
77# ifndef EMULATE_ATOMIC_REFCOUNTS
78# include "atomic.h"
79# endif
80
81# ifdef EMULATE_ATOMIC_REFCOUNTS
82# define ATOMIC_INC(count) STMT_START { \
83 MUTEX_LOCK(&svref_mutex); \
84 ++count; \
85 MUTEX_UNLOCK(&svref_mutex); \
86 } STMT_END
0bfcb09d 87# define ATOMIC_DEC_AND_TEST(res,count) STMT_START { \
88 MUTEX_LOCK(&svref_mutex); \
89 res = (--count == 0); \
90 MUTEX_UNLOCK(&svref_mutex); \
dce16143 91 } STMT_END
92# else
93# define ATOMIC_INC(count) atomic_inc(&count)
94# define ATOMIC_DEC_AND_TEST(res,count) (res = atomic_dec_and_test(&count))
95# endif /* EMULATE_ATOMIC_REFCOUNTS */
96#else
97# define ATOMIC_INC(count) (++count)
83b0a010 98# define ATOMIC_DEC_AND_TEST(res, count) (res = (--count == 0))
dce16143 99#endif /* USE_THREADS */
100
a863c7d1 101#ifdef __GNUC__
dce16143 102# define SvREFCNT_inc(sv) \
103 ({ \
104 SV *nsv = (SV*)(sv); \
105 if (nsv) \
106 ATOMIC_INC(SvREFCNT(nsv)); \
107 nsv; \
108 })
8990e307 109#else
a863c7d1 110# if defined(CRIPPLED_CC) || defined(USE_THREADS)
199100c8 111# define SvREFCNT_inc(sv) sv_newref((SV*)sv)
a863c7d1 112# else
dce16143 113# define SvREFCNT_inc(sv) \
114 ((Sv=(SV*)(sv)), (Sv && ATOMIC_INC(SvREFCNT(Sv))), (SV*)Sv)
a863c7d1 115# endif
8990e307 116#endif
117
a863c7d1 118#define SvREFCNT_dec(sv) sv_free((SV*)sv)
119
8990e307 120#define SVTYPEMASK 0xff
121#define SvTYPE(sv) ((sv)->sv_flags & SVTYPEMASK)
79072805 122
123#define SvUPGRADE(sv, mt) (SvTYPE(sv) >= mt || sv_upgrade(sv, mt))
124
8990e307 125#define SVs_PADBUSY 0x00000100 /* reserved for tmp or my already */
126#define SVs_PADTMP 0x00000200 /* in use as tmp */
127#define SVs_PADMY 0x00000400 /* in use a "my" variable */
128#define SVs_TEMP 0x00000800 /* string is stealable? */
129#define SVs_OBJECT 0x00001000 /* is "blessed" */
130#define SVs_GMG 0x00002000 /* has magical get method */
131#define SVs_SMG 0x00004000 /* has magical set method */
132#define SVs_RMG 0x00008000 /* has random magical methods */
133
134#define SVf_IOK 0x00010000 /* has valid public integer value */
135#define SVf_NOK 0x00020000 /* has valid public numeric value */
136#define SVf_POK 0x00040000 /* has valid public pointer value */
137#define SVf_ROK 0x00080000 /* has a valid reference pointer */
a0d0e21e 138
748a9306 139#define SVf_FAKE 0x00100000 /* glob or lexical is just a copy */
8990e307 140#define SVf_OOK 0x00200000 /* has valid offset value */
141#define SVf_BREAK 0x00400000 /* refcnt is artificially low */
142#define SVf_READONLY 0x00800000 /* may not be modified */
143
a0d0e21e 144#define SVf_THINKFIRST (SVf_READONLY|SVf_ROK)
145
8990e307 146#define SVp_IOK 0x01000000 /* has valid non-public integer value */
147#define SVp_NOK 0x02000000 /* has valid non-public numeric value */
148#define SVp_POK 0x04000000 /* has valid non-public pointer value */
149#define SVp_SCREAM 0x08000000 /* has been studied? */
150
a0d0e21e 151#define SVf_OK (SVf_IOK|SVf_NOK|SVf_POK|SVf_ROK| \
152 SVp_IOK|SVp_NOK|SVp_POK)
153
154#ifdef OVERLOAD
155#define SVf_AMAGIC 0x10000000 /* has magical overloaded methods */
156#endif /* OVERLOAD */
157
8990e307 158#define PRIVSHIFT 8
159
160/* Some private flags. */
161
162#define SVpfm_COMPILED 0x80000000
163
164#define SVpbm_VALID 0x80000000
bbce6d69 165#define SVpbm_TAIL 0x40000000
8990e307 166
bf6bd887 167#define SVphv_SHAREKEYS 0x20000000 /* keys live on shared string table */
51594c39 168#define SVphv_LAZYDEL 0x40000000 /* entry in xhv_eiter must be deleted */
bf6bd887 169
ed6116ce 170struct xrv {
171 SV * xrv_rv; /* pointer to another SV */
172};
173
79072805 174struct xpv {
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 */
79072805 178};
179
180struct xpviv {
ed6116ce 181 char * xpv_pv; /* pointer to malloced string */
182 STRLEN xpv_cur; /* length of xpv_pv as a C string */
183 STRLEN xpv_len; /* allocated size */
a0d0e21e 184 IV xiv_iv; /* integer value or pv offset */
79072805 185};
186
ff68c719 187struct xpvuv {
188 char * xpv_pv; /* pointer to malloced string */
189 STRLEN xpv_cur; /* length of xpv_pv as a C string */
190 STRLEN xpv_len; /* allocated size */
191 UV xuv_uv; /* unsigned value or pv offset */
192};
193
79072805 194struct xpvnv {
ed6116ce 195 char * xpv_pv; /* pointer to malloced string */
196 STRLEN xpv_cur; /* length of xpv_pv as a C string */
197 STRLEN xpv_len; /* allocated size */
a0d0e21e 198 IV xiv_iv; /* integer value or pv offset */
ed6116ce 199 double xnv_nv; /* numeric value, if any */
79072805 200};
201
202struct xpvmg {
ed6116ce 203 char * xpv_pv; /* pointer to malloced string */
204 STRLEN xpv_cur; /* length of xpv_pv as a C string */
205 STRLEN xpv_len; /* allocated size */
a0d0e21e 206 IV xiv_iv; /* integer value or pv offset */
ed6116ce 207 double xnv_nv; /* numeric value, if any */
79072805 208 MAGIC* xmg_magic; /* linked list of magicalness */
209 HV* xmg_stash; /* class package */
210};
211
212struct xpvlv {
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 STRLEN xlv_targoff;
222 STRLEN xlv_targlen;
223 SV* xlv_targ;
224 char xlv_type;
225};
226
227struct xpvgv {
ed6116ce 228 char * xpv_pv; /* pointer to malloced string */
229 STRLEN xpv_cur; /* length of xpv_pv as a C string */
230 STRLEN xpv_len; /* allocated size */
a0d0e21e 231 IV xiv_iv; /* integer value or pv offset */
ed6116ce 232 double xnv_nv; /* numeric value, if any */
79072805 233 MAGIC* xmg_magic; /* linked list of magicalness */
234 HV* xmg_stash; /* class package */
8990e307 235
79072805 236 GP* xgv_gp;
237 char* xgv_name;
238 STRLEN xgv_namelen;
239 HV* xgv_stash;
a5f75d66 240 U8 xgv_flags;
79072805 241};
242
243struct xpvbm {
ed6116ce 244 char * xpv_pv; /* pointer to malloced string */
245 STRLEN xpv_cur; /* length of xpv_pv as a C string */
246 STRLEN xpv_len; /* allocated size */
a0d0e21e 247 IV xiv_iv; /* integer value or pv offset */
ed6116ce 248 double xnv_nv; /* numeric value, if any */
79072805 249 MAGIC* xmg_magic; /* linked list of magicalness */
250 HV* xmg_stash; /* class package */
8990e307 251
79072805 252 I32 xbm_useful; /* is this constant pattern being useful? */
253 U16 xbm_previous; /* how many characters in string before rare? */
254 U8 xbm_rare; /* rarest character in string */
255};
256
44a8e56a 257/* This structure much match XPVCV */
258
77a005ab 259typedef U16 cv_flags_t;
260
79072805 261struct xpvfm {
ed6116ce 262 char * xpv_pv; /* pointer to malloced string */
263 STRLEN xpv_cur; /* length of xpv_pv as a C string */
264 STRLEN xpv_len; /* allocated size */
a0d0e21e 265 IV xiv_iv; /* integer value or pv offset */
ed6116ce 266 double xnv_nv; /* numeric value, if any */
79072805 267 MAGIC* xmg_magic; /* linked list of magicalness */
268 HV* xmg_stash; /* class package */
8990e307 269
79072805 270 HV * xcv_stash;
271 OP * xcv_start;
272 OP * xcv_root;
a0d0e21e 273 void (*xcv_xsub)_((CV*));
274 ANY xcv_xsubany;
275 GV * xcv_gv;
79072805 276 GV * xcv_filegv;
277 long xcv_depth; /* >= 2 indicates recursive call */
278 AV * xcv_padlist;
748a9306 279 CV * xcv_outside;
e858de61 280#ifdef USE_THREADS
f6d98b14 281 perl_mutex *xcv_mutexp; /* protects xcv_owner */
52e1cb5e 282 struct perl_thread *xcv_owner; /* current owner thread */
e858de61 283#endif /* USE_THREADS */
77a005ab 284 cv_flags_t xcv_flags;
44a8e56a 285
79072805 286 I32 xfm_lines;
287};
288
8990e307 289struct xpvio {
290 char * xpv_pv; /* pointer to malloced string */
291 STRLEN xpv_cur; /* length of xpv_pv as a C string */
292 STRLEN xpv_len; /* allocated size */
a0d0e21e 293 IV xiv_iv; /* integer value or pv offset */
8990e307 294 double xnv_nv; /* numeric value, if any */
295 MAGIC* xmg_magic; /* linked list of magicalness */
296 HV* xmg_stash; /* class package */
297
760ac839 298 PerlIO * xio_ifp; /* ifp and ofp are normally the same */
299 PerlIO * xio_ofp; /* but sockets need separate streams */
8990e307 300 DIR * xio_dirp; /* for opendir, readdir, etc */
301 long xio_lines; /* $. */
302 long xio_page; /* $% */
303 long xio_page_len; /* $= */
304 long xio_lines_left; /* $- */
305 char * xio_top_name; /* $^ */
306 GV * xio_top_gv; /* $^ */
307 char * xio_fmt_name; /* $~ */
308 GV * xio_fmt_gv; /* $~ */
309 char * xio_bottom_name;/* $^B */
310 GV * xio_bottom_gv; /* $^B */
311 short xio_subprocess; /* -| or |- */
312 char xio_type;
313 char xio_flags;
314};
315
316#define IOf_ARGV 1 /* this fp iterates over ARGV */
317#define IOf_START 2 /* check for null ARGV and substitute '-' */
318#define IOf_FLUSH 4 /* this fp wants a flush after write op */
748a9306 319#define IOf_DIDTOP 8 /* just did top of form */
51594c39 320#define IOf_UNTAINT 16 /* consider this fp (and it's data) "safe" */
8990e307 321
ed6116ce 322/* The following macros define implementation-independent predicates on SVs. */
323
79072805 324#define SvNIOK(sv) (SvFLAGS(sv) & (SVf_IOK|SVf_NOK))
748a9306 325#define SvNIOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK))
a0d0e21e 326#define SvNIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK| \
327 SVp_IOK|SVp_NOK))
79072805 328
463ee0b2 329#define SvOK(sv) (SvFLAGS(sv) & SVf_OK)
a0d0e21e 330
331#ifdef OVERLOAD
332#define SvOK_off(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC), \
333 SvOOK_off(sv))
334#else
335#define SvOK_off(sv) (SvFLAGS(sv) &= ~SVf_OK, SvOOK_off(sv))
336#endif /* OVERLOAD */
79072805 337
8990e307 338#define SvOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK))
339#define SvIOKp(sv) (SvFLAGS(sv) & SVp_IOK)
340#define SvIOKp_on(sv) (SvOOK_off(sv), SvFLAGS(sv) |= SVp_IOK)
341#define SvNOKp(sv) (SvFLAGS(sv) & SVp_NOK)
342#define SvNOKp_on(sv) (SvFLAGS(sv) |= SVp_NOK)
343#define SvPOKp(sv) (SvFLAGS(sv) & SVp_POK)
344#define SvPOKp_on(sv) (SvFLAGS(sv) |= SVp_POK)
463ee0b2 345
79072805 346#define SvIOK(sv) (SvFLAGS(sv) & SVf_IOK)
8990e307 347#define SvIOK_on(sv) (SvOOK_off(sv), \
a0d0e21e 348 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
8990e307 349#define SvIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVp_IOK))
a5f75d66 350#define SvIOK_only(sv) (SvOOK_off(sv), SvOK_off(sv), \
a0d0e21e 351 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
79072805 352
353#define SvNOK(sv) (SvFLAGS(sv) & SVf_NOK)
a0d0e21e 354#define SvNOK_on(sv) (SvFLAGS(sv) |= (SVf_NOK|SVp_NOK))
8990e307 355#define SvNOK_off(sv) (SvFLAGS(sv) &= ~(SVf_NOK|SVp_NOK))
356#define SvNOK_only(sv) (SvOK_off(sv), \
a0d0e21e 357 SvFLAGS(sv) |= (SVf_NOK|SVp_NOK))
79072805 358
359#define SvPOK(sv) (SvFLAGS(sv) & SVf_POK)
a0d0e21e 360#define SvPOK_on(sv) (SvFLAGS(sv) |= (SVf_POK|SVp_POK))
8990e307 361#define SvPOK_off(sv) (SvFLAGS(sv) &= ~(SVf_POK|SVp_POK))
c07a80fd 362
363#ifdef OVERLOAD
364#define SvPOK_only(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC), \
a0d0e21e 365 SvFLAGS(sv) |= (SVf_POK|SVp_POK))
c07a80fd 366#else
367#define SvPOK_only(sv) (SvFLAGS(sv) &= ~SVf_OK, \
368 SvFLAGS(sv) |= (SVf_POK|SVp_POK))
369#endif /* OVERLOAD */
79072805 370
371#define SvOOK(sv) (SvFLAGS(sv) & SVf_OOK)
372#define SvOOK_on(sv) (SvIOK_off(sv), SvFLAGS(sv) |= SVf_OOK)
373#define SvOOK_off(sv) (SvOOK(sv) && sv_backoff(sv))
79072805 374
a0d0e21e 375#define SvFAKE(sv) (SvFLAGS(sv) & SVf_FAKE)
376#define SvFAKE_on(sv) (SvFLAGS(sv) |= SVf_FAKE)
377#define SvFAKE_off(sv) (SvFLAGS(sv) &= ~SVf_FAKE)
378
ed6116ce 379#define SvROK(sv) (SvFLAGS(sv) & SVf_ROK)
a0d0e21e 380#define SvROK_on(sv) (SvFLAGS(sv) |= SVf_ROK)
381
382#ifdef OVERLOAD
383#define SvROK_off(sv) (SvFLAGS(sv) &= ~(SVf_ROK|SVf_AMAGIC))
384#else
ed6116ce 385#define SvROK_off(sv) (SvFLAGS(sv) &= ~SVf_ROK)
a0d0e21e 386#endif /* OVERLOAD */
79072805 387
8990e307 388#define SvMAGICAL(sv) (SvFLAGS(sv) & (SVs_GMG|SVs_SMG|SVs_RMG))
389#define SvMAGICAL_on(sv) (SvFLAGS(sv) |= (SVs_GMG|SVs_SMG|SVs_RMG))
390#define SvMAGICAL_off(sv) (SvFLAGS(sv) &= ~(SVs_GMG|SVs_SMG|SVs_RMG))
79072805 391
8990e307 392#define SvGMAGICAL(sv) (SvFLAGS(sv) & SVs_GMG)
393#define SvGMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_GMG)
394#define SvGMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_GMG)
ed6116ce 395
8990e307 396#define SvSMAGICAL(sv) (SvFLAGS(sv) & SVs_SMG)
397#define SvSMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_SMG)
398#define SvSMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_SMG)
ed6116ce 399
8990e307 400#define SvRMAGICAL(sv) (SvFLAGS(sv) & SVs_RMG)
401#define SvRMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_RMG)
402#define SvRMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_RMG)
ed6116ce 403
a0d0e21e 404#ifdef OVERLOAD
405#define SvAMAGIC(sv) (SvFLAGS(sv) & SVf_AMAGIC)
406#define SvAMAGIC_on(sv) (SvFLAGS(sv) |= SVf_AMAGIC)
407#define SvAMAGIC_off(sv) (SvFLAGS(sv) &= ~SVf_AMAGIC)
408
409/*
410#define Gv_AMG(stash) \
411 (HV_AMAGICmb(stash) && \
412 ((!HV_AMAGICbad(stash) && HV_AMAGIC(stash)) || Gv_AMupdate(stash)))
413*/
414#define Gv_AMG(stash) (amagic_generation && Gv_AMupdate(stash))
415#endif /* OVERLOAD */
416
417#define SvTHINKFIRST(sv) (SvFLAGS(sv) & SVf_THINKFIRST)
ed6116ce 418
8990e307 419#define SvPADBUSY(sv) (SvFLAGS(sv) & SVs_PADBUSY)
ed6116ce 420
8990e307 421#define SvPADTMP(sv) (SvFLAGS(sv) & SVs_PADTMP)
422#define SvPADTMP_on(sv) (SvFLAGS(sv) |= SVs_PADTMP|SVs_PADBUSY)
423#define SvPADTMP_off(sv) (SvFLAGS(sv) &= ~SVs_PADTMP)
ed6116ce 424
8990e307 425#define SvPADMY(sv) (SvFLAGS(sv) & SVs_PADMY)
426#define SvPADMY_on(sv) (SvFLAGS(sv) |= SVs_PADMY|SVs_PADBUSY)
ed6116ce 427
8990e307 428#define SvTEMP(sv) (SvFLAGS(sv) & SVs_TEMP)
429#define SvTEMP_on(sv) (SvFLAGS(sv) |= SVs_TEMP)
430#define SvTEMP_off(sv) (SvFLAGS(sv) &= ~SVs_TEMP)
79072805 431
8990e307 432#define SvOBJECT(sv) (SvFLAGS(sv) & SVs_OBJECT)
433#define SvOBJECT_on(sv) (SvFLAGS(sv) |= SVs_OBJECT)
434#define SvOBJECT_off(sv) (SvFLAGS(sv) &= ~SVs_OBJECT)
79072805 435
8990e307 436#define SvREADONLY(sv) (SvFLAGS(sv) & SVf_READONLY)
437#define SvREADONLY_on(sv) (SvFLAGS(sv) |= SVf_READONLY)
438#define SvREADONLY_off(sv) (SvFLAGS(sv) &= ~SVf_READONLY)
79072805 439
8990e307 440#define SvSCREAM(sv) (SvFLAGS(sv) & SVp_SCREAM)
441#define SvSCREAM_on(sv) (SvFLAGS(sv) |= SVp_SCREAM)
442#define SvSCREAM_off(sv) (SvFLAGS(sv) &= ~SVp_SCREAM)
79072805 443
8990e307 444#define SvCOMPILED(sv) (SvFLAGS(sv) & SVpfm_COMPILED)
445#define SvCOMPILED_on(sv) (SvFLAGS(sv) |= SVpfm_COMPILED)
446#define SvCOMPILED_off(sv) (SvFLAGS(sv) &= ~SVpfm_COMPILED)
79072805 447
8990e307 448#define SvTAIL(sv) (SvFLAGS(sv) & SVpbm_TAIL)
449#define SvTAIL_on(sv) (SvFLAGS(sv) |= SVpbm_TAIL)
450#define SvTAIL_off(sv) (SvFLAGS(sv) &= ~SVpbm_TAIL)
451
8990e307 452#define SvVALID(sv) (SvFLAGS(sv) & SVpbm_VALID)
453#define SvVALID_on(sv) (SvFLAGS(sv) |= SVpbm_VALID)
454#define SvVALID_off(sv) (SvFLAGS(sv) &= ~SVpbm_VALID)
455
ed6116ce 456#define SvRV(sv) ((XRV*) SvANY(sv))->xrv_rv
457#define SvRVx(sv) SvRV(sv)
458
463ee0b2 459#define SvIVX(sv) ((XPVIV*) SvANY(sv))->xiv_iv
460#define SvIVXx(sv) SvIVX(sv)
ff68c719 461#define SvUVX(sv) ((XPVUV*) SvANY(sv))->xuv_uv
462#define SvUVXx(sv) SvUVX(sv)
463ee0b2 463#define SvNVX(sv) ((XPVNV*)SvANY(sv))->xnv_nv
464#define SvNVXx(sv) SvNVX(sv)
465#define SvPVX(sv) ((XPV*) SvANY(sv))->xpv_pv
466#define SvPVXx(sv) SvPVX(sv)
79072805 467#define SvCUR(sv) ((XPV*) SvANY(sv))->xpv_cur
79072805 468#define SvLEN(sv) ((XPV*) SvANY(sv))->xpv_len
469#define SvLENx(sv) SvLEN(sv)
470#define SvEND(sv)(((XPV*) SvANY(sv))->xpv_pv + ((XPV*)SvANY(sv))->xpv_cur)
8990e307 471#define SvENDx(sv) ((Sv = (sv)), SvEND(Sv))
79072805 472#define SvMAGIC(sv) ((XPVMG*) SvANY(sv))->xmg_magic
473#define SvSTASH(sv) ((XPVMG*) SvANY(sv))->xmg_stash
474
475#define SvIV_set(sv, val) \
80b92232 476 STMT_START { assert(SvTYPE(sv) == SVt_IV || SvTYPE(sv) >= SVt_PVIV); \
477 (((XPVIV*) SvANY(sv))->xiv_iv = val); } STMT_END
79072805 478#define SvNV_set(sv, val) \
80b92232 479 STMT_START { assert(SvTYPE(sv) == SVt_NV || SvTYPE(sv) >= SVt_PVNV); \
480 (((XPVNV*) SvANY(sv))->xnv_nv = val); } STMT_END
79072805 481#define SvPV_set(sv, val) \
80b92232 482 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
483 (((XPV*) SvANY(sv))->xpv_pv = val); } STMT_END
79072805 484#define SvCUR_set(sv, val) \
80b92232 485 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
486 (((XPV*) SvANY(sv))->xpv_cur = val); } STMT_END
79072805 487#define SvLEN_set(sv, val) \
80b92232 488 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
489 (((XPV*) SvANY(sv))->xpv_len = val); } STMT_END
79072805 490#define SvEND_set(sv, val) \
80b92232 491 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
492 (((XPV*) SvANY(sv))->xpv_cur = val - SvPVX(sv)); } STMT_END
79072805 493
494#define BmRARE(sv) ((XPVBM*) SvANY(sv))->xbm_rare
495#define BmUSEFUL(sv) ((XPVBM*) SvANY(sv))->xbm_useful
496#define BmPREVIOUS(sv) ((XPVBM*) SvANY(sv))->xbm_previous
497
498#define FmLINES(sv) ((XPVFM*) SvANY(sv))->xfm_lines
499
500#define LvTYPE(sv) ((XPVLV*) SvANY(sv))->xlv_type
501#define LvTARG(sv) ((XPVLV*) SvANY(sv))->xlv_targ
502#define LvTARGOFF(sv) ((XPVLV*) SvANY(sv))->xlv_targoff
503#define LvTARGLEN(sv) ((XPVLV*) SvANY(sv))->xlv_targlen
504
8990e307 505#define IoIFP(sv) ((XPVIO*) SvANY(sv))->xio_ifp
506#define IoOFP(sv) ((XPVIO*) SvANY(sv))->xio_ofp
507#define IoDIRP(sv) ((XPVIO*) SvANY(sv))->xio_dirp
508#define IoLINES(sv) ((XPVIO*) SvANY(sv))->xio_lines
509#define IoPAGE(sv) ((XPVIO*) SvANY(sv))->xio_page
510#define IoPAGE_LEN(sv) ((XPVIO*) SvANY(sv))->xio_page_len
511#define IoLINES_LEFT(sv)((XPVIO*) SvANY(sv))->xio_lines_left
512#define IoTOP_NAME(sv) ((XPVIO*) SvANY(sv))->xio_top_name
513#define IoTOP_GV(sv) ((XPVIO*) SvANY(sv))->xio_top_gv
514#define IoFMT_NAME(sv) ((XPVIO*) SvANY(sv))->xio_fmt_name
515#define IoFMT_GV(sv) ((XPVIO*) SvANY(sv))->xio_fmt_gv
516#define IoBOTTOM_NAME(sv)((XPVIO*) SvANY(sv))->xio_bottom_name
517#define IoBOTTOM_GV(sv) ((XPVIO*) SvANY(sv))->xio_bottom_gv
518#define IoSUBPROCESS(sv)((XPVIO*) SvANY(sv))->xio_subprocess
519#define IoTYPE(sv) ((XPVIO*) SvANY(sv))->xio_type
520#define IoFLAGS(sv) ((XPVIO*) SvANY(sv))->xio_flags
521
bbce6d69 522#define SvTAINTED(sv) (SvMAGICAL(sv) && sv_tainted(sv))
523#define SvTAINTED_on(sv) STMT_START{ if(tainting){sv_taint(sv);} }STMT_END
524#define SvTAINTED_off(sv) STMT_START{ if(tainting){sv_untaint(sv);} }STMT_END
525
c6ee37c5 526#define SvTAINT(sv) \
527 STMT_START { \
528 if (tainting) { \
529 dTHR; \
530 if (tainted) \
531 SvTAINTED_on(sv); \
532 } \
533 } STMT_END
79072805 534
a0d0e21e 535#define SvPV_force(sv, lp) sv_pvn_force(sv, &lp)
463ee0b2 536#define SvPV(sv, lp) sv_pvn(sv, &lp)
4e35701f 537#define SvIVx(sv) sv_iv(sv)
538#define SvUVx(sv) sv_uv(sv)
539#define SvNVx(sv) sv_nv(sv)
463ee0b2 540#define SvPVx(sv, lp) sv_pvn(sv, &lp)
a0d0e21e 541#define SvPVx_force(sv, lp) sv_pvn_force(sv, &lp)
4e35701f 542#define SvTRUEx(sv) sv_true(sv)
543
544#define SvIV(sv) SvIVx(sv)
545#define SvNV(sv) SvNVx(sv)
546#define SvUV(sv) SvIVx(sv)
547#define SvTRUE(sv) SvTRUEx(sv)
79072805 548
a80f87c4 549#ifndef CRIPPLED_CC
550/* redefine some things to more efficient inlined versions */
79072805 551
ff68c719 552#undef SvIV
463ee0b2 553#define SvIV(sv) (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv))
79072805 554
ff68c719 555#undef SvUV
556#define SvUV(sv) (SvIOK(sv) ? SvUVX(sv) : sv_2uv(sv))
557
558#undef SvNV
463ee0b2 559#define SvNV(sv) (SvNOK(sv) ? SvNVX(sv) : sv_2nv(sv))
79072805 560
ff68c719 561#undef SvPV
562#define SvPV(sv, lp) \
563 (SvPOK(sv) ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pv(sv, &lp))
79072805 564
ff68c719 565#undef SvPV_force
566#define SvPV_force(sv, lp) \
567 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \
568 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvn_force(sv, &lp))
a0d0e21e 569
a80f87c4 570#ifdef __GNUC__
571# undef SvIVx
572# undef SvUVx
573# undef SvNVx
574# undef SvPVx
575# undef SvTRUE
576# undef SvTRUEx
577# define SvIVx(sv) ({SV *nsv = (SV*)(sv); SvIV(nsv); })
578# define SvUVx(sv) ({SV *nsv = (SV*)(sv); SvUV(nsv); })
579# define SvNVx(sv) ({SV *nsv = (SV*)(sv); SvNV(nsv); })
580# define SvPVx(sv, lp) ({SV *nsv = (sv); SvPV(nsv, lp); })
581# define SvTRUE(sv) ( \
8990e307 582 !sv \
583 ? 0 \
584 : SvPOK(sv) \
a80f87c4 585 ? (({XPV *nxpv = (XPV*)SvANY(sv); \
586 nxpv && \
587 (*nxpv->xpv_pv > '0' || \
588 nxpv->xpv_cur > 1 || \
589 (nxpv->xpv_cur && *nxpv->xpv_pv != '0')); }) \
79072805 590 ? 1 \
591 : 0) \
592 : \
593 SvIOK(sv) \
463ee0b2 594 ? SvIVX(sv) != 0 \
79072805 595 : SvNOK(sv) \
463ee0b2 596 ? SvNVX(sv) != 0.0 \
597 : sv_2bool(sv) )
a80f87c4 598# define SvTRUEx(sv) ({SV *nsv = (sv); SvTRUE(nsv); })
599#else /* __GNUC__ */
600#ifndef USE_THREADS
601/* These inlined macros use globals, which will require a thread
602 * declaration in user code, so we avoid them under threads */
603
604# undef SvIVx
605# undef SvUVx
606# undef SvNVx
607# undef SvPVx
608# undef SvTRUE
609# undef SvTRUEx
aeea060c 610# define SvIVx(sv) ((Sv = (sv)), SvIV(Sv))
611# define SvUVx(sv) ((Sv = (sv)), SvUV(Sv))
612# define SvNVx(sv) ((Sv = (sv)), SvNV(Sv))
613# define SvPVx(sv, lp) ((Sv = (sv)), SvPV(Sv, lp))
a80f87c4 614# define SvTRUE(sv) ( \
615 !sv \
616 ? 0 \
617 : SvPOK(sv) \
618 ? ((Xpv = (XPV*)SvANY(sv)) && \
619 (*Xpv->xpv_pv > '0' || \
620 Xpv->xpv_cur > 1 || \
621 (Xpv->xpv_cur && *Xpv->xpv_pv != '0')) \
622 ? 1 \
623 : 0) \
624 : \
625 SvIOK(sv) \
626 ? SvIVX(sv) != 0 \
627 : SvNOK(sv) \
628 ? SvNVX(sv) != 0.0 \
629 : sv_2bool(sv) )
630# define SvTRUEx(sv) ((Sv = (sv)), SvTRUE(Sv))
631#endif /* !USE_THREADS */
632#endif /* !__GNU__ */
633#endif /* !CRIPPLED_CC */
79072805 634
5f05dabc 635#define newRV_inc(sv) newRV(sv)
aeea060c 636#ifdef __GNUC__
637# undef newRV_noinc
638# define newRV_noinc(sv) ({SV *nsv=newRV((sv)); --SvREFCNT(SvRV(nsv)); nsv;})
639#else
640# if defined(CRIPPLED_CC) || defined(USE_THREADS)
641# else
642# undef newRV_noinc
643# define newRV_noinc(sv) ((Sv = newRV(sv)), --SvREFCNT(SvRV(Sv)), Sv)
644# endif
645#endif /* __GNUC__ */
5f05dabc 646
ef50df4b 647/* the following macros update any magic values this sv is associated with */
79072805 648
189b2af5 649#define SvGETMAGIC(x) STMT_START { if (SvGMAGICAL(x)) mg_get(x); } STMT_END
650#define SvSETMAGIC(x) STMT_START { if (SvSMAGICAL(x)) mg_set(x); } STMT_END
79072805 651
54310121 652#define SvSetSV_and(dst,src,finally) \
189b2af5 653 STMT_START { \
54310121 654 if ((dst) != (src)) { \
655 sv_setsv(dst, src); \
656 finally; \
189b2af5 657 } \
658 } STMT_END
54310121 659#define SvSetSV_nosteal_and(dst,src,finally) \
189b2af5 660 STMT_START { \
8ebc5c01 661 if ((dst) != (src)) { \
662 U32 tMpF = SvFLAGS(src) & SVs_TEMP; \
663 SvTEMP_off(src); \
664 sv_setsv(dst, src); \
665 SvFLAGS(src) |= tMpF; \
54310121 666 finally; \
189b2af5 667 } \
668 } STMT_END
79072805 669
54310121 670#define SvSetSV(dst,src) \
c9d716f7 671 SvSetSV_and(dst,src,/*nothing*/;)
54310121 672#define SvSetSV_nosteal(dst,src) \
c9d716f7 673 SvSetSV_nosteal_and(dst,src,/*nothing*/;)
54310121 674
675#define SvSetMagicSV(dst,src) \
676 SvSetSV_and(dst,src,SvSETMAGIC(dst))
677#define SvSetMagicSV_nosteal(dst,src) \
678 SvSetSV_nosteal_and(dst,src,SvSETMAGIC(dst))
679
79072805 680#define SvPEEK(sv) sv_peek(sv)
681
36477c24 682#define SvIMMORTAL(sv) ((sv)==&sv_undef || (sv)==&sv_yes || (sv)==&sv_no)
683
54310121 684#define boolSV(b) ((b) ? &sv_yes : &sv_no)
685
79072805 686#define isGV(sv) (SvTYPE(sv) == SVt_PVGV)
687
79072805 688#ifndef DOSISH
a0d0e21e 689# define SvGROW(sv,len) (SvLEN(sv) < (len) ? sv_grow(sv,len) : SvPVX(sv))
79072805 690# define Sv_Grow sv_grow
691#else
692 /* extra parentheses intentionally NOT placed around "len"! */
a0d0e21e 693# define SvGROW(sv,len) ((SvLEN(sv) < (unsigned long)len) \
694 ? sv_grow(sv,(unsigned long)len) : SvPVX(sv))
79072805 695# define Sv_Grow(sv,len) sv_grow(sv,(unsigned long)(len))
696#endif /* DOSISH */