Socket::my_inet_aton() tweak
[p5sagit/p5-mst-13.2.git] / sv.h
CommitLineData
a0d0e21e 1/* sv.h
79072805 2 *
bc89e66f 3 * Copyright (c) 1991-2001, 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
954c1994 14/*
15=for apidoc AmU||svtype
8cf8f3d1 16An enum of flags for Perl types. These are found in the file B<sv.h>
954c1994 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 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 60} svtype;
61
79072805 62/* Using C's structural equivalence to help emulate C++ inheritance here... */
63
5e045b90 64struct STRUCT_SV { /* struct 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 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 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 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 86};
87
88struct hv {
463ee0b2 89 XPVHV* sv_any; /* pointer to something */
79072805 90 U32 sv_refcnt; /* how many references to us */
8990e307 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 98};
99
954c1994 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
4d1ff10f 124#ifdef USE_5005THREADS
dce16143 125
3d35f11b 126# if defined(VMS)
127# define ATOMIC_INC(count) __ATOMIC_INCREMENT_LONG(&count)
128# define ATOMIC_DEC_AND_TEST(res,count) res=(1==__ATOMIC_DECREMENT_LONG(&count))
129 # else
130# ifdef EMULATE_ATOMIC_REFCOUNTS
131 # define ATOMIC_INC(count) STMT_START { \
132 MUTEX_LOCK(&PL_svref_mutex); \
133 ++count; \
134 MUTEX_UNLOCK(&PL_svref_mutex); \
135 } STMT_END
136# define ATOMIC_DEC_AND_TEST(res,count) STMT_START { \
137 MUTEX_LOCK(&PL_svref_mutex); \
138 res = (--count == 0); \
139 MUTEX_UNLOCK(&PL_svref_mutex); \
140 } STMT_END
141# else
142# define ATOMIC_INC(count) atomic_inc(&count)
143# define ATOMIC_DEC_AND_TEST(res,count) (res = atomic_dec_and_test(&count))
144# endif /* EMULATE_ATOMIC_REFCOUNTS */
145# endif /* VMS */
dce16143 146#else
147# define ATOMIC_INC(count) (++count)
83b0a010 148# define ATOMIC_DEC_AND_TEST(res, count) (res = (--count == 0))
4d1ff10f 149#endif /* USE_5005THREADS */
dce16143 150
a863c7d1 151#ifdef __GNUC__
dce16143 152# define SvREFCNT_inc(sv) \
153 ({ \
154 SV *nsv = (SV*)(sv); \
155 if (nsv) \
156 ATOMIC_INC(SvREFCNT(nsv)); \
157 nsv; \
158 })
8990e307 159#else
4d1ff10f 160# if defined(CRIPPLED_CC) || defined(USE_5005THREADS)
3d35f11b 161# if defined(VMS) && defined(__ALPHA)
162# define SvREFCNT_inc(sv) \
163 (PL_Sv=(SV*)(sv), (PL_Sv && __ATOMIC_INCREMENT_LONG(&(SvREFCNT(PL_Sv)))), (SV *)PL_Sv)
164# else
165# define SvREFCNT_inc(sv) sv_newref((SV*)sv)
166# endif
a863c7d1 167# else
dce16143 168# define SvREFCNT_inc(sv) \
6b88bc9c 169 ((PL_Sv=(SV*)(sv)), (PL_Sv && ATOMIC_INC(SvREFCNT(PL_Sv))), (SV*)PL_Sv)
a863c7d1 170# endif
8990e307 171#endif
172
a863c7d1 173#define SvREFCNT_dec(sv) sv_free((SV*)sv)
174
8990e307 175#define SVTYPEMASK 0xff
176#define SvTYPE(sv) ((sv)->sv_flags & SVTYPEMASK)
79072805 177
178#define SvUPGRADE(sv, mt) (SvTYPE(sv) >= mt || sv_upgrade(sv, mt))
179
8990e307 180#define SVs_PADBUSY 0x00000100 /* reserved for tmp or my already */
181#define SVs_PADTMP 0x00000200 /* in use as tmp */
182#define SVs_PADMY 0x00000400 /* in use a "my" variable */
183#define SVs_TEMP 0x00000800 /* string is stealable? */
184#define SVs_OBJECT 0x00001000 /* is "blessed" */
185#define SVs_GMG 0x00002000 /* has magical get method */
186#define SVs_SMG 0x00004000 /* has magical set method */
187#define SVs_RMG 0x00008000 /* has random magical methods */
188
189#define SVf_IOK 0x00010000 /* has valid public integer value */
190#define SVf_NOK 0x00020000 /* has valid public numeric value */
191#define SVf_POK 0x00040000 /* has valid public pointer value */
192#define SVf_ROK 0x00080000 /* has a valid reference pointer */
a0d0e21e 193
748a9306 194#define SVf_FAKE 0x00100000 /* glob or lexical is just a copy */
8990e307 195#define SVf_OOK 0x00200000 /* has valid offset value */
645c22ef 196#define SVf_BREAK 0x00400000 /* refcnt is artificially low - used
197 * by SV's in final arena cleanup */
8990e307 198#define SVf_READONLY 0x00800000 /* may not be modified */
199
a0d0e21e 200
8990e307 201#define SVp_IOK 0x01000000 /* has valid non-public integer value */
202#define SVp_NOK 0x02000000 /* has valid non-public numeric value */
203#define SVp_POK 0x04000000 /* has valid non-public pointer value */
204#define SVp_SCREAM 0x08000000 /* has been studied? */
205
5bc28da9 206#define SVf_UTF8 0x20000000 /* SvPVX is UTF-8 encoded */
207
430eacda 208#define SVf_THINKFIRST (SVf_READONLY|SVf_ROK|SVf_FAKE)
5bc28da9 209
a0d0e21e 210#define SVf_OK (SVf_IOK|SVf_NOK|SVf_POK|SVf_ROK| \
211 SVp_IOK|SVp_NOK|SVp_POK)
212
9e7bc3e8 213#define SVf_AMAGIC 0x10000000 /* has magical overloaded methods */
a0d0e21e 214
8990e307 215#define PRIVSHIFT 8
216
217/* Some private flags. */
218
f472eb5c 219/* SVpad_OUR may be set on SVt_PV{NV,MG,GV} types */
032d6771 220#define SVpad_OUR 0x80000000 /* pad name is "our" instead of "my" */
524189f1 221#define SVpad_TYPED 0x40000000 /* Typed Lexical */
032d6771 222
25da4f38 223#define SVf_IVisUV 0x80000000 /* use XPVUV instead of XPVIV */
224
225#define SVpfm_COMPILED 0x80000000 /* FORMLINE is compiled */
8990e307 226
227#define SVpbm_VALID 0x80000000
bbce6d69 228#define SVpbm_TAIL 0x40000000
8990e307 229
25da4f38 230#define SVrepl_EVAL 0x40000000 /* Replacement part of s///e */
231
6bfc225d 232#define SVphv_SHAREKEYS 0x20000000 /* keys live on shared string table */
51594c39 233#define SVphv_LAZYDEL 0x40000000 /* entry in xhv_eiter must be deleted */
bf6bd887 234
810b8aa5 235#define SVprv_WEAKREF 0x80000000 /* Weak reference */
236
ed6116ce 237struct xrv {
238 SV * xrv_rv; /* pointer to another SV */
239};
240
79072805 241struct xpv {
ed6116ce 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 */
79072805 245};
246
247struct xpviv {
ed6116ce 248 char * xpv_pv; /* pointer to malloced string */
249 STRLEN xpv_cur; /* length of xpv_pv as a C string */
250 STRLEN xpv_len; /* allocated size */
a0d0e21e 251 IV xiv_iv; /* integer value or pv offset */
79072805 252};
253
ff68c719 254struct xpvuv {
255 char * xpv_pv; /* pointer to malloced string */
256 STRLEN xpv_cur; /* length of xpv_pv as a C string */
257 STRLEN xpv_len; /* allocated size */
258 UV xuv_uv; /* unsigned value or pv offset */
259};
260
79072805 261struct xpvnv {
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 */
65202027 266 NV xnv_nv; /* numeric value, if any */
79072805 267};
268
6ee623d5 269/* These structure must match the beginning of struct xpvhv in hv.h. */
79072805 270struct xpvmg {
ed6116ce 271 char * xpv_pv; /* pointer to malloced string */
272 STRLEN xpv_cur; /* length of xpv_pv as a C string */
273 STRLEN xpv_len; /* allocated size */
a0d0e21e 274 IV xiv_iv; /* integer value or pv offset */
65202027 275 NV xnv_nv; /* numeric value, if any */
79072805 276 MAGIC* xmg_magic; /* linked list of magicalness */
277 HV* xmg_stash; /* class package */
278};
279
280struct xpvlv {
ed6116ce 281 char * xpv_pv; /* pointer to malloced string */
282 STRLEN xpv_cur; /* length of xpv_pv as a C string */
283 STRLEN xpv_len; /* allocated size */
a0d0e21e 284 IV xiv_iv; /* integer value or pv offset */
65202027 285 NV xnv_nv; /* numeric value, if any */
79072805 286 MAGIC* xmg_magic; /* linked list of magicalness */
287 HV* xmg_stash; /* class package */
8990e307 288
79072805 289 STRLEN xlv_targoff;
290 STRLEN xlv_targlen;
291 SV* xlv_targ;
292 char xlv_type;
293};
294
295struct xpvgv {
ed6116ce 296 char * xpv_pv; /* pointer to malloced string */
297 STRLEN xpv_cur; /* length of xpv_pv as a C string */
298 STRLEN xpv_len; /* allocated size */
a0d0e21e 299 IV xiv_iv; /* integer value or pv offset */
65202027 300 NV xnv_nv; /* numeric value, if any */
79072805 301 MAGIC* xmg_magic; /* linked list of magicalness */
302 HV* xmg_stash; /* class package */
8990e307 303
79072805 304 GP* xgv_gp;
305 char* xgv_name;
306 STRLEN xgv_namelen;
307 HV* xgv_stash;
a5f75d66 308 U8 xgv_flags;
79072805 309};
310
311struct xpvbm {
ed6116ce 312 char * xpv_pv; /* pointer to malloced string */
313 STRLEN xpv_cur; /* length of xpv_pv as a C string */
314 STRLEN xpv_len; /* allocated size */
a0d0e21e 315 IV xiv_iv; /* integer value or pv offset */
65202027 316 NV xnv_nv; /* numeric value, if any */
79072805 317 MAGIC* xmg_magic; /* linked list of magicalness */
318 HV* xmg_stash; /* class package */
8990e307 319
79072805 320 I32 xbm_useful; /* is this constant pattern being useful? */
321 U16 xbm_previous; /* how many characters in string before rare? */
322 U8 xbm_rare; /* rarest character in string */
323};
324
d22779f5 325/* This structure much match XPVCV in cv.h */
44a8e56a 326
77a005ab 327typedef U16 cv_flags_t;
328
79072805 329struct xpvfm {
ed6116ce 330 char * xpv_pv; /* pointer to malloced string */
331 STRLEN xpv_cur; /* length of xpv_pv as a C string */
332 STRLEN xpv_len; /* allocated size */
a0d0e21e 333 IV xiv_iv; /* integer value or pv offset */
65202027 334 NV xnv_nv; /* numeric value, if any */
79072805 335 MAGIC* xmg_magic; /* linked list of magicalness */
336 HV* xmg_stash; /* class package */
8990e307 337
79072805 338 HV * xcv_stash;
339 OP * xcv_start;
340 OP * xcv_root;
acfe0abc 341 void (*xcv_xsub)(pTHX_ CV*);
a0d0e21e 342 ANY xcv_xsubany;
343 GV * xcv_gv;
57843af0 344 char * xcv_file;
b195d487 345 long xcv_depth; /* >= 2 indicates recursive call */
79072805 346 AV * xcv_padlist;
748a9306 347 CV * xcv_outside;
4d1ff10f 348#ifdef USE_5005THREADS
f6d98b14 349 perl_mutex *xcv_mutexp; /* protects xcv_owner */
52e1cb5e 350 struct perl_thread *xcv_owner; /* current owner thread */
4d1ff10f 351#endif /* USE_5005THREADS */
77a005ab 352 cv_flags_t xcv_flags;
44a8e56a 353
79072805 354 I32 xfm_lines;
355};
356
8990e307 357struct xpvio {
358 char * xpv_pv; /* pointer to malloced string */
359 STRLEN xpv_cur; /* length of xpv_pv as a C string */
360 STRLEN xpv_len; /* allocated size */
a0d0e21e 361 IV xiv_iv; /* integer value or pv offset */
65202027 362 NV xnv_nv; /* numeric value, if any */
8990e307 363 MAGIC* xmg_magic; /* linked list of magicalness */
364 HV* xmg_stash; /* class package */
365
760ac839 366 PerlIO * xio_ifp; /* ifp and ofp are normally the same */
367 PerlIO * xio_ofp; /* but sockets need separate streams */
4755096e 368 /* Cray addresses everything by word boundaries (64 bits) and
369 * code and data pointers cannot be mixed (which is exactly what
370 * Perl_filter_add() tries to do with the dirp), hence the following
371 * union trick (as suggested by Gurusamy Sarathy).
372 * For further information see Geir Johansen's problem report titled
373 [ID 20000612.002] Perl problem on Cray system
374 * The any pointer (known as IoANY()) will also be a good place
375 * to hang any IO disciplines to.
376 */
377 union {
378 DIR * xiou_dirp; /* for opendir, readdir, etc */
379 void * xiou_any; /* for alignment */
380 } xio_dirpu;
8990e307 381 long xio_lines; /* $. */
382 long xio_page; /* $% */
383 long xio_page_len; /* $= */
384 long xio_lines_left; /* $- */
385 char * xio_top_name; /* $^ */
386 GV * xio_top_gv; /* $^ */
387 char * xio_fmt_name; /* $~ */
388 GV * xio_fmt_gv; /* $~ */
389 char * xio_bottom_name;/* $^B */
390 GV * xio_bottom_gv; /* $^B */
391 short xio_subprocess; /* -| or |- */
392 char xio_type;
393 char xio_flags;
394};
4755096e 395#define xio_dirp xio_dirpu.xiou_dirp
396#define xio_any xio_dirpu.xiou_any
8990e307 397
e0c19803 398#define IOf_ARGV 1 /* this fp iterates over ARGV */
399#define IOf_START 2 /* check for null ARGV and substitute '-' */
400#define IOf_FLUSH 4 /* this fp wants a flush after write op */
401#define IOf_DIDTOP 8 /* just did top of form */
402#define IOf_UNTAINT 16 /* consider this fp (and its data) "safe" */
403#define IOf_NOLINE 32 /* slurped a pseudo-line from empty file */
404#define IOf_FAKE_DIRP 64 /* xio_dirp is fake (source filters kludge) */
8990e307 405
ed6116ce 406/* The following macros define implementation-independent predicates on SVs. */
407
954c1994 408/*
409=for apidoc Am|bool|SvNIOK|SV* sv
410Returns a boolean indicating whether the SV contains a number, integer or
411double.
412
413=for apidoc Am|bool|SvNIOKp|SV* sv
414Returns a boolean indicating whether the SV contains a number, integer or
415double. Checks the B<private> setting. Use C<SvNIOK>.
416
417=for apidoc Am|void|SvNIOK_off|SV* sv
418Unsets the NV/IV status of an SV.
419
420=for apidoc Am|bool|SvOK|SV* sv
421Returns a boolean indicating whether the value is an SV.
422
423=for apidoc Am|bool|SvIOKp|SV* sv
424Returns a boolean indicating whether the SV contains an integer. Checks
425the B<private> setting. Use C<SvIOK>.
426
427=for apidoc Am|bool|SvNOKp|SV* sv
428Returns a boolean indicating whether the SV contains a double. Checks the
429B<private> setting. Use C<SvNOK>.
430
431=for apidoc Am|bool|SvPOKp|SV* sv
432Returns a boolean indicating whether the SV contains a character string.
433Checks the B<private> setting. Use C<SvPOK>.
434
435=for apidoc Am|bool|SvIOK|SV* sv
436Returns a boolean indicating whether the SV contains an integer.
437
438=for apidoc Am|void|SvIOK_on|SV* sv
439Tells an SV that it is an integer.
440
441=for apidoc Am|void|SvIOK_off|SV* sv
442Unsets the IV status of an SV.
443
444=for apidoc Am|void|SvIOK_only|SV* sv
445Tells an SV that it is an integer and disables all other OK bits.
446
e331fc52 447=for apidoc Am|void|SvIOK_only_UV|SV* sv
448Tells and SV that it is an unsigned integer and disables all other OK bits.
449
450=for apidoc Am|void|SvIOK_UV|SV* sv
451Returns a boolean indicating whether the SV contains an unsigned integer.
452
28e5dec8 453=for apidoc Am|void|SvUOK|SV* sv
454Returns a boolean indicating whether the SV contains an unsigned integer.
455
e331fc52 456=for apidoc Am|void|SvIOK_notUV|SV* sv
d1be9408 457Returns a boolean indicating whether the SV contains a signed integer.
e331fc52 458
954c1994 459=for apidoc Am|bool|SvNOK|SV* sv
460Returns a boolean indicating whether the SV contains a double.
461
462=for apidoc Am|void|SvNOK_on|SV* sv
463Tells an SV that it is a double.
464
465=for apidoc Am|void|SvNOK_off|SV* sv
466Unsets the NV status of an SV.
467
468=for apidoc Am|void|SvNOK_only|SV* sv
469Tells an SV that it is a double and disables all other OK bits.
470
471=for apidoc Am|bool|SvPOK|SV* sv
472Returns a boolean indicating whether the SV contains a character
473string.
474
475=for apidoc Am|void|SvPOK_on|SV* sv
476Tells an SV that it is a string.
477
478=for apidoc Am|void|SvPOK_off|SV* sv
479Unsets the PV status of an SV.
480
481=for apidoc Am|void|SvPOK_only|SV* sv
482Tells an SV that it is a string and disables all other OK bits.
d5ce4a7c 483Will also turn off the UTF8 status.
954c1994 484
485=for apidoc Am|bool|SvOOK|SV* sv
486Returns a boolean indicating whether the SvIVX is a valid offset value for
487the SvPVX. This hack is used internally to speed up removal of characters
488from the beginning of a SvPV. When SvOOK is true, then the start of the
489allocated string buffer is really (SvPVX - SvIVX).
490
491=for apidoc Am|bool|SvROK|SV* sv
492Tests if the SV is an RV.
493
494=for apidoc Am|void|SvROK_on|SV* sv
495Tells an SV that it is an RV.
496
497=for apidoc Am|void|SvROK_off|SV* sv
498Unsets the RV status of an SV.
499
500=for apidoc Am|SV*|SvRV|SV* sv
501Dereferences an RV to return the SV.
502
503=for apidoc Am|IV|SvIVX|SV* sv
645c22ef 504Returns the raw value in the SV's IV slot, without checks or conversions.
505Only use when you are sure SvIOK is true. See also C<SvIV()>.
954c1994 506
507=for apidoc Am|UV|SvUVX|SV* sv
645c22ef 508Returns the raw value in the SV's UV slot, without checks or conversions.
509Only use when you are sure SvIOK is true. See also C<SvUV()>.
954c1994 510
511=for apidoc Am|NV|SvNVX|SV* sv
645c22ef 512Returns the raw value in the SV's NV slot, without checks or conversions.
513Only use when you are sure SvNOK is true. See also C<SvNV()>.
954c1994 514
515=for apidoc Am|char*|SvPVX|SV* sv
645c22ef 516Returns a pointer to the physical string in the SV. The SV must contain a
954c1994 517string.
518
519=for apidoc Am|STRLEN|SvCUR|SV* sv
520Returns the length of the string which is in the SV. See C<SvLEN>.
521
522=for apidoc Am|STRLEN|SvLEN|SV* sv
659239a4 523Returns the size of the string buffer in the SV, not including any part
524attributable to C<SvOOK>. See C<SvCUR>.
954c1994 525
526=for apidoc Am|char*|SvEND|SV* sv
527Returns a pointer to the last character in the string which is in the SV.
528See C<SvCUR>. Access the character as *(SvEND(sv)).
529
530=for apidoc Am|HV*|SvSTASH|SV* sv
531Returns the stash of the SV.
532
533=for apidoc Am|void|SvCUR_set|SV* sv|STRLEN len
534Set the length of the string which is in the SV. See C<SvCUR>.
535
536=cut
537*/
538
79072805 539#define SvNIOK(sv) (SvFLAGS(sv) & (SVf_IOK|SVf_NOK))
748a9306 540#define SvNIOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK))
a0d0e21e 541#define SvNIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK| \
25da4f38 542 SVp_IOK|SVp_NOK|SVf_IVisUV))
79072805 543
463ee0b2 544#define SvOK(sv) (SvFLAGS(sv) & SVf_OK)
25da4f38 545#define SvOK_off(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC| \
d41ff1b8 546 SVf_IVisUV|SVf_UTF8), \
25da4f38 547 SvOOK_off(sv))
d41ff1b8 548#define SvOK_off_exc_UV(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC| \
549 SVf_UTF8), \
a0d0e21e 550 SvOOK_off(sv))
79072805 551
8990e307 552#define SvOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK))
553#define SvIOKp(sv) (SvFLAGS(sv) & SVp_IOK)
155aba94 554#define SvIOKp_on(sv) ((void)SvOOK_off(sv), SvFLAGS(sv) |= SVp_IOK)
8990e307 555#define SvNOKp(sv) (SvFLAGS(sv) & SVp_NOK)
556#define SvNOKp_on(sv) (SvFLAGS(sv) |= SVp_NOK)
557#define SvPOKp(sv) (SvFLAGS(sv) & SVp_POK)
558#define SvPOKp_on(sv) (SvFLAGS(sv) |= SVp_POK)
463ee0b2 559
79072805 560#define SvIOK(sv) (SvFLAGS(sv) & SVf_IOK)
155aba94 561#define SvIOK_on(sv) ((void)SvOOK_off(sv), \
a0d0e21e 562 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
25da4f38 563#define SvIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVp_IOK|SVf_IVisUV))
155aba94 564#define SvIOK_only(sv) ((void)SvOK_off(sv), \
a0d0e21e 565 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
155aba94 566#define SvIOK_only_UV(sv) ((void)SvOK_off_exc_UV(sv), \
25da4f38 567 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
70401c6b 568
25da4f38 569#define SvIOK_UV(sv) ((SvFLAGS(sv) & (SVf_IOK|SVf_IVisUV)) \
570 == (SVf_IOK|SVf_IVisUV))
28e5dec8 571#define SvUOK(sv) SvIOK_UV(sv)
25da4f38 572#define SvIOK_notUV(sv) ((SvFLAGS(sv) & (SVf_IOK|SVf_IVisUV)) \
573 == SVf_IOK)
574
575#define SvIsUV(sv) (SvFLAGS(sv) & SVf_IVisUV)
576#define SvIsUV_on(sv) (SvFLAGS(sv) |= SVf_IVisUV)
577#define SvIsUV_off(sv) (SvFLAGS(sv) &= ~SVf_IVisUV)
79072805 578
579#define SvNOK(sv) (SvFLAGS(sv) & SVf_NOK)
a0d0e21e 580#define SvNOK_on(sv) (SvFLAGS(sv) |= (SVf_NOK|SVp_NOK))
8990e307 581#define SvNOK_off(sv) (SvFLAGS(sv) &= ~(SVf_NOK|SVp_NOK))
155aba94 582#define SvNOK_only(sv) ((void)SvOK_off(sv), \
a0d0e21e 583 SvFLAGS(sv) |= (SVf_NOK|SVp_NOK))
79072805 584
914184e1 585/*
586=for apidoc Am|void|SvUTF8|SV* sv
587Returns a boolean indicating whether the SV contains UTF-8 encoded data.
588
589=for apidoc Am|void|SvUTF8_on|SV *sv
d5ce4a7c 590Turn on the UTF8 status of an SV (the data is not changed, just the flag).
591Do not use frivolously.
914184e1 592
593=for apidoc Am|void|SvUTF8_off|SV *sv
594Unsets the UTF8 status of an SV.
595
596=for apidoc Am|void|SvPOK_only_UTF8|SV* sv
d5ce4a7c 597Tells an SV that it is a string and disables all other OK bits,
598and leaves the UTF8 status as it was.
f1a1024e 599
914184e1 600=cut
601 */
602
a7cb1f99 603#define SvUTF8(sv) (SvFLAGS(sv) & SVf_UTF8)
604#define SvUTF8_on(sv) (SvFLAGS(sv) |= (SVf_UTF8))
605#define SvUTF8_off(sv) (SvFLAGS(sv) &= ~(SVf_UTF8))
5bc28da9 606
79072805 607#define SvPOK(sv) (SvFLAGS(sv) & SVf_POK)
a0d0e21e 608#define SvPOK_on(sv) (SvFLAGS(sv) |= (SVf_POK|SVp_POK))
8990e307 609#define SvPOK_off(sv) (SvFLAGS(sv) &= ~(SVf_POK|SVp_POK))
d41ff1b8 610#define SvPOK_only(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC| \
611 SVf_IVisUV|SVf_UTF8), \
612 SvFLAGS(sv) |= (SVf_POK|SVp_POK))
613#define SvPOK_only_UTF8(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC| \
614 SVf_IVisUV), \
a0d0e21e 615 SvFLAGS(sv) |= (SVf_POK|SVp_POK))
79072805 616
617#define SvOOK(sv) (SvFLAGS(sv) & SVf_OOK)
155aba94 618#define SvOOK_on(sv) ((void)SvIOK_off(sv), SvFLAGS(sv) |= SVf_OOK)
79072805 619#define SvOOK_off(sv) (SvOOK(sv) && sv_backoff(sv))
79072805 620
a0d0e21e 621#define SvFAKE(sv) (SvFLAGS(sv) & SVf_FAKE)
622#define SvFAKE_on(sv) (SvFLAGS(sv) |= SVf_FAKE)
623#define SvFAKE_off(sv) (SvFLAGS(sv) &= ~SVf_FAKE)
624
ed6116ce 625#define SvROK(sv) (SvFLAGS(sv) & SVf_ROK)
a0d0e21e 626#define SvROK_on(sv) (SvFLAGS(sv) |= SVf_ROK)
a0d0e21e 627#define SvROK_off(sv) (SvFLAGS(sv) &= ~(SVf_ROK|SVf_AMAGIC))
79072805 628
8990e307 629#define SvMAGICAL(sv) (SvFLAGS(sv) & (SVs_GMG|SVs_SMG|SVs_RMG))
630#define SvMAGICAL_on(sv) (SvFLAGS(sv) |= (SVs_GMG|SVs_SMG|SVs_RMG))
631#define SvMAGICAL_off(sv) (SvFLAGS(sv) &= ~(SVs_GMG|SVs_SMG|SVs_RMG))
79072805 632
8990e307 633#define SvGMAGICAL(sv) (SvFLAGS(sv) & SVs_GMG)
634#define SvGMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_GMG)
635#define SvGMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_GMG)
ed6116ce 636
8990e307 637#define SvSMAGICAL(sv) (SvFLAGS(sv) & SVs_SMG)
638#define SvSMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_SMG)
639#define SvSMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_SMG)
ed6116ce 640
8990e307 641#define SvRMAGICAL(sv) (SvFLAGS(sv) & SVs_RMG)
642#define SvRMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_RMG)
643#define SvRMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_RMG)
ed6116ce 644
9e7bc3e8 645#define SvAMAGIC(sv) (SvFLAGS(sv) & SVf_AMAGIC)
646#define SvAMAGIC_on(sv) (SvFLAGS(sv) |= SVf_AMAGIC)
647#define SvAMAGIC_off(sv) (SvFLAGS(sv) &= ~SVf_AMAGIC)
a0d0e21e 648
8cf8f3d1 649#define SvGAMAGIC(sv) (SvFLAGS(sv) & (SVs_GMG|SVf_AMAGIC))
1426bbf4 650
a0d0e21e 651/*
652#define Gv_AMG(stash) \
653 (HV_AMAGICmb(stash) && \
654 ((!HV_AMAGICbad(stash) && HV_AMAGIC(stash)) || Gv_AMupdate(stash)))
655*/
3280af22 656#define Gv_AMG(stash) (PL_amagic_generation && Gv_AMupdate(stash))
a0d0e21e 657
810b8aa5 658#define SvWEAKREF(sv) ((SvFLAGS(sv) & (SVf_ROK|SVprv_WEAKREF)) \
659 == (SVf_ROK|SVprv_WEAKREF))
660#define SvWEAKREF_on(sv) (SvFLAGS(sv) |= (SVf_ROK|SVprv_WEAKREF))
661#define SvWEAKREF_off(sv) (SvFLAGS(sv) &= ~(SVf_ROK|SVprv_WEAKREF))
662
a0d0e21e 663#define SvTHINKFIRST(sv) (SvFLAGS(sv) & SVf_THINKFIRST)
ed6116ce 664
8990e307 665#define SvPADBUSY(sv) (SvFLAGS(sv) & SVs_PADBUSY)
ed6116ce 666
8990e307 667#define SvPADTMP(sv) (SvFLAGS(sv) & SVs_PADTMP)
668#define SvPADTMP_on(sv) (SvFLAGS(sv) |= SVs_PADTMP|SVs_PADBUSY)
669#define SvPADTMP_off(sv) (SvFLAGS(sv) &= ~SVs_PADTMP)
ed6116ce 670
8990e307 671#define SvPADMY(sv) (SvFLAGS(sv) & SVs_PADMY)
672#define SvPADMY_on(sv) (SvFLAGS(sv) |= SVs_PADMY|SVs_PADBUSY)
ed6116ce 673
8990e307 674#define SvTEMP(sv) (SvFLAGS(sv) & SVs_TEMP)
675#define SvTEMP_on(sv) (SvFLAGS(sv) |= SVs_TEMP)
676#define SvTEMP_off(sv) (SvFLAGS(sv) &= ~SVs_TEMP)
79072805 677
8990e307 678#define SvOBJECT(sv) (SvFLAGS(sv) & SVs_OBJECT)
679#define SvOBJECT_on(sv) (SvFLAGS(sv) |= SVs_OBJECT)
680#define SvOBJECT_off(sv) (SvFLAGS(sv) &= ~SVs_OBJECT)
79072805 681
8990e307 682#define SvREADONLY(sv) (SvFLAGS(sv) & SVf_READONLY)
683#define SvREADONLY_on(sv) (SvFLAGS(sv) |= SVf_READONLY)
684#define SvREADONLY_off(sv) (SvFLAGS(sv) &= ~SVf_READONLY)
79072805 685
8990e307 686#define SvSCREAM(sv) (SvFLAGS(sv) & SVp_SCREAM)
687#define SvSCREAM_on(sv) (SvFLAGS(sv) |= SVp_SCREAM)
688#define SvSCREAM_off(sv) (SvFLAGS(sv) &= ~SVp_SCREAM)
79072805 689
8990e307 690#define SvCOMPILED(sv) (SvFLAGS(sv) & SVpfm_COMPILED)
691#define SvCOMPILED_on(sv) (SvFLAGS(sv) |= SVpfm_COMPILED)
692#define SvCOMPILED_off(sv) (SvFLAGS(sv) &= ~SVpfm_COMPILED)
79072805 693
25da4f38 694#define SvEVALED(sv) (SvFLAGS(sv) & SVrepl_EVAL)
695#define SvEVALED_on(sv) (SvFLAGS(sv) |= SVrepl_EVAL)
696#define SvEVALED_off(sv) (SvFLAGS(sv) &= ~SVrepl_EVAL)
697
8990e307 698#define SvTAIL(sv) (SvFLAGS(sv) & SVpbm_TAIL)
699#define SvTAIL_on(sv) (SvFLAGS(sv) |= SVpbm_TAIL)
700#define SvTAIL_off(sv) (SvFLAGS(sv) &= ~SVpbm_TAIL)
701
8990e307 702#define SvVALID(sv) (SvFLAGS(sv) & SVpbm_VALID)
703#define SvVALID_on(sv) (SvFLAGS(sv) |= SVpbm_VALID)
704#define SvVALID_off(sv) (SvFLAGS(sv) &= ~SVpbm_VALID)
705
1cc8b4c5 706#ifdef USE_ITHREADS
707/* The following uses the FAKE flag to show that a regex pointer is infact
8ca6097c 708 its own offset in the regexpad for ithreads */
1cc8b4c5 709#define SvREPADTMP(sv) (SvFLAGS(sv) & SVf_FAKE)
710#define SvREPADTMP_on(sv) (SvFLAGS(sv) |= SVf_FAKE)
711#define SvREPADTMP_off(sv) (SvFLAGS(sv) &= ~SVf_FAKE)
712#endif
713
ed6116ce 714#define SvRV(sv) ((XRV*) SvANY(sv))->xrv_rv
715#define SvRVx(sv) SvRV(sv)
716
463ee0b2 717#define SvIVX(sv) ((XPVIV*) SvANY(sv))->xiv_iv
718#define SvIVXx(sv) SvIVX(sv)
ff68c719 719#define SvUVX(sv) ((XPVUV*) SvANY(sv))->xuv_uv
720#define SvUVXx(sv) SvUVX(sv)
463ee0b2 721#define SvNVX(sv) ((XPVNV*)SvANY(sv))->xnv_nv
722#define SvNVXx(sv) SvNVX(sv)
723#define SvPVX(sv) ((XPV*) SvANY(sv))->xpv_pv
724#define SvPVXx(sv) SvPVX(sv)
79072805 725#define SvCUR(sv) ((XPV*) SvANY(sv))->xpv_cur
79072805 726#define SvLEN(sv) ((XPV*) SvANY(sv))->xpv_len
727#define SvLENx(sv) SvLEN(sv)
728#define SvEND(sv)(((XPV*) SvANY(sv))->xpv_pv + ((XPV*)SvANY(sv))->xpv_cur)
6b88bc9c 729#define SvENDx(sv) ((PL_Sv = (sv)), SvEND(PL_Sv))
79072805 730#define SvMAGIC(sv) ((XPVMG*) SvANY(sv))->xmg_magic
731#define SvSTASH(sv) ((XPVMG*) SvANY(sv))->xmg_stash
732
28e5dec8 733/* Ask a scalar nicely to try to become an IV, if possible.
734 Not guaranteed to stay returning void */
735/* Macro won't actually call sv_2iv if already IOK */
736#define SvIV_please(sv) \
737 STMT_START {if (!SvIOKp(sv) && (SvNOK(sv) || SvPOK(sv))) \
738 (void) SvIV(sv); } STMT_END
79072805 739#define SvIV_set(sv, val) \
80b92232 740 STMT_START { assert(SvTYPE(sv) == SVt_IV || SvTYPE(sv) >= SVt_PVIV); \
741 (((XPVIV*) SvANY(sv))->xiv_iv = val); } STMT_END
79072805 742#define SvNV_set(sv, val) \
80b92232 743 STMT_START { assert(SvTYPE(sv) == SVt_NV || SvTYPE(sv) >= SVt_PVNV); \
744 (((XPVNV*) SvANY(sv))->xnv_nv = val); } STMT_END
79072805 745#define SvPV_set(sv, val) \
80b92232 746 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
747 (((XPV*) SvANY(sv))->xpv_pv = val); } STMT_END
79072805 748#define SvCUR_set(sv, val) \
80b92232 749 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
750 (((XPV*) SvANY(sv))->xpv_cur = val); } STMT_END
79072805 751#define SvLEN_set(sv, val) \
80b92232 752 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
753 (((XPV*) SvANY(sv))->xpv_len = val); } STMT_END
79072805 754#define SvEND_set(sv, val) \
80b92232 755 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
756 (((XPV*) SvANY(sv))->xpv_cur = val - SvPVX(sv)); } STMT_END
79072805 757
758#define BmRARE(sv) ((XPVBM*) SvANY(sv))->xbm_rare
759#define BmUSEFUL(sv) ((XPVBM*) SvANY(sv))->xbm_useful
760#define BmPREVIOUS(sv) ((XPVBM*) SvANY(sv))->xbm_previous
761
762#define FmLINES(sv) ((XPVFM*) SvANY(sv))->xfm_lines
763
764#define LvTYPE(sv) ((XPVLV*) SvANY(sv))->xlv_type
765#define LvTARG(sv) ((XPVLV*) SvANY(sv))->xlv_targ
766#define LvTARGOFF(sv) ((XPVLV*) SvANY(sv))->xlv_targoff
767#define LvTARGLEN(sv) ((XPVLV*) SvANY(sv))->xlv_targlen
768
8990e307 769#define IoIFP(sv) ((XPVIO*) SvANY(sv))->xio_ifp
770#define IoOFP(sv) ((XPVIO*) SvANY(sv))->xio_ofp
771#define IoDIRP(sv) ((XPVIO*) SvANY(sv))->xio_dirp
4755096e 772#define IoANY(sv) ((XPVIO*) SvANY(sv))->xio_any
8990e307 773#define IoLINES(sv) ((XPVIO*) SvANY(sv))->xio_lines
774#define IoPAGE(sv) ((XPVIO*) SvANY(sv))->xio_page
775#define IoPAGE_LEN(sv) ((XPVIO*) SvANY(sv))->xio_page_len
776#define IoLINES_LEFT(sv)((XPVIO*) SvANY(sv))->xio_lines_left
777#define IoTOP_NAME(sv) ((XPVIO*) SvANY(sv))->xio_top_name
778#define IoTOP_GV(sv) ((XPVIO*) SvANY(sv))->xio_top_gv
779#define IoFMT_NAME(sv) ((XPVIO*) SvANY(sv))->xio_fmt_name
780#define IoFMT_GV(sv) ((XPVIO*) SvANY(sv))->xio_fmt_gv
781#define IoBOTTOM_NAME(sv)((XPVIO*) SvANY(sv))->xio_bottom_name
782#define IoBOTTOM_GV(sv) ((XPVIO*) SvANY(sv))->xio_bottom_gv
783#define IoSUBPROCESS(sv)((XPVIO*) SvANY(sv))->xio_subprocess
784#define IoTYPE(sv) ((XPVIO*) SvANY(sv))->xio_type
785#define IoFLAGS(sv) ((XPVIO*) SvANY(sv))->xio_flags
786
50952442 787/* IoTYPE(sv) is a single character telling the type of I/O connection. */
788#define IoTYPE_RDONLY '<'
789#define IoTYPE_WRONLY '>'
790#define IoTYPE_RDWR '+'
791#define IoTYPE_APPEND 'a'
792#define IoTYPE_PIPE '|'
793#define IoTYPE_STD '-' /* stdin or stdout */
794#define IoTYPE_SOCKET 's'
795#define IoTYPE_CLOSED ' '
03fcf2fc 796
797/*
954c1994 798=for apidoc Am|bool|SvTAINTED|SV* sv
799Checks to see if an SV is tainted. Returns TRUE if it is, FALSE if
800not.
801
802=for apidoc Am|void|SvTAINTED_on|SV* sv
803Marks an SV as tainted.
804
805=for apidoc Am|void|SvTAINTED_off|SV* sv
806Untaints an SV. Be I<very> careful with this routine, as it short-circuits
807some of Perl's fundamental security features. XS module authors should not
808use this function unless they fully understand all the implications of
809unconditionally untainting the value. Untainting should be done in the
810standard perl fashion, via a carefully crafted regexp, rather than directly
811untainting variables.
812
813=for apidoc Am|void|SvTAINT|SV* sv
814Taints an SV if tainting is enabled
815
816=cut
817*/
818
bbce6d69 819#define SvTAINTED(sv) (SvMAGICAL(sv) && sv_tainted(sv))
3280af22 820#define SvTAINTED_on(sv) STMT_START{ if(PL_tainting){sv_taint(sv);} }STMT_END
821#define SvTAINTED_off(sv) STMT_START{ if(PL_tainting){sv_untaint(sv);} }STMT_END
bbce6d69 822
c6ee37c5 823#define SvTAINT(sv) \
824 STMT_START { \
3280af22 825 if (PL_tainting) { \
3280af22 826 if (PL_tainted) \
c6ee37c5 827 SvTAINTED_on(sv); \
828 } \
829 } STMT_END
79072805 830
954c1994 831/*
832=for apidoc Am|char*|SvPV_force|SV* sv|STRLEN len
833Like <SvPV> but will force the SV into becoming a string (SvPOK). You want
834force if you are going to update the SvPVX directly.
835
645c22ef 836=for apidoc Am|char*|SvPV_force_nomg|SV* sv|STRLEN len
837Like <SvPV> but will force the SV into becoming a string (SvPOK). You want
838force if you are going to update the SvPVX directly. Doesn't process magic.
839
954c1994 840=for apidoc Am|char*|SvPV|SV* sv|STRLEN len
841Returns a pointer to the string in the SV, or a stringified form of the SV
645c22ef 842if the SV does not contain a string. Handles 'get' magic. See also
843C<SvPVx> for a version which guarantees to evaluate sv only once.
844
845=for apidoc Am|char*|SvPVx|SV* sv|STRLEN len
846A version of C<SvPV> which guarantees to evaluate sv only once.
954c1994 847
848=for apidoc Am|char*|SvPV_nolen|SV* sv
849Returns a pointer to the string in the SV, or a stringified form of the SV
850if the SV does not contain a string. Handles 'get' magic.
851
852=for apidoc Am|IV|SvIV|SV* sv
645c22ef 853Coerces the given SV to an integer and returns it. See C<SvIVx> for a
854version which guarantees to evaluate sv only once.
855
856=for apidoc Am|IV|SvIVx|SV* sv
857Coerces the given SV to an integer and returns it. Guarantees to evaluate
d1be9408 858sv only once. Use the more efficient C<SvIV> otherwise.
954c1994 859
860=for apidoc Am|NV|SvNV|SV* sv
645c22ef 861Coerce the given SV to a double and return it. See C<SvNVx> for a version
862which guarantees to evaluate sv only once.
863
864=for apidoc Am|NV|SvNVx|SV* sv
865Coerces the given SV to a double and returns it. Guarantees to evaluate
d1be9408 866sv only once. Use the more efficient C<SvNV> otherwise.
954c1994 867
868=for apidoc Am|UV|SvUV|SV* sv
645c22ef 869Coerces the given SV to an unsigned integer and returns it. See C<SvUVx>
870for a version which guarantees to evaluate sv only once.
871
872=for apidoc Am|UV|SvUVx|SV* sv
873Coerces the given SV to an unsigned integer and returns it. Guarantees to
d1be9408 874evaluate sv only once. Use the more efficient C<SvUV> otherwise.
954c1994 875
876=for apidoc Am|bool|SvTRUE|SV* sv
877Returns a boolean indicating whether Perl would evaluate the SV as true or
878false, defined or undefined. Does not handle 'get' magic.
879
645c22ef 880=for apidoc Am|char*|SvPVutf8_force|SV* sv|STRLEN len
b70b15d2 881Like C<SvPV_force>, but converts sv to utf8 first if necessary.
645c22ef 882
883=for apidoc Am|char*|SvPVutf8|SV* sv|STRLEN len
b70b15d2 884Like C<SvPV>, but converts sv to utf8 first if necessary.
645c22ef 885
b70b15d2 886=for apidoc Am|char*|SvPVutf8_nolen|SV* sv
887Like C<SvPV_nolen>, but converts sv to utf8 first if necessary.
645c22ef 888
889=for apidoc Am|char*|SvPVbyte_force|SV* sv|STRLEN len
890Like C<SvPV_force>, but converts sv to byte representation first if necessary.
891
892=for apidoc Am|char*|SvPVbyte|SV* sv|STRLEN len
893Like C<SvPV>, but converts sv to byte representation first if necessary.
894
b70b15d2 895=for apidoc Am|char*|SvPVbyte_nolen|SV* sv
645c22ef 896Like C<SvPV_nolen>, but converts sv to byte representation first if necessary.
897
898=for apidoc Am|char*|SvPVutf8x_force|SV* sv|STRLEN len
b70b15d2 899Like C<SvPV_force>, but converts sv to utf8 first if necessary.
d1be9408 900Guarantees to evaluate sv only once; use the more efficient C<SvPVutf8_force>
645c22ef 901otherwise.
902
903=for apidoc Am|char*|SvPVutf8x|SV* sv|STRLEN len
b70b15d2 904Like C<SvPV>, but converts sv to utf8 first if necessary.
d1be9408 905Guarantees to evaluate sv only once; use the more efficient C<SvPVutf8>
645c22ef 906otherwise.
907
908=for apidoc Am|char*|SvPVbytex_force|SV* sv|STRLEN len
909Like C<SvPV_force>, but converts sv to byte representation first if necessary.
d1be9408 910Guarantees to evaluate sv only once; use the more efficient C<SvPVbyte_force>
645c22ef 911otherwise.
912
913=for apidoc Am|char*|SvPVbytex|SV* sv|STRLEN len
914Like C<SvPV>, but converts sv to byte representation first if necessary.
d1be9408 915Guarantees to evaluate sv only once; use the more efficient C<SvPVbyte>
645c22ef 916otherwise.
917
918
954c1994 919=cut
920*/
921
a0d0e21e 922#define SvPV_force(sv, lp) sv_pvn_force(sv, &lp)
463ee0b2 923#define SvPV(sv, lp) sv_pvn(sv, &lp)
1fa8b10d 924#define SvPV_nolen(sv) sv_pv(sv)
6e9d1081 925#define SvPV_nomg(sv, lp) sv_pvn_nomg(sv, &lp)
926#define SvPV_force_flags(sv, lp, flags) sv_pvn_force_flags(sv, &lp, flags)
5bc28da9 927
928#define SvPVutf8_force(sv, lp) sv_pvutf8n_force(sv, &lp)
929#define SvPVutf8(sv, lp) sv_pvutf8n(sv, &lp)
930#define SvPVutf8_nolen(sv) sv_pvutf8(sv)
931
932#define SvPVbyte_force(sv, lp) sv_pvbyte_force(sv, &lp)
933#define SvPVbyte(sv, lp) sv_pvbyten(sv, &lp)
934#define SvPVbyte_nolen(sv) sv_pvbyte(sv)
935
936#define SvPVx(sv, lp) sv_pvn(sv, &lp)
937#define SvPVx_force(sv, lp) sv_pvn_force(sv, &lp)
938#define SvPVutf8x(sv, lp) sv_pvutf8n(sv, &lp)
939#define SvPVutf8x_force(sv, lp) sv_pvutf8n_force(sv, &lp)
940#define SvPVbytex(sv, lp) sv_pvbyten(sv, &lp)
941#define SvPVbytex_force(sv, lp) sv_pvbyten_force(sv, &lp)
942
4e35701f 943#define SvIVx(sv) sv_iv(sv)
944#define SvUVx(sv) sv_uv(sv)
945#define SvNVx(sv) sv_nv(sv)
5bc28da9 946
4e35701f 947#define SvTRUEx(sv) sv_true(sv)
948
949#define SvIV(sv) SvIVx(sv)
950#define SvNV(sv) SvNVx(sv)
25da4f38 951#define SvUV(sv) SvUVx(sv)
4e35701f 952#define SvTRUE(sv) SvTRUEx(sv)
79072805 953
6e9d1081 954/* flag values for sv_*_flags functions */
955#define SV_IMMEDIATE_UNREF 1
956#define SV_GMAGIC 2
957
958#define sv_pvn_force_nomg(sv, lp) sv_pvn_force_flags(sv, lp, 0)
959#define sv_utf8_upgrade_nomg(sv) sv_utf8_upgrade_flags(sv, 0)
960#define sv_catpvn_nomg(dsv, sstr, slen) sv_catpvn_flags(dsv, sstr, slen, 0)
961
a80f87c4 962#ifndef CRIPPLED_CC
963/* redefine some things to more efficient inlined versions */
79072805 964
25da4f38 965/* Let us hope that bitmaps for UV and IV are the same */
ff68c719 966#undef SvIV
463ee0b2 967#define SvIV(sv) (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv))
79072805 968
ff68c719 969#undef SvUV
970#define SvUV(sv) (SvIOK(sv) ? SvUVX(sv) : sv_2uv(sv))
971
972#undef SvNV
463ee0b2 973#define SvNV(sv) (SvNOK(sv) ? SvNVX(sv) : sv_2nv(sv))
79072805 974
af3c7592 975#define sv_setsv(dsv, ssv) sv_setsv_flags(dsv, ssv, SV_GMAGIC)
8d6d96c1 976#define sv_setsv_nomg(dsv, ssv) sv_setsv_flags(dsv, ssv, 0)
af3c7592 977#define sv_catsv(dsv, ssv) sv_catsv_flags(dsv, ssv, SV_GMAGIC)
8d6d96c1 978#define sv_catsv_nomg(dsv, ssv) sv_catsv_flags(dsv, ssv, 0)
af3c7592 979#define sv_catpvn(dsv, sstr, slen) sv_catpvn_flags(dsv, sstr, slen, SV_GMAGIC)
980#define sv_2pv(sv, lp) sv_2pv_flags(sv, lp, SV_GMAGIC)
8d6d96c1 981#define sv_2pv_nomg(sv, lp) sv_2pv_flags(sv, lp, 0)
af3c7592 982#define sv_pvn_force(sv, lp) sv_pvn_force_flags(sv, lp, SV_GMAGIC)
983#define sv_utf8_upgrade(sv) sv_utf8_upgrade_flags(sv, SV_GMAGIC)
8d6d96c1 984
ff68c719 985#undef SvPV
8d6d96c1 986#define SvPV(sv, lp) SvPV_flags(sv, lp, SV_GMAGIC)
987
988#undef SvPV_nomg
989#define SvPV_nomg(sv, lp) SvPV_flags(sv, lp, 0)
70401c6b 990
8d6d96c1 991#undef SvPV_flags
992#define SvPV_flags(sv, lp, flags) \
993 ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
994 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pv_flags(sv, &lp, flags))
79072805 995
ff68c719 996#undef SvPV_force
8d6d96c1 997#define SvPV_force(sv, lp) SvPV_force_flags(sv, lp, SV_GMAGIC)
998#undef SvPV_force_nomg
999#define SvPV_force_nomg(sv, lp) SvPV_force_flags(sv, lp, 0)
1000
1001#undef SvPV_force_flags
1002#define SvPV_force_flags(sv, lp, flags) \
ff68c719 1003 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \
8d6d96c1 1004 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvn_force_flags(sv, &lp, flags))
a0d0e21e 1005
1fa8b10d 1006#undef SvPV_nolen
1007#define SvPV_nolen(sv) \
5bc28da9 1008 ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
1009 ? SvPVX(sv) : sv_2pv_nolen(sv))
70401c6b 1010
5bc28da9 1011#undef SvPVutf8
1012#define SvPVutf8(sv, lp) \
1013 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8) \
1014 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvutf8(sv, &lp))
70401c6b 1015
5bc28da9 1016#undef SvPVutf8_force
1017#define SvPVutf8_force(sv, lp) \
70401c6b 1018 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == (SVf_POK|SVf_UTF8) \
5bc28da9 1019 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvutf8n_force(sv, &lp))
1020
1021#undef SvPVutf8_nolen
1022#define SvPVutf8_nolen(sv) \
70401c6b 1023 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8)\
5bc28da9 1024 ? SvPVX(sv) : sv_2pvutf8_nolen(sv))
70401c6b 1025
5bc28da9 1026#undef SvPVutf8
1027#define SvPVutf8(sv, lp) \
1028 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8) \
1029 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvutf8(sv, &lp))
70401c6b 1030
5bc28da9 1031#undef SvPVutf8_force
1032#define SvPVutf8_force(sv, lp) \
70401c6b 1033 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == (SVf_POK|SVf_UTF8) \
5bc28da9 1034 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvutf8n_force(sv, &lp))
1035
1036#undef SvPVutf8_nolen
1037#define SvPVutf8_nolen(sv) \
1038 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8)\
1039 ? SvPVX(sv) : sv_2pvutf8_nolen(sv))
70401c6b 1040
5bc28da9 1041#undef SvPVbyte
1042#define SvPVbyte(sv, lp) \
1043 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK) \
1044 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvbyte(sv, &lp))
70401c6b 1045
5bc28da9 1046#undef SvPVbyte_force
1047#define SvPVbyte_force(sv, lp) \
1048 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8|SVf_THINKFIRST)) == (SVf_POK) \
1049 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvbyte_force(sv, &lp))
1050
1051#undef SvPVbyte_nolen
1052#define SvPVbyte_nolen(sv) \
1053 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK)\
1054 ? SvPVX(sv) : sv_2pvbyte_nolen(sv))
70401c6b 1055
1fa8b10d 1056
a80f87c4 1057#ifdef __GNUC__
1058# undef SvIVx
1059# undef SvUVx
1060# undef SvNVx
1061# undef SvPVx
5bc28da9 1062# undef SvPVutf8x
1063# undef SvPVbytex
a80f87c4 1064# undef SvTRUE
1065# undef SvTRUEx
1066# define SvIVx(sv) ({SV *nsv = (SV*)(sv); SvIV(nsv); })
1067# define SvUVx(sv) ({SV *nsv = (SV*)(sv); SvUV(nsv); })
1068# define SvNVx(sv) ({SV *nsv = (SV*)(sv); SvNV(nsv); })
1069# define SvPVx(sv, lp) ({SV *nsv = (sv); SvPV(nsv, lp); })
5bc28da9 1070# define SvPVutf8x(sv, lp) ({SV *nsv = (sv); SvPVutf8(nsv, lp); })
1071# define SvPVbytex(sv, lp) ({SV *nsv = (sv); SvPVbyte(nsv, lp); })
a80f87c4 1072# define SvTRUE(sv) ( \
8990e307 1073 !sv \
1074 ? 0 \
1075 : SvPOK(sv) \
a80f87c4 1076 ? (({XPV *nxpv = (XPV*)SvANY(sv); \
1077 nxpv && \
c2f1de04 1078 (nxpv->xpv_cur > 1 || \
a80f87c4 1079 (nxpv->xpv_cur && *nxpv->xpv_pv != '0')); }) \
79072805 1080 ? 1 \
1081 : 0) \
1082 : \
1083 SvIOK(sv) \
463ee0b2 1084 ? SvIVX(sv) != 0 \
79072805 1085 : SvNOK(sv) \
463ee0b2 1086 ? SvNVX(sv) != 0.0 \
1087 : sv_2bool(sv) )
a80f87c4 1088# define SvTRUEx(sv) ({SV *nsv = (sv); SvTRUE(nsv); })
1089#else /* __GNUC__ */
4d1ff10f 1090#ifndef USE_5005THREADS
a80f87c4 1091/* These inlined macros use globals, which will require a thread
1092 * declaration in user code, so we avoid them under threads */
1093
1094# undef SvIVx
1095# undef SvUVx
1096# undef SvNVx
1097# undef SvPVx
5bc28da9 1098# undef SvPVutf8x
1099# undef SvPVbytex
a80f87c4 1100# undef SvTRUE
1101# undef SvTRUEx
6b88bc9c 1102# define SvIVx(sv) ((PL_Sv = (sv)), SvIV(PL_Sv))
1103# define SvUVx(sv) ((PL_Sv = (sv)), SvUV(PL_Sv))
1104# define SvNVx(sv) ((PL_Sv = (sv)), SvNV(PL_Sv))
1105# define SvPVx(sv, lp) ((PL_Sv = (sv)), SvPV(PL_Sv, lp))
5bc28da9 1106# define SvPVutf8x(sv, lp) ((PL_Sv = (sv)), SvPVutf8(PL_Sv, lp))
f83ee824 1107# define SvPVbytex(sv, lp) ((PL_Sv = (sv)), SvPVbyte(PL_Sv, lp))
a80f87c4 1108# define SvTRUE(sv) ( \
1109 !sv \
1110 ? 0 \
1111 : SvPOK(sv) \
6b88bc9c 1112 ? ((PL_Xpv = (XPV*)SvANY(sv)) && \
c2f1de04 1113 (PL_Xpv->xpv_cur > 1 || \
6b88bc9c 1114 (PL_Xpv->xpv_cur && *PL_Xpv->xpv_pv != '0')) \
a80f87c4 1115 ? 1 \
1116 : 0) \
1117 : \
1118 SvIOK(sv) \
1119 ? SvIVX(sv) != 0 \
1120 : SvNOK(sv) \
1121 ? SvNVX(sv) != 0.0 \
1122 : sv_2bool(sv) )
6b88bc9c 1123# define SvTRUEx(sv) ((PL_Sv = (sv)), SvTRUE(PL_Sv))
4d1ff10f 1124#endif /* !USE_5005THREADS */
a80f87c4 1125#endif /* !__GNU__ */
1126#endif /* !CRIPPLED_CC */
79072805 1127
954c1994 1128/*
1129=for apidoc Am|SV*|newRV_inc|SV* sv
1130
1131Creates an RV wrapper for an SV. The reference count for the original SV is
1132incremented.
1133
1134=cut
1135*/
1136
5f05dabc 1137#define newRV_inc(sv) newRV(sv)
5f05dabc 1138
ef50df4b 1139/* the following macros update any magic values this sv is associated with */
79072805 1140
954c1994 1141/*
1142=for apidoc Am|void|SvGETMAGIC|SV* sv
1143Invokes C<mg_get> on an SV if it has 'get' magic. This macro evaluates its
1144argument more than once.
1145
1146=for apidoc Am|void|SvSETMAGIC|SV* sv
1147Invokes C<mg_set> on an SV if it has 'set' magic. This macro evaluates its
1148argument more than once.
1149
1150=for apidoc Am|void|SvSetSV|SV* dsb|SV* ssv
1151Calls C<sv_setsv> if dsv is not the same as ssv. May evaluate arguments
1152more than once.
1153
1154=for apidoc Am|void|SvSetSV_nosteal|SV* dsv|SV* ssv
1155Calls a non-destructive version of C<sv_setsv> if dsv is not the same as
1156ssv. May evaluate arguments more than once.
1157
645c22ef 1158=for apidoc Am|void|SvSetMagicSV|SV* dsb|SV* ssv
1159Like C<SvSetSV>, but does any set magic required afterwards.
1160
1161=for apidoc Am|void|SvSetMagicSV_nosteal|SV* dsv|SV* ssv
1162Like C<SvSetMagicSV>, but does any set magic required afterwards.
1163
679ac26e 1164=for apidoc Am|char *|SvGROW|SV* sv|STRLEN len
954c1994 1165Expands the character buffer in the SV so that it has room for the
1166indicated number of bytes (remember to reserve space for an extra trailing
8cf8f3d1 1167NUL character). Calls C<sv_grow> to perform the expansion if necessary.
954c1994 1168Returns a pointer to the character buffer.
1169
1170=cut
1171*/
1172
189b2af5 1173#define SvGETMAGIC(x) STMT_START { if (SvGMAGICAL(x)) mg_get(x); } STMT_END
1174#define SvSETMAGIC(x) STMT_START { if (SvSMAGICAL(x)) mg_set(x); } STMT_END
79072805 1175
54310121 1176#define SvSetSV_and(dst,src,finally) \
189b2af5 1177 STMT_START { \
54310121 1178 if ((dst) != (src)) { \
1179 sv_setsv(dst, src); \
1180 finally; \
189b2af5 1181 } \
1182 } STMT_END
54310121 1183#define SvSetSV_nosteal_and(dst,src,finally) \
189b2af5 1184 STMT_START { \
8ebc5c01 1185 if ((dst) != (src)) { \
1186 U32 tMpF = SvFLAGS(src) & SVs_TEMP; \
1187 SvTEMP_off(src); \
1188 sv_setsv(dst, src); \
1189 SvFLAGS(src) |= tMpF; \
54310121 1190 finally; \
189b2af5 1191 } \
1192 } STMT_END
79072805 1193
54310121 1194#define SvSetSV(dst,src) \
c9d716f7 1195 SvSetSV_and(dst,src,/*nothing*/;)
54310121 1196#define SvSetSV_nosteal(dst,src) \
c9d716f7 1197 SvSetSV_nosteal_and(dst,src,/*nothing*/;)
54310121 1198
1199#define SvSetMagicSV(dst,src) \
1200 SvSetSV_and(dst,src,SvSETMAGIC(dst))
1201#define SvSetMagicSV_nosteal(dst,src) \
1202 SvSetSV_nosteal_and(dst,src,SvSETMAGIC(dst))
1203
3967c732 1204#ifdef DEBUGGING
79072805 1205#define SvPEEK(sv) sv_peek(sv)
3967c732 1206#else
1207#define SvPEEK(sv) ""
1208#endif
79072805 1209
3280af22 1210#define SvIMMORTAL(sv) ((sv)==&PL_sv_undef || (sv)==&PL_sv_yes || (sv)==&PL_sv_no)
36477c24 1211
3280af22 1212#define boolSV(b) ((b) ? &PL_sv_yes : &PL_sv_no)
54310121 1213
79072805 1214#define isGV(sv) (SvTYPE(sv) == SVt_PVGV)
1215
933fea7f 1216#define SvGROW(sv,len) (SvLEN(sv) < (len) ? sv_grow(sv,len) : SvPVX(sv))
1217#define Sv_Grow sv_grow
3d35f11b 1218
a0739874 1219#define CLONEf_COPY_STACKS 1
1220#define CLONEf_KEEP_PTR_TABLE 2
c43294b8 1221#define CLONEf_CLONE_HOST 4
a0739874 1222
8cf8f3d1 1223struct clone_params {
d2d73c3e 1224 AV* stashes;
1225 UV flags;
8cf8f3d1 1226};