3 * Copyright (c) 1991-2003, Larry Wall
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
11 #undef sv_flags /* Convex has this in <signal.h> for sigvec() */
17 =for apidoc AmU||svtype
18 An enum of flags for Perl types. These are found in the file B<sv.h>
19 in the C<svtype> enum. Test these flags with the C<SvTYPE> macro.
21 =for apidoc AmU||SVt_PV
22 Pointer type flag for scalars. See C<svtype>.
24 =for apidoc AmU||SVt_IV
25 Integer type flag for scalars. See C<svtype>.
27 =for apidoc AmU||SVt_NV
28 Double type flag for scalars. See C<svtype>.
30 =for apidoc AmU||SVt_PVMG
31 Type flag for blessed scalars. See C<svtype>.
33 =for apidoc AmU||SVt_PVAV
34 Type flag for arrays. See C<svtype>.
36 =for apidoc AmU||SVt_PVHV
37 Type flag for hashes. See C<svtype>.
39 =for apidoc AmU||SVt_PVCV
40 Type flag for code refs. See C<svtype>.
64 /* Using C's structural equivalence to help emulate C++ inheritance here... */
66 struct STRUCT_SV { /* struct sv { */
67 void* sv_any; /* pointer to something */
68 U32 sv_refcnt; /* how many references to us */
69 U32 sv_flags; /* what we are */
73 XPVGV* sv_any; /* pointer to something */
74 U32 sv_refcnt; /* how many references to us */
75 U32 sv_flags; /* what we are */
79 XPVCV* sv_any; /* pointer to something */
80 U32 sv_refcnt; /* how many references to us */
81 U32 sv_flags; /* what we are */
85 XPVAV* sv_any; /* pointer to something */
86 U32 sv_refcnt; /* how many references to us */
87 U32 sv_flags; /* what we are */
91 XPVHV* sv_any; /* pointer to something */
92 U32 sv_refcnt; /* how many references to us */
93 U32 sv_flags; /* what we are */
97 XPVIO* sv_any; /* pointer to something */
98 U32 sv_refcnt; /* how many references to us */
99 U32 sv_flags; /* what we are */
103 =head1 SV Manipulation Functions
105 =for apidoc Am|U32|SvREFCNT|SV* sv
106 Returns the value of the object's reference count.
108 =for apidoc Am|SV*|SvREFCNT_inc|SV* sv
109 Increments the reference count of the given SV.
111 =for apidoc Am|void|SvREFCNT_dec|SV* sv
112 Decrements the reference count of the given SV.
114 =for apidoc Am|svtype|SvTYPE|SV* sv
115 Returns the type of the SV. See C<svtype>.
117 =for apidoc Am|void|SvUPGRADE|SV* sv|svtype type
118 Used to upgrade an SV to a more complex form. Uses C<sv_upgrade> to
119 perform the upgrade if necessary. See C<svtype>.
124 #define SvANY(sv) (sv)->sv_any
125 #define SvFLAGS(sv) (sv)->sv_flags
126 #define SvREFCNT(sv) (sv)->sv_refcnt
128 #if defined(__GNUC__) && !defined(__STRICT_ANSI__) && !defined(PERL_GCC_PEDANTIC)
129 # define SvREFCNT_inc(sv) \
131 SV *nsv = (SV*)(sv); \
137 # define SvREFCNT_inc(sv) \
138 ((PL_Sv=(SV*)(sv)), (PL_Sv && ++(SvREFCNT(PL_Sv))), (SV*)PL_Sv)
141 #if defined(__GNUC__) && !defined(__STRICT_ANSI__) && !defined(PERL_GCC_PEDANTIC)
142 # define SvREFCNT_dec(sv) \
144 SV *nsv = (SV*)(sv); \
146 if (SvREFCNT(nsv)) { \
147 if (--(SvREFCNT(nsv)) == 0) \
148 Perl_sv_free2(aTHX_ nsv); \
155 #define SvREFCNT_dec(sv) sv_free((SV*)(sv))
158 #define SVTYPEMASK 0xff
159 #define SvTYPE(sv) ((sv)->sv_flags & SVTYPEMASK)
161 #define SvUPGRADE(sv, mt) (SvTYPE(sv) >= mt || sv_upgrade(sv, mt))
163 #define SVs_PADSTALE 0x00000100 /* lexical has gone out of scope */
164 #define SVs_PADTMP 0x00000200 /* in use as tmp */
165 #define SVs_PADMY 0x00000400 /* in use a "my" variable */
166 #define SVs_TEMP 0x00000800 /* string is stealable? */
167 #define SVs_OBJECT 0x00001000 /* is "blessed" */
168 #define SVs_GMG 0x00002000 /* has magical get method */
169 #define SVs_SMG 0x00004000 /* has magical set method */
170 #define SVs_RMG 0x00008000 /* has random magical methods */
172 #define SVf_IOK 0x00010000 /* has valid public integer value */
173 #define SVf_NOK 0x00020000 /* has valid public numeric value */
174 #define SVf_POK 0x00040000 /* has valid public pointer value */
175 #define SVf_ROK 0x00080000 /* has a valid reference pointer */
177 #define SVf_FAKE 0x00100000 /* glob or lexical is just a copy */
178 #define SVf_OOK 0x00200000 /* has valid offset value */
179 #define SVf_BREAK 0x00400000 /* refcnt is artificially low - used
180 * by SV's in final arena cleanup */
181 #define SVf_READONLY 0x00800000 /* may not be modified */
184 #define SVp_IOK 0x01000000 /* has valid non-public integer value */
185 #define SVp_NOK 0x02000000 /* has valid non-public numeric value */
186 #define SVp_POK 0x04000000 /* has valid non-public pointer value */
187 #define SVp_SCREAM 0x08000000 /* has been studied? */
189 #define SVf_UTF8 0x20000000 /* SvPV is UTF-8 encoded */
191 #define SVf_THINKFIRST (SVf_READONLY|SVf_ROK|SVf_FAKE)
193 #define SVf_OK (SVf_IOK|SVf_NOK|SVf_POK|SVf_ROK| \
194 SVp_IOK|SVp_NOK|SVp_POK)
196 #define SVf_AMAGIC 0x10000000 /* has magical overloaded methods */
198 #define PRIVSHIFT 8 /* (SVp_?OK >> PRIVSHIFT) == SVf_?OK */
200 /* Some private flags. */
202 /* SVpad_OUR may be set on SVt_PV{NV,MG,GV} types */
203 #define SVpad_OUR 0x80000000 /* pad name is "our" instead of "my" */
204 #define SVpad_TYPED 0x40000000 /* Typed Lexical */
206 #define SVf_IVisUV 0x80000000 /* use XPVUV instead of XPVIV */
208 #define SVpfm_COMPILED 0x80000000 /* FORMLINE is compiled */
210 #define SVpbm_VALID 0x80000000
211 #define SVpbm_TAIL 0x40000000
213 #define SVrepl_EVAL 0x40000000 /* Replacement part of s///e */
215 #define SVphv_SHAREKEYS 0x20000000 /* keys live on shared string table */
216 #define SVphv_LAZYDEL 0x40000000 /* entry in xhv_eiter must be deleted */
217 #define SVphv_HASKFLAGS 0x80000000 /* keys have flag byte after hash */
219 #define SVprv_WEAKREF 0x80000000 /* Weak reference */
222 SV * xrv_rv; /* pointer to another SV */
226 char * xpv_pv; /* pointer to malloced string */
227 STRLEN xpv_cur; /* length of xpv_pv as a C string */
228 STRLEN xpv_len; /* allocated size */
232 char * xpv_pv; /* pointer to malloced string */
233 STRLEN xpv_cur; /* length of xpv_pv as a C string */
234 STRLEN xpv_len; /* allocated size */
235 IV xiv_iv; /* integer value or pv offset */
239 char * xpv_pv; /* pointer to malloced string */
240 STRLEN xpv_cur; /* length of xpv_pv as a C string */
241 STRLEN xpv_len; /* allocated size */
242 UV xuv_uv; /* unsigned value or pv offset */
246 char * xpv_pv; /* pointer to malloced string */
247 STRLEN xpv_cur; /* length of xpv_pv as a C string */
248 STRLEN xpv_len; /* allocated size */
249 IV xiv_iv; /* integer value or pv offset */
250 NV xnv_nv; /* numeric value, if any */
253 /* These structure must match the beginning of struct xpvhv in hv.h. */
255 char * xpv_pv; /* pointer to malloced string */
256 STRLEN xpv_cur; /* length of xpv_pv as a C string */
257 STRLEN xpv_len; /* allocated size */
258 IV xiv_iv; /* integer value or pv offset */
259 NV xnv_nv; /* numeric value, if any */
260 MAGIC* xmg_magic; /* linked list of magicalness */
261 HV* xmg_stash; /* class package */
265 char * xpv_pv; /* pointer to malloced string */
266 STRLEN xpv_cur; /* length of xpv_pv as a C string */
267 STRLEN xpv_len; /* allocated size */
268 IV xiv_iv; /* integer value or pv offset */
269 NV xnv_nv; /* numeric value, if any */
270 MAGIC* xmg_magic; /* linked list of magicalness */
271 HV* xmg_stash; /* class package */
280 char * xpv_pv; /* pointer to malloced string */
281 STRLEN xpv_cur; /* length of xpv_pv as a C string */
282 STRLEN xpv_len; /* allocated size */
283 IV xiv_iv; /* integer value or pv offset */
284 NV xnv_nv; /* numeric value, if any */
285 MAGIC* xmg_magic; /* linked list of magicalness */
286 HV* xmg_stash; /* class package */
296 char * xpv_pv; /* pointer to malloced string */
297 STRLEN xpv_cur; /* length of xpv_pv as a C string */
298 STRLEN xpv_len; /* allocated size */
299 IV xiv_iv; /* integer value or pv offset */
300 NV xnv_nv; /* numeric value, if any */
301 MAGIC* xmg_magic; /* linked list of magicalness */
302 HV* xmg_stash; /* class package */
304 I32 xbm_useful; /* is this constant pattern being useful? */
305 U16 xbm_previous; /* how many characters in string before rare? */
306 U8 xbm_rare; /* rarest character in string */
309 /* This structure must match XPVCV in cv.h */
311 typedef U16 cv_flags_t;
314 char * xpv_pv; /* pointer to malloced string */
315 STRLEN xpv_cur; /* length of xpv_pv as a C string */
316 STRLEN xpv_len; /* allocated size */
317 IV xiv_iv; /* integer value or pv offset */
318 NV xnv_nv; /* numeric value, if any */
319 MAGIC* xmg_magic; /* linked list of magicalness */
320 HV* xmg_stash; /* class package */
325 void (*xcv_xsub)(pTHX_ CV*);
329 long xcv_depth; /* >= 2 indicates recursive call */
332 cv_flags_t xcv_flags;
333 U32 xcv_outside_seq; /* the COP sequence (at the point of our
334 * compilation) in the lexically enclosing
340 char * xpv_pv; /* pointer to malloced string */
341 STRLEN xpv_cur; /* length of xpv_pv as a C string */
342 STRLEN xpv_len; /* allocated size */
343 IV xiv_iv; /* integer value or pv offset */
344 NV xnv_nv; /* numeric value, if any */
345 MAGIC* xmg_magic; /* linked list of magicalness */
346 HV* xmg_stash; /* class package */
348 PerlIO * xio_ifp; /* ifp and ofp are normally the same */
349 PerlIO * xio_ofp; /* but sockets need separate streams */
350 /* Cray addresses everything by word boundaries (64 bits) and
351 * code and data pointers cannot be mixed (which is exactly what
352 * Perl_filter_add() tries to do with the dirp), hence the following
353 * union trick (as suggested by Gurusamy Sarathy).
354 * For further information see Geir Johansen's problem report titled
355 [ID 20000612.002] Perl problem on Cray system
356 * The any pointer (known as IoANY()) will also be a good place
357 * to hang any IO disciplines to.
360 DIR * xiou_dirp; /* for opendir, readdir, etc */
361 void * xiou_any; /* for alignment */
363 IV xio_lines; /* $. */
364 IV xio_page; /* $% */
365 IV xio_page_len; /* $= */
366 IV xio_lines_left; /* $- */
367 char * xio_top_name; /* $^ */
368 GV * xio_top_gv; /* $^ */
369 char * xio_fmt_name; /* $~ */
370 GV * xio_fmt_gv; /* $~ */
371 char * xio_bottom_name;/* $^B */
372 GV * xio_bottom_gv; /* $^B */
373 short xio_subprocess; /* -| or |- */
377 #define xio_dirp xio_dirpu.xiou_dirp
378 #define xio_any xio_dirpu.xiou_any
380 #define IOf_ARGV 1 /* this fp iterates over ARGV */
381 #define IOf_START 2 /* check for null ARGV and substitute '-' */
382 #define IOf_FLUSH 4 /* this fp wants a flush after write op */
383 #define IOf_DIDTOP 8 /* just did top of form */
384 #define IOf_UNTAINT 16 /* consider this fp (and its data) "safe" */
385 #define IOf_NOLINE 32 /* slurped a pseudo-line from empty file */
386 #define IOf_FAKE_DIRP 64 /* xio_dirp is fake (source filters kludge) */
388 /* The following macros define implementation-independent predicates on SVs. */
391 =for apidoc Am|bool|SvNIOK|SV* sv
392 Returns a boolean indicating whether the SV contains a number, integer or
395 =for apidoc Am|bool|SvNIOKp|SV* sv
396 Returns a boolean indicating whether the SV contains a number, integer or
397 double. Checks the B<private> setting. Use C<SvNIOK>.
399 =for apidoc Am|void|SvNIOK_off|SV* sv
400 Unsets the NV/IV status of an SV.
402 =for apidoc Am|bool|SvOK|SV* sv
403 Returns a boolean indicating whether the value is an SV.
405 =for apidoc Am|bool|SvIOKp|SV* sv
406 Returns a boolean indicating whether the SV contains an integer. Checks
407 the B<private> setting. Use C<SvIOK>.
409 =for apidoc Am|bool|SvNOKp|SV* sv
410 Returns a boolean indicating whether the SV contains a double. Checks the
411 B<private> setting. Use C<SvNOK>.
413 =for apidoc Am|bool|SvPOKp|SV* sv
414 Returns a boolean indicating whether the SV contains a character string.
415 Checks the B<private> setting. Use C<SvPOK>.
417 =for apidoc Am|bool|SvIOK|SV* sv
418 Returns a boolean indicating whether the SV contains an integer.
420 =for apidoc Am|void|SvIOK_on|SV* sv
421 Tells an SV that it is an integer.
423 =for apidoc Am|void|SvIOK_off|SV* sv
424 Unsets the IV status of an SV.
426 =for apidoc Am|void|SvIOK_only|SV* sv
427 Tells an SV that it is an integer and disables all other OK bits.
429 =for apidoc Am|void|SvIOK_only_UV|SV* sv
430 Tells and SV that it is an unsigned integer and disables all other OK bits.
432 =for apidoc Am|void|SvIOK_UV|SV* sv
433 Returns a boolean indicating whether the SV contains an unsigned integer.
435 =for apidoc Am|void|SvUOK|SV* sv
436 Returns a boolean indicating whether the SV contains an unsigned integer.
438 =for apidoc Am|void|SvIOK_notUV|SV* sv
439 Returns a boolean indicating whether the SV contains a signed integer.
441 =for apidoc Am|bool|SvNOK|SV* sv
442 Returns a boolean indicating whether the SV contains a double.
444 =for apidoc Am|void|SvNOK_on|SV* sv
445 Tells an SV that it is a double.
447 =for apidoc Am|void|SvNOK_off|SV* sv
448 Unsets the NV status of an SV.
450 =for apidoc Am|void|SvNOK_only|SV* sv
451 Tells an SV that it is a double and disables all other OK bits.
453 =for apidoc Am|bool|SvPOK|SV* sv
454 Returns a boolean indicating whether the SV contains a character
457 =for apidoc Am|void|SvPOK_on|SV* sv
458 Tells an SV that it is a string.
460 =for apidoc Am|void|SvPOK_off|SV* sv
461 Unsets the PV status of an SV.
463 =for apidoc Am|void|SvPOK_only|SV* sv
464 Tells an SV that it is a string and disables all other OK bits.
465 Will also turn off the UTF8 status.
467 =for apidoc Am|bool|SvVOK|SV* sv
468 Returns a boolean indicating whether the SV contains a v-string.
470 =for apidoc Am|bool|SvOOK|SV* sv
471 Returns a boolean indicating whether the SvIVX is a valid offset value for
472 the SvPVX. This hack is used internally to speed up removal of characters
473 from the beginning of a SvPV. When SvOOK is true, then the start of the
474 allocated string buffer is really (SvPVX - SvIVX).
476 =for apidoc Am|bool|SvROK|SV* sv
477 Tests if the SV is an RV.
479 =for apidoc Am|void|SvROK_on|SV* sv
480 Tells an SV that it is an RV.
482 =for apidoc Am|void|SvROK_off|SV* sv
483 Unsets the RV status of an SV.
485 =for apidoc Am|SV*|SvRV|SV* sv
486 Dereferences an RV to return the SV.
488 =for apidoc Am|IV|SvIVX|SV* sv
489 Returns the raw value in the SV's IV slot, without checks or conversions.
490 Only use when you are sure SvIOK is true. See also C<SvIV()>.
492 =for apidoc Am|UV|SvUVX|SV* sv
493 Returns the raw value in the SV's UV slot, without checks or conversions.
494 Only use when you are sure SvIOK is true. See also C<SvUV()>.
496 =for apidoc Am|NV|SvNVX|SV* sv
497 Returns the raw value in the SV's NV slot, without checks or conversions.
498 Only use when you are sure SvNOK is true. See also C<SvNV()>.
500 =for apidoc Am|char*|SvPVX|SV* sv
501 Returns a pointer to the physical string in the SV. The SV must contain a
504 =for apidoc Am|STRLEN|SvCUR|SV* sv
505 Returns the length of the string which is in the SV. See C<SvLEN>.
507 =for apidoc Am|STRLEN|SvLEN|SV* sv
508 Returns the size of the string buffer in the SV, not including any part
509 attributable to C<SvOOK>. See C<SvCUR>.
511 =for apidoc Am|char*|SvEND|SV* sv
512 Returns a pointer to the last character in the string which is in the SV.
513 See C<SvCUR>. Access the character as *(SvEND(sv)).
515 =for apidoc Am|HV*|SvSTASH|SV* sv
516 Returns the stash of the SV.
518 =for apidoc Am|void|SvCUR_set|SV* sv|STRLEN len
519 Set the length of the string which is in the SV. See C<SvCUR>.
524 #define SvNIOK(sv) (SvFLAGS(sv) & (SVf_IOK|SVf_NOK))
525 #define SvNIOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK))
526 #define SvNIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK| \
527 SVp_IOK|SVp_NOK|SVf_IVisUV))
530 #define assert_not_ROK(sv) ({assert(!SvROK(sv) || !SvRV(sv))}),
532 #define assert_not_ROK(sv)
535 #define SvOK(sv) (SvFLAGS(sv) & SVf_OK)
536 #define SvOK_off(sv) (assert_not_ROK(sv) \
537 SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC| \
538 SVf_IVisUV|SVf_UTF8), \
540 #define SvOK_off_exc_UV(sv) (assert_not_ROK(sv) \
541 SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC| \
545 #define SvOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK))
546 #define SvIOKp(sv) (SvFLAGS(sv) & SVp_IOK)
547 #define SvIOKp_on(sv) (SvRELEASE_IVX(sv), \
548 SvFLAGS(sv) |= SVp_IOK)
549 #define SvNOKp(sv) (SvFLAGS(sv) & SVp_NOK)
550 #define SvNOKp_on(sv) (SvFLAGS(sv) |= SVp_NOK)
551 #define SvPOKp(sv) (SvFLAGS(sv) & SVp_POK)
552 #define SvPOKp_on(sv) (assert_not_ROK(sv) \
553 SvFLAGS(sv) |= SVp_POK)
555 #define SvIOK(sv) (SvFLAGS(sv) & SVf_IOK)
556 #define SvIOK_on(sv) (SvRELEASE_IVX(sv), \
557 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
558 #define SvIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVp_IOK|SVf_IVisUV))
559 #define SvIOK_only(sv) ((void)SvOK_off(sv), \
560 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
561 #define SvIOK_only_UV(sv) ((void)SvOK_off_exc_UV(sv), \
562 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
564 #define SvIOK_UV(sv) ((SvFLAGS(sv) & (SVf_IOK|SVf_IVisUV)) \
565 == (SVf_IOK|SVf_IVisUV))
566 #define SvUOK(sv) SvIOK_UV(sv)
567 #define SvIOK_notUV(sv) ((SvFLAGS(sv) & (SVf_IOK|SVf_IVisUV)) \
570 #define SvIsUV(sv) (SvFLAGS(sv) & SVf_IVisUV)
571 #define SvIsUV_on(sv) (SvFLAGS(sv) |= SVf_IVisUV)
572 #define SvIsUV_off(sv) (SvFLAGS(sv) &= ~SVf_IVisUV)
574 #define SvNOK(sv) (SvFLAGS(sv) & SVf_NOK)
575 #define SvNOK_on(sv) (SvFLAGS(sv) |= (SVf_NOK|SVp_NOK))
576 #define SvNOK_off(sv) (SvFLAGS(sv) &= ~(SVf_NOK|SVp_NOK))
577 #define SvNOK_only(sv) ((void)SvOK_off(sv), \
578 SvFLAGS(sv) |= (SVf_NOK|SVp_NOK))
581 =for apidoc Am|void|SvUTF8|SV* sv
582 Returns a boolean indicating whether the SV contains UTF-8 encoded data.
584 =for apidoc Am|void|SvUTF8_on|SV *sv
585 Turn on the UTF8 status of an SV (the data is not changed, just the flag).
586 Do not use frivolously.
588 =for apidoc Am|void|SvUTF8_off|SV *sv
589 Unsets the UTF8 status of an SV.
591 =for apidoc Am|void|SvPOK_only_UTF8|SV* sv
592 Tells an SV that it is a string and disables all other OK bits,
593 and leaves the UTF8 status as it was.
598 #define SvUTF8(sv) (SvFLAGS(sv) & SVf_UTF8)
599 #define SvUTF8_on(sv) (SvFLAGS(sv) |= (SVf_UTF8))
600 #define SvUTF8_off(sv) (SvFLAGS(sv) &= ~(SVf_UTF8))
602 #define SvPOK(sv) (SvFLAGS(sv) & SVf_POK)
603 #define SvPOK_on(sv) (assert_not_ROK(sv) \
604 SvFLAGS(sv) |= (SVf_POK|SVp_POK))
605 #define SvPOK_off(sv) (SvFLAGS(sv) &= ~(SVf_POK|SVp_POK))
606 #define SvPOK_only(sv) (assert_not_ROK(sv) \
607 SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC| \
608 SVf_IVisUV|SVf_UTF8), \
609 SvFLAGS(sv) |= (SVf_POK|SVp_POK))
610 #define SvPOK_only_UTF8(sv) (assert_not_ROK(sv) \
611 SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC| \
613 SvFLAGS(sv) |= (SVf_POK|SVp_POK))
615 #define SvVOK(sv) (SvMAGICAL(sv) && mg_find(sv,'V'))
616 #define SvOOK(sv) (SvFLAGS(sv) & SVf_OOK)
617 #define SvOOK_on(sv) ((void)SvIOK_off(sv), SvFLAGS(sv) |= SVf_OOK)
618 #define SvOOK_off(sv) (SvOOK(sv) && sv_backoff(sv))
620 #define SvFAKE(sv) (SvFLAGS(sv) & SVf_FAKE)
621 #define SvFAKE_on(sv) (SvFLAGS(sv) |= SVf_FAKE)
622 #define SvFAKE_off(sv) (SvFLAGS(sv) &= ~SVf_FAKE)
624 #define SvROK(sv) (SvFLAGS(sv) & SVf_ROK)
625 #define SvROK_on(sv) (SvFLAGS(sv) |= SVf_ROK)
626 #define SvROK_off(sv) (SvFLAGS(sv) &= ~(SVf_ROK|SVf_AMAGIC))
628 #define SvMAGICAL(sv) (SvFLAGS(sv) & (SVs_GMG|SVs_SMG|SVs_RMG))
629 #define SvMAGICAL_on(sv) (SvFLAGS(sv) |= (SVs_GMG|SVs_SMG|SVs_RMG))
630 #define SvMAGICAL_off(sv) (SvFLAGS(sv) &= ~(SVs_GMG|SVs_SMG|SVs_RMG))
632 #define SvGMAGICAL(sv) (SvFLAGS(sv) & SVs_GMG)
633 #define SvGMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_GMG)
634 #define SvGMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_GMG)
636 #define SvSMAGICAL(sv) (SvFLAGS(sv) & SVs_SMG)
637 #define SvSMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_SMG)
638 #define SvSMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_SMG)
640 #define SvRMAGICAL(sv) (SvFLAGS(sv) & SVs_RMG)
641 #define SvRMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_RMG)
642 #define SvRMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_RMG)
644 #define SvAMAGIC(sv) (SvFLAGS(sv) & SVf_AMAGIC)
645 #define SvAMAGIC_on(sv) (SvFLAGS(sv) |= SVf_AMAGIC)
646 #define SvAMAGIC_off(sv) (SvFLAGS(sv) &= ~SVf_AMAGIC)
648 #define SvGAMAGIC(sv) (SvFLAGS(sv) & (SVs_GMG|SVf_AMAGIC))
651 #define Gv_AMG(stash) \
652 (HV_AMAGICmb(stash) && \
653 ((!HV_AMAGICbad(stash) && HV_AMAGIC(stash)) || Gv_AMupdate(stash)))
655 #define Gv_AMG(stash) (PL_amagic_generation && Gv_AMupdate(stash))
657 #define SvWEAKREF(sv) ((SvFLAGS(sv) & (SVf_ROK|SVprv_WEAKREF)) \
658 == (SVf_ROK|SVprv_WEAKREF))
659 #define SvWEAKREF_on(sv) (SvFLAGS(sv) |= (SVf_ROK|SVprv_WEAKREF))
660 #define SvWEAKREF_off(sv) (SvFLAGS(sv) &= ~(SVf_ROK|SVprv_WEAKREF))
662 #define SvTHINKFIRST(sv) (SvFLAGS(sv) & SVf_THINKFIRST)
664 #define SvPADSTALE(sv) (SvFLAGS(sv) & SVs_PADSTALE)
665 #define SvPADSTALE_on(sv) (SvFLAGS(sv) |= SVs_PADSTALE)
666 #define SvPADSTALE_off(sv) (SvFLAGS(sv) &= ~SVs_PADSTALE)
668 #define SvPADTMP(sv) (SvFLAGS(sv) & SVs_PADTMP)
669 #define SvPADTMP_on(sv) (SvFLAGS(sv) |= SVs_PADTMP)
670 #define SvPADTMP_off(sv) (SvFLAGS(sv) &= ~SVs_PADTMP)
672 #define SvPADMY(sv) (SvFLAGS(sv) & SVs_PADMY)
673 #define SvPADMY_on(sv) (SvFLAGS(sv) |= SVs_PADMY)
675 #define SvTEMP(sv) (SvFLAGS(sv) & SVs_TEMP)
676 #define SvTEMP_on(sv) (SvFLAGS(sv) |= SVs_TEMP)
677 #define SvTEMP_off(sv) (SvFLAGS(sv) &= ~SVs_TEMP)
679 #define SvOBJECT(sv) (SvFLAGS(sv) & SVs_OBJECT)
680 #define SvOBJECT_on(sv) (SvFLAGS(sv) |= SVs_OBJECT)
681 #define SvOBJECT_off(sv) (SvFLAGS(sv) &= ~SVs_OBJECT)
683 #define SvREADONLY(sv) (SvFLAGS(sv) & SVf_READONLY)
684 #define SvREADONLY_on(sv) (SvFLAGS(sv) |= SVf_READONLY)
685 #define SvREADONLY_off(sv) (SvFLAGS(sv) &= ~SVf_READONLY)
687 #define SvSCREAM(sv) (SvFLAGS(sv) & SVp_SCREAM)
688 #define SvSCREAM_on(sv) (SvFLAGS(sv) |= SVp_SCREAM)
689 #define SvSCREAM_off(sv) (SvFLAGS(sv) &= ~SVp_SCREAM)
691 #define SvCOMPILED(sv) (SvFLAGS(sv) & SVpfm_COMPILED)
692 #define SvCOMPILED_on(sv) (SvFLAGS(sv) |= SVpfm_COMPILED)
693 #define SvCOMPILED_off(sv) (SvFLAGS(sv) &= ~SVpfm_COMPILED)
695 #define SvEVALED(sv) (SvFLAGS(sv) & SVrepl_EVAL)
696 #define SvEVALED_on(sv) (SvFLAGS(sv) |= SVrepl_EVAL)
697 #define SvEVALED_off(sv) (SvFLAGS(sv) &= ~SVrepl_EVAL)
699 #define SvTAIL(sv) (SvFLAGS(sv) & SVpbm_TAIL)
700 #define SvTAIL_on(sv) (SvFLAGS(sv) |= SVpbm_TAIL)
701 #define SvTAIL_off(sv) (SvFLAGS(sv) &= ~SVpbm_TAIL)
703 #define SvVALID(sv) (SvFLAGS(sv) & SVpbm_VALID)
704 #define SvVALID_on(sv) (SvFLAGS(sv) |= SVpbm_VALID)
705 #define SvVALID_off(sv) (SvFLAGS(sv) &= ~SVpbm_VALID)
708 /* The following uses the FAKE flag to show that a regex pointer is infact
709 its own offset in the regexpad for ithreads */
710 #define SvREPADTMP(sv) (SvFLAGS(sv) & SVf_FAKE)
711 #define SvREPADTMP_on(sv) (SvFLAGS(sv) |= SVf_FAKE)
712 #define SvREPADTMP_off(sv) (SvFLAGS(sv) &= ~SVf_FAKE)
715 #define SvRV(sv) ((XRV*) SvANY(sv))->xrv_rv
716 #define SvRVx(sv) SvRV(sv)
718 #define SvIVX(sv) ((XPVIV*) SvANY(sv))->xiv_iv
719 #define SvIVXx(sv) SvIVX(sv)
720 #define SvUVX(sv) ((XPVUV*) SvANY(sv))->xuv_uv
721 #define SvUVXx(sv) SvUVX(sv)
722 #define SvNVX(sv) ((XPVNV*)SvANY(sv))->xnv_nv
723 #define SvNVXx(sv) SvNVX(sv)
724 #define SvPVX(sv) ((XPV*) SvANY(sv))->xpv_pv
725 #define SvPVXx(sv) SvPVX(sv)
726 #define SvCUR(sv) ((XPV*) SvANY(sv))->xpv_cur
727 #define SvLEN(sv) ((XPV*) SvANY(sv))->xpv_len
728 #define SvLENx(sv) SvLEN(sv)
729 #define SvEND(sv)(((XPV*) SvANY(sv))->xpv_pv + ((XPV*)SvANY(sv))->xpv_cur)
730 #define SvENDx(sv) ((PL_Sv = (sv)), SvEND(PL_Sv))
731 #define SvMAGIC(sv) ((XPVMG*) SvANY(sv))->xmg_magic
732 #define SvSTASH(sv) ((XPVMG*) SvANY(sv))->xmg_stash
734 /* Ask a scalar nicely to try to become an IV, if possible.
735 Not guaranteed to stay returning void */
736 /* Macro won't actually call sv_2iv if already IOK */
737 #define SvIV_please(sv) \
738 STMT_START {if (!SvIOKp(sv) && (SvNOK(sv) || SvPOK(sv))) \
739 (void) SvIV(sv); } STMT_END
740 #define SvIV_set(sv, val) \
741 STMT_START { assert(SvTYPE(sv) == SVt_IV || SvTYPE(sv) >= SVt_PVIV); \
742 (((XPVIV*) SvANY(sv))->xiv_iv = val); } STMT_END
743 #define SvNV_set(sv, val) \
744 STMT_START { assert(SvTYPE(sv) == SVt_NV || SvTYPE(sv) >= SVt_PVNV); \
745 (((XPVNV*) SvANY(sv))->xnv_nv = val); } STMT_END
746 #define SvPV_set(sv, val) \
747 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
748 (((XPV*) SvANY(sv))->xpv_pv = val); } STMT_END
749 #define SvCUR_set(sv, val) \
750 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
751 (((XPV*) SvANY(sv))->xpv_cur = val); } STMT_END
752 #define SvLEN_set(sv, val) \
753 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
754 (((XPV*) SvANY(sv))->xpv_len = val); } STMT_END
755 #define SvEND_set(sv, val) \
756 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
757 (((XPV*) SvANY(sv))->xpv_cur = val - SvPVX(sv)); } STMT_END
759 #define BmRARE(sv) ((XPVBM*) SvANY(sv))->xbm_rare
760 #define BmUSEFUL(sv) ((XPVBM*) SvANY(sv))->xbm_useful
761 #define BmPREVIOUS(sv) ((XPVBM*) SvANY(sv))->xbm_previous
763 #define FmLINES(sv) ((XPVFM*) SvANY(sv))->xfm_lines
765 #define LvTYPE(sv) ((XPVLV*) SvANY(sv))->xlv_type
766 #define LvTARG(sv) ((XPVLV*) SvANY(sv))->xlv_targ
767 #define LvTARGOFF(sv) ((XPVLV*) SvANY(sv))->xlv_targoff
768 #define LvTARGLEN(sv) ((XPVLV*) SvANY(sv))->xlv_targlen
770 #define IoIFP(sv) ((XPVIO*) SvANY(sv))->xio_ifp
771 #define IoOFP(sv) ((XPVIO*) SvANY(sv))->xio_ofp
772 #define IoDIRP(sv) ((XPVIO*) SvANY(sv))->xio_dirp
773 #define IoANY(sv) ((XPVIO*) SvANY(sv))->xio_any
774 #define IoLINES(sv) ((XPVIO*) SvANY(sv))->xio_lines
775 #define IoPAGE(sv) ((XPVIO*) SvANY(sv))->xio_page
776 #define IoPAGE_LEN(sv) ((XPVIO*) SvANY(sv))->xio_page_len
777 #define IoLINES_LEFT(sv)((XPVIO*) SvANY(sv))->xio_lines_left
778 #define IoTOP_NAME(sv) ((XPVIO*) SvANY(sv))->xio_top_name
779 #define IoTOP_GV(sv) ((XPVIO*) SvANY(sv))->xio_top_gv
780 #define IoFMT_NAME(sv) ((XPVIO*) SvANY(sv))->xio_fmt_name
781 #define IoFMT_GV(sv) ((XPVIO*) SvANY(sv))->xio_fmt_gv
782 #define IoBOTTOM_NAME(sv)((XPVIO*) SvANY(sv))->xio_bottom_name
783 #define IoBOTTOM_GV(sv) ((XPVIO*) SvANY(sv))->xio_bottom_gv
784 #define IoSUBPROCESS(sv)((XPVIO*) SvANY(sv))->xio_subprocess
785 #define IoTYPE(sv) ((XPVIO*) SvANY(sv))->xio_type
786 #define IoFLAGS(sv) ((XPVIO*) SvANY(sv))->xio_flags
788 /* IoTYPE(sv) is a single character telling the type of I/O connection. */
789 #define IoTYPE_RDONLY '<'
790 #define IoTYPE_WRONLY '>'
791 #define IoTYPE_RDWR '+'
792 #define IoTYPE_APPEND 'a'
793 #define IoTYPE_PIPE '|'
794 #define IoTYPE_STD '-' /* stdin or stdout */
795 #define IoTYPE_SOCKET 's'
796 #define IoTYPE_CLOSED ' '
799 =for apidoc Am|bool|SvTAINTED|SV* sv
800 Checks to see if an SV is tainted. Returns TRUE if it is, FALSE if
803 =for apidoc Am|void|SvTAINTED_on|SV* sv
804 Marks an SV as tainted.
806 =for apidoc Am|void|SvTAINTED_off|SV* sv
807 Untaints an SV. Be I<very> careful with this routine, as it short-circuits
808 some of Perl's fundamental security features. XS module authors should not
809 use this function unless they fully understand all the implications of
810 unconditionally untainting the value. Untainting should be done in the
811 standard perl fashion, via a carefully crafted regexp, rather than directly
812 untainting variables.
814 =for apidoc Am|void|SvTAINT|SV* sv
815 Taints an SV if tainting is enabled
820 #define SvTAINTED(sv) (SvMAGICAL(sv) && sv_tainted(sv))
821 #define SvTAINTED_on(sv) STMT_START{ if(PL_tainting){sv_taint(sv);} }STMT_END
822 #define SvTAINTED_off(sv) STMT_START{ if(PL_tainting){sv_untaint(sv);} }STMT_END
824 #define SvTAINT(sv) \
833 =for apidoc Am|char*|SvPV_force|SV* sv|STRLEN len
834 Like C<SvPV> but will force the SV into containing just a string
835 (C<SvPOK_only>). You want force if you are going to update the C<SvPVX>
838 =for apidoc Am|char*|SvPV_force_nomg|SV* sv|STRLEN len
839 Like C<SvPV> but will force the SV into containing just a string
840 (C<SvPOK_only>). You want force if you are going to update the C<SvPVX>
841 directly. Doesn't process magic.
843 =for apidoc Am|char*|SvPV|SV* sv|STRLEN len
844 Returns a pointer to the string in the SV, or a stringified form of
845 the SV if the SV does not contain a string. The SV may cache the
846 stringified version becoming C<SvPOK>. Handles 'get' magic. See also
847 C<SvPVx> for a version which guarantees to evaluate sv only once.
849 =for apidoc Am|char*|SvPVx|SV* sv|STRLEN len
850 A version of C<SvPV> which guarantees to evaluate sv only once.
852 =for apidoc Am|char*|SvPV_nolen|SV* sv
853 Returns a pointer to the string in the SV, or a stringified form of
854 the SV if the SV does not contain a string. The SV may cache the
855 stringified form becoming C<SvPOK>. Handles 'get' magic.
857 =for apidoc Am|IV|SvIV|SV* sv
858 Coerces the given SV to an integer and returns it. See C<SvIVx> for a
859 version which guarantees to evaluate sv only once.
861 =for apidoc Am|IV|SvIVx|SV* sv
862 Coerces the given SV to an integer and returns it. Guarantees to evaluate
863 sv only once. Use the more efficient C<SvIV> otherwise.
865 =for apidoc Am|NV|SvNV|SV* sv
866 Coerce the given SV to a double and return it. See C<SvNVx> for a version
867 which guarantees to evaluate sv only once.
869 =for apidoc Am|NV|SvNVx|SV* sv
870 Coerces the given SV to a double and returns it. Guarantees to evaluate
871 sv only once. Use the more efficient C<SvNV> otherwise.
873 =for apidoc Am|UV|SvUV|SV* sv
874 Coerces the given SV to an unsigned integer and returns it. See C<SvUVx>
875 for a version which guarantees to evaluate sv only once.
877 =for apidoc Am|UV|SvUVx|SV* sv
878 Coerces the given SV to an unsigned integer and returns it. Guarantees to
879 evaluate sv only once. Use the more efficient C<SvUV> otherwise.
881 =for apidoc Am|bool|SvTRUE|SV* sv
882 Returns a boolean indicating whether Perl would evaluate the SV as true or
883 false, defined or undefined. Does not handle 'get' magic.
885 =for apidoc Am|char*|SvPVutf8_force|SV* sv|STRLEN len
886 Like C<SvPV_force>, but converts sv to utf8 first if necessary.
888 =for apidoc Am|char*|SvPVutf8|SV* sv|STRLEN len
889 Like C<SvPV>, but converts sv to utf8 first if necessary.
891 =for apidoc Am|char*|SvPVutf8_nolen|SV* sv
892 Like C<SvPV_nolen>, but converts sv to utf8 first if necessary.
894 =for apidoc Am|char*|SvPVbyte_force|SV* sv|STRLEN len
895 Like C<SvPV_force>, but converts sv to byte representation first if necessary.
897 =for apidoc Am|char*|SvPVbyte|SV* sv|STRLEN len
898 Like C<SvPV>, but converts sv to byte representation first if necessary.
900 =for apidoc Am|char*|SvPVbyte_nolen|SV* sv
901 Like C<SvPV_nolen>, but converts sv to byte representation first if necessary.
903 =for apidoc Am|char*|SvPVutf8x_force|SV* sv|STRLEN len
904 Like C<SvPV_force>, but converts sv to utf8 first if necessary.
905 Guarantees to evaluate sv only once; use the more efficient C<SvPVutf8_force>
908 =for apidoc Am|char*|SvPVutf8x|SV* sv|STRLEN len
909 Like C<SvPV>, but converts sv to utf8 first if necessary.
910 Guarantees to evaluate sv only once; use the more efficient C<SvPVutf8>
913 =for apidoc Am|char*|SvPVbytex_force|SV* sv|STRLEN len
914 Like C<SvPV_force>, but converts sv to byte representation first if necessary.
915 Guarantees to evaluate sv only once; use the more efficient C<SvPVbyte_force>
918 =for apidoc Am|char*|SvPVbytex|SV* sv|STRLEN len
919 Like C<SvPV>, but converts sv to byte representation first if necessary.
920 Guarantees to evaluate sv only once; use the more efficient C<SvPVbyte>
923 =for apidoc Am|bool|SvIsCOW|SV* sv
924 Returns a boolean indicating whether the SV is Copy-On-Write. (either shared
925 hash key scalars, or full Copy On Write scalars if 5.9.0 is configured for
928 =for apidoc Am|bool|SvIsCOW_shared_hash|SV* sv
929 Returns a boolean indicating whether the SV is Copy-On-Write shared hash key
935 /* Let us hope that bitmaps for UV and IV are the same */
936 #define SvIV(sv) (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv))
937 #define SvUV(sv) (SvIOK(sv) ? SvUVX(sv) : sv_2uv(sv))
938 #define SvNV(sv) (SvNOK(sv) ? SvNVX(sv) : sv_2nv(sv))
942 #define SvPV(sv, lp) SvPV_flags(sv, lp, SV_GMAGIC)
944 #define SvPV_flags(sv, lp, flags) \
945 ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
946 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pv_flags(sv, &lp, flags))
948 #define SvPV_force(sv, lp) SvPV_force_flags(sv, lp, SV_GMAGIC)
950 #define SvPV_force_nomg(sv, lp) SvPV_force_flags(sv, lp, 0)
952 #define SvPV_force_flags(sv, lp, flags) \
953 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \
954 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvn_force_flags(sv, &lp, flags))
956 #define SvPV_nolen(sv) \
957 ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
958 ? SvPVX(sv) : sv_2pv_nolen(sv))
960 #define SvPV_nomg(sv, lp) SvPV_flags(sv, lp, 0)
964 #define SvPVutf8(sv, lp) \
965 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8) \
966 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvutf8(sv, &lp))
968 #define SvPVutf8_force(sv, lp) \
969 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == (SVf_POK|SVf_UTF8) \
970 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvutf8n_force(sv, &lp))
973 #define SvPVutf8_nolen(sv) \
974 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8)\
975 ? SvPVX(sv) : sv_2pvutf8_nolen(sv))
979 #define SvPVbyte(sv, lp) \
980 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK) \
981 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvbyte(sv, &lp))
983 #define SvPVbyte_force(sv, lp) \
984 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8|SVf_THINKFIRST)) == (SVf_POK) \
985 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvbyte_force(sv, &lp))
987 #define SvPVbyte_nolen(sv) \
988 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK)\
989 ? SvPVX(sv) : sv_2pvbyte_nolen(sv))
993 /* define FOOx(): idempotent versions of FOO(). If possible, use a local
994 * var to evaluate the arg once; failing that, use a global if possible;
995 * failing that, call a function to do the work
998 #define SvPVx_force(sv, lp) sv_pvn_force(sv, &lp)
999 #define SvPVutf8x_force(sv, lp) sv_pvutf8n_force(sv, &lp)
1000 #define SvPVbytex_force(sv, lp) sv_pvbyten_force(sv, &lp)
1002 #if defined(__GNUC__) && !defined(__STRICT_ANSI__) && !defined(PERL_GCC_PEDANTIC)
1004 # define SvIVx(sv) ({SV *nsv = (SV*)(sv); SvIV(nsv); })
1005 # define SvUVx(sv) ({SV *nsv = (SV*)(sv); SvUV(nsv); })
1006 # define SvNVx(sv) ({SV *nsv = (SV*)(sv); SvNV(nsv); })
1007 # define SvPVx(sv, lp) ({SV *nsv = (sv); SvPV(nsv, lp); })
1008 # define SvPVutf8x(sv, lp) ({SV *nsv = (sv); SvPVutf8(nsv, lp); })
1009 # define SvPVbytex(sv, lp) ({SV *nsv = (sv); SvPVbyte(nsv, lp); })
1010 # define SvTRUE(sv) ( \
1014 ? (({XPV *nxpv = (XPV*)SvANY(sv); \
1016 (nxpv->xpv_cur > 1 || \
1017 (nxpv->xpv_cur && *nxpv->xpv_pv != '0')); }) \
1024 ? SvNVX(sv) != 0.0 \
1026 # define SvTRUEx(sv) ({SV *nsv = (sv); SvTRUE(nsv); })
1028 #else /* __GNUC__ */
1030 /* These inlined macros use globals, which will require a thread
1031 * declaration in user code, so we avoid them under threads */
1033 # define SvIVx(sv) ((PL_Sv = (sv)), SvIV(PL_Sv))
1034 # define SvUVx(sv) ((PL_Sv = (sv)), SvUV(PL_Sv))
1035 # define SvNVx(sv) ((PL_Sv = (sv)), SvNV(PL_Sv))
1036 # define SvPVx(sv, lp) ((PL_Sv = (sv)), SvPV(PL_Sv, lp))
1037 # define SvPVutf8x(sv, lp) ((PL_Sv = (sv)), SvPVutf8(PL_Sv, lp))
1038 # define SvPVbytex(sv, lp) ((PL_Sv = (sv)), SvPVbyte(PL_Sv, lp))
1039 # define SvTRUE(sv) ( \
1043 ? ((PL_Xpv = (XPV*)SvANY(sv)) && \
1044 (PL_Xpv->xpv_cur > 1 || \
1045 (PL_Xpv->xpv_cur && *PL_Xpv->xpv_pv != '0')) \
1052 ? SvNVX(sv) != 0.0 \
1054 # define SvTRUEx(sv) ((PL_Sv = (sv)), SvTRUE(PL_Sv))
1055 #endif /* __GNU__ */
1057 #define SvIsCOW(sv) ((SvFLAGS(sv) & (SVf_FAKE | SVf_READONLY)) == \
1058 (SVf_FAKE | SVf_READONLY))
1059 #define SvIsCOW_shared_hash(sv) (SvIsCOW(sv) && SvLEN(sv) == 0)
1061 /* flag values for sv_*_flags functions */
1062 #define SV_IMMEDIATE_UNREF 1
1064 #define SV_COW_DROP_PV 4
1065 #define SV_UTF8_NO_ENCODING 8
1067 /* We are about to replace the SV's current value. So if it's copy on write
1068 we need to normalise it. Use the SV_COW_DROP_PV flag hint to say that
1069 the value is about to get thrown away, so drop the PV rather than go to
1070 the effort of making a read-write copy only for it to get immediately
1073 #define SV_CHECK_THINKFIRST_COW_DROP(sv) if (SvTHINKFIRST(sv)) \
1074 sv_force_normal_flags(sv, SV_COW_DROP_PV)
1076 #ifdef PERL_COPY_ON_WRITE
1077 # define SvRELEASE_IVX(sv) ((void)((SvFLAGS(sv) & (SVf_OOK|SVf_READONLY|SVf_FAKE)) \
1078 && Perl_sv_release_IVX(aTHX_ sv)))
1079 # define SvIsCOW_normal(sv) (SvIsCOW(sv) && SvLEN(sv))
1081 #define CAN_COW_MASK (SVs_OBJECT|SVs_GMG|SVs_SMG|SVs_RMG|SVf_IOK|SVf_NOK| \
1082 SVf_POK|SVf_ROK|SVp_IOK|SVp_NOK|SVp_POK|SVf_FAKE| \
1083 SVf_OOK|SVf_BREAK|SVf_READONLY|SVf_AMAGIC)
1084 #define CAN_COW_FLAGS (SVp_POK|SVf_POK)
1087 # define SvRELEASE_IVX(sv) ((void)SvOOK_off(sv))
1088 #endif /* PERL_COPY_ON_WRITE */
1090 #define SV_CHECK_THINKFIRST(sv) if (SvTHINKFIRST(sv)) \
1091 sv_force_normal_flags(sv, 0)
1094 /* all these 'functions' are now just macros */
1096 #define sv_pv(sv) SvPV_nolen(sv)
1097 #define sv_pvutf8(sv) SvPVutf8_nolen(sv)
1098 #define sv_pvbyte(sv) SvPVbyte_nolen(sv)
1100 #define sv_pvn_force_nomg(sv, lp) sv_pvn_force_flags(sv, lp, 0)
1101 #define sv_utf8_upgrade_nomg(sv) sv_utf8_upgrade_flags(sv, 0)
1102 #define sv_catpvn_nomg(dsv, sstr, slen) sv_catpvn_flags(dsv, sstr, slen, 0)
1103 #define sv_setsv(dsv, ssv) sv_setsv_flags(dsv, ssv, SV_GMAGIC)
1104 #define sv_setsv_nomg(dsv, ssv) sv_setsv_flags(dsv, ssv, 0)
1105 #define sv_catsv(dsv, ssv) sv_catsv_flags(dsv, ssv, SV_GMAGIC)
1106 #define sv_catsv_nomg(dsv, ssv) sv_catsv_flags(dsv, ssv, 0)
1107 #define sv_catpvn(dsv, sstr, slen) sv_catpvn_flags(dsv, sstr, slen, SV_GMAGIC)
1108 #define sv_2pv(sv, lp) sv_2pv_flags(sv, lp, SV_GMAGIC)
1109 #define sv_2pv_nomg(sv, lp) sv_2pv_flags(sv, lp, 0)
1110 #define sv_pvn_force(sv, lp) sv_pvn_force_flags(sv, lp, SV_GMAGIC)
1111 #define sv_utf8_upgrade(sv) sv_utf8_upgrade_flags(sv, SV_GMAGIC)
1113 /* Should be named SvCatPVN_utf8_upgrade? */
1114 #define sv_catpvn_utf8_upgrade(dsv, sstr, slen, nsv) \
1117 nsv = sv_2mortal(newSVpvn(sstr, slen)); \
1119 sv_setpvn(nsv, sstr, slen); \
1121 sv_utf8_upgrade(nsv); \
1122 sv_catsv(dsv, nsv); \
1126 =for apidoc Am|SV*|newRV_inc|SV* sv
1128 Creates an RV wrapper for an SV. The reference count for the original SV is
1134 #define newRV_inc(sv) newRV(sv)
1136 /* the following macros update any magic values this sv is associated with */
1139 =head1 Magical Functions
1141 =for apidoc Am|void|SvGETMAGIC|SV* sv
1142 Invokes C<mg_get> on an SV if it has 'get' magic. This macro evaluates its
1143 argument more than once.
1145 =for apidoc Am|void|SvSETMAGIC|SV* sv
1146 Invokes C<mg_set> on an SV if it has 'set' magic. This macro evaluates its
1147 argument more than once.
1149 =for apidoc Am|void|SvSetSV|SV* dsb|SV* ssv
1150 Calls C<sv_setsv> if dsv is not the same as ssv. May evaluate arguments
1153 =for apidoc Am|void|SvSetSV_nosteal|SV* dsv|SV* ssv
1154 Calls a non-destructive version of C<sv_setsv> if dsv is not the same as
1155 ssv. May evaluate arguments more than once.
1157 =for apidoc Am|void|SvSetMagicSV|SV* dsb|SV* ssv
1158 Like C<SvSetSV>, but does any set magic required afterwards.
1160 =for apidoc Am|void|SvSetMagicSV_nosteal|SV* dsv|SV* ssv
1161 Like C<SvSetMagicSV>, but does any set magic required afterwards.
1163 =for apidoc Am|void|SvSHARE|SV* sv
1164 Arranges for sv to be shared between threads if a suitable module
1167 =for apidoc Am|void|SvLOCK|SV* sv
1168 Arranges for a mutual exclusion lock to be obtained on sv if a suitable module
1171 =for apidoc Am|void|SvUNLOCK|SV* sv
1172 Releases a mutual exclusion lock on sv if a suitable module
1175 =head1 SV Manipulation Functions
1177 =for apidoc Am|char *|SvGROW|SV* sv|STRLEN len
1178 Expands the character buffer in the SV so that it has room for the
1179 indicated number of bytes (remember to reserve space for an extra trailing
1180 NUL character). Calls C<sv_grow> to perform the expansion if necessary.
1181 Returns a pointer to the character buffer.
1186 #define SvSHARE(sv) CALL_FPTR(PL_sharehook)(aTHX_ sv)
1187 #define SvLOCK(sv) CALL_FPTR(PL_lockhook)(aTHX_ sv)
1188 #define SvUNLOCK(sv) CALL_FPTR(PL_unlockhook)(aTHX_ sv)
1190 #define SvGETMAGIC(x) STMT_START { if (SvGMAGICAL(x)) mg_get(x); } STMT_END
1191 #define SvSETMAGIC(x) STMT_START { if (SvSMAGICAL(x)) mg_set(x); } STMT_END
1193 #define SvSetSV_and(dst,src,finally) \
1195 if ((dst) != (src)) { \
1196 sv_setsv(dst, src); \
1200 #define SvSetSV_nosteal_and(dst,src,finally) \
1202 if ((dst) != (src)) { \
1203 U32 tMpF = SvFLAGS(src) & SVs_TEMP; \
1205 sv_setsv(dst, src); \
1206 SvFLAGS(src) |= tMpF; \
1211 #define SvSetSV(dst,src) \
1212 SvSetSV_and(dst,src,/*nothing*/;)
1213 #define SvSetSV_nosteal(dst,src) \
1214 SvSetSV_nosteal_and(dst,src,/*nothing*/;)
1216 #define SvSetMagicSV(dst,src) \
1217 SvSetSV_and(dst,src,SvSETMAGIC(dst))
1218 #define SvSetMagicSV_nosteal(dst,src) \
1219 SvSetSV_nosteal_and(dst,src,SvSETMAGIC(dst))
1222 #if !defined(SKIP_DEBUGGING)
1223 #define SvPEEK(sv) sv_peek(sv)
1225 #define SvPEEK(sv) ""
1228 #define SvIMMORTAL(sv) ((sv)==&PL_sv_undef || (sv)==&PL_sv_yes || (sv)==&PL_sv_no)
1230 #define boolSV(b) ((b) ? &PL_sv_yes : &PL_sv_no)
1232 #define isGV(sv) (SvTYPE(sv) == SVt_PVGV)
1234 #define SvGROW(sv,len) (SvLEN(sv) < (len) ? sv_grow(sv,len) : SvPVX(sv))
1235 #define Sv_Grow sv_grow
1237 #define CLONEf_COPY_STACKS 1
1238 #define CLONEf_KEEP_PTR_TABLE 2
1239 #define CLONEf_CLONE_HOST 4
1240 #define CLONEf_JOIN_IN 8
1242 struct clone_params {
1245 PerlInterpreter *proto_perl;