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