This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
!USING_WIDE() branch is busted in win32_stat()
[perl5.git] / sv.h
CommitLineData
a0d0e21e 1/* sv.h
79072805 2 *
4eb8286e 3 * Copyright (c) 1991-1999, 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
954c1994
GS
14/*
15=for apidoc AmU||svtype
16An enum of flags for Perl types. These are found in the file B<sv.h>
17in the C<svtype> enum. Test these flags with the C<SvTYPE> macro.
18
19=for apidoc AmU||SVt_PV
20Pointer type flag for scalars. See C<svtype>.
21
22=for apidoc AmU||SVt_IV
23Integer type flag for scalars. See C<svtype>.
24
25=for apidoc AmU||SVt_NV
26Double type flag for scalars. See C<svtype>.
27
28=for apidoc AmU||SVt_PVMG
29Type flag for blessed scalars. See C<svtype>.
30
31=for apidoc AmU||SVt_PVAV
32Type flag for arrays. See C<svtype>.
33
34=for apidoc AmU||SVt_PVHV
35Type flag for hashes. See C<svtype>.
36
37=for apidoc AmU||SVt_PVCV
38Type flag for code refs. See C<svtype>.
39
40=cut
41*/
42
79072805 43typedef enum {
a0d0e21e
LW
44 SVt_NULL, /* 0 */
45 SVt_IV, /* 1 */
46 SVt_NV, /* 2 */
47 SVt_RV, /* 3 */
48 SVt_PV, /* 4 */
49 SVt_PVIV, /* 5 */
50 SVt_PVNV, /* 6 */
51 SVt_PVMG, /* 7 */
52 SVt_PVBM, /* 8 */
53 SVt_PVLV, /* 9 */
54 SVt_PVAV, /* 10 */
55 SVt_PVHV, /* 11 */
56 SVt_PVCV, /* 12 */
57 SVt_PVGV, /* 13 */
58 SVt_PVFM, /* 14 */
59 SVt_PVIO /* 15 */
79072805
LW
60} svtype;
61
79072805
LW
62/* Using C's structural equivalence to help emulate C++ inheritance here... */
63
64struct sv {
463ee0b2 65 void* sv_any; /* pointer to something */
79072805 66 U32 sv_refcnt; /* how many references to us */
8990e307 67 U32 sv_flags; /* what we are */
79072805
LW
68};
69
70struct gv {
463ee0b2 71 XPVGV* sv_any; /* pointer to something */
79072805 72 U32 sv_refcnt; /* how many references to us */
8990e307 73 U32 sv_flags; /* what we are */
79072805
LW
74};
75
76struct cv {
232e078e 77 XPVCV* sv_any; /* pointer to something */
79072805 78 U32 sv_refcnt; /* how many references to us */
8990e307 79 U32 sv_flags; /* what we are */
79072805
LW
80};
81
82struct av {
463ee0b2 83 XPVAV* sv_any; /* pointer to something */
79072805 84 U32 sv_refcnt; /* how many references to us */
8990e307 85 U32 sv_flags; /* what we are */
79072805
LW
86};
87
88struct hv {
463ee0b2 89 XPVHV* sv_any; /* pointer to something */
79072805 90 U32 sv_refcnt; /* how many references to us */
8990e307
LW
91 U32 sv_flags; /* what we are */
92};
93
94struct io {
95 XPVIO* sv_any; /* pointer to something */
96 U32 sv_refcnt; /* how many references to us */
97 U32 sv_flags; /* what we are */
79072805
LW
98};
99
954c1994
GS
100/*
101=for apidoc Am|U32|SvREFCNT|SV* sv
102Returns the value of the object's reference count.
103
104=for apidoc Am|SV*|SvREFCNT_inc|SV* sv
105Increments the reference count of the given SV.
106
107=for apidoc Am|void|SvREFCNT_dec|SV* sv
108Decrements the reference count of the given SV.
109
110=for apidoc Am|svtype|SvTYPE|SV* sv
111Returns the type of the SV. See C<svtype>.
112
113=for apidoc Am|void|SvUPGRADE|SV* sv|svtype type
114Used to upgrade an SV to a more complex form. Uses C<sv_upgrade> to
115perform the upgrade if necessary. See C<svtype>.
116
117=cut
118*/
119
463ee0b2 120#define SvANY(sv) (sv)->sv_any
79072805 121#define SvFLAGS(sv) (sv)->sv_flags
aeea060c 122#define SvREFCNT(sv) (sv)->sv_refcnt
a863c7d1 123
dce16143
MB
124#ifdef USE_THREADS
125
dce16143
MB
126# ifdef EMULATE_ATOMIC_REFCOUNTS
127# define ATOMIC_INC(count) STMT_START { \
533c011a 128 MUTEX_LOCK(&PL_svref_mutex); \
dce16143 129 ++count; \
533c011a 130 MUTEX_UNLOCK(&PL_svref_mutex); \
dce16143 131 } STMT_END
0bfcb09d 132# define ATOMIC_DEC_AND_TEST(res,count) STMT_START { \
533c011a 133 MUTEX_LOCK(&PL_svref_mutex); \
0bfcb09d 134 res = (--count == 0); \
533c011a 135 MUTEX_UNLOCK(&PL_svref_mutex); \
dce16143
MB
136 } STMT_END
137# else
138# define ATOMIC_INC(count) atomic_inc(&count)
139# define ATOMIC_DEC_AND_TEST(res,count) (res = atomic_dec_and_test(&count))
140# endif /* EMULATE_ATOMIC_REFCOUNTS */
141#else
142# define ATOMIC_INC(count) (++count)
83b0a010 143# define ATOMIC_DEC_AND_TEST(res, count) (res = (--count == 0))
dce16143
MB
144#endif /* USE_THREADS */
145
a863c7d1 146#ifdef __GNUC__
dce16143
MB
147# define SvREFCNT_inc(sv) \
148 ({ \
149 SV *nsv = (SV*)(sv); \
150 if (nsv) \
151 ATOMIC_INC(SvREFCNT(nsv)); \
152 nsv; \
153 })
8990e307 154#else
a863c7d1 155# if defined(CRIPPLED_CC) || defined(USE_THREADS)
199100c8 156# define SvREFCNT_inc(sv) sv_newref((SV*)sv)
a863c7d1 157# else
dce16143 158# define SvREFCNT_inc(sv) \
6b88bc9c 159 ((PL_Sv=(SV*)(sv)), (PL_Sv && ATOMIC_INC(SvREFCNT(PL_Sv))), (SV*)PL_Sv)
a863c7d1 160# endif
8990e307
LW
161#endif
162
a863c7d1
MB
163#define SvREFCNT_dec(sv) sv_free((SV*)sv)
164
8990e307
LW
165#define SVTYPEMASK 0xff
166#define SvTYPE(sv) ((sv)->sv_flags & SVTYPEMASK)
79072805
LW
167
168#define SvUPGRADE(sv, mt) (SvTYPE(sv) >= mt || sv_upgrade(sv, mt))
169
8990e307
LW
170#define SVs_PADBUSY 0x00000100 /* reserved for tmp or my already */
171#define SVs_PADTMP 0x00000200 /* in use as tmp */
172#define SVs_PADMY 0x00000400 /* in use a "my" variable */
173#define SVs_TEMP 0x00000800 /* string is stealable? */
174#define SVs_OBJECT 0x00001000 /* is "blessed" */
175#define SVs_GMG 0x00002000 /* has magical get method */
176#define SVs_SMG 0x00004000 /* has magical set method */
177#define SVs_RMG 0x00008000 /* has random magical methods */
178
179#define SVf_IOK 0x00010000 /* has valid public integer value */
180#define SVf_NOK 0x00020000 /* has valid public numeric value */
181#define SVf_POK 0x00040000 /* has valid public pointer value */
182#define SVf_ROK 0x00080000 /* has a valid reference pointer */
a0d0e21e 183
748a9306 184#define SVf_FAKE 0x00100000 /* glob or lexical is just a copy */
8990e307
LW
185#define SVf_OOK 0x00200000 /* has valid offset value */
186#define SVf_BREAK 0x00400000 /* refcnt is artificially low */
187#define SVf_READONLY 0x00800000 /* may not be modified */
188
a0d0e21e 189
8990e307
LW
190#define SVp_IOK 0x01000000 /* has valid non-public integer value */
191#define SVp_NOK 0x02000000 /* has valid non-public numeric value */
192#define SVp_POK 0x04000000 /* has valid non-public pointer value */
193#define SVp_SCREAM 0x08000000 /* has been studied? */
194
5bc28da9
NIS
195#define SVf_UTF8 0x20000000 /* SvPVX is UTF-8 encoded */
196
197#define SVf_THINKFIRST (SVf_READONLY|SVf_ROK|SVf_FAKE|SVf_UTF8)
198
a0d0e21e
LW
199#define SVf_OK (SVf_IOK|SVf_NOK|SVf_POK|SVf_ROK| \
200 SVp_IOK|SVp_NOK|SVp_POK)
201
9e7bc3e8 202#define SVf_AMAGIC 0x10000000 /* has magical overloaded methods */
a0d0e21e 203
8990e307
LW
204#define PRIVSHIFT 8
205
206/* Some private flags. */
207
f472eb5c 208/* SVpad_OUR may be set on SVt_PV{NV,MG,GV} types */
032d6771
GS
209#define SVpad_OUR 0x80000000 /* pad name is "our" instead of "my" */
210
25da4f38
IZ
211#define SVf_IVisUV 0x80000000 /* use XPVUV instead of XPVIV */
212
213#define SVpfm_COMPILED 0x80000000 /* FORMLINE is compiled */
8990e307
LW
214
215#define SVpbm_VALID 0x80000000
bbce6d69 216#define SVpbm_TAIL 0x40000000
8990e307 217
25da4f38
IZ
218#define SVrepl_EVAL 0x40000000 /* Replacement part of s///e */
219
bf6bd887 220#define SVphv_SHAREKEYS 0x20000000 /* keys live on shared string table */
51594c39 221#define SVphv_LAZYDEL 0x40000000 /* entry in xhv_eiter must be deleted */
bf6bd887 222
810b8aa5
GS
223#define SVprv_WEAKREF 0x80000000 /* Weak reference */
224
ed6116ce
LW
225struct xrv {
226 SV * xrv_rv; /* pointer to another SV */
227};
228
79072805 229struct xpv {
ed6116ce
LW
230 char * xpv_pv; /* pointer to malloced string */
231 STRLEN xpv_cur; /* length of xpv_pv as a C string */
232 STRLEN xpv_len; /* allocated size */
79072805
LW
233};
234
235struct xpviv {
ed6116ce
LW
236 char * xpv_pv; /* pointer to malloced string */
237 STRLEN xpv_cur; /* length of xpv_pv as a C string */
238 STRLEN xpv_len; /* allocated size */
a0d0e21e 239 IV xiv_iv; /* integer value or pv offset */
79072805
LW
240};
241
ff68c719
PP
242struct xpvuv {
243 char * xpv_pv; /* pointer to malloced string */
244 STRLEN xpv_cur; /* length of xpv_pv as a C string */
245 STRLEN xpv_len; /* allocated size */
246 UV xuv_uv; /* unsigned value or pv offset */
247};
248
79072805 249struct xpvnv {
ed6116ce
LW
250 char * xpv_pv; /* pointer to malloced string */
251 STRLEN xpv_cur; /* length of xpv_pv as a C string */
252 STRLEN xpv_len; /* allocated size */
a0d0e21e 253 IV xiv_iv; /* integer value or pv offset */
65202027 254 NV xnv_nv; /* numeric value, if any */
79072805
LW
255};
256
6ee623d5 257/* These structure must match the beginning of struct xpvhv in hv.h. */
79072805 258struct xpvmg {
ed6116ce
LW
259 char * xpv_pv; /* pointer to malloced string */
260 STRLEN xpv_cur; /* length of xpv_pv as a C string */
261 STRLEN xpv_len; /* allocated size */
a0d0e21e 262 IV xiv_iv; /* integer value or pv offset */
65202027 263 NV xnv_nv; /* numeric value, if any */
79072805
LW
264 MAGIC* xmg_magic; /* linked list of magicalness */
265 HV* xmg_stash; /* class package */
266};
267
268struct xpvlv {
ed6116ce
LW
269 char * xpv_pv; /* pointer to malloced string */
270 STRLEN xpv_cur; /* length of xpv_pv as a C string */
271 STRLEN xpv_len; /* allocated size */
a0d0e21e 272 IV xiv_iv; /* integer value or pv offset */
65202027 273 NV xnv_nv; /* numeric value, if any */
79072805
LW
274 MAGIC* xmg_magic; /* linked list of magicalness */
275 HV* xmg_stash; /* class package */
8990e307 276
79072805
LW
277 STRLEN xlv_targoff;
278 STRLEN xlv_targlen;
279 SV* xlv_targ;
280 char xlv_type;
281};
282
283struct xpvgv {
ed6116ce
LW
284 char * xpv_pv; /* pointer to malloced string */
285 STRLEN xpv_cur; /* length of xpv_pv as a C string */
286 STRLEN xpv_len; /* allocated size */
a0d0e21e 287 IV xiv_iv; /* integer value or pv offset */
65202027 288 NV xnv_nv; /* numeric value, if any */
79072805
LW
289 MAGIC* xmg_magic; /* linked list of magicalness */
290 HV* xmg_stash; /* class package */
8990e307 291
79072805
LW
292 GP* xgv_gp;
293 char* xgv_name;
294 STRLEN xgv_namelen;
295 HV* xgv_stash;
a5f75d66 296 U8 xgv_flags;
79072805
LW
297};
298
299struct xpvbm {
ed6116ce
LW
300 char * xpv_pv; /* pointer to malloced string */
301 STRLEN xpv_cur; /* length of xpv_pv as a C string */
302 STRLEN xpv_len; /* allocated size */
a0d0e21e 303 IV xiv_iv; /* integer value or pv offset */
65202027 304 NV xnv_nv; /* numeric value, if any */
79072805
LW
305 MAGIC* xmg_magic; /* linked list of magicalness */
306 HV* xmg_stash; /* class package */
8990e307 307
79072805
LW
308 I32 xbm_useful; /* is this constant pattern being useful? */
309 U16 xbm_previous; /* how many characters in string before rare? */
310 U8 xbm_rare; /* rarest character in string */
311};
312
57843af0 313/* This structure much match XPVCV in cv.h */
44a8e56a 314
77a005ab
MB
315typedef U16 cv_flags_t;
316
79072805 317struct xpvfm {
ed6116ce
LW
318 char * xpv_pv; /* pointer to malloced string */
319 STRLEN xpv_cur; /* length of xpv_pv as a C string */
320 STRLEN xpv_len; /* allocated size */
a0d0e21e 321 IV xiv_iv; /* integer value or pv offset */
65202027 322 NV xnv_nv; /* numeric value, if any */
79072805
LW
323 MAGIC* xmg_magic; /* linked list of magicalness */
324 HV* xmg_stash; /* class package */
8990e307 325
79072805
LW
326 HV * xcv_stash;
327 OP * xcv_start;
328 OP * xcv_root;
0cb96387 329 void (*xcv_xsub)(pTHXo_ CV*);
a0d0e21e
LW
330 ANY xcv_xsubany;
331 GV * xcv_gv;
57843af0 332 char * xcv_file;
b195d487 333 long xcv_depth; /* >= 2 indicates recursive call */
79072805 334 AV * xcv_padlist;
748a9306 335 CV * xcv_outside;
e858de61 336#ifdef USE_THREADS
f6d98b14 337 perl_mutex *xcv_mutexp; /* protects xcv_owner */
52e1cb5e 338 struct perl_thread *xcv_owner; /* current owner thread */
e858de61 339#endif /* USE_THREADS */
77a005ab 340 cv_flags_t xcv_flags;
44a8e56a 341
79072805
LW
342 I32 xfm_lines;
343};
344
8990e307
LW
345struct xpvio {
346 char * xpv_pv; /* pointer to malloced string */
347 STRLEN xpv_cur; /* length of xpv_pv as a C string */
348 STRLEN xpv_len; /* allocated size */
a0d0e21e 349 IV xiv_iv; /* integer value or pv offset */
65202027 350 NV xnv_nv; /* numeric value, if any */
8990e307
LW
351 MAGIC* xmg_magic; /* linked list of magicalness */
352 HV* xmg_stash; /* class package */
353
760ac839
LW
354 PerlIO * xio_ifp; /* ifp and ofp are normally the same */
355 PerlIO * xio_ofp; /* but sockets need separate streams */
8990e307
LW
356 DIR * xio_dirp; /* for opendir, readdir, etc */
357 long xio_lines; /* $. */
358 long xio_page; /* $% */
359 long xio_page_len; /* $= */
360 long xio_lines_left; /* $- */
361 char * xio_top_name; /* $^ */
362 GV * xio_top_gv; /* $^ */
363 char * xio_fmt_name; /* $~ */
364 GV * xio_fmt_gv; /* $~ */
365 char * xio_bottom_name;/* $^B */
366 GV * xio_bottom_gv; /* $^B */
367 short xio_subprocess; /* -| or |- */
368 char xio_type;
369 char xio_flags;
370};
371
e0c19803
GS
372#define IOf_ARGV 1 /* this fp iterates over ARGV */
373#define IOf_START 2 /* check for null ARGV and substitute '-' */
374#define IOf_FLUSH 4 /* this fp wants a flush after write op */
375#define IOf_DIDTOP 8 /* just did top of form */
376#define IOf_UNTAINT 16 /* consider this fp (and its data) "safe" */
377#define IOf_NOLINE 32 /* slurped a pseudo-line from empty file */
378#define IOf_FAKE_DIRP 64 /* xio_dirp is fake (source filters kludge) */
8990e307 379
ed6116ce
LW
380/* The following macros define implementation-independent predicates on SVs. */
381
954c1994
GS
382/*
383=for apidoc Am|bool|SvNIOK|SV* sv
384Returns a boolean indicating whether the SV contains a number, integer or
385double.
386
387=for apidoc Am|bool|SvNIOKp|SV* sv
388Returns a boolean indicating whether the SV contains a number, integer or
389double. Checks the B<private> setting. Use C<SvNIOK>.
390
391=for apidoc Am|void|SvNIOK_off|SV* sv
392Unsets the NV/IV status of an SV.
393
394=for apidoc Am|bool|SvOK|SV* sv
395Returns a boolean indicating whether the value is an SV.
396
397=for apidoc Am|bool|SvIOKp|SV* sv
398Returns a boolean indicating whether the SV contains an integer. Checks
399the B<private> setting. Use C<SvIOK>.
400
401=for apidoc Am|bool|SvNOKp|SV* sv
402Returns a boolean indicating whether the SV contains a double. Checks the
403B<private> setting. Use C<SvNOK>.
404
405=for apidoc Am|bool|SvPOKp|SV* sv
406Returns a boolean indicating whether the SV contains a character string.
407Checks the B<private> setting. Use C<SvPOK>.
408
409=for apidoc Am|bool|SvIOK|SV* sv
410Returns a boolean indicating whether the SV contains an integer.
411
412=for apidoc Am|void|SvIOK_on|SV* sv
413Tells an SV that it is an integer.
414
415=for apidoc Am|void|SvIOK_off|SV* sv
416Unsets the IV status of an SV.
417
418=for apidoc Am|void|SvIOK_only|SV* sv
419Tells an SV that it is an integer and disables all other OK bits.
420
421=for apidoc Am|bool|SvNOK|SV* sv
422Returns a boolean indicating whether the SV contains a double.
423
424=for apidoc Am|void|SvNOK_on|SV* sv
425Tells an SV that it is a double.
426
427=for apidoc Am|void|SvNOK_off|SV* sv
428Unsets the NV status of an SV.
429
430=for apidoc Am|void|SvNOK_only|SV* sv
431Tells an SV that it is a double and disables all other OK bits.
432
433=for apidoc Am|bool|SvPOK|SV* sv
434Returns a boolean indicating whether the SV contains a character
435string.
436
437=for apidoc Am|void|SvPOK_on|SV* sv
438Tells an SV that it is a string.
439
440=for apidoc Am|void|SvPOK_off|SV* sv
441Unsets the PV status of an SV.
442
443=for apidoc Am|void|SvPOK_only|SV* sv
444Tells an SV that it is a string and disables all other OK bits.
445
446=for apidoc Am|bool|SvOOK|SV* sv
447Returns a boolean indicating whether the SvIVX is a valid offset value for
448the SvPVX. This hack is used internally to speed up removal of characters
449from the beginning of a SvPV. When SvOOK is true, then the start of the
450allocated string buffer is really (SvPVX - SvIVX).
451
452=for apidoc Am|bool|SvROK|SV* sv
453Tests if the SV is an RV.
454
455=for apidoc Am|void|SvROK_on|SV* sv
456Tells an SV that it is an RV.
457
458=for apidoc Am|void|SvROK_off|SV* sv
459Unsets the RV status of an SV.
460
461=for apidoc Am|SV*|SvRV|SV* sv
462Dereferences an RV to return the SV.
463
464=for apidoc Am|IV|SvIVX|SV* sv
465Returns the integer which is stored in the SV, assuming SvIOK is
466true.
467
468=for apidoc Am|UV|SvUVX|SV* sv
469Returns the unsigned integer which is stored in the SV, assuming SvIOK is
470true.
471
472=for apidoc Am|NV|SvNVX|SV* sv
473Returns the double which is stored in the SV, assuming SvNOK is
474true.
475
476=for apidoc Am|char*|SvPVX|SV* sv
477Returns a pointer to the string in the SV. The SV must contain a
478string.
479
480=for apidoc Am|STRLEN|SvCUR|SV* sv
481Returns the length of the string which is in the SV. See C<SvLEN>.
482
483=for apidoc Am|STRLEN|SvLEN|SV* sv
484Returns the size of the string buffer in the SV. See C<SvCUR>.
485
486=for apidoc Am|char*|SvEND|SV* sv
487Returns a pointer to the last character in the string which is in the SV.
488See C<SvCUR>. Access the character as *(SvEND(sv)).
489
490=for apidoc Am|HV*|SvSTASH|SV* sv
491Returns the stash of the SV.
492
493=for apidoc Am|void|SvCUR_set|SV* sv|STRLEN len
494Set the length of the string which is in the SV. See C<SvCUR>.
495
496=cut
497*/
498
79072805 499#define SvNIOK(sv) (SvFLAGS(sv) & (SVf_IOK|SVf_NOK))
748a9306 500#define SvNIOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK))
a0d0e21e 501#define SvNIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK| \
25da4f38 502 SVp_IOK|SVp_NOK|SVf_IVisUV))
79072805 503
463ee0b2 504#define SvOK(sv) (SvFLAGS(sv) & SVf_OK)
25da4f38
IZ
505#define SvOK_off(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC| \
506 SVf_IVisUV), \
507 SvOOK_off(sv))
508#define SvOK_off_exc_UV(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC), \
a0d0e21e 509 SvOOK_off(sv))
79072805 510
8990e307
LW
511#define SvOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK))
512#define SvIOKp(sv) (SvFLAGS(sv) & SVp_IOK)
513#define SvIOKp_on(sv) (SvOOK_off(sv), SvFLAGS(sv) |= SVp_IOK)
514#define SvNOKp(sv) (SvFLAGS(sv) & SVp_NOK)
515#define SvNOKp_on(sv) (SvFLAGS(sv) |= SVp_NOK)
516#define SvPOKp(sv) (SvFLAGS(sv) & SVp_POK)
517#define SvPOKp_on(sv) (SvFLAGS(sv) |= SVp_POK)
463ee0b2 518
79072805 519#define SvIOK(sv) (SvFLAGS(sv) & SVf_IOK)
8990e307 520#define SvIOK_on(sv) (SvOOK_off(sv), \
a0d0e21e 521 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
25da4f38 522#define SvIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVp_IOK|SVf_IVisUV))
827b7e14 523#define SvIOK_only(sv) (SvOK_off(sv), \
a0d0e21e 524 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
25da4f38
IZ
525#define SvIOK_only_UV(sv) (SvOK_off_exc_UV(sv), \
526 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
70401c6b 527
25da4f38
IZ
528#define SvIOK_UV(sv) ((SvFLAGS(sv) & (SVf_IOK|SVf_IVisUV)) \
529 == (SVf_IOK|SVf_IVisUV))
530#define SvIOK_notUV(sv) ((SvFLAGS(sv) & (SVf_IOK|SVf_IVisUV)) \
531 == SVf_IOK)
532
533#define SvIsUV(sv) (SvFLAGS(sv) & SVf_IVisUV)
534#define SvIsUV_on(sv) (SvFLAGS(sv) |= SVf_IVisUV)
535#define SvIsUV_off(sv) (SvFLAGS(sv) &= ~SVf_IVisUV)
79072805
LW
536
537#define SvNOK(sv) (SvFLAGS(sv) & SVf_NOK)
a0d0e21e 538#define SvNOK_on(sv) (SvFLAGS(sv) |= (SVf_NOK|SVp_NOK))
8990e307
LW
539#define SvNOK_off(sv) (SvFLAGS(sv) &= ~(SVf_NOK|SVp_NOK))
540#define SvNOK_only(sv) (SvOK_off(sv), \
a0d0e21e 541 SvFLAGS(sv) |= (SVf_NOK|SVp_NOK))
79072805 542
a7cb1f99
GS
543#define SvUTF8(sv) (SvFLAGS(sv) & SVf_UTF8)
544#define SvUTF8_on(sv) (SvFLAGS(sv) |= (SVf_UTF8))
545#define SvUTF8_off(sv) (SvFLAGS(sv) &= ~(SVf_UTF8))
5bc28da9 546
79072805 547#define SvPOK(sv) (SvFLAGS(sv) & SVf_POK)
a0d0e21e 548#define SvPOK_on(sv) (SvFLAGS(sv) |= (SVf_POK|SVp_POK))
8990e307 549#define SvPOK_off(sv) (SvFLAGS(sv) &= ~(SVf_POK|SVp_POK))
25da4f38 550#define SvPOK_only(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC|SVf_IVisUV), \
a0d0e21e 551 SvFLAGS(sv) |= (SVf_POK|SVp_POK))
79072805
LW
552
553#define SvOOK(sv) (SvFLAGS(sv) & SVf_OOK)
554#define SvOOK_on(sv) (SvIOK_off(sv), SvFLAGS(sv) |= SVf_OOK)
555#define SvOOK_off(sv) (SvOOK(sv) && sv_backoff(sv))
79072805 556
a0d0e21e
LW
557#define SvFAKE(sv) (SvFLAGS(sv) & SVf_FAKE)
558#define SvFAKE_on(sv) (SvFLAGS(sv) |= SVf_FAKE)
559#define SvFAKE_off(sv) (SvFLAGS(sv) &= ~SVf_FAKE)
560
ed6116ce 561#define SvROK(sv) (SvFLAGS(sv) & SVf_ROK)
a0d0e21e 562#define SvROK_on(sv) (SvFLAGS(sv) |= SVf_ROK)
a0d0e21e 563#define SvROK_off(sv) (SvFLAGS(sv) &= ~(SVf_ROK|SVf_AMAGIC))
79072805 564
8990e307
LW
565#define SvMAGICAL(sv) (SvFLAGS(sv) & (SVs_GMG|SVs_SMG|SVs_RMG))
566#define SvMAGICAL_on(sv) (SvFLAGS(sv) |= (SVs_GMG|SVs_SMG|SVs_RMG))
567#define SvMAGICAL_off(sv) (SvFLAGS(sv) &= ~(SVs_GMG|SVs_SMG|SVs_RMG))
79072805 568
8990e307
LW
569#define SvGMAGICAL(sv) (SvFLAGS(sv) & SVs_GMG)
570#define SvGMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_GMG)
571#define SvGMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_GMG)
ed6116ce 572
8990e307
LW
573#define SvSMAGICAL(sv) (SvFLAGS(sv) & SVs_SMG)
574#define SvSMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_SMG)
575#define SvSMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_SMG)
ed6116ce 576
8990e307
LW
577#define SvRMAGICAL(sv) (SvFLAGS(sv) & SVs_RMG)
578#define SvRMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_RMG)
579#define SvRMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_RMG)
ed6116ce 580
9e7bc3e8
JD
581#define SvAMAGIC(sv) (SvFLAGS(sv) & SVf_AMAGIC)
582#define SvAMAGIC_on(sv) (SvFLAGS(sv) |= SVf_AMAGIC)
583#define SvAMAGIC_off(sv) (SvFLAGS(sv) &= ~SVf_AMAGIC)
a0d0e21e
LW
584
585/*
586#define Gv_AMG(stash) \
587 (HV_AMAGICmb(stash) && \
588 ((!HV_AMAGICbad(stash) && HV_AMAGIC(stash)) || Gv_AMupdate(stash)))
589*/
3280af22 590#define Gv_AMG(stash) (PL_amagic_generation && Gv_AMupdate(stash))
a0d0e21e 591
810b8aa5
GS
592#define SvWEAKREF(sv) ((SvFLAGS(sv) & (SVf_ROK|SVprv_WEAKREF)) \
593 == (SVf_ROK|SVprv_WEAKREF))
594#define SvWEAKREF_on(sv) (SvFLAGS(sv) |= (SVf_ROK|SVprv_WEAKREF))
595#define SvWEAKREF_off(sv) (SvFLAGS(sv) &= ~(SVf_ROK|SVprv_WEAKREF))
596
a0d0e21e 597#define SvTHINKFIRST(sv) (SvFLAGS(sv) & SVf_THINKFIRST)
ed6116ce 598
8990e307 599#define SvPADBUSY(sv) (SvFLAGS(sv) & SVs_PADBUSY)
ed6116ce 600
8990e307
LW
601#define SvPADTMP(sv) (SvFLAGS(sv) & SVs_PADTMP)
602#define SvPADTMP_on(sv) (SvFLAGS(sv) |= SVs_PADTMP|SVs_PADBUSY)
603#define SvPADTMP_off(sv) (SvFLAGS(sv) &= ~SVs_PADTMP)
ed6116ce 604
8990e307
LW
605#define SvPADMY(sv) (SvFLAGS(sv) & SVs_PADMY)
606#define SvPADMY_on(sv) (SvFLAGS(sv) |= SVs_PADMY|SVs_PADBUSY)
ed6116ce 607
8990e307
LW
608#define SvTEMP(sv) (SvFLAGS(sv) & SVs_TEMP)
609#define SvTEMP_on(sv) (SvFLAGS(sv) |= SVs_TEMP)
610#define SvTEMP_off(sv) (SvFLAGS(sv) &= ~SVs_TEMP)
79072805 611
8990e307
LW
612#define SvOBJECT(sv) (SvFLAGS(sv) & SVs_OBJECT)
613#define SvOBJECT_on(sv) (SvFLAGS(sv) |= SVs_OBJECT)
614#define SvOBJECT_off(sv) (SvFLAGS(sv) &= ~SVs_OBJECT)
79072805 615
8990e307
LW
616#define SvREADONLY(sv) (SvFLAGS(sv) & SVf_READONLY)
617#define SvREADONLY_on(sv) (SvFLAGS(sv) |= SVf_READONLY)
618#define SvREADONLY_off(sv) (SvFLAGS(sv) &= ~SVf_READONLY)
79072805 619
8990e307
LW
620#define SvSCREAM(sv) (SvFLAGS(sv) & SVp_SCREAM)
621#define SvSCREAM_on(sv) (SvFLAGS(sv) |= SVp_SCREAM)
622#define SvSCREAM_off(sv) (SvFLAGS(sv) &= ~SVp_SCREAM)
79072805 623
8990e307
LW
624#define SvCOMPILED(sv) (SvFLAGS(sv) & SVpfm_COMPILED)
625#define SvCOMPILED_on(sv) (SvFLAGS(sv) |= SVpfm_COMPILED)
626#define SvCOMPILED_off(sv) (SvFLAGS(sv) &= ~SVpfm_COMPILED)
79072805 627
25da4f38
IZ
628#define SvEVALED(sv) (SvFLAGS(sv) & SVrepl_EVAL)
629#define SvEVALED_on(sv) (SvFLAGS(sv) |= SVrepl_EVAL)
630#define SvEVALED_off(sv) (SvFLAGS(sv) &= ~SVrepl_EVAL)
631
8990e307
LW
632#define SvTAIL(sv) (SvFLAGS(sv) & SVpbm_TAIL)
633#define SvTAIL_on(sv) (SvFLAGS(sv) |= SVpbm_TAIL)
634#define SvTAIL_off(sv) (SvFLAGS(sv) &= ~SVpbm_TAIL)
635
8990e307
LW
636#define SvVALID(sv) (SvFLAGS(sv) & SVpbm_VALID)
637#define SvVALID_on(sv) (SvFLAGS(sv) |= SVpbm_VALID)
638#define SvVALID_off(sv) (SvFLAGS(sv) &= ~SVpbm_VALID)
639
ed6116ce
LW
640#define SvRV(sv) ((XRV*) SvANY(sv))->xrv_rv
641#define SvRVx(sv) SvRV(sv)
642
463ee0b2
LW
643#define SvIVX(sv) ((XPVIV*) SvANY(sv))->xiv_iv
644#define SvIVXx(sv) SvIVX(sv)
ff68c719
PP
645#define SvUVX(sv) ((XPVUV*) SvANY(sv))->xuv_uv
646#define SvUVXx(sv) SvUVX(sv)
463ee0b2
LW
647#define SvNVX(sv) ((XPVNV*)SvANY(sv))->xnv_nv
648#define SvNVXx(sv) SvNVX(sv)
649#define SvPVX(sv) ((XPV*) SvANY(sv))->xpv_pv
650#define SvPVXx(sv) SvPVX(sv)
79072805 651#define SvCUR(sv) ((XPV*) SvANY(sv))->xpv_cur
79072805
LW
652#define SvLEN(sv) ((XPV*) SvANY(sv))->xpv_len
653#define SvLENx(sv) SvLEN(sv)
654#define SvEND(sv)(((XPV*) SvANY(sv))->xpv_pv + ((XPV*)SvANY(sv))->xpv_cur)
6b88bc9c 655#define SvENDx(sv) ((PL_Sv = (sv)), SvEND(PL_Sv))
79072805
LW
656#define SvMAGIC(sv) ((XPVMG*) SvANY(sv))->xmg_magic
657#define SvSTASH(sv) ((XPVMG*) SvANY(sv))->xmg_stash
658
659#define SvIV_set(sv, val) \
80b92232
PP
660 STMT_START { assert(SvTYPE(sv) == SVt_IV || SvTYPE(sv) >= SVt_PVIV); \
661 (((XPVIV*) SvANY(sv))->xiv_iv = val); } STMT_END
79072805 662#define SvNV_set(sv, val) \
80b92232
PP
663 STMT_START { assert(SvTYPE(sv) == SVt_NV || SvTYPE(sv) >= SVt_PVNV); \
664 (((XPVNV*) SvANY(sv))->xnv_nv = val); } STMT_END
79072805 665#define SvPV_set(sv, val) \
80b92232
PP
666 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
667 (((XPV*) SvANY(sv))->xpv_pv = val); } STMT_END
79072805 668#define SvCUR_set(sv, val) \
80b92232
PP
669 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
670 (((XPV*) SvANY(sv))->xpv_cur = val); } STMT_END
79072805 671#define SvLEN_set(sv, val) \
80b92232
PP
672 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
673 (((XPV*) SvANY(sv))->xpv_len = val); } STMT_END
79072805 674#define SvEND_set(sv, val) \
80b92232
PP
675 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
676 (((XPV*) SvANY(sv))->xpv_cur = val - SvPVX(sv)); } STMT_END
79072805
LW
677
678#define BmRARE(sv) ((XPVBM*) SvANY(sv))->xbm_rare
679#define BmUSEFUL(sv) ((XPVBM*) SvANY(sv))->xbm_useful
680#define BmPREVIOUS(sv) ((XPVBM*) SvANY(sv))->xbm_previous
681
682#define FmLINES(sv) ((XPVFM*) SvANY(sv))->xfm_lines
683
684#define LvTYPE(sv) ((XPVLV*) SvANY(sv))->xlv_type
685#define LvTARG(sv) ((XPVLV*) SvANY(sv))->xlv_targ
686#define LvTARGOFF(sv) ((XPVLV*) SvANY(sv))->xlv_targoff
687#define LvTARGLEN(sv) ((XPVLV*) SvANY(sv))->xlv_targlen
688
8990e307
LW
689#define IoIFP(sv) ((XPVIO*) SvANY(sv))->xio_ifp
690#define IoOFP(sv) ((XPVIO*) SvANY(sv))->xio_ofp
691#define IoDIRP(sv) ((XPVIO*) SvANY(sv))->xio_dirp
692#define IoLINES(sv) ((XPVIO*) SvANY(sv))->xio_lines
693#define IoPAGE(sv) ((XPVIO*) SvANY(sv))->xio_page
694#define IoPAGE_LEN(sv) ((XPVIO*) SvANY(sv))->xio_page_len
695#define IoLINES_LEFT(sv)((XPVIO*) SvANY(sv))->xio_lines_left
696#define IoTOP_NAME(sv) ((XPVIO*) SvANY(sv))->xio_top_name
697#define IoTOP_GV(sv) ((XPVIO*) SvANY(sv))->xio_top_gv
698#define IoFMT_NAME(sv) ((XPVIO*) SvANY(sv))->xio_fmt_name
699#define IoFMT_GV(sv) ((XPVIO*) SvANY(sv))->xio_fmt_gv
700#define IoBOTTOM_NAME(sv)((XPVIO*) SvANY(sv))->xio_bottom_name
701#define IoBOTTOM_GV(sv) ((XPVIO*) SvANY(sv))->xio_bottom_gv
702#define IoSUBPROCESS(sv)((XPVIO*) SvANY(sv))->xio_subprocess
703#define IoTYPE(sv) ((XPVIO*) SvANY(sv))->xio_type
704#define IoFLAGS(sv) ((XPVIO*) SvANY(sv))->xio_flags
705
954c1994
GS
706/*
707=for apidoc Am|bool|SvTAINTED|SV* sv
708Checks to see if an SV is tainted. Returns TRUE if it is, FALSE if
709not.
710
711=for apidoc Am|void|SvTAINTED_on|SV* sv
712Marks an SV as tainted.
713
714=for apidoc Am|void|SvTAINTED_off|SV* sv
715Untaints an SV. Be I<very> careful with this routine, as it short-circuits
716some of Perl's fundamental security features. XS module authors should not
717use this function unless they fully understand all the implications of
718unconditionally untainting the value. Untainting should be done in the
719standard perl fashion, via a carefully crafted regexp, rather than directly
720untainting variables.
721
722=for apidoc Am|void|SvTAINT|SV* sv
723Taints an SV if tainting is enabled
724
725=cut
726*/
727
bbce6d69 728#define SvTAINTED(sv) (SvMAGICAL(sv) && sv_tainted(sv))
3280af22
NIS
729#define SvTAINTED_on(sv) STMT_START{ if(PL_tainting){sv_taint(sv);} }STMT_END
730#define SvTAINTED_off(sv) STMT_START{ if(PL_tainting){sv_untaint(sv);} }STMT_END
bbce6d69 731
c6ee37c5
MB
732#define SvTAINT(sv) \
733 STMT_START { \
3280af22 734 if (PL_tainting) { \
c6ee37c5 735 dTHR; \
3280af22 736 if (PL_tainted) \
c6ee37c5
MB
737 SvTAINTED_on(sv); \
738 } \
739 } STMT_END
79072805 740
954c1994
GS
741/*
742=for apidoc Am|char*|SvPV_force|SV* sv|STRLEN len
743Like <SvPV> but will force the SV into becoming a string (SvPOK). You want
744force if you are going to update the SvPVX directly.
745
746=for apidoc Am|char*|SvPV|SV* sv|STRLEN len
747Returns a pointer to the string in the SV, or a stringified form of the SV
748if the SV does not contain a string. Handles 'get' magic.
749
750=for apidoc Am|char*|SvPV_nolen|SV* sv
751Returns a pointer to the string in the SV, or a stringified form of the SV
752if the SV does not contain a string. Handles 'get' magic.
753
754=for apidoc Am|IV|SvIV|SV* sv
755Coerces the given SV to an integer and returns it.
756
757=for apidoc Am|NV|SvNV|SV* sv
758Coerce the given SV to a double and return it.
759
760=for apidoc Am|UV|SvUV|SV* sv
761Coerces the given SV to an unsigned integer and returns it.
762
763=for apidoc Am|bool|SvTRUE|SV* sv
764Returns a boolean indicating whether Perl would evaluate the SV as true or
765false, defined or undefined. Does not handle 'get' magic.
766
767=cut
768*/
769
a0d0e21e 770#define SvPV_force(sv, lp) sv_pvn_force(sv, &lp)
463ee0b2 771#define SvPV(sv, lp) sv_pvn(sv, &lp)
1fa8b10d 772#define SvPV_nolen(sv) sv_pv(sv)
5bc28da9
NIS
773
774#define SvPVutf8_force(sv, lp) sv_pvutf8n_force(sv, &lp)
775#define SvPVutf8(sv, lp) sv_pvutf8n(sv, &lp)
776#define SvPVutf8_nolen(sv) sv_pvutf8(sv)
777
778#define SvPVbyte_force(sv, lp) sv_pvbyte_force(sv, &lp)
779#define SvPVbyte(sv, lp) sv_pvbyten(sv, &lp)
780#define SvPVbyte_nolen(sv) sv_pvbyte(sv)
781
782#define SvPVx(sv, lp) sv_pvn(sv, &lp)
783#define SvPVx_force(sv, lp) sv_pvn_force(sv, &lp)
784#define SvPVutf8x(sv, lp) sv_pvutf8n(sv, &lp)
785#define SvPVutf8x_force(sv, lp) sv_pvutf8n_force(sv, &lp)
786#define SvPVbytex(sv, lp) sv_pvbyten(sv, &lp)
787#define SvPVbytex_force(sv, lp) sv_pvbyten_force(sv, &lp)
788
4e35701f
NIS
789#define SvIVx(sv) sv_iv(sv)
790#define SvUVx(sv) sv_uv(sv)
791#define SvNVx(sv) sv_nv(sv)
5bc28da9 792
4e35701f
NIS
793#define SvTRUEx(sv) sv_true(sv)
794
795#define SvIV(sv) SvIVx(sv)
796#define SvNV(sv) SvNVx(sv)
25da4f38 797#define SvUV(sv) SvUVx(sv)
4e35701f 798#define SvTRUE(sv) SvTRUEx(sv)
79072805 799
a80f87c4
GS
800#ifndef CRIPPLED_CC
801/* redefine some things to more efficient inlined versions */
79072805 802
25da4f38 803/* Let us hope that bitmaps for UV and IV are the same */
ff68c719 804#undef SvIV
463ee0b2 805#define SvIV(sv) (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv))
79072805 806
ff68c719
PP
807#undef SvUV
808#define SvUV(sv) (SvIOK(sv) ? SvUVX(sv) : sv_2uv(sv))
809
810#undef SvNV
463ee0b2 811#define SvNV(sv) (SvNOK(sv) ? SvNVX(sv) : sv_2nv(sv))
79072805 812
ff68c719
PP
813#undef SvPV
814#define SvPV(sv, lp) \
5bc28da9
NIS
815 ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
816 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pv(sv, &lp))
70401c6b 817
79072805 818
ff68c719
PP
819#undef SvPV_force
820#define SvPV_force(sv, lp) \
821 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \
822 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvn_force(sv, &lp))
a0d0e21e 823
1fa8b10d
JD
824#undef SvPV_nolen
825#define SvPV_nolen(sv) \
5bc28da9
NIS
826 ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
827 ? SvPVX(sv) : sv_2pv_nolen(sv))
70401c6b 828
5bc28da9
NIS
829#undef SvPVutf8
830#define SvPVutf8(sv, lp) \
831 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8) \
832 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvutf8(sv, &lp))
70401c6b 833
5bc28da9
NIS
834#undef SvPVutf8_force
835#define SvPVutf8_force(sv, lp) \
70401c6b 836 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == (SVf_POK|SVf_UTF8) \
5bc28da9
NIS
837 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvutf8n_force(sv, &lp))
838
839#undef SvPVutf8_nolen
840#define SvPVutf8_nolen(sv) \
70401c6b 841 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8)\
5bc28da9 842 ? SvPVX(sv) : sv_2pvutf8_nolen(sv))
70401c6b 843
5bc28da9
NIS
844#undef SvPVutf8
845#define SvPVutf8(sv, lp) \
846 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8) \
847 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvutf8(sv, &lp))
70401c6b 848
5bc28da9
NIS
849#undef SvPVutf8_force
850#define SvPVutf8_force(sv, lp) \
70401c6b 851 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == (SVf_POK|SVf_UTF8) \
5bc28da9
NIS
852 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvutf8n_force(sv, &lp))
853
854#undef SvPVutf8_nolen
855#define SvPVutf8_nolen(sv) \
856 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8)\
857 ? SvPVX(sv) : sv_2pvutf8_nolen(sv))
70401c6b 858
5bc28da9
NIS
859#undef SvPVbyte
860#define SvPVbyte(sv, lp) \
861 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK) \
862 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvbyte(sv, &lp))
70401c6b 863
5bc28da9
NIS
864#undef SvPVbyte_force
865#define SvPVbyte_force(sv, lp) \
866 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8|SVf_THINKFIRST)) == (SVf_POK) \
867 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvbyte_force(sv, &lp))
868
869#undef SvPVbyte_nolen
870#define SvPVbyte_nolen(sv) \
871 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK)\
872 ? SvPVX(sv) : sv_2pvbyte_nolen(sv))
70401c6b 873
1fa8b10d 874
a80f87c4
GS
875#ifdef __GNUC__
876# undef SvIVx
877# undef SvUVx
878# undef SvNVx
879# undef SvPVx
5bc28da9
NIS
880# undef SvPVutf8x
881# undef SvPVbytex
a80f87c4
GS
882# undef SvTRUE
883# undef SvTRUEx
884# define SvIVx(sv) ({SV *nsv = (SV*)(sv); SvIV(nsv); })
885# define SvUVx(sv) ({SV *nsv = (SV*)(sv); SvUV(nsv); })
886# define SvNVx(sv) ({SV *nsv = (SV*)(sv); SvNV(nsv); })
887# define SvPVx(sv, lp) ({SV *nsv = (sv); SvPV(nsv, lp); })
5bc28da9
NIS
888# define SvPVutf8x(sv, lp) ({SV *nsv = (sv); SvPVutf8(nsv, lp); })
889# define SvPVbytex(sv, lp) ({SV *nsv = (sv); SvPVbyte(nsv, lp); })
a80f87c4 890# define SvTRUE(sv) ( \
8990e307
LW
891 !sv \
892 ? 0 \
893 : SvPOK(sv) \
a80f87c4
GS
894 ? (({XPV *nxpv = (XPV*)SvANY(sv); \
895 nxpv && \
c2f1de04 896 (nxpv->xpv_cur > 1 || \
a80f87c4 897 (nxpv->xpv_cur && *nxpv->xpv_pv != '0')); }) \
79072805
LW
898 ? 1 \
899 : 0) \
900 : \
901 SvIOK(sv) \
463ee0b2 902 ? SvIVX(sv) != 0 \
79072805 903 : SvNOK(sv) \
463ee0b2
LW
904 ? SvNVX(sv) != 0.0 \
905 : sv_2bool(sv) )
a80f87c4
GS
906# define SvTRUEx(sv) ({SV *nsv = (sv); SvTRUE(nsv); })
907#else /* __GNUC__ */
908#ifndef USE_THREADS
909/* These inlined macros use globals, which will require a thread
910 * declaration in user code, so we avoid them under threads */
911
912# undef SvIVx
913# undef SvUVx
914# undef SvNVx
915# undef SvPVx
5bc28da9
NIS
916# undef SvPVutf8x
917# undef SvPVbytex
a80f87c4
GS
918# undef SvTRUE
919# undef SvTRUEx
6b88bc9c
GS
920# define SvIVx(sv) ((PL_Sv = (sv)), SvIV(PL_Sv))
921# define SvUVx(sv) ((PL_Sv = (sv)), SvUV(PL_Sv))
922# define SvNVx(sv) ((PL_Sv = (sv)), SvNV(PL_Sv))
923# define SvPVx(sv, lp) ((PL_Sv = (sv)), SvPV(PL_Sv, lp))
5bc28da9 924# define SvPVutf8x(sv, lp) ((PL_Sv = (sv)), SvPVutf8(PL_Sv, lp))
f83ee824 925# define SvPVbytex(sv, lp) ((PL_Sv = (sv)), SvPVbyte(PL_Sv, lp))
a80f87c4
GS
926# define SvTRUE(sv) ( \
927 !sv \
928 ? 0 \
929 : SvPOK(sv) \
6b88bc9c 930 ? ((PL_Xpv = (XPV*)SvANY(sv)) && \
c2f1de04 931 (PL_Xpv->xpv_cur > 1 || \
6b88bc9c 932 (PL_Xpv->xpv_cur && *PL_Xpv->xpv_pv != '0')) \
a80f87c4
GS
933 ? 1 \
934 : 0) \
935 : \
936 SvIOK(sv) \
937 ? SvIVX(sv) != 0 \
938 : SvNOK(sv) \
939 ? SvNVX(sv) != 0.0 \
940 : sv_2bool(sv) )
6b88bc9c 941# define SvTRUEx(sv) ((PL_Sv = (sv)), SvTRUE(PL_Sv))
a80f87c4
GS
942#endif /* !USE_THREADS */
943#endif /* !__GNU__ */
944#endif /* !CRIPPLED_CC */
79072805 945
954c1994
GS
946/*
947=for apidoc Am|SV*|newRV_inc|SV* sv
948
949Creates an RV wrapper for an SV. The reference count for the original SV is
950incremented.
951
952=cut
953*/
954
5f05dabc 955#define newRV_inc(sv) newRV(sv)
5f05dabc 956
ef50df4b 957/* the following macros update any magic values this sv is associated with */
79072805 958
954c1994
GS
959/*
960=for apidoc Am|void|SvGETMAGIC|SV* sv
961Invokes C<mg_get> on an SV if it has 'get' magic. This macro evaluates its
962argument more than once.
963
964=for apidoc Am|void|SvSETMAGIC|SV* sv
965Invokes C<mg_set> on an SV if it has 'set' magic. This macro evaluates its
966argument more than once.
967
968=for apidoc Am|void|SvSetSV|SV* dsb|SV* ssv
969Calls C<sv_setsv> if dsv is not the same as ssv. May evaluate arguments
970more than once.
971
972=for apidoc Am|void|SvSetSV_nosteal|SV* dsv|SV* ssv
973Calls a non-destructive version of C<sv_setsv> if dsv is not the same as
974ssv. May evaluate arguments more than once.
975
976=for apidoc Am|void|SvGROW|SV* sv|STRLEN len
977Expands the character buffer in the SV so that it has room for the
978indicated number of bytes (remember to reserve space for an extra trailing
979NUL character). Calls C<sv_grow> to perform the expansion if necessary.
980Returns a pointer to the character buffer.
981
982=cut
983*/
984
189b2af5
GS
985#define SvGETMAGIC(x) STMT_START { if (SvGMAGICAL(x)) mg_get(x); } STMT_END
986#define SvSETMAGIC(x) STMT_START { if (SvSMAGICAL(x)) mg_set(x); } STMT_END
79072805 987
54310121 988#define SvSetSV_and(dst,src,finally) \
189b2af5 989 STMT_START { \
54310121
PP
990 if ((dst) != (src)) { \
991 sv_setsv(dst, src); \
992 finally; \
189b2af5
GS
993 } \
994 } STMT_END
54310121 995#define SvSetSV_nosteal_and(dst,src,finally) \
189b2af5 996 STMT_START { \
8ebc5c01
PP
997 if ((dst) != (src)) { \
998 U32 tMpF = SvFLAGS(src) & SVs_TEMP; \
999 SvTEMP_off(src); \
1000 sv_setsv(dst, src); \
1001 SvFLAGS(src) |= tMpF; \
54310121 1002 finally; \
189b2af5
GS
1003 } \
1004 } STMT_END
79072805 1005
54310121 1006#define SvSetSV(dst,src) \
c9d716f7 1007 SvSetSV_and(dst,src,/*nothing*/;)
54310121 1008#define SvSetSV_nosteal(dst,src) \
c9d716f7 1009 SvSetSV_nosteal_and(dst,src,/*nothing*/;)
54310121
PP
1010
1011#define SvSetMagicSV(dst,src) \
1012 SvSetSV_and(dst,src,SvSETMAGIC(dst))
1013#define SvSetMagicSV_nosteal(dst,src) \
1014 SvSetSV_nosteal_and(dst,src,SvSETMAGIC(dst))
1015
3967c732 1016#ifdef DEBUGGING
79072805 1017#define SvPEEK(sv) sv_peek(sv)
3967c732
JD
1018#else
1019#define SvPEEK(sv) ""
1020#endif
79072805 1021
3280af22 1022#define SvIMMORTAL(sv) ((sv)==&PL_sv_undef || (sv)==&PL_sv_yes || (sv)==&PL_sv_no)
36477c24 1023
3280af22 1024#define boolSV(b) ((b) ? &PL_sv_yes : &PL_sv_no)
54310121 1025
79072805
LW
1026#define isGV(sv) (SvTYPE(sv) == SVt_PVGV)
1027
933fea7f
GS
1028#define SvGROW(sv,len) (SvLEN(sv) < (len) ? sv_grow(sv,len) : SvPVX(sv))
1029#define Sv_Grow sv_grow