xref: /openbsd/gnu/usr.bin/perl/sv.h (revision e0680481)
1 /*    sv.h
2  *
3  *    Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
4  *    2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 by Larry Wall and others
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  *
9  */
10 
11 #ifdef sv_flags
12 #undef sv_flags		/* Convex has this in <signal.h> for sigvec() */
13 #endif
14 
15 /*
16 =for apidoc_section $SV_flags
17 
18 =for apidoc Ay||svtype
19 An enum of flags for Perl types.  These are found in the file F<sv.h>
20 in the C<svtype> enum.  Test these flags with the C<SvTYPE> macro.
21 
22 The types are:
23 
24     SVt_NULL
25     SVt_IV
26     SVt_NV
27     SVt_RV
28     SVt_PV
29     SVt_PVIV
30     SVt_PVNV
31     SVt_PVMG
32     SVt_INVLIST
33     SVt_REGEXP
34     SVt_PVGV
35     SVt_PVLV
36     SVt_PVAV
37     SVt_PVHV
38     SVt_PVCV
39     SVt_PVFM
40     SVt_PVIO
41     SVt_PVOBJ
42 
43 These are most easily explained from the bottom up.
44 
45 C<SVt_PVOBJ> is for object instances of the new `use feature 'class'` kind.
46 C<SVt_PVIO> is for I/O objects, C<SVt_PVFM> for formats, C<SVt_PVCV> for
47 subroutines, C<SVt_PVHV> for hashes and C<SVt_PVAV> for arrays.
48 
49 All the others are scalar types, that is, things that can be bound to a
50 C<$> variable.  For these, the internal types are mostly orthogonal to
51 types in the Perl language.
52 
53 Hence, checking C<< SvTYPE(sv) < SVt_PVAV >> is the best way to see whether
54 something is a scalar.
55 
56 C<SVt_PVGV> represents a typeglob.  If C<!SvFAKE(sv)>, then it is a real,
57 incoercible typeglob.  If C<SvFAKE(sv)>, then it is a scalar to which a
58 typeglob has been assigned.  Assigning to it again will stop it from being
59 a typeglob.  C<SVt_PVLV> represents a scalar that delegates to another scalar
60 behind the scenes.  It is used, e.g., for the return value of C<substr> and
61 for tied hash and array elements.  It can hold any scalar value, including
62 a typeglob.  C<SVt_REGEXP> is for regular
63 expressions.  C<SVt_INVLIST> is for Perl
64 core internal use only.
65 
66 C<SVt_PVMG> represents a "normal" scalar (not a typeglob, regular expression,
67 or delegate).  Since most scalars do not need all the internal fields of a
68 PVMG, we save memory by allocating smaller structs when possible.  All the
69 other types are just simpler forms of C<SVt_PVMG>, with fewer internal fields.
70 C<SVt_NULL> can only hold undef.  C<SVt_IV> can hold undef, an integer, or a
71 reference.  (C<SVt_RV> is an alias for C<SVt_IV>, which exists for backward
72 compatibility.)  C<SVt_NV> can hold undef or a double. (In builds that support
73 headless NVs, these could also hold a reference via a suitable offset, in the
74 same way that SVt_IV does, but this is not currently supported and seems to
75 be a rare use case.) C<SVt_PV> can hold C<undef>, a string, or a reference.
76 C<SVt_PVIV> is a superset of C<SVt_PV> and C<SVt_IV>. C<SVt_PVNV> is a
77 superset of C<SVt_PV> and C<SVt_NV>. C<SVt_PVMG> can hold anything C<SVt_PVNV>
78 can hold, but it may also be blessed or magical.
79 
80 =for apidoc AmnU||SVt_NULL
81 Type flag for scalars.  See L</svtype>.
82 
83 =for apidoc AmnU||SVt_IV
84 Type flag for scalars.  See L</svtype>.
85 
86 =for apidoc AmnU||SVt_NV
87 Type flag for scalars.  See L</svtype>.
88 
89 =for apidoc AmnU||SVt_PV
90 Type flag for scalars.  See L</svtype>.
91 
92 =for apidoc AmnU||SVt_PVIV
93 Type flag for scalars.  See L</svtype>.
94 
95 =for apidoc AmnU||SVt_PVNV
96 Type flag for scalars.  See L</svtype>.
97 
98 =for apidoc AmnU||SVt_PVMG
99 Type flag for scalars.  See L</svtype>.
100 
101 =for apidoc CmnU||SVt_INVLIST
102 Type flag for scalars.  See L<perlapi/svtype>.
103 
104 =for apidoc AmnU||SVt_REGEXP
105 Type flag for regular expressions.  See L</svtype>.
106 
107 =for apidoc AmnU||SVt_PVGV
108 Type flag for typeglobs.  See L</svtype>.
109 
110 =for apidoc AmnU||SVt_PVLV
111 Type flag for scalars.  See L</svtype>.
112 
113 =for apidoc AmnU||SVt_PVAV
114 Type flag for arrays.  See L</svtype>.
115 
116 =for apidoc AmnU||SVt_PVHV
117 Type flag for hashes.  See L</svtype>.
118 
119 =for apidoc AmnU||SVt_PVCV
120 Type flag for subroutines.  See L</svtype>.
121 
122 =for apidoc AmnU||SVt_PVFM
123 Type flag for formats.  See L</svtype>.
124 
125 =for apidoc AmnU||SVt_PVIO
126 Type flag for I/O objects.  See L</svtype>.
127 
128 =for apidoc AmnUx||SVt_PVOBJ
129 Type flag for object instances.  See L</svtype>.
130 
131 =cut
132 
133   These are ordered so that the simpler types have a lower value; SvUPGRADE
134   doesn't allow you to upgrade from a higher numbered type to a lower numbered
135   one; also there is code that assumes that anything that has as a PV component
136   has a type numbered >= SVt_PV.
137 */
138 
139 
140 typedef enum {
141         SVt_NULL,	/* 0 */
142         /* BIND was here, before INVLIST replaced it.  */
143         SVt_IV,		/* 1 */
144         SVt_NV,		/* 2 */
145         /* RV was here, before it was merged with IV.  */
146         SVt_PV,		/* 3 */
147         SVt_INVLIST,	/* 4, implemented as a PV */
148         SVt_PVIV,	/* 5 */
149         SVt_PVNV,	/* 6 */
150         SVt_PVMG,	/* 7 */
151         SVt_REGEXP,	/* 8 */
152         /* PVBM was here, before BIND replaced it.  */
153         SVt_PVGV,	/* 9 */
154         SVt_PVLV,	/* 10 */
155         SVt_PVAV,	/* 11 */
156         SVt_PVHV,	/* 12 */
157         SVt_PVCV,	/* 13 */
158         SVt_PVFM,	/* 14 */
159         SVt_PVIO,	/* 15 */
160         SVt_PVOBJ,      /* 16 */
161                         /* 17-31: Unused, though one should be reserved for a
162                          * freed sv, if the other 3 bits below the flags ones
163                          * get allocated */
164         SVt_LAST	/* keep last in enum. used to size arrays */
165 } svtype;
166 
167 /* *** any alterations to the SV types above need to be reflected in
168  * SVt_MASK and the various PL_valid_types_* tables.  As of this writing those
169  * tables are in perl.h.  There are also two affected names tables in dump.c,
170  * one in B.xs, and 'bodies_by_type[]' in sv_inline.h.
171  *
172  * The bits that match 0xe0 are CURRENTLY UNUSED
173  * The bits above that are for flags, like SVf_IOK */
174 
175 #define SVt_MASK 0x1f	/* smallest bitmask that covers all types */
176 
177 #ifndef PERL_CORE
178 /* Fast Boyer Moore tables are now stored in magic attached to PVMGs */
179 #  define SVt_PVBM	SVt_PVMG
180 /* Anything wanting to create a reference from clean should ensure that it has
181    a scalar of type SVt_IV now:  */
182 #  define SVt_RV	SVt_IV
183 #endif
184 
185 /* The array of arena roots for SV bodies is indexed by SvTYPE. SVt_NULL doesn't
186  * use a body, so that arena root is re-used for HEs. SVt_IV also doesn't, so
187  * that arena root is used for HVs with struct xpvhv_aux. */
188 
189 #if defined(PERL_IN_HV_C) || defined(PERL_IN_XS_APITEST)
190 #  define HE_ARENA_ROOT_IX      SVt_NULL
191 #endif
192 #if defined(PERL_IN_HV_C) || defined(PERL_IN_SV_C)
193 #  define HVAUX_ARENA_ROOT_IX   SVt_IV
194 #endif
195 #ifdef PERL_IN_SV_C
196 #  define SVt_FIRST SVt_NULL	/* the type of SV that new_SV() in sv.c returns */
197 #endif
198 
199 #define PERL_ARENA_ROOTS_SIZE	(SVt_LAST)
200 
201 /* typedefs to eliminate some typing */
202 typedef struct he HE;
203 typedef struct hek HEK;
204 
205 /* Using C's structural equivalence to help emulate C++ inheritance here... */
206 
207 /* start with 2 sv-head building blocks */
208 #define _SV_HEAD(ptrtype) \
209     ptrtype	sv_any;		/* pointer to body */	\
210     U32		sv_refcnt;	/* how many references to us */	\
211     U32		sv_flags	/* what we are */
212 
213 #if NVSIZE <= IVSIZE
214 #  define _NV_BODYLESS_UNION NV svu_nv;
215 #else
216 #  define _NV_BODYLESS_UNION
217 #endif
218 
219 #define _SV_HEAD_UNION \
220     union {				\
221         char*   svu_pv;		/* pointer to malloced string */	\
222         IV      svu_iv;			\
223         UV      svu_uv;			\
224         _NV_BODYLESS_UNION		\
225         SV*     svu_rv;		/* pointer to another SV */		\
226         SV**    svu_array;		\
227         HE**	svu_hash;		\
228         GP*	svu_gp;			\
229         PerlIO *svu_fp;			\
230     }	sv_u				\
231     _SV_HEAD_DEBUG
232 
233 #ifdef DEBUG_LEAKING_SCALARS
234 #define _SV_HEAD_DEBUG ;\
235     PERL_BITFIELD32 sv_debug_optype:9;	/* the type of OP that allocated us */ \
236     PERL_BITFIELD32 sv_debug_inpad:1;	/* was allocated in a pad for an OP */ \
237     PERL_BITFIELD32 sv_debug_line:16;	/* the line where we were allocated */ \
238     UV		    sv_debug_serial;	/* serial number of sv allocation   */ \
239     char *	    sv_debug_file;	/* the file where we were allocated */ \
240     SV *	    sv_debug_parent	/* what we were cloned from (ithreads)*/
241 #else
242 #define _SV_HEAD_DEBUG
243 #endif
244 
245 struct STRUCT_SV {		/* struct sv { */
246     _SV_HEAD(void*);
247     _SV_HEAD_UNION;
248 };
249 
250 struct gv {
251     _SV_HEAD(XPVGV*);		/* pointer to xpvgv body */
252     _SV_HEAD_UNION;
253 };
254 
255 struct cv {
256     _SV_HEAD(XPVCV*);		/* pointer to xpvcv body */
257     _SV_HEAD_UNION;
258 };
259 
260 struct av {
261     _SV_HEAD(XPVAV*);		/* pointer to xpvav body */
262     _SV_HEAD_UNION;
263 };
264 
265 struct hv {
266     _SV_HEAD(XPVHV*);		/* pointer to xpvhv body */
267     _SV_HEAD_UNION;
268 };
269 
270 struct io {
271     _SV_HEAD(XPVIO*);		/* pointer to xpvio body */
272     _SV_HEAD_UNION;
273 };
274 
275 struct p5rx {
276     _SV_HEAD(struct regexp*);	/* pointer to regexp body */
277     _SV_HEAD_UNION;
278 };
279 
280 struct invlist {
281     _SV_HEAD(XINVLIST*);       /* pointer to xpvinvlist body */
282     _SV_HEAD_UNION;
283 };
284 
285 struct object {
286     _SV_HEAD(XPVOBJ*);          /* pointer to xobject body */
287     _SV_HEAD_UNION;
288 };
289 
290 #undef _SV_HEAD
291 #undef _SV_HEAD_UNION		/* ensure no pollution */
292 
293 /*
294 =for apidoc_section $SV
295 
296 =for apidoc Am|U32|SvREFCNT|SV* sv
297 Returns the value of the object's reference count. Exposed
298 to perl code via Internals::SvREFCNT().
299 
300 =for apidoc            SvREFCNT_inc
301 =for apidoc_item       SvREFCNT_inc_NN
302 =for apidoc_item |SV* |SvREFCNT_inc_simple|SV* sv
303 =for apidoc_item |SV* |SvREFCNT_inc_simple_NN|SV* sv
304 =for apidoc_item |void|SvREFCNT_inc_simple_void|SV* sv
305 =for apidoc_item |void|SvREFCNT_inc_simple_void_NN|SV* sv
306 =for apidoc_item       SvREFCNT_inc_void
307 =for apidoc_item |void|SvREFCNT_inc_void_NN|SV* sv
308 
309 These all increment the reference count of the given SV.
310 The ones without C<void> in their names return the SV.
311 
312 C<SvREFCNT_inc> is the base operation; the rest are optimizations if various
313 input constraints are known to be true; hence, all can be replaced with
314 C<SvREFCNT_inc>.
315 
316 C<SvREFCNT_inc_NN> can only be used if you know C<sv> is not C<NULL>.  Since we
317 don't have to check the NULLness, it's faster and smaller.
318 
319 C<SvREFCNT_inc_void> can only be used if you don't need the
320 return value.  The macro doesn't need to return a meaningful value.
321 
322 C<SvREFCNT_inc_void_NN> can only be used if you both don't need the return
323 value, and you know that C<sv> is not C<NULL>.  The macro doesn't need to
324 return a meaningful value, or check for NULLness, so it's smaller and faster.
325 
326 C<SvREFCNT_inc_simple> can only be used with expressions without side
327 effects.  Since we don't have to store a temporary value, it's faster.
328 
329 C<SvREFCNT_inc_simple_NN> can only be used with expressions without side
330 effects and you know C<sv> is not C<NULL>.  Since we don't have to store a
331 temporary value, nor check for NULLness, it's faster and smaller.
332 
333 C<SvREFCNT_inc_simple_void> can only be used with expressions without side
334 effects and you don't need the return value.
335 
336 C<SvREFCNT_inc_simple_void_NN> can only be used with expressions without side
337 effects, you don't need the return value, and you know C<sv> is not C<NULL>.
338 
339 =for apidoc      SvREFCNT_dec
340 =for apidoc_item SvREFCNT_dec_set_NULL
341 =for apidoc_item SvREFCNT_dec_ret_NULL
342 =for apidoc_item SvREFCNT_dec_NN
343 
344 These decrement the reference count of the given SV.
345 
346 C<SvREFCNT_dec_NN> may only be used when C<sv> is known to not be C<NULL>.
347 
348 The function C<SvREFCNT_dec_ret_NULL()> is identical to the
349 C<SvREFCNT_dec()> except it returns a NULL C<SV *>.  It is used by
350 C<SvREFCNT_dec_set_NULL()> which is a macro which will, when passed a
351 non-NULL argument, decrement the reference count of its argument and
352 then set it to NULL. You can replace code of the following form:
353 
354     if (sv) {
355        SvREFCNT_dec_NN(sv);
356        sv = NULL;
357     }
358 
359 with
360 
361     SvREFCNT_dec_set_NULL(sv);
362 
363 =for apidoc Am|svtype|SvTYPE|SV* sv
364 Returns the type of the SV.  See C<L</svtype>>.
365 
366 =for apidoc Am|void|SvUPGRADE|SV* sv|svtype type
367 Used to upgrade an SV to a more complex form.  Uses C<sv_upgrade> to
368 perform the upgrade if necessary.  See C<L</svtype>>.
369 
370 =cut
371 */
372 
373 #define SvANY(sv)	(sv)->sv_any
374 #define SvFLAGS(sv)	(sv)->sv_flags
375 #define SvREFCNT(sv)	(sv)->sv_refcnt
376 
377 #define SvREFCNT_inc(sv)		Perl_SvREFCNT_inc(MUTABLE_SV(sv))
378 #define SvREFCNT_inc_simple(sv)		SvREFCNT_inc(sv)
379 #define SvREFCNT_inc_NN(sv)		Perl_SvREFCNT_inc_NN(MUTABLE_SV(sv))
380 #define SvREFCNT_inc_void(sv)		Perl_SvREFCNT_inc_void(MUTABLE_SV(sv))
381 
382 /* These guys don't need the curly blocks */
383 #define SvREFCNT_inc_simple_void(sv)	                                \
384         STMT_START {                                                    \
385             SV * sv_ = MUTABLE_SV(sv);                                  \
386             if (sv_)                                                    \
387                 SvREFCNT(sv_)++;                                        \
388         } STMT_END
389 
390 #define SvREFCNT_inc_simple_NN(sv)	(++(SvREFCNT(sv)),MUTABLE_SV(sv))
391 #define SvREFCNT_inc_void_NN(sv)	(void)(++SvREFCNT(MUTABLE_SV(sv)))
392 #define SvREFCNT_inc_simple_void_NN(sv)	(void)(++SvREFCNT(MUTABLE_SV(sv)))
393 
394 #define SvREFCNT_dec(sv)	Perl_SvREFCNT_dec(aTHX_ MUTABLE_SV(sv))
395 #define SvREFCNT_dec_set_NULL(sv)                               \
396     STMT_START {                                                \
397         sv = Perl_SvREFCNT_dec_ret_NULL(aTHX_ MUTABLE_SV(sv));  \
398     } STMT_END
399 #define SvREFCNT_dec_NN(sv)	Perl_SvREFCNT_dec_NN(aTHX_ MUTABLE_SV(sv))
400 
401 #define SVTYPEMASK	0xff
402 #define SvTYPE(sv)	((svtype)((sv)->sv_flags & SVTYPEMASK))
403 
404 /* Sadly there are some parts of the core that have pointers to already-freed
405    SV heads, and rely on being able to tell that they are now free. So mark
406    them all by using a consistent macro.  */
407 #define SvIS_FREED(sv)	UNLIKELY(((sv)->sv_flags == SVTYPEMASK))
408 
409 /* this is defined in this peculiar way to avoid compiler warnings.
410  * See the <20121213131428.GD1842@iabyn.com> thread in p5p */
411 #define SvUPGRADE(sv, mt) \
412     ((void)(SvTYPE(sv) >= (mt) || (sv_upgrade(sv, mt),1)))
413 
414 #define SVf_IOK		0x00000100  /* has valid public integer value */
415 #define SVf_NOK		0x00000200  /* has valid public numeric value */
416 #define SVf_POK		0x00000400  /* has valid public pointer value */
417 #define SVf_ROK		0x00000800  /* has a valid reference pointer */
418 
419 #define SVp_IOK		0x00001000  /* has valid non-public integer value */
420 #define SVp_NOK		0x00002000  /* has valid non-public numeric value */
421 #define SVp_POK		0x00004000  /* has valid non-public pointer value */
422 #define SVp_SCREAM	0x00008000  /* currently unused on plain scalars */
423 #define SVphv_CLONEABLE	SVp_SCREAM  /* PVHV (stashes) clone its objects */
424 #define SVpgv_GP	SVp_SCREAM  /* GV has a valid GP */
425 #define SVprv_PCS_IMPORTED  SVp_SCREAM  /* RV is a proxy for a constant
426                                        subroutine in another package. Set the
427                                        GvIMPORTED_CV_on() if it needs to be
428                                        expanded to a real GV */
429 
430 /* SVf_PROTECT is what SVf_READONLY should have been: i.e. modifying
431  * this SV is completely illegal. However, SVf_READONLY (via
432  * Internals::SvREADONLY()) has come to be seen as a flag that can be
433  * temporarily set and unset by the user to indicate e.g. whether a hash
434  * is "locked". Now, Hash::Util et al only set SVf_READONLY, while core
435  * sets both (SVf_READONLY|SVf_PROTECT) to indicate both to core and user
436  * code that this SV should not be messed with.
437  */
438 #define SVf_PROTECT	0x00010000  /* very read-only */
439 #define SVs_PADTMP	0x00020000  /* in use as tmp */
440 #define SVs_PADSTALE	0x00040000  /* lexical has gone out of scope;
441                                         only used when !PADTMP */
442 #define SVs_TEMP	0x00080000  /* mortal (implies string is stealable) */
443 #define SVs_OBJECT	0x00100000  /* is "blessed" */
444 #define SVs_GMG		0x00200000  /* has magical get method */
445 #define SVs_SMG		0x00400000  /* has magical set method */
446 #define SVs_RMG		0x00800000  /* has random magical methods */
447 
448 #define SVf_FAKE	0x01000000  /* 0: glob is just a copy
449                                        1: SV head arena wasn't malloc()ed
450                                        2: For PVCV, whether CvUNIQUE(cv)
451                                           refers to an eval or once only
452                                           [CvEVAL(cv), CvSPECIAL(cv)]
453                                        3: HV: informally reserved by DAPM
454                                           for vtables
455                                        4: Together with other flags (or
456                                            lack thereof) indicates a regex,
457                                            including PVLV-as-regex. See
458                                            isREGEXP().
459                                        */
460 #define SVf_OOK		0x02000000  /* has valid offset value */
461 #define SVphv_HasAUX    SVf_OOK     /* PVHV has an additional hv_aux struct */
462 #define SVf_BREAK	0x04000000  /* refcnt is artificially low - used by
463                                        SVs in final arena cleanup.
464                                        Set in S_regtry on PL_reg_curpm, so that
465                                        perl_destruct will skip it.
466                                        Used for mark and sweep by OP_AASSIGN
467                                        */
468 #define SVf_READONLY	0x08000000  /* may not be modified */
469 
470 
471 
472 
473 #define SVf_THINKFIRST	(SVf_READONLY|SVf_PROTECT|SVf_ROK|SVf_FAKE \
474                         |SVs_RMG|SVf_IsCOW)
475 
476 #define SVf_OK		(SVf_IOK|SVf_NOK|SVf_POK|SVf_ROK| \
477                          SVp_IOK|SVp_NOK|SVp_POK|SVpgv_GP)
478 
479 #define PRIVSHIFT 4	/* (SVp_?OK >> PRIVSHIFT) == SVf_?OK */
480 
481 /* SVf_AMAGIC means that the stash *may* have overload methods. It's
482  * set each time a function is compiled into a stash, and is reset by the
483  * overload code when called for the first time and finds that there are
484  * no overload methods. Note that this used to be set on the object; but
485  * is now only set on stashes.
486  */
487 #define SVf_AMAGIC	0x10000000  /* has magical overloaded methods */
488 #define SVf_IsCOW	0x10000000  /* copy on write (shared hash key if
489                                        SvLEN == 0) */
490 
491 /* Ensure this value does not clash with the GV_ADD* flags in gv.h, or the
492    CV_CKPROTO_* flags in op.c, or the padadd_* flags in pad.h: */
493 #define SVf_UTF8        0x20000000  /* SvPV is UTF-8 encoded
494                                        This is also set on RVs whose overloaded
495                                        stringification is UTF-8. This might
496                                        only happen as a side effect of SvPV() */
497 /* PVHV */
498 #define SVphv_SHAREKEYS 0x20000000  /* PVHV keys live on shared string table */
499 
500 /* PVAV could probably use 0x2000000 without conflict. I assume that PVFM can
501    be UTF-8 encoded, and PVCVs could well have UTF-8 prototypes. PVIOs haven't
502    been restructured, so sometimes get used as string buffers.  */
503 
504 
505 /* Some private flags. */
506 
507 
508 /* scalar SVs with SVp_POK */
509 #define SVppv_STATIC    0x40000000 /* PV is pointer to static const; must be set with SVf_IsCOW */
510 /* PVAV */
511 #define SVpav_REAL	0x40000000  /* free old entries */
512 /* PVHV */
513 #define SVphv_LAZYDEL	0x40000000  /* entry in xhv_eiter must be deleted */
514 
515 /* IV, PVIV, PVNV, PVMG, PVGV and (I assume) PVLV  */
516 #define SVf_IVisUV	0x80000000  /* use XPVUV instead of XPVIV */
517 /* PVAV */
518 #define SVpav_REIFY 	0x80000000  /* can become real */
519 /* PVHV */
520 #define SVphv_HASKFLAGS	0x80000000  /* keys have flag byte after hash */
521 /* RV upwards. However, SVf_ROK and SVp_IOK are exclusive  */
522 #define SVprv_WEAKREF   0x80000000  /* Weak reference */
523 /* pad name vars only */
524 
525 #define _XPV_HEAD							\
526     HV*		xmg_stash;	/* class package */			\
527     union _xmgu	xmg_u;							\
528     STRLEN	xpv_cur;	/* length of svu_pv as a C string */    \
529     union {								\
530         STRLEN	xpvlenu_len; 	/* allocated size */			\
531         struct regexp* xpvlenu_rx; /* regex when SV body is XPVLV */    \
532     } xpv_len_u
533 
534 #define xpv_len	xpv_len_u.xpvlenu_len
535 
536 union _xnvu {
537     NV	    xnv_nv;		/* numeric value, if any */
538     HV *    xgv_stash;
539     line_t  xnv_lines;           /* used internally by S_scan_subst() */
540     bool    xnv_bm_tail;        /* an SvVALID (BM) SV has an implicit "\n" */
541 };
542 
543 union _xivu {
544     IV	    xivu_iv;		/* integer value */
545     UV	    xivu_uv;
546     HEK *   xivu_namehek;	/* xpvlv, xpvgv: GvNAME */
547     bool    xivu_eval_seen;     /* used internally by S_scan_subst() */
548 
549 };
550 
551 union _xmgu {
552     MAGIC*  xmg_magic;		/* linked list of magicalness */
553     STRLEN  xmg_hash_index;	/* used while freeing hash entries */
554 };
555 
556 struct xpv {
557     _XPV_HEAD;
558 };
559 
560 struct xpviv {
561     _XPV_HEAD;
562     union _xivu xiv_u;
563 };
564 
565 #define xiv_iv xiv_u.xivu_iv
566 
567 struct xpvuv {
568     _XPV_HEAD;
569     union _xivu xuv_u;
570 };
571 
572 #define xuv_uv xuv_u.xivu_uv
573 
574 struct xpvnv {
575     _XPV_HEAD;
576     union _xivu xiv_u;
577     union _xnvu xnv_u;
578 };
579 
580 /* This structure must match the beginning of struct xpvhv in hv.h. */
581 struct xpvmg {
582     _XPV_HEAD;
583     union _xivu xiv_u;
584     union _xnvu xnv_u;
585 };
586 
587 struct xpvlv {
588     _XPV_HEAD;
589     union _xivu xiv_u;
590     union _xnvu xnv_u;
591     union {
592         STRLEN	xlvu_targoff;
593         SSize_t xlvu_stargoff;
594     } xlv_targoff_u;
595     STRLEN	xlv_targlen;
596     SV*		xlv_targ;
597     char	xlv_type;	/* k=keys .=pos x=substr v=vec /=join/re
598                                  * y=alem/helem/iter t=tie T=tied HE */
599     char	xlv_flags;	/* 1 = negative offset  2 = negative len
600                                    4 = out of range (vec) */
601 };
602 
603 #define xlv_targoff xlv_targoff_u.xlvu_targoff
604 
605 struct xpvinvlist {
606     _XPV_HEAD;
607     IV          prev_index;     /* caches result of previous invlist_search() */
608     STRLEN	iterator;       /* Stores where we are in iterating */
609     bool	is_offset;	/* The data structure for all inversion lists
610                                    begins with an element for code point U+0000.
611                                    If this bool is set, the actual list contains
612                                    that 0; otherwise, the list actually begins
613                                    with the following element.  Thus to invert
614                                    the list, merely toggle this flag  */
615 };
616 
617 /* This structure works in 2 ways - regular scalar, or GV with GP */
618 
619 struct xpvgv {
620     _XPV_HEAD;
621     union _xivu xiv_u;
622     union _xnvu xnv_u;
623 };
624 
625 typedef U32 cv_flags_t;
626 
627 #define _XPVCV_COMMON								\
628     HV *	xcv_stash;							\
629     union {									\
630         OP *	xcv_start;							\
631         ANY	xcv_xsubany;							\
632     }		xcv_start_u;					    		\
633     union {									\
634         OP *	xcv_root;							\
635         void	(*xcv_xsub) (pTHX_ CV*);					\
636     }		xcv_root_u;							\
637     union {								\
638         GV *	xcv_gv;							\
639         HEK *	xcv_hek;						\
640     }		xcv_gv_u;						\
641     char *	xcv_file;							\
642     union {									\
643         PADLIST *	xcv_padlist;						\
644         void *		xcv_hscxt;						\
645     }		xcv_padlist_u;							\
646     CV *	xcv_outside;							\
647     U32		xcv_outside_seq; /* the COP sequence (at the point of our	\
648                                   * compilation) in the lexically enclosing	\
649                                   * sub */					\
650     cv_flags_t	xcv_flags;						\
651     I32	xcv_depth	/* >= 2 indicates recursive call */
652 
653 /* This structure must match XPVCV in cv.h */
654 
655 struct xpvfm {
656     _XPV_HEAD;
657     _XPVCV_COMMON;
658 };
659 
660 
661 struct xpvio {
662     _XPV_HEAD;
663     union _xivu xiv_u;
664     /* ifp and ofp are normally the same, but sockets need separate streams */
665     PerlIO *	xio_ofp;
666     /* Cray addresses everything by word boundaries (64 bits) and
667      * code and data pointers cannot be mixed (which is exactly what
668      * Perl_filter_add() tries to do with the dirp), hence the
669      *  following union trick (as suggested by Gurusamy Sarathy).
670      * For further information see Geir Johansen's problem report
671      * titled [ID 20000612.002 (#3366)] Perl problem on Cray system
672      * The any pointer (known as IoANY()) will also be a good place
673      * to hang any IO disciplines to.
674      */
675     union {
676         DIR *	xiou_dirp;	/* for opendir, readdir, etc */
677         void *	xiou_any;	/* for alignment */
678     } xio_dirpu;
679     /* IV xio_lines is now in IVX  $. */
680     IV		xio_page;	/* $% */
681     IV		xio_page_len;	/* $= */
682     IV		xio_lines_left;	/* $- */
683     char *	xio_top_name;	/* $^ */
684     GV *	xio_top_gv;	/* $^ */
685     char *	xio_fmt_name;	/* $~ */
686     GV *	xio_fmt_gv;	/* $~ */
687     char *	xio_bottom_name;/* $^B */
688     GV *	xio_bottom_gv;	/* $^B */
689     char	xio_type;
690     U8		xio_flags;
691 };
692 
693 #define xio_dirp	xio_dirpu.xiou_dirp
694 #define xio_any		xio_dirpu.xiou_any
695 
696 #define IOf_ARGV	1	/* this fp iterates over ARGV */
697 #define IOf_START	2	/* check for null ARGV and substitute '-' */
698 #define IOf_FLUSH	4	/* this fp wants a flush after write op */
699 #define IOf_DIDTOP	8	/* just did top of form */
700 #define IOf_UNTAINT	16	/* consider this fp (and its data) "safe" */
701 #define IOf_NOLINE	32	/* slurped a pseudo-line from empty file */
702 #define IOf_FAKE_DIRP	64	/* xio_dirp is fake (source filters kludge)
703                                    Also, when this is set, SvPVX() is valid */
704 
705 struct xobject {
706     HV*         xmg_stash;
707     union _xmgu xmg_u;
708     SSize_t     xobject_maxfield;
709     SSize_t     xobject_iter_sv_at; /* this is only used by Perl_sv_clear() */
710     SV**        xobject_fields;
711 };
712 
713 #define ObjectMAXFIELD(inst)  ((XPVOBJ *)SvANY(inst))->xobject_maxfield
714 #define ObjectITERSVAT(inst)  ((XPVOBJ *)SvANY(inst))->xobject_iter_sv_at
715 #define ObjectFIELDS(inst)    ((XPVOBJ *)SvANY(inst))->xobject_fields
716 
717 /* The following macros define implementation-independent predicates on SVs. */
718 
719 /*
720 =for apidoc Am|U32|SvNIOK|SV* sv
721 Returns a U32 value indicating whether the SV contains a number, integer or
722 double.
723 
724 =for apidoc Am|U32|SvNIOKp|SV* sv
725 Returns a U32 value indicating whether the SV contains a number, integer or
726 double.  Checks the B<private> setting.  Use C<SvNIOK> instead.
727 
728 =for apidoc Am|void|SvNIOK_off|SV* sv
729 Unsets the NV/IV status of an SV.
730 
731 =for apidoc Am|U32|SvOK|SV* sv
732 Returns a U32 value indicating whether the value is defined.  This is
733 only meaningful for scalars.
734 
735 =for apidoc Am|U32|SvIOKp|SV* sv
736 Returns a U32 value indicating whether the SV contains an integer.  Checks
737 the B<private> setting.  Use C<SvIOK> instead.
738 
739 =for apidoc Am|U32|SvNOKp|SV* sv
740 Returns a U32 value indicating whether the SV contains a double.  Checks the
741 B<private> setting.  Use C<SvNOK> instead.
742 
743 =for apidoc Am|U32|SvPOKp|SV* sv
744 Returns a U32 value indicating whether the SV contains a character string.
745 Checks the B<private> setting.  Use C<SvPOK> instead.
746 
747 =for apidoc Am|U32|SvIOK|SV* sv
748 Returns a U32 value indicating whether the SV contains an integer.
749 
750 =for apidoc Am|void|SvIOK_on|SV* sv
751 Tells an SV that it is an integer.
752 
753 =for apidoc Am|void|SvIOK_off|SV* sv
754 Unsets the IV status of an SV.
755 
756 =for apidoc Am|void|SvIOK_only|SV* sv
757 Tells an SV that it is an integer and disables all other C<OK> bits.
758 
759 =for apidoc Am|void|SvIOK_only_UV|SV* sv
760 Tells an SV that it is an unsigned integer and disables all other C<OK> bits.
761 
762 =for apidoc Am|bool|SvIOK_UV|SV* sv
763 Returns a boolean indicating whether the SV contains an integer that must be
764 interpreted as unsigned.  A non-negative integer whose value is within the
765 range of both an IV and a UV may be flagged as either C<SvUOK> or C<SvIOK>.
766 
767 =for apidoc Am|bool|SvUOK|SV* sv
768 Returns a boolean indicating whether the SV contains an integer that must be
769 interpreted as unsigned.  A non-negative integer whose value is within the
770 range of both an IV and a UV may be flagged as either C<SvUOK> or C<SvIOK>.
771 
772 =for apidoc Am|bool|SvIOK_notUV|SV* sv
773 Returns a boolean indicating whether the SV contains a signed integer.
774 
775 =for apidoc Am|U32|SvNOK|SV* sv
776 Returns a U32 value indicating whether the SV contains a double.
777 
778 =for apidoc Am|void|SvNOK_on|SV* sv
779 Tells an SV that it is a double.
780 
781 =for apidoc Am|void|SvNOK_off|SV* sv
782 Unsets the NV status of an SV.
783 
784 =for apidoc Am|void|SvNOK_only|SV* sv
785 Tells an SV that it is a double and disables all other OK bits.
786 
787 =for apidoc Am|U32|SvPOK|SV* sv
788 Returns a U32 value indicating whether the SV contains a character
789 string.
790 
791 =for apidoc Am|void|SvPOK_on|SV* sv
792 Tells an SV that it is a string.
793 
794 =for apidoc Am|void|SvPOK_off|SV* sv
795 Unsets the PV status of an SV.
796 
797 =for apidoc Am|void|SvPOK_only|SV* sv
798 Tells an SV that it is a string and disables all other C<OK> bits.
799 Will also turn off the UTF-8 status.
800 
801 =for apidoc Am|U32|SvBoolFlagsOK|SV* sv
802 Returns a bool indicating whether the SV has the right flags set such
803 that it is safe to call C<BOOL_INTERNALS_sv_isbool()> or
804 C<BOOL_INTERNALS_sv_isbool_true()> or
805 C<BOOL_INTERNALS_sv_isbool_false()>. Currently equivalent to
806 C<SvIandPOK(sv)> or C<SvIOK(sv) && SvPOK(sv)>. Serialization may want to
807 unroll this check. If so you are strongly recommended to add code like
808 C<assert(SvBoolFlagsOK(sv));> B<before> calling using any of the
809 BOOL_INTERNALS macros.
810 
811 =for apidoc Am|U32|SvIandPOK|SV* sv
812 Returns a bool indicating whether the SV is both C<SvPOK()> and
813 C<SvIOK()> at the same time. Equivalent to C<SvIOK(sv) && SvPOK(sv)> but
814 more efficient.
815 
816 =for apidoc Am|void|SvIandPOK_on|SV* sv
817 Tells an SV that is a string and a number in one operation. Equivalent
818 to C<SvIOK_on(sv); SvPOK_on(sv);> but more efficient.
819 
820 =for apidoc Am|void|SvIandPOK_off|SV* sv
821 Unsets the PV and IV status of an SV in one operation. Equivalent to
822 C<SvIOK_off(sv); SvPK_off(v);> but more efficient.
823 
824 =for apidoc Am|bool|BOOL_INTERNALS_sv_isbool|SV* sv
825 Checks if a C<SvBoolFlagsOK()> sv is a bool. B<Note> that it is the
826 caller's responsibility to ensure that the sv is C<SvBoolFlagsOK()> before
827 calling this. This is only useful in specialized logic like
828 serialization code where performance is critical and the flags have
829 already been checked to be correct. Almost always you should be using
830 C<sv_isbool(sv)> instead.
831 
832 =for apidoc Am|bool|BOOL_INTERNALS_sv_isbool_true|SV* sv
833 Checks if a C<SvBoolFlagsOK()> sv is a true bool. B<Note> that it is
834 the caller's responsibility to ensure that the sv is C<SvBoolFlagsOK()>
835 before calling this. This is only useful in specialized logic like
836 serialization code where performance is critical and the flags have
837 already been checked to be correct. This is B<NOT> what you should use
838 to check if an SV is "true", for that you should be using
839 C<SvTRUE(sv)> instead.
840 
841 =for apidoc Am|bool|BOOL_INTERNALS_sv_isbool_false|SV* sv
842 Checks if a C<SvBoolFlagsOK()> sv is a false bool. B<Note> that it is
843 the caller's responsibility to ensure that the sv is C<SvBoolFlagsOK()>
844 before calling this. This is only useful in specialized logic like
845 serialization code where performance is critical and the flags have
846 already been checked to be correct. This is B<NOT> what you should use
847 to check if an SV is "false", for that you should be using
848 C<!SvTRUE(sv)> instead.
849 
850 =for apidoc Am|bool|SvVOK|SV* sv
851 Returns a boolean indicating whether the SV contains a v-string.
852 
853 =for apidoc Am|U32|SvOOK|SV* sv
854 Returns a U32 indicating whether the pointer to the string buffer is offset.
855 This hack is used internally to speed up removal of characters from the
856 beginning of a C<L</SvPV>>.  When C<SvOOK> is true, then the start of the
857 allocated string buffer is actually C<SvOOK_offset()> bytes before C<SvPVX>.
858 This offset used to be stored in C<SvIVX>, but is now stored within the spare
859 part of the buffer.
860 
861 =for apidoc Am|U32|SvROK|SV* sv
862 Tests if the SV is an RV.
863 
864 =for apidoc Am|void|SvROK_on|SV* sv
865 Tells an SV that it is an RV.
866 
867 =for apidoc Am|void|SvROK_off|SV* sv
868 Unsets the RV status of an SV.
869 
870 =for apidoc Am|SV*|SvRV|SV* sv
871 Dereferences an RV to return the SV.
872 
873 =for apidoc Am|IV|SvIVX|SV* sv
874 Returns the raw value in the SV's IV slot, without checks or conversions.
875 Only use when you are sure C<SvIOK> is true.  See also C<L</SvIV>>.
876 
877 =for apidoc Am|UV|SvUVX|SV* sv
878 Returns the raw value in the SV's UV slot, without checks or conversions.
879 Only use when you are sure C<SvIOK> is true.  See also C<L</SvUV>>.
880 
881 =for apidoc AmD|UV|SvUVXx|SV* sv
882 This is an unnecessary synonym for L</SvUVX>
883 
884 =for apidoc Am|NV|SvNVX|SV* sv
885 Returns the raw value in the SV's NV slot, without checks or conversions.
886 Only use when you are sure C<SvNOK> is true.  See also C<L</SvNV>>.
887 
888 =for apidoc Am   |char*      |SvPVX|SV* sv
889 =for apidoc_item |const char*|SvPVX_const|SV* sv
890 =for apidoc_item |char*      |SvPVX_mutable|SV* sv
891 =for apidoc_item |char*      |SvPVXx|SV* sv
892 
893 These return a pointer to the physical string in the SV.  The SV must contain a
894 string.  Prior to 5.9.3 it is not safe to execute these unless the SV's
895 type >= C<SVt_PV>.
896 
897 These are also used to store the name of an autoloaded subroutine in an XS
898 AUTOLOAD routine.  See L<perlguts/Autoloading with XSUBs>.
899 
900 C<SvPVXx> is identical to C<SvPVX>.
901 
902 C<SvPVX_mutable> is merely a synonym for C<SvPVX>, but its name emphasizes that
903 the string is modifiable by the caller.
904 
905 C<SvPVX_const> differs in that the return value has been cast so that the
906 compiler will complain if you were to try to modify the contents of the string,
907 (unless you cast away const yourself).
908 
909 =for apidoc Am|STRLEN|SvCUR|SV* sv
910 Returns the length, in bytes, of the PV inside the SV.
911 Note that this may not match Perl's C<length>; for that, use
912 C<sv_len_utf8(sv)>. See C<L</SvLEN>> also.
913 
914 =for apidoc Am|STRLEN|SvLEN|SV* sv
915 Returns the size of the string buffer in the SV, not including any part
916 attributable to C<SvOOK>.  See C<L</SvCUR>>.
917 
918 =for apidoc Am|char*|SvEND|SV* sv
919 Returns a pointer to the spot just after the last character in
920 the string which is in the SV, where there is usually a trailing
921 C<NUL> character (even though Perl scalars do not strictly require it).
922 See C<L</SvCUR>>.  Access the character as C<*(SvEND(sv))>.
923 
924 Warning: If C<SvCUR> is equal to C<SvLEN>, then C<SvEND> points to
925 unallocated memory.
926 
927 =for apidoc Am|HV*|SvSTASH|SV* sv
928 Returns the stash of the SV.
929 
930 =for apidoc Am|void|SvIV_set|SV* sv|IV val
931 Set the value of the IV pointer in sv to val.  It is possible to perform
932 the same function of this macro with an lvalue assignment to C<SvIVX>.
933 With future Perls, however, it will be more efficient to use
934 C<SvIV_set> instead of the lvalue assignment to C<SvIVX>.
935 
936 =for apidoc Am|void|SvNV_set|SV* sv|NV val
937 Set the value of the NV pointer in C<sv> to val.  See C<L</SvIV_set>>.
938 
939 =for apidoc Am|void|SvPV_set|SV* sv|char* val
940 This is probably not what you want to use, you probably wanted
941 L</sv_usepvn_flags> or L</sv_setpvn> or L</sv_setpvs>.
942 
943 Set the value of the PV pointer in C<sv> to the Perl allocated
944 C<NUL>-terminated string C<val>.  See also C<L</SvIV_set>>.
945 
946 Remember to free the previous PV buffer. There are many things to check.
947 Beware that the existing pointer may be involved in copy-on-write or other
948 mischief, so do C<SvOOK_off(sv)> and use C<sv_force_normal> or
949 C<SvPV_force> (or check the C<SvIsCOW> flag) first to make sure this
950 modification is safe. Then finally, if it is not a COW, call
951 C<L</SvPV_free>> to free the previous PV buffer.
952 
953 =for apidoc Am|void|SvUV_set|SV* sv|UV val
954 Set the value of the UV pointer in C<sv> to val.  See C<L</SvIV_set>>.
955 
956 =for apidoc Am|void|SvRV_set|SV* sv|SV* val
957 Set the value of the RV pointer in C<sv> to val.  See C<L</SvIV_set>>.
958 
959 =for apidoc Am|void|SvMAGIC_set|SV* sv|MAGIC* val
960 Set the value of the MAGIC pointer in C<sv> to val.  See C<L</SvIV_set>>.
961 
962 =for apidoc Am|void|SvSTASH_set|SV* sv|HV* val
963 Set the value of the STASH pointer in C<sv> to val.  See C<L</SvIV_set>>.
964 
965 =for apidoc Am|void|SvCUR_set|SV* sv|STRLEN len
966 Sets the current length, in bytes, of the C string which is in the SV.
967 See C<L</SvCUR>> and C<SvIV_set>>.
968 
969 =for apidoc Am|void|SvLEN_set|SV* sv|STRLEN len
970 Set the size of the string buffer for the SV. See C<L</SvLEN>>.
971 
972 =cut
973 */
974 
975 #define SvNIOK(sv)		(SvFLAGS(sv) & (SVf_IOK|SVf_NOK))
976 #define SvNIOKp(sv)		(SvFLAGS(sv) & (SVp_IOK|SVp_NOK))
977 #define SvNIOK_off(sv)		(SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK| \
978                                                   SVp_IOK|SVp_NOK|SVf_IVisUV))
979 
980 #define assert_not_ROK(sv)	assert_(!SvROK(sv) || !SvRV(sv))
981 #define assert_not_glob(sv)	assert_(!isGV_with_GP(sv))
982 
983 #define SvOK(sv)		(SvFLAGS(sv) & SVf_OK)
984 #define SvOK_off(sv)		(assert_not_ROK(sv) assert_not_glob(sv)	\
985                                  SvFLAGS(sv) &=	~(SVf_OK|		\
986                                                   SVf_IVisUV|SVf_UTF8),	\
987                                                         SvOOK_off(sv))
988 #define SvOK_off_exc_UV(sv)	(assert_not_ROK(sv)			\
989                                  SvFLAGS(sv) &=	~(SVf_OK|		\
990                                                   SVf_UTF8),		\
991                                                         SvOOK_off(sv))
992 
993 #define SvOKp(sv)		(SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK))
994 #define SvIOKp(sv)		(SvFLAGS(sv) & SVp_IOK)
995 #define SvIOKp_on(sv)		(assert_not_glob(sv)	\
996                                     SvFLAGS(sv) |= SVp_IOK)
997 #define SvNOKp(sv)		(SvFLAGS(sv) & SVp_NOK)
998 #define SvNOKp_on(sv)		(assert_not_glob(sv) SvFLAGS(sv) |= SVp_NOK)
999 #define SvPOKp(sv)		(SvFLAGS(sv) & SVp_POK)
1000 #define SvPOKp_on(sv)		(assert_not_ROK(sv) assert_not_glob(sv)	\
1001                                  SvFLAGS(sv) |= SVp_POK)
1002 
1003 #define SvIOK(sv)		(SvFLAGS(sv) & SVf_IOK)
1004 #define SvIOK_on(sv)		(assert_not_glob(sv)	\
1005                                     SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
1006 #define SvIOK_off(sv)		(SvFLAGS(sv) &= ~(SVf_IOK|SVp_IOK|SVf_IVisUV))
1007 #define SvIOK_only(sv)		(SvOK_off(sv), \
1008                                     SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
1009 #define SvIOK_only_UV(sv)	(assert_not_glob(sv) SvOK_off_exc_UV(sv), \
1010                                     SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
1011 
1012 #define SvIOK_UV(sv)		((SvFLAGS(sv) & (SVf_IOK|SVf_IVisUV))	\
1013                                  == (SVf_IOK|SVf_IVisUV))
1014 #define SvUOK(sv)		SvIOK_UV(sv)
1015 #define SvIOK_notUV(sv)		((SvFLAGS(sv) & (SVf_IOK|SVf_IVisUV))	\
1016                                  == SVf_IOK)
1017 
1018 #define SvIandPOK(sv)              ((SvFLAGS(sv) & (SVf_IOK|SVf_POK)) == (SVf_IOK|SVf_POK))
1019 #define SvIandPOK_on(sv)           (assert_not_glob(sv) \
1020                                     (SvFLAGS(sv) |= (SVf_IOK|SVp_IOK|SVf_POK|SVp_POK)))
1021 #define SvIandPOK_off(sv)          (SvFLAGS(sv) &= ~(SVf_IOK|SVp_IOK|SVf_IVisUV|SVf_POK|SVp_POK))
1022 
1023 #define SvBoolFlagsOK(sv)           SvIandPOK(sv)
1024 
1025 #define BOOL_INTERNALS_sv_isbool(sv)      (SvIsCOW_static(sv) && \
1026         (SvPVX_const(sv) == PL_Yes || SvPVX_const(sv) == PL_No))
1027 #define BOOL_INTERNALS_sv_isbool_true(sv)      (SvIsCOW_static(sv) && \
1028         (SvPVX_const(sv) == PL_Yes))
1029 #define BOOL_INTERNALS_sv_isbool_false(sv)      (SvIsCOW_static(sv) && \
1030         (SvPVX_const(sv) == PL_No))
1031 
1032 #define SvIsUV(sv)		(SvFLAGS(sv) & SVf_IVisUV)
1033 #define SvIsUV_on(sv)		(SvFLAGS(sv) |= SVf_IVisUV)
1034 #define SvIsUV_off(sv)		(SvFLAGS(sv) &= ~SVf_IVisUV)
1035 
1036 #define SvNOK(sv)		(SvFLAGS(sv) & SVf_NOK)
1037 #define SvNOK_on(sv)		(assert_not_glob(sv) \
1038                                  SvFLAGS(sv) |= (SVf_NOK|SVp_NOK))
1039 #define SvNOK_off(sv)		(SvFLAGS(sv) &= ~(SVf_NOK|SVp_NOK))
1040 #define SvNOK_only(sv)		(SvOK_off(sv), \
1041                                     SvFLAGS(sv) |= (SVf_NOK|SVp_NOK))
1042 
1043 /*
1044 =for apidoc Am|U32|SvUTF8|SV* sv
1045 Returns a U32 value indicating the UTF-8 status of an SV.  If things are set-up
1046 properly, this indicates whether or not the SV contains UTF-8 encoded data.
1047 You should use this I<after> a call to C<L</SvPV>> or one of its variants, in
1048 case any call to string overloading updates the internal flag.
1049 
1050 If you want to take into account the L<bytes> pragma, use C<L</DO_UTF8>>
1051 instead.
1052 
1053 =for apidoc Am|void|SvUTF8_on|SV *sv
1054 Turn on the UTF-8 status of an SV (the data is not changed, just the flag).
1055 Do not use frivolously.
1056 
1057 =for apidoc Am|void|SvUTF8_off|SV *sv
1058 Unsets the UTF-8 status of an SV (the data is not changed, just the flag).
1059 Do not use frivolously.
1060 
1061 =for apidoc Am|void|SvPOK_only_UTF8|SV* sv
1062 Tells an SV that it is a string and disables all other C<OK> bits,
1063 and leaves the UTF-8 status as it was.
1064 
1065 =cut
1066  */
1067 
1068 /* Ensure the return value of this macro does not clash with the GV_ADD* flags
1069 in gv.h: */
1070 #define SvUTF8(sv)		(SvFLAGS(sv) & SVf_UTF8)
1071 #define SvUTF8_on(sv)		(SvFLAGS(sv) |= (SVf_UTF8))
1072 #define SvUTF8_off(sv)		(SvFLAGS(sv) &= ~(SVf_UTF8))
1073 
1074 #define SvPOK(sv)		(SvFLAGS(sv) & SVf_POK)
1075 #define SvPOK_on(sv)		(assert_not_ROK(sv) assert_not_glob(sv)	\
1076                                  SvFLAGS(sv) |= (SVf_POK|SVp_POK))
1077 #define SvPOK_off(sv)		(SvFLAGS(sv) &= ~(SVf_POK|SVp_POK))
1078 #define SvPOK_only(sv)		(assert_not_ROK(sv) assert_not_glob(sv)	\
1079                                  SvFLAGS(sv) &= ~(SVf_OK|		\
1080                                                   SVf_IVisUV|SVf_UTF8),	\
1081                                     SvFLAGS(sv) |= (SVf_POK|SVp_POK))
1082 #define SvPOK_only_UTF8(sv)	(assert_not_ROK(sv) assert_not_glob(sv)	\
1083                                  SvFLAGS(sv) &= ~(SVf_OK|		\
1084                                                   SVf_IVisUV),		\
1085                                     SvFLAGS(sv) |= (SVf_POK|SVp_POK))
1086 
1087 #define SvVOK(sv)		(SvMAGICAL(sv)				\
1088                                  && mg_find(sv,PERL_MAGIC_vstring))
1089 /*
1090 =for apidoc Am|MAGIC*|SvVSTRING_mg|SV * sv
1091 
1092 Returns the vstring magic, or NULL if none
1093 
1094 =cut
1095 */
1096 #define SvVSTRING_mg(sv)	(SvMAGICAL(sv) \
1097                                  ? mg_find(sv,PERL_MAGIC_vstring) : NULL)
1098 
1099 #define SvOOK(sv)		(SvFLAGS(sv) & SVf_OOK)
1100 #define SvOOK_on(sv)		(SvFLAGS(sv) |= SVf_OOK)
1101 
1102 
1103 /*
1104 =for apidoc Am|void|SvOOK_off|SV * sv
1105 
1106 Remove any string offset.
1107 
1108 =cut
1109 */
1110 
1111 #define SvOOK_off(sv)		((void)(SvOOK(sv) && (sv_backoff(sv),0)))
1112 
1113 #define SvFAKE(sv)		(SvFLAGS(sv) & SVf_FAKE)
1114 #define SvFAKE_on(sv)		(SvFLAGS(sv) |= SVf_FAKE)
1115 #define SvFAKE_off(sv)		(SvFLAGS(sv) &= ~SVf_FAKE)
1116 
1117 #define SvROK(sv)		(SvFLAGS(sv) & SVf_ROK)
1118 #define SvROK_on(sv)		(SvFLAGS(sv) |= SVf_ROK)
1119 #define SvROK_off(sv)		(SvFLAGS(sv) &= ~(SVf_ROK))
1120 
1121 #define SvMAGICAL(sv)		(SvFLAGS(sv) & (SVs_GMG|SVs_SMG|SVs_RMG))
1122 #define SvMAGICAL_on(sv)	(SvFLAGS(sv) |= (SVs_GMG|SVs_SMG|SVs_RMG))
1123 #define SvMAGICAL_off(sv)	(SvFLAGS(sv) &= ~(SVs_GMG|SVs_SMG|SVs_RMG))
1124 
1125 #define SvGMAGICAL(sv)		(SvFLAGS(sv) & SVs_GMG)
1126 #define SvGMAGICAL_on(sv)	(SvFLAGS(sv) |= SVs_GMG)
1127 #define SvGMAGICAL_off(sv)	(SvFLAGS(sv) &= ~SVs_GMG)
1128 
1129 #define SvSMAGICAL(sv)		(SvFLAGS(sv) & SVs_SMG)
1130 #define SvSMAGICAL_on(sv)	(SvFLAGS(sv) |= SVs_SMG)
1131 #define SvSMAGICAL_off(sv)	(SvFLAGS(sv) &= ~SVs_SMG)
1132 
1133 #define SvRMAGICAL(sv)		(SvFLAGS(sv) & SVs_RMG)
1134 #define SvRMAGICAL_on(sv)	(SvFLAGS(sv) |= SVs_RMG)
1135 #define SvRMAGICAL_off(sv)	(SvFLAGS(sv) &= ~SVs_RMG)
1136 
1137 /*
1138 =for apidoc Am|bool|SvAMAGIC|SV * sv
1139 
1140 Returns a boolean as to whether C<sv> has overloading (active magic) enabled or
1141 not.
1142 
1143 =cut
1144 */
1145 
1146 #define SvAMAGIC(sv)		(SvROK(sv) && SvOBJECT(SvRV(sv)) &&	\
1147                                  HvAMAGIC(SvSTASH(SvRV(sv))))
1148 
1149 /* To be used on the stashes themselves: */
1150 #define HvAMAGIC(hv)		(SvFLAGS(hv) & SVf_AMAGIC)
1151 #define HvAMAGIC_on(hv)		(SvFLAGS(hv) |= SVf_AMAGIC)
1152 #define HvAMAGIC_off(hv)	(SvFLAGS(hv) &=~ SVf_AMAGIC)
1153 
1154 
1155 /* "nog" means "doesn't have get magic" */
1156 #define SvPOK_nog(sv)		((SvFLAGS(sv) & (SVf_POK|SVs_GMG)) == SVf_POK)
1157 #define SvIOK_nog(sv)		((SvFLAGS(sv) & (SVf_IOK|SVs_GMG)) == SVf_IOK)
1158 #define SvUOK_nog(sv)		((SvFLAGS(sv) & (SVf_IOK|SVf_IVisUV|SVs_GMG)) == (SVf_IOK|SVf_IVisUV))
1159 #define SvNOK_nog(sv)		((SvFLAGS(sv) & (SVf_NOK|SVs_GMG)) == SVf_NOK)
1160 #define SvNIOK_nog(sv)		(SvNIOK(sv) && !(SvFLAGS(sv) & SVs_GMG))
1161 
1162 #define SvPOK_nogthink(sv)	((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST|SVs_GMG)) == SVf_POK)
1163 #define SvIOK_nogthink(sv)	((SvFLAGS(sv) & (SVf_IOK|SVf_THINKFIRST|SVs_GMG)) == SVf_IOK)
1164 #define SvUOK_nogthink(sv)	((SvFLAGS(sv) & (SVf_IOK|SVf_IVisUV|SVf_THINKFIRST|SVs_GMG)) == (SVf_IOK|SVf_IVisUV))
1165 #define SvNOK_nogthink(sv)	((SvFLAGS(sv) & (SVf_NOK|SVf_THINKFIRST|SVs_GMG)) == SVf_NOK)
1166 #define SvNIOK_nogthink(sv)	(SvNIOK(sv) && !(SvFLAGS(sv) & (SVf_THINKFIRST|SVs_GMG)))
1167 
1168 #define SvPOK_utf8_nog(sv)	((SvFLAGS(sv) & (SVf_POK|SVf_UTF8|SVs_GMG)) == (SVf_POK|SVf_UTF8))
1169 #define SvPOK_utf8_nogthink(sv)	((SvFLAGS(sv) & (SVf_POK|SVf_UTF8|SVf_THINKFIRST|SVs_GMG)) == (SVf_POK|SVf_UTF8))
1170 
1171 #define SvPOK_byte_nog(sv)	((SvFLAGS(sv) & (SVf_POK|SVf_UTF8|SVs_GMG)) == SVf_POK)
1172 #define SvPOK_byte_nogthink(sv)	((SvFLAGS(sv) & (SVf_POK|SVf_UTF8|SVf_THINKFIRST|SVs_GMG)) == SVf_POK)
1173 
1174 #define SvPOK_pure_nogthink(sv) \
1175     ((SvFLAGS(sv) & (SVf_POK|SVf_IOK|SVf_NOK|SVf_ROK|SVpgv_GP|SVf_THINKFIRST|SVs_GMG)) == SVf_POK)
1176 #define SvPOK_utf8_pure_nogthink(sv) \
1177     ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8|SVf_IOK|SVf_NOK|SVf_ROK|SVpgv_GP|SVf_THINKFIRST|SVs_GMG)) == (SVf_POK|SVf_UTF8))
1178 #define SvPOK_byte_pure_nogthink(sv) \
1179     ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8|SVf_IOK|SVf_NOK|SVf_ROK|SVpgv_GP|SVf_THINKFIRST|SVs_GMG)) == SVf_POK)
1180 
1181 /*
1182 =for apidoc Am|bool|SvIsBOOL|SV* sv
1183 
1184 Returns true if the SV is one of the special boolean constants (PL_sv_yes or
1185 PL_sv_no), or is a regular SV whose last assignment stored a copy of one.
1186 
1187 =cut
1188 */
1189 
1190 #define SvIsBOOL(sv)            Perl_sv_isbool(aTHX_ sv)
1191 
1192 /*
1193 =for apidoc Am|U32|SvGAMAGIC|SV* sv
1194 
1195 Returns true if the SV has get magic or
1196 overloading.  If either is true then
1197 the scalar is active data, and has the potential to return a new value every
1198 time it is accessed.  Hence you must be careful to
1199 only read it once per user logical operation and work
1200 with that returned value.  If neither is true then
1201 the scalar's value cannot change unless written to.
1202 
1203 =cut
1204 */
1205 
1206 #define SvGAMAGIC(sv)           (SvGMAGICAL(sv) || SvAMAGIC(sv))
1207 
1208 #define Gv_AMG(stash) \
1209         (HvNAME(stash) && Gv_AMupdate(stash,FALSE) \
1210             ? 1					    \
1211             : (HvAMAGIC_off(stash), 0))
1212 
1213 #define SvWEAKREF(sv)		((SvFLAGS(sv) & (SVf_ROK|SVprv_WEAKREF)) \
1214                                   == (SVf_ROK|SVprv_WEAKREF))
1215 #define SvWEAKREF_on(sv)	(SvFLAGS(sv) |=  (SVf_ROK|SVprv_WEAKREF))
1216 #define SvWEAKREF_off(sv)	(SvFLAGS(sv) &= ~(SVf_ROK|SVprv_WEAKREF))
1217 
1218 #define SvPCS_IMPORTED(sv)	((SvFLAGS(sv) & (SVf_ROK|SVprv_PCS_IMPORTED)) \
1219                                  == (SVf_ROK|SVprv_PCS_IMPORTED))
1220 #define SvPCS_IMPORTED_on(sv)	(SvFLAGS(sv) |=  (SVf_ROK|SVprv_PCS_IMPORTED))
1221 #define SvPCS_IMPORTED_off(sv)	(SvFLAGS(sv) &= ~(SVf_ROK|SVprv_PCS_IMPORTED))
1222 
1223 /*
1224 =for apidoc m|U32|SvTHINKFIRST|SV *sv
1225 
1226 A quick flag check to see whether an C<sv> should be passed to C<sv_force_normal>
1227 to be "downgraded" before C<SvIVX> or C<SvPVX> can be modified directly.
1228 
1229 For example, if your scalar is a reference and you want to modify the C<SvIVX>
1230 slot, you can't just do C<SvROK_off>, as that will leak the referent.
1231 
1232 This is used internally by various sv-modifying functions, such as
1233 C<sv_setsv>, C<sv_setiv> and C<sv_pvn_force>.
1234 
1235 One case that this does not handle is a gv without SvFAKE set.  After
1236 
1237     if (SvTHINKFIRST(gv)) sv_force_normal(gv);
1238 
1239 it will still be a gv.
1240 
1241 C<SvTHINKFIRST> sometimes produces false positives.  In those cases
1242 C<sv_force_normal> does nothing.
1243 
1244 =cut
1245 */
1246 
1247 #define SvTHINKFIRST(sv)	(SvFLAGS(sv) & SVf_THINKFIRST)
1248 
1249 #define SVs_PADMY		0
1250 #define SvPADMY(sv)		(!(SvFLAGS(sv) & SVs_PADTMP))
1251 #ifndef PERL_CORE
1252 # define SvPADMY_on(sv)		SvPADTMP_off(sv)
1253 #endif
1254 
1255 #define SvPADTMP(sv)		(SvFLAGS(sv) & (SVs_PADTMP))
1256 #define SvPADSTALE(sv)		(SvFLAGS(sv) & (SVs_PADSTALE))
1257 
1258 #define SvPADTMP_on(sv)		(SvFLAGS(sv) |= SVs_PADTMP)
1259 #define SvPADTMP_off(sv)	(SvFLAGS(sv) &= ~SVs_PADTMP)
1260 #define SvPADSTALE_on(sv)	Perl_SvPADSTALE_on(MUTABLE_SV(sv))
1261 #define SvPADSTALE_off(sv)	Perl_SvPADSTALE_off(MUTABLE_SV(sv))
1262 
1263 #define SvTEMP(sv)		(SvFLAGS(sv) & SVs_TEMP)
1264 #define SvTEMP_on(sv)		(SvFLAGS(sv) |= SVs_TEMP)
1265 #define SvTEMP_off(sv)		(SvFLAGS(sv) &= ~SVs_TEMP)
1266 
1267 #define SvOBJECT(sv)		(SvFLAGS(sv) & SVs_OBJECT)
1268 #define SvOBJECT_on(sv)		(SvFLAGS(sv) |= SVs_OBJECT)
1269 #define SvOBJECT_off(sv)	(SvFLAGS(sv) &= ~SVs_OBJECT)
1270 
1271 /*
1272 =for apidoc Am|U32|SvREADONLY|SV* sv
1273 Returns true if the argument is readonly, otherwise returns false.
1274 Exposed to perl code via Internals::SvREADONLY().
1275 
1276 =for apidoc Am|U32|SvREADONLY_on|SV* sv
1277 Mark an object as readonly. Exactly what this means depends on the object
1278 type. Exposed to perl code via Internals::SvREADONLY().
1279 
1280 =for apidoc Am|U32|SvREADONLY_off|SV* sv
1281 Mark an object as not-readonly. Exactly what this mean depends on the
1282 object type. Exposed to perl code via Internals::SvREADONLY().
1283 
1284 =cut
1285 */
1286 
1287 #define SvREADONLY(sv)		(SvFLAGS(sv) & (SVf_READONLY|SVf_PROTECT))
1288 #ifdef PERL_CORE
1289 # define SvREADONLY_on(sv)	(SvFLAGS(sv) |= (SVf_READONLY|SVf_PROTECT))
1290 # define SvREADONLY_off(sv)	(SvFLAGS(sv) &=~(SVf_READONLY|SVf_PROTECT))
1291 #else
1292 # define SvREADONLY_on(sv)	(SvFLAGS(sv) |= SVf_READONLY)
1293 # define SvREADONLY_off(sv)	(SvFLAGS(sv) &= ~SVf_READONLY)
1294 #endif
1295 
1296 #define SvSCREAM(sv) ((SvFLAGS(sv) & (SVp_SCREAM|SVp_POK)) == (SVp_SCREAM|SVp_POK))
1297 #define SvSCREAM_on(sv)		(SvFLAGS(sv) |= SVp_SCREAM)
1298 #define SvSCREAM_off(sv)	(SvFLAGS(sv) &= ~SVp_SCREAM)
1299 
1300 #ifndef PERL_CORE
1301 #  define SvCOMPILED(sv)	0
1302 #  define SvCOMPILED_on(sv)
1303 #  define SvCOMPILED_off(sv)
1304 #endif
1305 
1306 
1307 #if defined (DEBUGGING) && defined(PERL_USE_GCC_BRACE_GROUPS)
1308 #  define SvTAIL(sv)	({ const SV *const _svtail = (const SV *)(sv);	\
1309                             assert(SvTYPE(_svtail) != SVt_PVAV);	\
1310                             assert(SvTYPE(_svtail) != SVt_PVHV);	\
1311                             assert(!(SvFLAGS(_svtail) & (SVf_NOK|SVp_NOK))); \
1312                             assert(SvVALID(_svtail));                        \
1313                             ((XPVNV*)SvANY(_svtail))->xnv_u.xnv_bm_tail;     \
1314                         })
1315 #else
1316 #  define SvTAIL(_svtail)  (((XPVNV*)SvANY(_svtail))->xnv_u.xnv_bm_tail)
1317 #endif
1318 
1319 /* Does the SV have a Boyer-Moore table attached as magic?
1320  * 'VALID' is a poor name, but is kept for historical reasons.  */
1321 #define SvVALID(_svvalid) (                                  \
1322                SvPOKp(_svvalid)                              \
1323             && SvSMAGICAL(_svvalid)                          \
1324             && SvMAGIC(_svvalid)                             \
1325             && (SvMAGIC(_svvalid)->mg_type == PERL_MAGIC_bm  \
1326                 || mg_find(_svvalid, PERL_MAGIC_bm))         \
1327         )
1328 
1329 #define SvRVx(sv) SvRV(sv)
1330 
1331 #ifdef PERL_DEBUG_COW
1332 /* Need -0.0 for SvNVX to preserve IEEE FP "negative zero" because
1333    +0.0 + -0.0 => +0.0 but -0.0 + -0.0 => -0.0 */
1334 #  define SvIVX(sv) (0 + ((XPVIV*) SvANY(sv))->xiv_iv)
1335 #  define SvUVX(sv) (0 + ((XPVUV*) SvANY(sv))->xuv_uv)
1336 #  define SvNVX(sv) (-0.0 + ((XPVNV*) SvANY(sv))->xnv_u.xnv_nv)
1337 #  define SvRV(sv) (0 + (sv)->sv_u.svu_rv)
1338 #  define SvRV_const(sv) (0 + (sv)->sv_u.svu_rv)
1339 /* Don't test the core XS code yet.  */
1340 #  if defined (PERL_CORE) && PERL_DEBUG_COW > 1
1341 #    define SvPVX(sv) (0 + (assert_(!SvREADONLY(sv)) (sv)->sv_u.svu_pv))
1342 #  else
1343 #  define SvPVX(sv) SvPVX_mutable(sv)
1344 #  endif
1345 #  define SvCUR(sv) (0 + ((XPV*) SvANY(sv))->xpv_cur)
1346 #  define SvLEN(sv) (0 + ((XPV*) SvANY(sv))->xpv_len)
1347 #  define SvEND(sv) ((sv)->sv_u.svu_pv + ((XPV*)SvANY(sv))->xpv_cur)
1348 
1349 #  define SvMAGIC(sv)	(0 + *(assert_(SvTYPE(sv) >= SVt_PVMG) &((XPVMG*)  SvANY(sv))->xmg_u.xmg_magic))
1350 #  define SvSTASH(sv)	(0 + *(assert_(SvTYPE(sv) >= SVt_PVMG) &((XPVMG*)  SvANY(sv))->xmg_stash))
1351 #else   /* Below is not PERL_DEBUG_COW */
1352 # ifdef PERL_CORE
1353 #  define SvLEN(sv) (0 + ((XPV*) SvANY(sv))->xpv_len)
1354 # else
1355 #  define SvLEN(sv) ((XPV*) SvANY(sv))->xpv_len
1356 # endif
1357 #  define SvEND(sv) ((sv)->sv_u.svu_pv + ((XPV*)SvANY(sv))->xpv_cur)
1358 
1359 #  if defined (DEBUGGING) && defined(PERL_USE_GCC_BRACE_GROUPS)
1360 /* These get expanded inside other macros that already use a variable _sv  */
1361 #    define SvPVX(sv)							\
1362         (*({ SV *const _svpvx = MUTABLE_SV(sv);				\
1363             assert(PL_valid_types_PVX[SvTYPE(_svpvx) & SVt_MASK]);	\
1364             assert(!isGV_with_GP(_svpvx));				\
1365             assert(!(SvTYPE(_svpvx) == SVt_PVIO				\
1366                      && !(IoFLAGS(_svpvx) & IOf_FAKE_DIRP)));		\
1367             &((_svpvx)->sv_u.svu_pv);					\
1368          }))
1369 #   ifdef PERL_CORE
1370 #    define SvCUR(sv)							\
1371         ({ const SV *const _svcur = (const SV *)(sv);			\
1372             assert(PL_valid_types_PVX[SvTYPE(_svcur) & SVt_MASK]);	\
1373             assert(!isGV_with_GP(_svcur));				\
1374             assert(!(SvTYPE(_svcur) == SVt_PVIO				\
1375                      && !(IoFLAGS(_svcur) & IOf_FAKE_DIRP)));		\
1376             (((XPV*) MUTABLE_PTR(SvANY(_svcur)))->xpv_cur);		\
1377          })
1378 #   else
1379 #    define SvCUR(sv)							\
1380         (*({ const SV *const _svcur = (const SV *)(sv);			\
1381             assert(PL_valid_types_PVX[SvTYPE(_svcur) & SVt_MASK]);	\
1382             assert(!isGV_with_GP(_svcur));				\
1383             assert(!(SvTYPE(_svcur) == SVt_PVIO				\
1384                      && !(IoFLAGS(_svcur) & IOf_FAKE_DIRP)));		\
1385             &(((XPV*) MUTABLE_PTR(SvANY(_svcur)))->xpv_cur);		\
1386          }))
1387 #   endif
1388 #    define SvIVX(sv)							\
1389         (*({ const SV *const _svivx = (const SV *)(sv);			\
1390             assert(PL_valid_types_IVX[SvTYPE(_svivx) & SVt_MASK]);	\
1391             assert(!isGV_with_GP(_svivx));				\
1392             &(((XPVIV*) MUTABLE_PTR(SvANY(_svivx)))->xiv_iv);		\
1393          }))
1394 #    define SvUVX(sv)							\
1395         (*({ const SV *const _svuvx = (const SV *)(sv);			\
1396             assert(PL_valid_types_IVX[SvTYPE(_svuvx) & SVt_MASK]);	\
1397             assert(!isGV_with_GP(_svuvx));				\
1398             &(((XPVUV*) MUTABLE_PTR(SvANY(_svuvx)))->xuv_uv);		\
1399          }))
1400 #    define SvNVX(sv)							\
1401         (*({ const SV *const _svnvx = (const SV *)(sv);			\
1402             assert(PL_valid_types_NVX[SvTYPE(_svnvx) & SVt_MASK]);	\
1403             assert(!isGV_with_GP(_svnvx));				\
1404             &(((XPVNV*) MUTABLE_PTR(SvANY(_svnvx)))->xnv_u.xnv_nv);	\
1405          }))
1406 #    define SvRV(sv)							\
1407         (*({ SV *const _svrv = MUTABLE_SV(sv);				\
1408             assert(PL_valid_types_RV[SvTYPE(_svrv) & SVt_MASK]);	\
1409             assert(!isGV_with_GP(_svrv));				\
1410             assert(!(SvTYPE(_svrv) == SVt_PVIO				\
1411                      && !(IoFLAGS(_svrv) & IOf_FAKE_DIRP)));		\
1412             &((_svrv)->sv_u.svu_rv);					\
1413          }))
1414 #    define SvRV_const(sv)						\
1415         ({ const SV *const _svrv = (const SV *)(sv);			\
1416             assert(PL_valid_types_RV[SvTYPE(_svrv) & SVt_MASK]);	\
1417             assert(!isGV_with_GP(_svrv));				\
1418             assert(!(SvTYPE(_svrv) == SVt_PVIO				\
1419                      && !(IoFLAGS(_svrv) & IOf_FAKE_DIRP)));		\
1420             (_svrv)->sv_u.svu_rv;					\
1421          })
1422 #    define SvMAGIC(sv)							\
1423         (*({ const SV *const _svmagic = (const SV *)(sv);		\
1424             assert(SvTYPE(_svmagic) >= SVt_PVMG);			\
1425             &(((XPVMG*) MUTABLE_PTR(SvANY(_svmagic)))->xmg_u.xmg_magic); \
1426           }))
1427 #    define SvSTASH(sv)							\
1428         (*({ const SV *const _svstash = (const SV *)(sv);		\
1429             assert(SvTYPE(_svstash) >= SVt_PVMG);			\
1430             &(((XPVMG*) MUTABLE_PTR(SvANY(_svstash)))->xmg_stash);	\
1431           }))
1432 #  else     /* Below is not DEBUGGING or can't use brace groups */
1433 #    define SvPVX(sv) ((sv)->sv_u.svu_pv)
1434 #    define SvCUR(sv) ((XPV*) SvANY(sv))->xpv_cur
1435 #    define SvIVX(sv) ((XPVIV*) SvANY(sv))->xiv_iv
1436 #    define SvUVX(sv) ((XPVUV*) SvANY(sv))->xuv_uv
1437 #    define SvNVX(sv) ((XPVNV*) SvANY(sv))->xnv_u.xnv_nv
1438 #    define SvRV(sv) ((sv)->sv_u.svu_rv)
1439 #    define SvRV_const(sv) (0 + (sv)->sv_u.svu_rv)
1440 #    define SvMAGIC(sv)	((XPVMG*)  SvANY(sv))->xmg_u.xmg_magic
1441 #    define SvSTASH(sv)	((XPVMG*)  SvANY(sv))->xmg_stash
1442 #  endif
1443 #endif
1444 
1445 #ifndef PERL_POISON
1446 /* Given that these two are new, there can't be any existing code using them
1447  *  as LVALUEs, so prevent that from happening  */
1448 #  define SvPVX_mutable(sv)	((char *)((sv)->sv_u.svu_pv))
1449 #  define SvPVX_const(sv)	((const char*)((sv)->sv_u.svu_pv))
1450 #else
1451 /* Except for the poison code, which uses & to scribble over the pointer after
1452    free() is called.  */
1453 #  define SvPVX_mutable(sv)	((sv)->sv_u.svu_pv)
1454 #  define SvPVX_const(sv)	((const char*)((sv)->sv_u.svu_pv))
1455 #endif
1456 
1457 #define SvIVXx(sv) SvIVX(sv)
1458 #define SvUVXx(sv) SvUVX(sv)
1459 #define SvNVXx(sv) SvNVX(sv)
1460 #define SvPVXx(sv) SvPVX(sv)
1461 #define SvLENx(sv) SvLEN(sv)
1462 #define SvENDx(sv) ((PL_Sv = (sv)), SvEND(PL_Sv))
1463 
1464 
1465 /* Ask a scalar nicely to try to become an IV, if possible.
1466    Not guaranteed to stay returning void */
1467 /* Macro won't actually call sv_2iv if already IOK */
1468 #define SvIV_please(sv) \
1469         STMT_START {                                                        \
1470             SV * sv_ = MUTABLE_SV(sv);                                      \
1471             if (!SvIOKp(sv_) && (SvFLAGS(sv_) & (SVf_NOK|SVf_POK)))         \
1472                 (void) SvIV(sv_);                                           \
1473         } STMT_END
1474 #define SvIV_please_nomg(sv) \
1475         (!(SvFLAGS(sv) & (SVf_IOK|SVp_IOK)) && (SvFLAGS(sv) & (SVf_NOK|SVf_POK)) \
1476             ? (sv_2iv_flags(sv, 0), SvIOK(sv))	  \
1477             : SvIOK(sv))
1478 
1479 #define SvIV_set(sv, val) \
1480         STMT_START { \
1481                 SV * sv_ = MUTABLE_SV(sv);                                  \
1482                 assert(PL_valid_types_IV_set[SvTYPE(sv_) & SVt_MASK]);      \
1483                 assert(!isGV_with_GP(sv_));                                 \
1484                 (((XPVIV*)  SvANY(sv_))->xiv_iv = (val));                   \
1485         } STMT_END
1486 
1487 #define SvNV_set(sv, val) \
1488         STMT_START { \
1489                 SV * sv_ = MUTABLE_SV(sv);                                  \
1490                 assert(PL_valid_types_NV_set[SvTYPE(sv_) & SVt_MASK]);      \
1491                 assert(!isGV_with_GP(sv_));                                 \
1492                 (((XPVNV*)SvANY(sv_))->xnv_u.xnv_nv = (val));               \
1493         } STMT_END
1494 
1495 #define SvPV_set(sv, val) \
1496         STMT_START { \
1497                 SV * sv_ = MUTABLE_SV(sv);                                  \
1498                 assert(PL_valid_types_PVX[SvTYPE(sv_) & SVt_MASK]);         \
1499                 assert(!isGV_with_GP(sv_));		                    \
1500                 assert(!(SvTYPE(sv_) == SVt_PVIO		            \
1501                      && !(IoFLAGS(sv_) & IOf_FAKE_DIRP)));                  \
1502                 ((sv_)->sv_u.svu_pv = (val));                               \
1503         } STMT_END
1504 
1505 #define SvUV_set(sv, val) \
1506         STMT_START { \
1507                 SV * sv_ = MUTABLE_SV(sv);                                  \
1508                 assert(PL_valid_types_IV_set[SvTYPE(sv_) & SVt_MASK]);	    \
1509                 assert(!isGV_with_GP(sv_));		                    \
1510                 (((XPVUV*)SvANY(sv_))->xuv_uv = (val));                     \
1511         } STMT_END
1512 
1513 #define SvRV_set(sv, val) \
1514         STMT_START { \
1515                 SV * sv_ = MUTABLE_SV(sv);                                  \
1516                 assert(PL_valid_types_RV[SvTYPE(sv_) & SVt_MASK]);	    \
1517                 assert(!isGV_with_GP(sv_));		                    \
1518                 assert(!(SvTYPE(sv_) == SVt_PVIO		            \
1519                      && !(IoFLAGS(sv_) & IOf_FAKE_DIRP)));                  \
1520                 ((sv_)->sv_u.svu_rv = (val));                               \
1521         } STMT_END
1522 #define SvMAGIC_set(sv, val) \
1523         STMT_START { assert(SvTYPE(sv) >= SVt_PVMG); \
1524                 (((XPVMG*)SvANY(sv))->xmg_u.xmg_magic = (val)); } STMT_END
1525 #define SvSTASH_set(sv, val) \
1526         STMT_START { assert(SvTYPE(sv) >= SVt_PVMG); \
1527                 (((XPVMG*)  SvANY(sv))->xmg_stash = (val)); } STMT_END
1528 #define SvCUR_set(sv, val) \
1529         STMT_START { \
1530                 assert(PL_valid_types_PVX[SvTYPE(sv) & SVt_MASK]);	\
1531                 assert(!isGV_with_GP(sv));		\
1532                 assert(!(SvTYPE(sv) == SVt_PVIO		\
1533                      && !(IoFLAGS(sv) & IOf_FAKE_DIRP))); \
1534                 (((XPV*)  SvANY(sv))->xpv_cur = (val)); } STMT_END
1535 #define SvLEN_set(sv, val) \
1536         STMT_START { \
1537                 assert(PL_valid_types_PVX[SvTYPE(sv) & SVt_MASK]);	\
1538                 assert(!isGV_with_GP(sv));	\
1539                 assert(!(SvTYPE(sv) == SVt_PVIO		\
1540                      && !(IoFLAGS(sv) & IOf_FAKE_DIRP))); \
1541                 (((XPV*)  SvANY(sv))->xpv_len = (val)); } STMT_END
1542 #define SvEND_set(sv, val) \
1543         STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
1544                 SvCUR_set(sv, (val) - SvPVX(sv)); } STMT_END
1545 
1546 /*
1547 =for apidoc Am|void|SvPV_renew|SV* sv|STRLEN len
1548 Low level micro optimization of C<L</SvGROW>>.  It is generally better to use
1549 C<SvGROW> instead.  This is because C<SvPV_renew> ignores potential issues that
1550 C<SvGROW> handles.  C<sv> needs to have a real C<PV> that is unencumbered by
1551 things like COW.  Using C<SV_CHECK_THINKFIRST> or
1552 C<SV_CHECK_THINKFIRST_COW_DROP> before calling this should clean it up, but
1553 why not just use C<SvGROW> if you're not sure about the provenance?
1554 
1555 =cut
1556 */
1557 #define SvPV_renew(sv,n) \
1558         STMT_START { SvLEN_set(sv, n); \
1559                 SvPV_set((sv), (MEM_WRAP_CHECK_(n,char)			\
1560                                 (char*)saferealloc((Malloc_t)SvPVX(sv), \
1561                                                    (MEM_SIZE)((n)))));  \
1562                  } STMT_END
1563 /*
1564 =for apidoc Am|void|SvPV_shrink_to_cur|SV* sv
1565 
1566 Trim any trailing unused memory in the PV of C<sv>, which needs to have a real
1567 C<PV> that is unencumbered by things like COW.  Think first before using this
1568 functionality.  Is the space saving really worth giving up COW?  Will the
1569 needed size of C<sv> stay the same?
1570 
1571 If the answers are both yes, then use L</C<SV_CHECK_THINKFIRST>> or
1572 L</C<SV_CHECK_THINKFIRST_COW_DROP>> before calling this.
1573 
1574 =cut
1575 */
1576 
1577 #define SvPV_shrink_to_cur(sv) STMT_START { \
1578                    const STRLEN _lEnGtH = SvCUR(sv) + 1; \
1579                    SvPV_renew(sv, _lEnGtH); \
1580                  } STMT_END
1581 
1582 /*
1583 =for apidoc Am|void|SvPV_free|SV * sv
1584 
1585 Frees the PV buffer in C<sv>, leaving things in a precarious state, so should
1586 only be used as part of a larger operation
1587 
1588 =cut
1589 */
1590 #define SvPV_free(sv)							\
1591     STMT_START {							\
1592                      assert(SvTYPE(sv) >= SVt_PV);			\
1593                      if (SvLEN(sv)) {					\
1594                          assert(!SvROK(sv));				\
1595                          if(UNLIKELY(SvOOK(sv))) {			\
1596                              STRLEN zok; 				\
1597                              SvOOK_offset(sv, zok);			\
1598                              SvPV_set(sv, SvPVX_mutable(sv) - zok);	\
1599                              SvFLAGS(sv) &= ~SVf_OOK;			\
1600                          }						\
1601                          Safefree(SvPVX(sv));				\
1602                      }							\
1603                  } STMT_END
1604 
1605 #ifdef PERL_CORE
1606 /* Code that crops up in three places to take a scalar and ready it to hold
1607    a reference */
1608 #  define prepare_SV_for_RV(sv)						\
1609     STMT_START {							\
1610                     if (SvTYPE(sv) < SVt_PV && SvTYPE(sv) != SVt_IV)	\
1611                         sv_upgrade(sv, SVt_IV);				\
1612                     else if (SvTYPE(sv) >= SVt_PV) {			\
1613                         SvPV_free(sv);					\
1614                         SvLEN_set(sv, 0);				\
1615                         SvCUR_set(sv, 0);				\
1616                     }							\
1617                  } STMT_END
1618 #endif
1619 
1620 #ifndef PERL_CORE
1621 #  define BmFLAGS(sv)		(SvTAIL(sv) ? FBMcf_TAIL : 0)
1622 #endif
1623 
1624 #if defined (DEBUGGING) && defined(PERL_USE_GCC_BRACE_GROUPS)
1625 #  define BmUSEFUL(sv)							\
1626         (*({ SV *const _bmuseful = MUTABLE_SV(sv);			\
1627             assert(SvTYPE(_bmuseful) >= SVt_PVIV);			\
1628             assert(SvVALID(_bmuseful));					\
1629             assert(!SvIOK(_bmuseful));					\
1630             &(((XPVIV*) SvANY(_bmuseful))->xiv_u.xivu_iv);              \
1631          }))
1632 #else
1633 #  define BmUSEFUL(sv)          ((XPVIV*) SvANY(sv))->xiv_u.xivu_iv
1634 
1635 #endif
1636 
1637 #ifndef PERL_CORE
1638 # define BmRARE(sv)	0
1639 # define BmPREVIOUS(sv)	0
1640 #endif
1641 
1642 #define FmLINES(sv)	((XPVIV*)  SvANY(sv))->xiv_iv
1643 
1644 #define LvTYPE(sv)	((XPVLV*)  SvANY(sv))->xlv_type
1645 #define LvTARG(sv)	((XPVLV*)  SvANY(sv))->xlv_targ
1646 #define LvTARGOFF(sv)	((XPVLV*)  SvANY(sv))->xlv_targoff
1647 #define LvSTARGOFF(sv)	((XPVLV*)  SvANY(sv))->xlv_targoff_u.xlvu_stargoff
1648 #define LvTARGLEN(sv)	((XPVLV*)  SvANY(sv))->xlv_targlen
1649 #define LvFLAGS(sv)	((XPVLV*)  SvANY(sv))->xlv_flags
1650 
1651 #define LVf_NEG_OFF      0x1
1652 #define LVf_NEG_LEN      0x2
1653 #define LVf_OUT_OF_RANGE 0x4
1654 
1655 #define IoIFP(sv)	(sv)->sv_u.svu_fp
1656 #define IoOFP(sv)	((XPVIO*)  SvANY(sv))->xio_ofp
1657 #define IoDIRP(sv)	((XPVIO*)  SvANY(sv))->xio_dirp
1658 #define IoANY(sv)	((XPVIO*)  SvANY(sv))->xio_any
1659 #define IoLINES(sv)	((XPVIO*)  SvANY(sv))->xiv_u.xivu_iv
1660 #define IoPAGE(sv)	((XPVIO*)  SvANY(sv))->xio_page
1661 #define IoPAGE_LEN(sv)	((XPVIO*)  SvANY(sv))->xio_page_len
1662 #define IoLINES_LEFT(sv)((XPVIO*)  SvANY(sv))->xio_lines_left
1663 #define IoTOP_NAME(sv)	((XPVIO*)  SvANY(sv))->xio_top_name
1664 #define IoTOP_GV(sv)	((XPVIO*)  SvANY(sv))->xio_top_gv
1665 #define IoFMT_NAME(sv)	((XPVIO*)  SvANY(sv))->xio_fmt_name
1666 #define IoFMT_GV(sv)	((XPVIO*)  SvANY(sv))->xio_fmt_gv
1667 #define IoBOTTOM_NAME(sv)((XPVIO*) SvANY(sv))->xio_bottom_name
1668 #define IoBOTTOM_GV(sv)	((XPVIO*)  SvANY(sv))->xio_bottom_gv
1669 #define IoTYPE(sv)	((XPVIO*)  SvANY(sv))->xio_type
1670 #define IoFLAGS(sv)	((XPVIO*)  SvANY(sv))->xio_flags
1671 
1672 /* IoTYPE(sv) is a single character telling the type of I/O connection. */
1673 #define IoTYPE_RDONLY		'<'
1674 #define IoTYPE_WRONLY		'>'
1675 #define IoTYPE_RDWR		'+'
1676 #define IoTYPE_APPEND 		'a'
1677 #define IoTYPE_PIPE		'|'
1678 #define IoTYPE_STD		'-'	/* stdin or stdout */
1679 #define IoTYPE_SOCKET		's'
1680 #define IoTYPE_CLOSED		' '
1681 #define IoTYPE_IMPLICIT		'I'	/* stdin or stdout or stderr */
1682 #define IoTYPE_NUMERIC		'#'	/* fdopen */
1683 
1684 /*
1685 =for apidoc_section $tainting
1686 =for apidoc Am|bool|SvTAINTED|SV* sv
1687 Checks to see if an SV is tainted.  Returns TRUE if it is, FALSE if
1688 not.
1689 
1690 =for apidoc Am|void|SvTAINTED_on|SV* sv
1691 Marks an SV as tainted if tainting is enabled.
1692 
1693 =for apidoc Am|void|SvTAINTED_off|SV* sv
1694 Untaints an SV.  Be I<very> careful with this routine, as it short-circuits
1695 some of Perl's fundamental security features.  XS module authors should not
1696 use this function unless they fully understand all the implications of
1697 unconditionally untainting the value.  Untainting should be done in the
1698 standard perl fashion, via a carefully crafted regexp, rather than directly
1699 untainting variables.
1700 
1701 =for apidoc Am|void|SvTAINT|SV* sv
1702 Taints an SV if tainting is enabled, and if some input to the current
1703 expression is tainted--usually a variable, but possibly also implicit
1704 inputs such as locale settings.  C<SvTAINT> propagates that taintedness to
1705 the outputs of an expression in a pessimistic fashion; i.e., without paying
1706 attention to precisely which outputs are influenced by which inputs.
1707 
1708 =cut
1709 */
1710 
1711 #define sv_taint(sv)	  sv_magic((sv), NULL, PERL_MAGIC_taint, NULL, 0)
1712 
1713 #ifdef NO_TAINT_SUPPORT
1714 #   define SvTAINTED(sv) 0
1715 #else
1716 #   define SvTAINTED(sv)	  (SvMAGICAL(sv) && sv_tainted(sv))
1717 #endif
1718 #define SvTAINTED_on(sv)  STMT_START{ if(UNLIKELY(TAINTING_get)){sv_taint(sv);}   }STMT_END
1719 #define SvTAINTED_off(sv) STMT_START{ if(UNLIKELY(TAINTING_get)){sv_untaint(sv);} }STMT_END
1720 
1721 #define SvTAINT(sv)			\
1722     STMT_START {			\
1723         assert(TAINTING_get || !TAINT_get); \
1724         if (UNLIKELY(TAINT_get))	\
1725             SvTAINTED_on(sv);	        \
1726     } STMT_END
1727 
1728 /*
1729 =for apidoc_section $SV
1730 =for apidoc Am|char*|SvPV_force              |SV* sv|STRLEN len
1731 =for apidoc_item   ||SvPV_force_flags        |SV * sv|STRLEN len|U32 flags
1732 =for apidoc_item   ||SvPV_force_flags_mutable|SV * sv|STRLEN len|U32 flags
1733 =for apidoc_item   ||SvPV_force_flags_nolen  |SV * sv           |U32 flags
1734 =for apidoc_item   ||SvPV_force_mutable      |SV * sv|STRLEN len
1735 =for apidoc_item   ||SvPV_force_nolen        |SV* sv
1736 =for apidoc_item   ||SvPV_force_nomg         |SV* sv|STRLEN len
1737 =for apidoc_item   ||SvPV_force_nomg_nolen   |SV * sv
1738 =for apidoc_item   ||SvPVbyte_force          |SV * sv|STRLEN len
1739 =for apidoc_item   ||SvPVbytex_force         |SV * sv|STRLEN len
1740 =for apidoc_item   ||SvPVutf8_force          |SV * sv|STRLEN len
1741 =for apidoc_item   ||SvPVutf8x_force         |SV * sv|STRLEN len
1742 =for apidoc_item   ||SvPVx_force             |SV* sv|STRLEN len
1743 
1744 These are like C<L</SvPV>>, returning the string in the SV, but will force the
1745 SV into containing a string (C<L</SvPOK>>), and only a string
1746 (C<L</SvPOK_only>>), by hook or by crook.  You need to use one of these
1747 C<force> routines if you are going to update the C<L</SvPVX>> directly.
1748 
1749 Note that coercing an arbitrary scalar into a plain PV will potentially
1750 strip useful data from it.  For example if the SV was C<SvROK>, then the
1751 referent will have its reference count decremented, and the SV itself may
1752 be converted to an C<SvPOK> scalar with a string buffer containing a value
1753 such as C<"ARRAY(0x1234)">.
1754 
1755 The differences between the forms are:
1756 
1757 The forms with C<flags> in their names allow you to use the C<flags> parameter
1758 to specify to perform 'get' magic (by setting the C<SV_GMAGIC> flag) or to skip
1759 'get' magic (by clearing it).  The other forms do perform 'get' magic, except
1760 for the ones with C<nomg> in their names, which skip 'get' magic.
1761 
1762 The forms that take a C<len> parameter will set that variable to the byte
1763 length of the resultant string (these are macros, so don't use C<&len>).
1764 
1765 The forms with C<nolen> in their names indicate they don't have a C<len>
1766 parameter.  They should be used only when it is known that the PV is a C
1767 string, terminated by a NUL byte, and without intermediate NUL characters; or
1768 when you don't care about its length.
1769 
1770 The forms with C<mutable> in their names are effectively the same as those without,
1771 but the name emphasizes that the string is modifiable by the caller, which it is
1772 in all the forms.
1773 
1774 C<SvPVutf8_force> is like C<SvPV_force>, but converts C<sv> to UTF-8 first if
1775 not already UTF-8.
1776 
1777 C<SvPVutf8x_force> is like C<SvPVutf8_force>, but guarantees to evaluate C<sv>
1778 only once; use the more efficient C<SvPVutf8_force> otherwise.
1779 
1780 C<SvPVbyte_force> is like C<SvPV_force>, but converts C<sv> to byte
1781 representation first if currently encoded as UTF-8.  If the SV cannot be
1782 downgraded from UTF-8, this croaks.
1783 
1784 C<SvPVbytex_force> is like C<SvPVbyte_force>, but guarantees to evaluate C<sv>
1785 only once; use the more efficient C<SvPVbyte_force> otherwise.
1786 
1787 =for apidoc Am   |      char*|SvPV                 |SV* sv|STRLEN len
1788 =for apidoc_item |const char*|SvPV_const           |SV* sv|STRLEN len
1789 =for apidoc_item |      char*|SvPV_flags           |SV* sv|STRLEN len|U32 flags
1790 =for apidoc_item |const char*|SvPV_flags_const     |SV* sv|STRLEN len|U32 flags
1791 =for apidoc_item |      char*|SvPV_flags_mutable   |SV* sv|STRLEN len|U32 flags
1792 =for apidoc_item |      char*|SvPV_mutable         |SV* sv|STRLEN len
1793 =for apidoc_item |      char*|SvPV_nolen           |SV* sv
1794 =for apidoc_item |const char*|SvPV_nolen_const     |SV* sv
1795 =for apidoc_item |      char*|SvPV_nomg            |SV* sv|STRLEN len
1796 =for apidoc_item |const char*|SvPV_nomg_const      |SV* sv|STRLEN len
1797 =for apidoc_item |const char*|SvPV_nomg_const_nolen|SV* sv
1798 =for apidoc_item |      char*|SvPV_nomg_nolen      |SV* sv
1799 =for apidoc_item |      char*|SvPVbyte             |SV* sv|STRLEN len
1800 =for apidoc_item |      char*|SvPVbyte_nolen       |SV* sv
1801 =for apidoc_item |      char*|SvPVbyte_nomg        |SV* sv|STRLEN len
1802 =for apidoc_item |      char*|SvPVbyte_or_null     |SV* sv|STRLEN len
1803 =for apidoc_item |      char*|SvPVbyte_or_null_nomg|SV* sv|STRLEN len
1804 =for apidoc_item |      char*|SvPVbytex            |SV* sv|STRLEN len
1805 =for apidoc_item |      char*|SvPVbytex_nolen      |SV* sv
1806 =for apidoc_item |      char*|SvPVutf8             |SV* sv|STRLEN len
1807 =for apidoc_item |      char*|SvPVutf8_nolen       |SV* sv
1808 =for apidoc_item |      char*|SvPVutf8_nomg        |SV* sv|STRLEN len
1809 =for apidoc_item |      char*|SvPVutf8_or_null     |SV* sv|STRLEN len
1810 =for apidoc_item |      char*|SvPVutf8_or_null_nomg|SV* sv|STRLEN len
1811 =for apidoc_item |      char*|SvPVutf8x            |SV* sv|STRLEN len
1812 =for apidoc_item |      char*|SvPVx                |SV* sv|STRLEN len
1813 =for apidoc_item |const char*|SvPVx_const          |SV* sv|STRLEN len
1814 =for apidoc_item |      char*|SvPVx_nolen          |SV* sv
1815 =for apidoc_item |const char*|SvPVx_nolen_const    |SV* sv
1816 
1817 These each return a pointer to the string in C<sv>, or a stringified form of
1818 C<sv> if it does not contain a string.  The SV may cache the stringified
1819 version becoming C<SvPOK>.
1820 
1821 This is a very basic and common operation, so there are lots of slightly
1822 different versions of it.
1823 
1824 Note that there is no guarantee that the return value of C<SvPV(sv)>, for
1825 example, is equal to C<SvPVX(sv)>, or that C<SvPVX(sv)> contains valid data, or
1826 that successive calls to C<SvPV(sv)> (or another of these forms) will return
1827 the same pointer value each time.  This is due to the way that things like
1828 overloading and Copy-On-Write are handled.  In these cases, the return value
1829 may point to a temporary buffer or similar.  If you absolutely need the
1830 C<SvPVX> field to be valid (for example, if you intend to write to it), then
1831 see C<L</SvPV_force>>.
1832 
1833 The differences between the forms are:
1834 
1835 The forms with neither C<byte> nor C<utf8> in their names (e.g., C<SvPV> or
1836 C<SvPV_nolen>) can expose the SV's internal string buffer. If
1837 that buffer consists entirely of bytes 0-255 and includes any bytes above
1838 127, then you B<MUST> consult C<SvUTF8> to determine the actual code points
1839 the string is meant to contain. Generally speaking, it is probably safer to
1840 prefer C<SvPVbyte>, C<SvPVutf8>, and the like. See
1841 L<perlguts/How do I pass a Perl string to a C library?> for more details.
1842 
1843 The forms with C<flags> in their names allow you to use the C<flags> parameter
1844 to specify to process 'get' magic (by setting the C<SV_GMAGIC> flag) or to skip
1845 'get' magic (by clearing it).  The other forms process 'get' magic, except for
1846 the ones with C<nomg> in their names, which skip 'get' magic.
1847 
1848 The forms that take a C<len> parameter will set that variable to the byte
1849 length of the resultant string (these are macros, so don't use C<&len>).
1850 
1851 The forms with C<nolen> in their names indicate they don't have a C<len>
1852 parameter.  They should be used only when it is known that the PV is a C
1853 string, terminated by a NUL byte, and without intermediate NUL characters; or
1854 when you don't care about its length.
1855 
1856 The forms with C<const> in their names return S<C<const char *>> so that the
1857 compiler will hopefully complain if you were to try to modify the contents of
1858 the string (unless you cast away const yourself).
1859 
1860 The other forms return a mutable pointer so that the string is modifiable by
1861 the caller; this is emphasized for the ones with C<mutable> in their names.
1862 
1863 As of 5.38, all forms are guaranteed to evaluate C<sv> exactly once.  For
1864 earlier Perls, use a form whose name ends with C<x> for single evaluation.
1865 
1866 C<SvPVutf8> is like C<SvPV>, but converts C<sv> to UTF-8 first if not already
1867 UTF-8.  Similarly, the other forms with C<utf8> in their names correspond to
1868 their respective forms without.
1869 
1870 C<SvPVutf8_or_null> and C<SvPVutf8_or_null_nomg> don't have corresponding
1871 non-C<utf8> forms.  Instead they are like C<SvPVutf8_nomg>, but when C<sv> is
1872 undef, they return C<NULL>.
1873 
1874 C<SvPVbyte> is like C<SvPV>, but converts C<sv> to byte representation first if
1875 currently encoded as UTF-8.  If C<sv> cannot be downgraded from UTF-8, it
1876 croaks.  Similarly, the other forms with C<byte> in their names correspond to
1877 their respective forms without.
1878 
1879 C<SvPVbyte_or_null> doesn't have a corresponding non-C<byte> form.  Instead it
1880 is like C<SvPVbyte>, but when C<sv> is undef, it returns C<NULL>.
1881 
1882 =for apidoc      SvTRUE
1883 =for apidoc_item SvTRUE_NN
1884 =for apidoc_item SvTRUE_nomg
1885 =for apidoc_item SvTRUE_nomg_NN
1886 =for apidoc_item SvTRUEx
1887 
1888 These return a boolean indicating whether Perl would evaluate the SV as true or
1889 false.  See C<L</SvOK>> for a defined/undefined test.
1890 
1891 As of Perl 5.32, all are guaranteed to evaluate C<sv> only once.  Prior to that
1892 release, only C<SvTRUEx> guaranteed single evaluation; now C<SvTRUEx> is
1893 identical to C<SvTRUE>.
1894 
1895 C<SvTRUE_nomg> and C<TRUE_nomg_NN> do not perform 'get' magic; the others do
1896 unless the scalar is already C<SvPOK>, C<SvIOK>, or C<SvNOK> (the public, not
1897 the private flags).
1898 
1899 C<SvTRUE_NN> is like C<L</SvTRUE>>, but C<sv> is assumed to be
1900 non-null (NN).  If there is a possibility that it is NULL, use plain
1901 C<SvTRUE>.
1902 
1903 C<SvTRUE_nomg_NN> is like C<L</SvTRUE_nomg>>, but C<sv> is assumed to be
1904 non-null (NN).  If there is a possibility that it is NULL, use plain
1905 C<SvTRUE_nomg>.
1906 
1907 =for apidoc Am|U32|SvIsCOW|SV* sv
1908 Returns a U32 value indicating whether the SV is Copy-On-Write (either shared
1909 hash key scalars, or full Copy On Write scalars if 5.9.0 is configured for
1910 COW).
1911 
1912 =for apidoc Am|bool|SvIsCOW_shared_hash|SV* sv
1913 Returns a boolean indicating whether the SV is Copy-On-Write shared hash key
1914 scalar.
1915 
1916 =cut
1917 */
1918 
1919 /* To pass the action to the functions called by the following macros */
1920 typedef enum {
1921     SvPVutf8_type_,
1922     SvPVbyte_type_,
1923     SvPVnormal_type_,
1924     SvPVforce_type_,
1925     SvPVutf8_pure_type_,
1926     SvPVbyte_pure_type_
1927 } PL_SvPVtype;
1928 
1929 START_EXTERN_C
1930 
1931 /* When this code was written, embed.fnc could not handle function pointer
1932  * parameters; perhaps it still can't */
1933 #ifndef PERL_NO_INLINE_FUNCTIONS
1934 PERL_STATIC_INLINE char*
1935 Perl_SvPV_helper(pTHX_ SV *const sv, STRLEN *const lp, const U32 flags, const PL_SvPVtype type, char * (*non_trivial)(pTHX_ SV *, STRLEN * const, const U32), const bool or_null, const U32 return_flags);
1936 #endif
1937 
1938 END_EXTERN_C
1939 
1940 /* This test is "is there a cached PV that we can use directly?"
1941  * We can if
1942  * a) SVf_POK is true and there's definitely no get magic on the scalar
1943  * b) SVp_POK is true, there's no get magic, and we know that the cached PV
1944  *    came from an IV conversion.
1945  * For the latter case, we don't set SVf_POK so that we can distinguish whether
1946  * the value originated as a string or as an integer, before we cached the
1947  * second representation. */
1948 #define SvPOK_or_cached_IV(sv) \
1949     (((SvFLAGS(sv) & (SVf_POK|SVs_GMG)) == SVf_POK) || ((SvFLAGS(sv) & (SVf_IOK|SVp_POK|SVs_GMG)) == (SVf_IOK|SVp_POK)))
1950 
1951 #define SvPV_flags(sv, len, flags)                                          \
1952    Perl_SvPV_helper(aTHX_ sv, &len, flags, SvPVnormal_type_,                \
1953                     Perl_sv_2pv_flags, FALSE, 0)
1954 #define SvPV_flags_const(sv, len, flags)                                    \
1955    ((const char*) Perl_SvPV_helper(aTHX_ sv, &len, flags, SvPVnormal_type_, \
1956                                    Perl_sv_2pv_flags, FALSE,                \
1957                                    SV_CONST_RETURN))
1958 #define SvPV_flags_const_nolen(sv, flags)                                   \
1959    ((const char*) Perl_SvPV_helper(aTHX_ sv, NULL, flags, SvPVnormal_type_, \
1960                                    Perl_sv_2pv_flags, FALSE,                \
1961                                    SV_CONST_RETURN))
1962 #define SvPV_flags_mutable(sv, len, flags)                                  \
1963     Perl_SvPV_helper(aTHX_ sv, &len, flags, SvPVnormal_type_,               \
1964                      Perl_sv_2pv_flags, FALSE, SV_MUTABLE_RETURN)
1965 
1966 #define SvPV_nolen(sv)                                                      \
1967     Perl_SvPV_helper(aTHX_ sv, NULL, SV_GMAGIC, SvPVnormal_type_,           \
1968                      Perl_sv_2pv_flags, FALSE, 0)
1969 
1970 #define SvPV_nolen_const(sv)  SvPV_flags_const_nolen(sv, SV_GMAGIC)
1971 
1972 #define SvPV(sv, len)               SvPV_flags(sv, len, SV_GMAGIC)
1973 #define SvPV_const(sv, len)         SvPV_flags_const(sv, len, SV_GMAGIC)
1974 #define SvPV_mutable(sv, len)       SvPV_flags_mutable(sv, len, SV_GMAGIC)
1975 
1976 #define SvPV_nomg_nolen(sv)                                                 \
1977     Perl_SvPV_helper(aTHX_ sv, NULL, 0, SvPVnormal_type_,Perl_sv_2pv_flags, \
1978                      FALSE, 0)
1979 #define SvPV_nomg(sv, len)          SvPV_flags(sv, len, 0)
1980 #define SvPV_nomg_const(sv, len)    SvPV_flags_const(sv, len, 0)
1981 #define SvPV_nomg_const_nolen(sv)   SvPV_flags_const_nolen(sv, 0)
1982 
1983 #define SvPV_force_flags(sv, len, flags)                                    \
1984     Perl_SvPV_helper(aTHX_ sv, &len, flags, SvPVforce_type_,                \
1985                      Perl_sv_pvn_force_flags, FALSE, 0)
1986 #define SvPV_force_flags_nolen(sv, flags)                                   \
1987     Perl_SvPV_helper(aTHX_ sv, NULL, flags, SvPVforce_type_,                \
1988                      Perl_sv_pvn_force_flags, FALSE, 0)
1989 #define SvPV_force_flags_mutable(sv, len, flags)                            \
1990     Perl_SvPV_helper(aTHX_ sv, &len, flags, SvPVforce_type_,                \
1991                      Perl_sv_pvn_force_flags, FALSE, SV_MUTABLE_RETURN)
1992 
1993 #define SvPV_force(sv, len)         SvPV_force_flags(sv, len, SV_GMAGIC)
1994 #define SvPV_force_nolen(sv)        SvPV_force_flags_nolen(sv, SV_GMAGIC)
1995 #define SvPV_force_mutable(sv, len) SvPV_force_flags_mutable(sv, len, SV_GMAGIC)
1996 
1997 /* "_nomg" in these defines means no mg_get() */
1998 #define SvPV_force_nomg(sv, len)    SvPV_force_flags(sv, len, 0)
1999 #define SvPV_force_nomg_nolen(sv)   SvPV_force_flags_nolen(sv, 0)
2000 
2001 #define SvPVutf8(sv, len)                                                   \
2002     Perl_SvPV_helper(aTHX_ sv, &len, SV_GMAGIC, SvPVutf8_type_,             \
2003                      Perl_sv_2pvutf8_flags, FALSE, 0)
2004 #define SvPVutf8_nomg(sv, len)                                              \
2005     Perl_SvPV_helper(aTHX_ sv, &len, 0, SvPVutf8_type_,                     \
2006                      Perl_sv_2pvutf8_flags, FALSE, 0)
2007 #define SvPVutf8_nolen(sv)                                                  \
2008     Perl_SvPV_helper(aTHX_ sv, NULL, SV_GMAGIC, SvPVutf8_type_,             \
2009                      Perl_sv_2pvutf8_flags, FALSE, 0)
2010 #define SvPVutf8_or_null(sv, len)                                           \
2011     Perl_SvPV_helper(aTHX_ sv, &len, SV_GMAGIC, SvPVutf8_type_,             \
2012                      Perl_sv_2pvutf8_flags, TRUE, 0)
2013 #define SvPVutf8_or_null_nomg(sv, len)                                      \
2014     Perl_SvPV_helper(aTHX_ sv, &len, 0, SvPVutf8_type_,                     \
2015                      Perl_sv_2pvutf8_flags, TRUE, 0)
2016 
2017 #define SvPVbyte(sv, len)                                                   \
2018     Perl_SvPV_helper(aTHX_ sv, &len, SV_GMAGIC, SvPVbyte_type_,             \
2019                      Perl_sv_2pvbyte_flags, FALSE, 0)
2020 #define SvPVbyte_nomg(sv, len)                                              \
2021     Perl_SvPV_helper(aTHX_ sv, &len, 0, SvPVbyte_type_,                     \
2022                      Perl_sv_2pvbyte_flags, FALSE, 0)
2023 #define SvPVbyte_nolen(sv)                                                  \
2024     Perl_SvPV_helper(aTHX_ sv, NULL, SV_GMAGIC, SvPVbyte_type_,             \
2025                      Perl_sv_2pvbyte_flags, FALSE, 0)
2026 #define SvPVbyte_or_null(sv, len)                                           \
2027     Perl_SvPV_helper(aTHX_ sv, &len, SV_GMAGIC, SvPVbyte_type_,             \
2028                      Perl_sv_2pvbyte_flags, TRUE, 0)
2029 #define SvPVbyte_or_null_nomg(sv, len)                                      \
2030     Perl_SvPV_helper(aTHX_ sv, &len, 0, SvPVbyte_type_,                     \
2031                      Perl_sv_2pvbyte_flags, TRUE, 0)
2032 
2033 #define SvPVutf8_force(sv, len)                                             \
2034     Perl_SvPV_helper(aTHX_ sv, &len, 0, SvPVutf8_pure_type_,                \
2035                      Perl_sv_pvutf8n_force_wrapper, FALSE, 0)
2036 
2037 #define SvPVbyte_force(sv, len)                                             \
2038     Perl_SvPV_helper(aTHX_ sv, &len, 0, SvPVbyte_pure_type_,                \
2039                      Perl_sv_pvbyten_force_wrapper, FALSE, 0)
2040 
2041 /* define FOOx(): Before FOO(x) was inlined, these were idempotent versions of
2042  * FOO(). */
2043 
2044 #define SvPVx_force(sv, len) sv_pvn_force(sv, &len)
2045 #define SvPVutf8x_force(sv, len) sv_pvutf8n_force(sv, &len)
2046 #define SvPVbytex_force(sv, len) sv_pvbyten_force(sv, &len)
2047 
2048 #define SvTRUEx(sv)        SvTRUE(sv)
2049 #define SvTRUEx_nomg(sv)   SvTRUE_nomg(sv)
2050 #define SvTRUE_nomg_NN(sv) SvTRUE_common(sv, TRUE)
2051 
2052 #  define SvIVx(sv) SvIV(sv)
2053 #  define SvUVx(sv) SvUV(sv)
2054 #  define SvNVx(sv) SvNV(sv)
2055 
2056 #if defined(PERL_USE_GCC_BRACE_GROUPS)
2057 
2058 #  define SvPVx(sv, len) ({SV *_sv = (sv); SvPV(_sv, len); })
2059 #  define SvPVx_const(sv, len) ({SV *_sv = (sv); SvPV_const(_sv, len); })
2060 #  define SvPVx_nolen(sv) ({SV *_sv = (sv); SvPV_nolen(_sv); })
2061 #  define SvPVx_nolen_const(sv) ({SV *_sv = (sv); SvPV_nolen_const(_sv); })
2062 #  define SvPVutf8x(sv, len) ({SV *_sv = (sv); SvPVutf8(_sv, len); })
2063 #  define SvPVbytex(sv, len) ({SV *_sv = (sv); SvPVbyte(_sv, len); })
2064 #  define SvPVbytex_nolen(sv) ({SV *_sv = (sv); SvPVbyte_nolen(_sv); })
2065 
2066 #else /* __GNUC__ */
2067 
2068 /* These inlined macros use globals, which will require a thread
2069  * declaration in user code, so we avoid them under threads */
2070 
2071 #  define SvPVx(sv, len) ((PL_Sv = (sv)), SvPV(PL_Sv, len))
2072 #  define SvPVx_const(sv, len) ((PL_Sv = (sv)), SvPV_const(PL_Sv, len))
2073 #  define SvPVx_nolen(sv) ((PL_Sv = (sv)), SvPV_nolen(PL_Sv))
2074 #  define SvPVx_nolen_const(sv) ((PL_Sv = (sv)), SvPV_nolen_const(PL_Sv))
2075 #  define SvPVutf8x(sv, len) ((PL_Sv = (sv)), SvPVutf8(PL_Sv, len))
2076 #  define SvPVbytex(sv, len) ((PL_Sv = (sv)), SvPVbyte(PL_Sv, len))
2077 #  define SvPVbytex_nolen(sv) ((PL_Sv = (sv)), SvPVbyte_nolen(PL_Sv))
2078 #endif /* __GNU__ */
2079 
2080 #define SvIsCOW(sv)              (SvFLAGS(sv) & SVf_IsCOW)
2081 #define SvIsCOW_on(sv)           (SvFLAGS(sv) |= SVf_IsCOW)
2082 #define SvIsCOW_off(sv)          (SvFLAGS(sv) &= ~(SVf_IsCOW|SVppv_STATIC))
2083 #define SvIsCOW_shared_hash(sv)  ((SvFLAGS(sv) & (SVf_IsCOW|SVppv_STATIC)) == (SVf_IsCOW) && SvLEN(sv) == 0)
2084 #define SvIsCOW_static(sv)       ((SvFLAGS(sv) & (SVf_IsCOW|SVppv_STATIC)) == (SVf_IsCOW|SVppv_STATIC))
2085 
2086 #define SvSHARED_HEK_FROM_PV(pvx) \
2087         ((struct hek*)(pvx - STRUCT_OFFSET(struct hek, hek_key)))
2088 /*
2089 =for apidoc Am|struct hek*|SvSHARED_HASH|SV * sv
2090 Returns the hash for C<sv> created by C<L</newSVpvn_share>>.
2091 
2092 =cut
2093 */
2094 #define SvSHARED_HASH(sv) (0 + SvSHARED_HEK_FROM_PV(SvPVX_const(sv))->hek_hash)
2095 
2096 /* flag values for sv_*_flags functions */
2097 #define SV_UTF8_NO_ENCODING	0       /* No longer used */
2098 
2099 /*
2100 =for apidoc AmnhD||SV_UTF8_NO_ENCODING
2101 
2102 =cut
2103 */
2104 
2105 /* Flags used as `U32 flags` arguments to various functions */
2106 #define SV_IMMEDIATE_UNREF      (1 <<  0) /* 0x0001 -     1 */
2107 #define SV_GMAGIC               (1 <<  1) /* 0x0002 -     2 */
2108 #define SV_COW_DROP_PV          (1 <<  2) /* 0x0004 -     4 */
2109 /* SV_NOT_USED                  (1 <<  3)    0x0008 -     8 */
2110 #define SV_NOSTEAL              (1 <<  4) /* 0x0010 -    16 */
2111 #define SV_CONST_RETURN         (1 <<  5) /* 0x0020 -    32 */
2112 #define SV_MUTABLE_RETURN       (1 <<  6) /* 0x0040 -    64 */
2113 #define SV_SMAGIC               (1 <<  7) /* 0x0080 -   128 */
2114 #define SV_HAS_TRAILING_NUL     (1 <<  8) /* 0x0100 -   256 */
2115 #define SV_COW_SHARED_HASH_KEYS (1 <<  9) /* 0x0200 -   512 */
2116 /* This one is only enabled for PERL_OLD_COPY_ON_WRITE */
2117 /* XXX This flag actually enabled for any COW.  But it appears not to do
2118        anything.  Can we just remove it?  Or will it serve some future
2119        purpose.  */
2120 #define SV_COW_OTHER_PVS        (1 << 10) /* 0x0400 -  1024 */
2121 /* Make sv_2pv_flags return NULL if something is undefined.  */
2122 #define SV_UNDEF_RETURNS_NULL   (1 << 11) /* 0x0800 -  2048 */
2123 /* Tell sv_utf8_upgrade() to not check to see if an upgrade is really needed.
2124  * This is used when the caller has already determined it is, and avoids
2125  * redundant work */
2126 #define SV_FORCE_UTF8_UPGRADE   (1 << 12) /* 0x1000 -  4096 */
2127 /* if (after resolving magic etc), the SV is found to be overloaded,
2128  * don't call the overload magic, just return as-is */
2129 #define SV_SKIP_OVERLOAD        (1 << 13) /* 0x2000 -  8192 */
2130 #define SV_CATBYTES             (1 << 14) /* 0x4000 - 16384 */
2131 #define SV_CATUTF8              (1 << 15) /* 0x8000 - 32768 */
2132 
2133 /* The core is safe for this COW optimisation. XS code on CPAN may not be.
2134    So only default to doing the COW setup if we're in the core.
2135  */
2136 #ifdef PERL_CORE
2137 #  ifndef SV_DO_COW_SVSETSV
2138 #    define SV_DO_COW_SVSETSV	SV_COW_SHARED_HASH_KEYS|SV_COW_OTHER_PVS
2139 #  endif
2140 #endif
2141 
2142 #ifndef SV_DO_COW_SVSETSV
2143 #  define SV_DO_COW_SVSETSV	0
2144 #endif
2145 
2146 
2147 #define sv_unref(sv)    	sv_unref_flags(sv, 0)
2148 #define sv_force_normal(sv)	sv_force_normal_flags(sv, 0)
2149 #define sv_usepvn(sv, p, l)	sv_usepvn_flags(sv, p, l, 0)
2150 #define sv_usepvn_mg(sv, p, l)	sv_usepvn_flags(sv, p, l, SV_SMAGIC)
2151 
2152 /*
2153 =for apidoc Am|void|SV_CHECK_THINKFIRST_COW_DROP|SV * sv
2154 
2155 Call this when you are about to replace the PV value in C<sv>, which is
2156 potentially copy-on-write.  It stops any sharing with other SVs, so that no
2157 Copy on Write (COW) actually happens.  This COW would be useless, as it would
2158 immediately get changed to something else.  This function also removes any
2159 other encumbrances that would be problematic when changing C<sv>.
2160 
2161 =cut
2162 */
2163 
2164 #define SV_CHECK_THINKFIRST_COW_DROP(sv) if (SvTHINKFIRST(sv)) \
2165                                     sv_force_normal_flags(sv, SV_COW_DROP_PV)
2166 
2167 #ifdef PERL_COPY_ON_WRITE
2168 #   define SvCANCOW(sv)					    \
2169         (SvIsCOW(sv)					     \
2170          ? SvLEN(sv) ? CowREFCNT(sv) != SV_COW_REFCNT_MAX : 1 \
2171          : (SvFLAGS(sv) & CAN_COW_MASK) == CAN_COW_FLAGS       \
2172                             && SvCUR(sv)+1 < SvLEN(sv))
2173    /* Note: To allow 256 COW "copies", a refcnt of 0 means 1. */
2174 #   define CowREFCNT(sv)	(*(U8 *)(SvPVX(sv)+SvLEN(sv)-1))
2175 #   define SV_COW_REFCNT_MAX	nBIT_UMAX(sizeof(U8) * CHARBITS)
2176 #   define CAN_COW_MASK	(SVf_POK|SVf_ROK|SVp_POK|SVf_FAKE| \
2177                          SVf_OOK|SVf_BREAK|SVf_READONLY|SVf_PROTECT)
2178 #endif
2179 
2180 #define CAN_COW_FLAGS	(SVp_POK|SVf_POK)
2181 
2182 /*
2183 =for apidoc Am|void|SV_CHECK_THINKFIRST|SV * sv
2184 
2185 Remove any encumbrances from C<sv>, that need to be taken care of before it
2186 is modifiable.  For example if it is Copy on Write (COW), now is the time to
2187 make that copy.
2188 
2189 If you know that you are about to change the PV value of C<sv>, instead use
2190 L</C<SV_CHECK_THINKFIRST_COW_DROP>> to avoid the write that would be
2191 immediately written again.
2192 
2193 =cut
2194 */
2195 #define SV_CHECK_THINKFIRST(sv) if (SvTHINKFIRST(sv)) \
2196                                     sv_force_normal_flags(sv, 0)
2197 
2198 
2199 /* all these 'functions' are now just macros */
2200 
2201 #define sv_pv(sv) SvPV_nolen(sv)
2202 #define sv_pvutf8(sv) SvPVutf8_nolen(sv)
2203 #define sv_pvbyte(sv) SvPVbyte_nolen(sv)
2204 
2205 #define sv_pvn_force_nomg(sv, lp) sv_pvn_force_flags(sv, lp, 0)
2206 #define sv_utf8_upgrade_flags(sv, flags) sv_utf8_upgrade_flags_grow(sv, flags, 0)
2207 #define sv_utf8_upgrade_nomg(sv) sv_utf8_upgrade_flags(sv, 0)
2208 #define sv_utf8_downgrade(sv, fail_ok) sv_utf8_downgrade_flags(sv, fail_ok, SV_GMAGIC)
2209 #define sv_utf8_downgrade_nomg(sv, fail_ok) sv_utf8_downgrade_flags(sv, fail_ok, 0)
2210 #define sv_catpvn_nomg(dsv, sstr, slen) sv_catpvn_flags(dsv, sstr, slen, 0)
2211 #define sv_catpv_nomg(dsv, sstr) sv_catpv_flags(dsv, sstr, 0)
2212 #define sv_setsv(dsv, ssv) \
2213         sv_setsv_flags(dsv, ssv, SV_GMAGIC|SV_DO_COW_SVSETSV)
2214 #define sv_setsv_nomg(dsv, ssv) sv_setsv_flags(dsv, ssv, SV_DO_COW_SVSETSV)
2215 #define sv_catsv(dsv, ssv) sv_catsv_flags(dsv, ssv, SV_GMAGIC)
2216 #define sv_catsv_nomg(dsv, ssv) sv_catsv_flags(dsv, ssv, 0)
2217 #define sv_catsv_mg(dsv, ssv) sv_catsv_flags(dsv, ssv, SV_GMAGIC|SV_SMAGIC)
2218 #define sv_catpvn(dsv, sstr, slen) sv_catpvn_flags(dsv, sstr, slen, SV_GMAGIC)
2219 #define sv_catpvn_mg(dsv, sstr, slen) sv_catpvn_flags(dsv, sstr, slen, SV_GMAGIC|SV_SMAGIC);
2220 #define sv_copypv(dsv, ssv) sv_copypv_flags(dsv, ssv, SV_GMAGIC)
2221 #define sv_copypv_nomg(dsv, ssv) sv_copypv_flags(dsv, ssv, 0)
2222 #define sv_2pv(sv, lp) sv_2pv_flags(sv, lp, SV_GMAGIC)
2223 #define sv_2pv_nolen(sv) sv_2pv(sv, 0)
2224 #define sv_2pvbyte(sv, lp) sv_2pvbyte_flags(sv, lp, SV_GMAGIC)
2225 #define sv_2pvbyte_nolen(sv) sv_2pvbyte(sv, 0)
2226 #define sv_2pvutf8(sv, lp) sv_2pvutf8_flags(sv, lp, SV_GMAGIC)
2227 #define sv_2pvutf8_nolen(sv) sv_2pvutf8(sv, 0)
2228 #define sv_2pv_nomg(sv, lp) sv_2pv_flags(sv, lp, 0)
2229 #define sv_pvn_force(sv, lp) sv_pvn_force_flags(sv, lp, SV_GMAGIC)
2230 #define sv_utf8_upgrade(sv) sv_utf8_upgrade_flags(sv, SV_GMAGIC)
2231 #define sv_2iv(sv) sv_2iv_flags(sv, SV_GMAGIC)
2232 #define sv_2uv(sv) sv_2uv_flags(sv, SV_GMAGIC)
2233 #define sv_2nv(sv) sv_2nv_flags(sv, SV_GMAGIC)
2234 #define sv_eq(sv1, sv2) sv_eq_flags(sv1, sv2, SV_GMAGIC)
2235 #define sv_cmp(sv1, sv2) sv_cmp_flags(sv1, sv2, SV_GMAGIC)
2236 #define sv_cmp_locale(sv1, sv2) sv_cmp_locale_flags(sv1, sv2, SV_GMAGIC)
2237 #define sv_numeq(sv1, sv2) sv_numeq_flags(sv1, sv2, SV_GMAGIC)
2238 #define sv_streq(sv1, sv2) sv_streq_flags(sv1, sv2, SV_GMAGIC)
2239 #define sv_collxfrm(sv, nxp) sv_collxfrm_flags(sv, nxp, SV_GMAGIC)
2240 #define sv_2bool(sv) sv_2bool_flags(sv, SV_GMAGIC)
2241 #define sv_2bool_nomg(sv) sv_2bool_flags(sv, 0)
2242 #define sv_insert(bigstr, offset, len, little, littlelen)		\
2243         Perl_sv_insert_flags(aTHX_ (bigstr),(offset), (len), (little),	\
2244                              (littlelen), SV_GMAGIC)
2245 #define sv_mortalcopy(sv) \
2246         Perl_sv_mortalcopy_flags(aTHX_ sv, SV_GMAGIC|SV_DO_COW_SVSETSV)
2247 #define sv_cathek(sv,hek)					    \
2248         STMT_START {						     \
2249             HEK * const bmxk = hek;				      \
2250             sv_catpvn_flags(sv, HEK_KEY(bmxk), HEK_LEN(bmxk),	       \
2251                             HEK_UTF8(bmxk) ? SV_CATUTF8 : SV_CATBYTES); \
2252         } STMT_END
2253 
2254 /* Should be named SvCatPVN_utf8_upgrade? */
2255 #define sv_catpvn_nomg_utf8_upgrade(dsv, sstr, slen, nsv)	\
2256         STMT_START {					\
2257             if (!(nsv))					\
2258                 nsv = newSVpvn_flags(sstr, slen, SVs_TEMP);	\
2259             else					\
2260                 sv_setpvn(nsv, sstr, slen);		\
2261             SvUTF8_off(nsv);				\
2262             sv_utf8_upgrade(nsv);			\
2263             sv_catsv_nomg(dsv, nsv);			\
2264         } STMT_END
2265 #define sv_catpvn_nomg_maybeutf8(dsv, sstr, len, is_utf8) \
2266         sv_catpvn_flags(dsv, sstr, len, (is_utf8)?SV_CATUTF8:SV_CATBYTES)
2267 
2268 #if defined(PERL_CORE) || defined(PERL_EXT)
2269 # define sv_or_pv_len_utf8(sv, pv, bytelen)	      \
2270     (SvGAMAGIC(sv)				       \
2271         ? utf8_length((U8 *)(pv), (U8 *)(pv)+(bytelen))	\
2272         : sv_len_utf8(sv))
2273 #endif
2274 
2275 /*
2276 =for apidoc newRV
2277 =for apidoc_item ||newRV_inc|
2278 
2279 These are identical.  They create an RV wrapper for an SV.  The reference count
2280 for the original SV is incremented.
2281 
2282 =cut
2283 */
2284 
2285 #define newRV_inc(sv)	newRV(sv)
2286 
2287 /* the following macros update any magic values this C<sv> is associated with */
2288 
2289 /*
2290 =for apidoc_section $SV
2291 
2292 =for apidoc Am|void|SvSETMAGIC|SV* sv
2293 Invokes C<L</mg_set>> on an SV if it has 'set' magic.  This is necessary
2294 after modifying a scalar, in case it is a magical variable like C<$|>
2295 or a tied variable (it calls C<STORE>).  This macro evaluates its
2296 argument more than once.
2297 
2298 =for apidoc Am|void|SvSetMagicSV|SV* dsv|SV* ssv
2299 =for apidoc_item    SvSetMagicSV_nosteal
2300 =for apidoc_item    SvSetSV
2301 =for apidoc_item    SvSetSV_nosteal
2302 
2303 if C<dsv> is the same as C<ssv>, these do nothing.  Otherwise they all call
2304 some form of C<L</sv_setsv>>.  They may evaluate their arguments more than
2305 once.
2306 
2307 The only differences are:
2308 
2309 C<SvSetMagicSV> and C<SvSetMagicSV_nosteal> perform any required 'set' magic
2310 afterwards on the destination SV; C<SvSetSV> and C<SvSetSV_nosteal> do not.
2311 
2312 C<SvSetSV_nosteal> C<SvSetMagicSV_nosteal> call a non-destructive version of
2313 C<sv_setsv>.
2314 
2315 =for apidoc Am|void|SvSHARE|SV* sv
2316 Arranges for C<sv> to be shared between threads if a suitable module
2317 has been loaded.
2318 
2319 =for apidoc Am|void|SvLOCK|SV* sv
2320 Arranges for a mutual exclusion lock to be obtained on C<sv> if a suitable module
2321 has been loaded.
2322 
2323 =for apidoc Am|void|SvUNLOCK|SV* sv
2324 Releases a mutual exclusion lock on C<sv> if a suitable module
2325 has been loaded.
2326 
2327 =for apidoc_section $SV
2328 
2329 =for apidoc Am|char *|SvGROW|SV* sv|STRLEN len
2330 Expands the character buffer in the SV so that it has room for the
2331 indicated number of bytes (remember to reserve space for an extra trailing
2332 C<NUL> character).  Calls C<sv_grow> to perform the expansion if necessary.
2333 Returns a pointer to the character
2334 buffer.  SV must be of type >= C<SVt_PV>.  One
2335 alternative is to call C<sv_grow> if you are not sure of the type of SV.
2336 
2337 You might mistakenly think that C<len> is the number of bytes to add to the
2338 existing size, but instead it is the total size C<sv> should be.
2339 
2340 =for apidoc Am|char *|SvPVCLEAR|SV* sv
2341 Ensures that sv is a SVt_PV and that its SvCUR is 0, and that it is
2342 properly null terminated. Equivalent to sv_setpvs(""), but more efficient.
2343 
2344 =for apidoc Am|char *|SvPVCLEAR_FRESH|SV* sv
2345 
2346 Like SvPVCLEAR, but optimized for newly-minted SVt_PV/PVIV/PVNV/PVMG
2347 that already have a PV buffer allocated, but no SvTHINKFIRST.
2348 
2349 =cut
2350 */
2351 
2352 #define SvPVCLEAR(sv) sv_setpv_bufsize(sv,0,0)
2353 #define SvPVCLEAR_FRESH(sv) sv_setpv_freshbuf(sv)
2354 #define SvSHARE(sv) PL_sharehook(aTHX_ sv)
2355 #define SvLOCK(sv) PL_lockhook(aTHX_ sv)
2356 #define SvUNLOCK(sv) PL_unlockhook(aTHX_ sv)
2357 #define SvDESTROYABLE(sv) PL_destroyhook(aTHX_ sv)
2358 
2359 #define SvSETMAGIC(x) STMT_START { if (UNLIKELY(SvSMAGICAL(x))) mg_set(x); } STMT_END
2360 
2361 #define SvSetSV_and(dst,src,finally) \
2362         STMT_START {					\
2363             SV * src_ = src;                            \
2364             SV * dst_ = dst;                            \
2365             if (LIKELY((dst_) != (src_))) {             \
2366                 sv_setsv(dst_, src_);                   \
2367                 finally;				\
2368             }						\
2369         } STMT_END
2370 
2371 #define SvSetSV_nosteal_and(dst,src,finally) \
2372         STMT_START {					\
2373             SV * src_ = src;                            \
2374             SV * dst_ = dst;                            \
2375             if (LIKELY((dst_) != (src_))) {             \
2376                 sv_setsv_flags(dst_, src_,              \
2377                         SV_GMAGIC                       \
2378                       | SV_NOSTEAL                      \
2379                       | SV_DO_COW_SVSETSV);             \
2380                 finally;				\
2381             }						\
2382         } STMT_END
2383 
2384 #define SvSetSV(dst,src) \
2385                 SvSetSV_and(dst,src,/*nothing*/;)
2386 #define SvSetSV_nosteal(dst,src) \
2387                 SvSetSV_nosteal_and(dst,src,/*nothing*/;)
2388 
2389 #define SvSetMagicSV(dst,src) \
2390                 SvSetSV_and(dst,src,SvSETMAGIC(dst))
2391 #define SvSetMagicSV_nosteal(dst,src) \
2392                 SvSetSV_nosteal_and(dst,src,SvSETMAGIC(dst))
2393 
2394 
2395 #if !defined(SKIP_DEBUGGING)
2396 #define SvPEEK(sv) sv_peek(sv)
2397 #else
2398 #define SvPEEK(sv) ""
2399 #endif
2400 
2401 /* Is this a per-interpreter immortal SV (rather than global)?
2402  * These should either occupy adjacent entries in the interpreter struct
2403  * (MULTIPLICITY) or adjacent elements of PL_sv_immortals[] otherwise.
2404  * The unsigned (Size_t) cast avoids the need for a second < 0 condition.
2405  */
2406 #define SvIMMORTAL_INTERP(sv) ((Size_t)((sv) - &PL_sv_yes) < 4)
2407 
2408 /* Does this immortal have a true value? Currently only PL_sv_yes does. */
2409 #define SvIMMORTAL_TRUE(sv)   ((sv) == &PL_sv_yes)
2410 
2411 /* the SvREADONLY() test is to quickly reject most SVs */
2412 #define SvIMMORTAL(sv) \
2413                 (  SvREADONLY(sv) \
2414                 && (SvIMMORTAL_INTERP(sv) || (sv) == &PL_sv_placeholder))
2415 
2416 #ifdef DEBUGGING
2417    /* exercise the immortal resurrection code in sv_free2() */
2418 #  define SvREFCNT_IMMORTAL 1000
2419 #else
2420 #  define SvREFCNT_IMMORTAL ((~(U32)0)/2)
2421 #endif
2422 
2423 /*
2424 =for apidoc Am|SV *|boolSV|bool b
2425 
2426 Returns a true SV if C<b> is a true value, or a false SV if C<b> is 0.
2427 
2428 See also C<L</PL_sv_yes>> and C<L</PL_sv_no>>.
2429 
2430 =cut
2431 */
2432 
2433 #define boolSV(b) ((b) ? &PL_sv_yes : &PL_sv_no)
2434 
2435 /*
2436 =for apidoc Am|void|sv_setbool|SV *sv|bool b
2437 =for apidoc_item |void|sv_setbool_mg|SV *sv|bool b
2438 
2439 These set an SV to a true or false boolean value, upgrading first if necessary.
2440 
2441 They differ only in that C<sv_setbool_mg> handles 'set' magic; C<sv_setbool>
2442 does not.
2443 
2444 =cut
2445 */
2446 
2447 #define sv_setbool(sv, b)     sv_setsv(sv, boolSV(b))
2448 #define sv_setbool_mg(sv, b)  sv_setsv_mg(sv, boolSV(b))
2449 
2450 #define isGV(sv) (SvTYPE(sv) == SVt_PVGV)
2451 /* If I give every macro argument a different name, then there won't be bugs
2452    where nested macros get confused. Been there, done that.  */
2453 /*
2454 =for apidoc Am|bool|isGV_with_GP|SV * sv
2455 Returns a boolean as to whether or not C<sv> is a GV with a pointer to a GP
2456 (glob pointer).
2457 
2458 =cut
2459 */
2460 #define isGV_with_GP(pwadak) \
2461         (((SvFLAGS(pwadak) & (SVp_POK|SVpgv_GP)) == SVpgv_GP)	\
2462         && (SvTYPE(pwadak) == SVt_PVGV || SvTYPE(pwadak) == SVt_PVLV))
2463 
2464 #define isGV_with_GP_on(sv)                                            \
2465     STMT_START {			                               \
2466         SV * sv_ = MUTABLE_SV(sv);                                     \
2467         assert (SvTYPE(sv_) == SVt_PVGV || SvTYPE(sv_) == SVt_PVLV);   \
2468         assert (!SvPOKp(sv_));					       \
2469         assert (!SvIOKp(sv_));					       \
2470         (SvFLAGS(sv_) |= SVpgv_GP);				       \
2471     } STMT_END
2472 
2473 #define isGV_with_GP_off(sv)                                           \
2474     STMT_START {                                                       \
2475         SV * sv_ = MUTABLE_SV(sv);                                     \
2476         assert (SvTYPE(sv_) == SVt_PVGV || SvTYPE(sv_) == SVt_PVLV);   \
2477         assert (!SvPOKp(sv_));                                         \
2478         assert (!SvIOKp(sv_));					       \
2479         (SvFLAGS(sv_) &= ~SVpgv_GP);				       \
2480     } STMT_END
2481 
2482 #ifdef PERL_CORE
2483 # define isGV_or_RVCV(kadawp) \
2484     (isGV(kadawp) || (SvROK(kadawp) && SvTYPE(SvRV(kadawp)) == SVt_PVCV))
2485 #endif
2486 #define isREGEXP(sv) \
2487     (SvTYPE(sv) == SVt_REGEXP				      \
2488      || (SvFLAGS(sv) & (SVTYPEMASK|SVpgv_GP|SVf_FAKE))        \
2489          == (SVt_PVLV|SVf_FAKE))
2490 
2491 
2492 #ifdef PERL_ANY_COW
2493 # define SvGROW(sv,len) \
2494         (SvIsCOW(sv) || SvLEN(sv) < (len) ? sv_grow(sv,len) : SvPVX(sv))
2495 #else
2496 # define SvGROW(sv,len) (SvLEN(sv) < (len) ? sv_grow(sv,len) : SvPVX(sv))
2497 #endif
2498 #define SvGROW_mutable(sv,len) \
2499     (SvLEN(sv) < (len) ? sv_grow(sv,len) : SvPVX_mutable(sv))
2500 #define Sv_Grow sv_grow
2501 
2502 #define CLONEf_COPY_STACKS 1
2503 #define CLONEf_KEEP_PTR_TABLE 2
2504 #define CLONEf_CLONE_HOST 4
2505 #define CLONEf_JOIN_IN 8
2506 
2507 struct clone_params {
2508   AV* stashes;
2509   UV  flags;
2510   PerlInterpreter *proto_perl;
2511   PerlInterpreter *new_perl;
2512   AV *unreferenced;
2513 };
2514 
2515 /* SV_NOSTEAL prevents TEMP buffers being, well, stolen, and saves games
2516    with SvTEMP_off and SvTEMP_on round a call to sv_setsv.  */
2517 #define newSVsv(sv) newSVsv_flags((sv), SV_GMAGIC|SV_NOSTEAL)
2518 #define newSVsv_nomg(sv) newSVsv_flags((sv), SV_NOSTEAL)
2519 
2520 /*
2521 =for apidoc Am|SV*|newSVpvn_utf8|const char* s|STRLEN len|U32 utf8
2522 
2523 Creates a new SV and copies a string (which may contain C<NUL> (C<\0>)
2524 characters) into it.  If C<utf8> is true, calls
2525 C<SvUTF8_on> on the new SV.  Implemented as a wrapper around C<newSVpvn_flags>.
2526 
2527 =cut
2528 */
2529 
2530 #define newSVpvn_utf8(s, len, u) newSVpvn_flags((s), (len), (u) ? SVf_UTF8 : 0)
2531 
2532 /*
2533 =for apidoc Amx|SV*|newSVpadname|PADNAME *pn
2534 
2535 Creates a new SV containing the pad name.
2536 
2537 =cut
2538 */
2539 
2540 #define newSVpadname(pn) newSVpvn_utf8(PadnamePV(pn), PadnameLEN(pn), TRUE)
2541 
2542 /*
2543 =for apidoc Am|void|SvOOK_offset|SV*sv|STRLEN len
2544 
2545 Reads into C<len> the offset from C<SvPVX> back to the true start of the
2546 allocated buffer, which will be non-zero if C<sv_chop> has been used to
2547 efficiently remove characters from start of the buffer.  Implemented as a
2548 macro, which takes the address of C<len>, which must be of type C<STRLEN>.
2549 Evaluates C<sv> more than once.  Sets C<len> to 0 if C<SvOOK(sv)> is false.
2550 
2551 =cut
2552 */
2553 
2554 #ifdef DEBUGGING
2555 /* Does the bot know something I don't?
2556 10:28 <@Nicholas> metabatman
2557 10:28 <+meta> Nicholas: crash
2558 */
2559 #  define SvOOK_offset(sv, offset) STMT_START {				\
2560         STATIC_ASSERT_STMT(sizeof(offset) == sizeof(STRLEN));		\
2561         if (SvOOK(sv)) {						\
2562             const U8 *_crash = (U8*)SvPVX_const(sv);			\
2563             (offset) = *--_crash;					\
2564             if (!(offset)) {						\
2565                 _crash -= sizeof(STRLEN);				\
2566                 Copy(_crash, (U8 *)&(offset), sizeof(STRLEN), U8);	\
2567             }								\
2568             {								\
2569                 /* Validate the preceding buffer's sentinels to		\
2570                    verify that no-one is using it.  */			\
2571                 const U8 *const _bonk = (U8*)SvPVX_const(sv) - (offset);\
2572                 while (_crash > _bonk) {				\
2573                     --_crash;						\
2574                     assert (*_crash == (U8)PTR2UV(_crash));		\
2575                 }							\
2576             }								\
2577         } else {							\
2578             (offset) = 0;						\
2579         }								\
2580     } STMT_END
2581 #else
2582     /* This is the same code, but avoids using any temporary variables:  */
2583 #  define SvOOK_offset(sv, offset) STMT_START {				\
2584         STATIC_ASSERT_STMT(sizeof(offset) == sizeof(STRLEN));		\
2585         if (SvOOK(sv)) {						\
2586             (offset) = ((U8*)SvPVX_const(sv))[-1];			\
2587             if (!(offset)) {						\
2588                 Copy(SvPVX_const(sv) - 1 - sizeof(STRLEN),		\
2589                      (U8*)&(offset), sizeof(STRLEN), U8);		\
2590             }								\
2591         } else {							\
2592             (offset) = 0;						\
2593         }								\
2594     } STMT_END
2595 #endif
2596 
2597 /*
2598 =for apidoc_section $io
2599 =for apidoc newIO
2600 
2601 Create a new IO, setting the reference count to 1.
2602 
2603 =cut
2604 */
2605 #define newIO()	MUTABLE_IO(newSV_type(SVt_PVIO))
2606 
2607 #if defined(PERL_CORE) || defined(PERL_EXT)
2608 
2609 #  define SV_CONST(name) \
2610         PL_sv_consts[SV_CONST_##name] \
2611                 ? PL_sv_consts[SV_CONST_##name] \
2612                 : (PL_sv_consts[SV_CONST_##name] = newSVpv_share(#name, 0))
2613 
2614 #  define SV_CONST_TIESCALAR 0
2615 #  define SV_CONST_TIEARRAY 1
2616 #  define SV_CONST_TIEHASH 2
2617 #  define SV_CONST_TIEHANDLE 3
2618 
2619 #  define SV_CONST_FETCH 4
2620 #  define SV_CONST_FETCHSIZE 5
2621 #  define SV_CONST_STORE 6
2622 #  define SV_CONST_STORESIZE 7
2623 #  define SV_CONST_EXISTS 8
2624 
2625 #  define SV_CONST_PUSH 9
2626 #  define SV_CONST_POP 10
2627 #  define SV_CONST_SHIFT 11
2628 #  define SV_CONST_UNSHIFT 12
2629 #  define SV_CONST_SPLICE 13
2630 #  define SV_CONST_EXTEND 14
2631 
2632 #  define SV_CONST_FIRSTKEY 15
2633 #  define SV_CONST_NEXTKEY 16
2634 #  define SV_CONST_SCALAR 17
2635 
2636 #  define SV_CONST_OPEN 18
2637 #  define SV_CONST_WRITE 19
2638 #  define SV_CONST_PRINT 20
2639 #  define SV_CONST_PRINTF 21
2640 #  define SV_CONST_READ 22
2641 #  define SV_CONST_READLINE 23
2642 #  define SV_CONST_GETC 24
2643 #  define SV_CONST_SEEK 25
2644 #  define SV_CONST_TELL 26
2645 #  define SV_CONST_EOF 27
2646 #  define SV_CONST_BINMODE 28
2647 #  define SV_CONST_FILENO 29
2648 #  define SV_CONST_CLOSE 30
2649 
2650 #  define SV_CONST_DELETE 31
2651 #  define SV_CONST_CLEAR 32
2652 #  define SV_CONST_UNTIE 33
2653 #  define SV_CONST_DESTROY 34
2654 #endif
2655 
2656 #define SV_CONSTS_COUNT 35
2657 
2658 /*
2659  * Bodyless IVs and NVs!
2660  *
2661  * Since 5.9.2, we can avoid allocating a body for SVt_IV-type SVs.
2662  * Since the larger IV-holding variants of SVs store their integer
2663  * values in their respective bodies, the family of SvIV() accessor
2664  * macros would  naively have to branch on the SV type to find the
2665  * integer value either in the HEAD or BODY. In order to avoid this
2666  * expensive branch, a clever soul has deployed a great hack:
2667  * We set up the SvANY pointer such that instead of pointing to a
2668  * real body, it points into the memory before the location of the
2669  * head. We compute this pointer such that the location of
2670  * the integer member of the hypothetical body struct happens to
2671  * be the same as the location of the integer member of the bodyless
2672  * SV head. This now means that the SvIV() family of accessors can
2673  * always read from the (hypothetical or real) body via SvANY.
2674  *
2675  * Since the 5.21 dev series, we employ the same trick for NVs
2676  * if the architecture can support it (NVSIZE <= IVSIZE).
2677  */
2678 
2679 /* The following two macros compute the necessary offsets for the above
2680  * trick and store them in SvANY for SvIV() (and friends) to use. */
2681 
2682 #  define SET_SVANY_FOR_BODYLESS_IV(sv) \
2683     STMT_START {                                            \
2684         SV * sv_ = MUTABLE_SV(sv);                          \
2685         SvANY(sv_) =   (XPVIV*)((char*)&(sv_->sv_u.svu_iv)  \
2686                     - STRUCT_OFFSET(XPVIV, xiv_iv));        \
2687     } STMT_END
2688 
2689 #  define SET_SVANY_FOR_BODYLESS_NV(sv) \
2690     STMT_START {                                            \
2691         SV * sv_ = MUTABLE_SV(sv);                          \
2692         SvANY(sv_) =   (XPVNV*)((char*)&(sv_->sv_u.svu_nv)  \
2693                     - STRUCT_OFFSET(XPVNV, xnv_u.xnv_nv));  \
2694     } STMT_END
2695 
2696 #if defined(PERL_CORE) && defined(USE_ITHREADS)
2697 /* Certain cases in Perl_ss_dup have been merged, by relying on the fact
2698    that currently av_dup, gv_dup and hv_dup are the same as sv_dup.
2699    If this changes, please unmerge ss_dup.
2700    Likewise, sv_dup_inc_multiple() relies on this fact.  */
2701 #  define sv_dup_inc_NN(s,t)	SvREFCNT_inc_NN(sv_dup_inc(s,t))
2702 #  define av_dup(s,t)	MUTABLE_AV(sv_dup((const SV *)s,t))
2703 #  define av_dup_inc(s,t)	MUTABLE_AV(sv_dup_inc((const SV *)s,t))
2704 #  define hv_dup(s,t)	MUTABLE_HV(sv_dup((const SV *)s,t))
2705 #  define hv_dup_inc(s,t)	MUTABLE_HV(sv_dup_inc((const SV *)s,t))
2706 #  define cv_dup(s,t)	MUTABLE_CV(sv_dup((const SV *)s,t))
2707 #  define cv_dup_inc(s,t)	MUTABLE_CV(sv_dup_inc((const SV *)s,t))
2708 #  define io_dup(s,t)	MUTABLE_IO(sv_dup((const SV *)s,t))
2709 #  define io_dup_inc(s,t)	MUTABLE_IO(sv_dup_inc((const SV *)s,t))
2710 #  define gv_dup(s,t)	MUTABLE_GV(sv_dup((const SV *)s,t))
2711 #  define gv_dup_inc(s,t)	MUTABLE_GV(sv_dup_inc((const SV *)s,t))
2712 #endif
2713 
2714 /*
2715  * ex: set ts=8 sts=4 sw=4 et:
2716  */
2717