3 * Copyright (c) 1991-2001, 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() */
15 =for apidoc AmU||svtype
16 An enum of flags for Perl types. These are found in the file B<sv.h>
17 in the C<svtype> enum. Test these flags with the C<SvTYPE> macro.
19 =for apidoc AmU||SVt_PV
20 Pointer type flag for scalars. See C<svtype>.
22 =for apidoc AmU||SVt_IV
23 Integer type flag for scalars. See C<svtype>.
25 =for apidoc AmU||SVt_NV
26 Double type flag for scalars. See C<svtype>.
28 =for apidoc AmU||SVt_PVMG
29 Type flag for blessed scalars. See C<svtype>.
31 =for apidoc AmU||SVt_PVAV
32 Type flag for arrays. See C<svtype>.
34 =for apidoc AmU||SVt_PVHV
35 Type flag for hashes. See C<svtype>.
37 =for apidoc AmU||SVt_PVCV
38 Type flag for code refs. See C<svtype>.
62 /* Using C's structural equivalence to help emulate C++ inheritance here... */
64 struct STRUCT_SV { /* struct sv { */
65 void* sv_any; /* pointer to something */
66 U32 sv_refcnt; /* how many references to us */
67 U32 sv_flags; /* what we are */
71 XPVGV* sv_any; /* pointer to something */
72 U32 sv_refcnt; /* how many references to us */
73 U32 sv_flags; /* what we are */
77 XPVCV* sv_any; /* pointer to something */
78 U32 sv_refcnt; /* how many references to us */
79 U32 sv_flags; /* what we are */
83 XPVAV* sv_any; /* pointer to something */
84 U32 sv_refcnt; /* how many references to us */
85 U32 sv_flags; /* what we are */
89 XPVHV* sv_any; /* pointer to something */
90 U32 sv_refcnt; /* how many references to us */
91 U32 sv_flags; /* what we are */
95 XPVIO* sv_any; /* pointer to something */
96 U32 sv_refcnt; /* how many references to us */
97 U32 sv_flags; /* what we are */
101 =for apidoc Am|U32|SvREFCNT|SV* sv
102 Returns the value of the object's reference count.
104 =for apidoc Am|SV*|SvREFCNT_inc|SV* sv
105 Increments the reference count of the given SV.
107 =for apidoc Am|void|SvREFCNT_dec|SV* sv
108 Decrements the reference count of the given SV.
110 =for apidoc Am|svtype|SvTYPE|SV* sv
111 Returns the type of the SV. See C<svtype>.
113 =for apidoc Am|void|SvUPGRADE|SV* sv|svtype type
114 Used to upgrade an SV to a more complex form. Uses C<sv_upgrade> to
115 perform the upgrade if necessary. See C<svtype>.
120 #define SvANY(sv) (sv)->sv_any
121 #define SvFLAGS(sv) (sv)->sv_flags
122 #define SvREFCNT(sv) (sv)->sv_refcnt
124 #ifdef USE_5005THREADS
127 # define ATOMIC_INC(count) __ATOMIC_INCREMENT_LONG(&count)
128 # define ATOMIC_DEC_AND_TEST(res,count) res=(1==__ATOMIC_DECREMENT_LONG(&count))
130 # ifdef EMULATE_ATOMIC_REFCOUNTS
131 # define ATOMIC_INC(count) STMT_START { \
132 MUTEX_LOCK(&PL_svref_mutex); \
134 MUTEX_UNLOCK(&PL_svref_mutex); \
136 # define ATOMIC_DEC_AND_TEST(res,count) STMT_START { \
137 MUTEX_LOCK(&PL_svref_mutex); \
138 res = (--count == 0); \
139 MUTEX_UNLOCK(&PL_svref_mutex); \
142 # define ATOMIC_INC(count) atomic_inc(&count)
143 # define ATOMIC_DEC_AND_TEST(res,count) (res = atomic_dec_and_test(&count))
144 # endif /* EMULATE_ATOMIC_REFCOUNTS */
147 # define ATOMIC_INC(count) (++count)
148 # define ATOMIC_DEC_AND_TEST(res, count) (res = (--count == 0))
149 #endif /* USE_5005THREADS */
152 # define SvREFCNT_inc(sv) \
154 SV *nsv = (SV*)(sv); \
156 ATOMIC_INC(SvREFCNT(nsv)); \
160 # if defined(CRIPPLED_CC) || defined(USE_5005THREADS)
161 # if defined(VMS) && defined(__ALPHA)
162 # define SvREFCNT_inc(sv) \
163 (PL_Sv=(SV*)(sv), (PL_Sv && __ATOMIC_INCREMENT_LONG(&(SvREFCNT(PL_Sv)))), (SV *)PL_Sv)
165 # define SvREFCNT_inc(sv) sv_newref((SV*)sv)
168 # define SvREFCNT_inc(sv) \
169 ((PL_Sv=(SV*)(sv)), (PL_Sv && ATOMIC_INC(SvREFCNT(PL_Sv))), (SV*)PL_Sv)
173 #define SvREFCNT_dec(sv) sv_free((SV*)sv)
175 #define SVTYPEMASK 0xff
176 #define SvTYPE(sv) ((sv)->sv_flags & SVTYPEMASK)
178 #define SvUPGRADE(sv, mt) (SvTYPE(sv) >= mt || sv_upgrade(sv, mt))
180 #define SVs_PADBUSY 0x00000100 /* reserved for tmp or my already */
181 #define SVs_PADTMP 0x00000200 /* in use as tmp */
182 #define SVs_PADMY 0x00000400 /* in use a "my" variable */
183 #define SVs_TEMP 0x00000800 /* string is stealable? */
184 #define SVs_OBJECT 0x00001000 /* is "blessed" */
185 #define SVs_GMG 0x00002000 /* has magical get method */
186 #define SVs_SMG 0x00004000 /* has magical set method */
187 #define SVs_RMG 0x00008000 /* has random magical methods */
189 #define SVf_IOK 0x00010000 /* has valid public integer value */
190 #define SVf_NOK 0x00020000 /* has valid public numeric value */
191 #define SVf_POK 0x00040000 /* has valid public pointer value */
192 #define SVf_ROK 0x00080000 /* has a valid reference pointer */
194 #define SVf_FAKE 0x00100000 /* glob or lexical is just a copy */
195 #define SVf_OOK 0x00200000 /* has valid offset value */
196 #define SVf_BREAK 0x00400000 /* refcnt is artificially low - used
197 * by SV's in final arena cleanup */
198 #define SVf_READONLY 0x00800000 /* may not be modified */
201 #define SVp_IOK 0x01000000 /* has valid non-public integer value */
202 #define SVp_NOK 0x02000000 /* has valid non-public numeric value */
203 #define SVp_POK 0x04000000 /* has valid non-public pointer value */
204 #define SVp_SCREAM 0x08000000 /* has been studied? */
206 #define SVf_UTF8 0x20000000 /* SvPVX is UTF-8 encoded */
208 #define SVf_THINKFIRST (SVf_READONLY|SVf_ROK|SVf_FAKE)
210 #define SVf_OK (SVf_IOK|SVf_NOK|SVf_POK|SVf_ROK| \
211 SVp_IOK|SVp_NOK|SVp_POK)
213 #define SVf_AMAGIC 0x10000000 /* has magical overloaded methods */
217 /* Some private flags. */
219 /* SVpad_OUR may be set on SVt_PV{NV,MG,GV} types */
220 #define SVpad_OUR 0x80000000 /* pad name is "our" instead of "my" */
221 #define SVpad_TYPED 0x40000000 /* Typed Lexical */
223 #define SVf_IVisUV 0x80000000 /* use XPVUV instead of XPVIV */
225 #define SVpfm_COMPILED 0x80000000 /* FORMLINE is compiled */
227 #define SVpbm_VALID 0x80000000
228 #define SVpbm_TAIL 0x40000000
230 #define SVrepl_EVAL 0x40000000 /* Replacement part of s///e */
232 #define SVphv_SHAREKEYS 0x20000000 /* keys live on shared string table */
233 #define SVphv_LAZYDEL 0x40000000 /* entry in xhv_eiter must be deleted */
235 #define SVprv_WEAKREF 0x80000000 /* Weak reference */
238 SV * xrv_rv; /* pointer to another SV */
242 char * xpv_pv; /* pointer to malloced string */
243 STRLEN xpv_cur; /* length of xpv_pv as a C string */
244 STRLEN xpv_len; /* allocated size */
248 char * xpv_pv; /* pointer to malloced string */
249 STRLEN xpv_cur; /* length of xpv_pv as a C string */
250 STRLEN xpv_len; /* allocated size */
251 IV xiv_iv; /* integer value or pv offset */
255 char * xpv_pv; /* pointer to malloced string */
256 STRLEN xpv_cur; /* length of xpv_pv as a C string */
257 STRLEN xpv_len; /* allocated size */
258 UV xuv_uv; /* unsigned value or pv offset */
262 char * xpv_pv; /* pointer to malloced string */
263 STRLEN xpv_cur; /* length of xpv_pv as a C string */
264 STRLEN xpv_len; /* allocated size */
265 IV xiv_iv; /* integer value or pv offset */
266 NV xnv_nv; /* numeric value, if any */
269 /* These structure must match the beginning of struct xpvhv in hv.h. */
271 char * xpv_pv; /* pointer to malloced string */
272 STRLEN xpv_cur; /* length of xpv_pv as a C string */
273 STRLEN xpv_len; /* allocated size */
274 IV xiv_iv; /* integer value or pv offset */
275 NV xnv_nv; /* numeric value, if any */
276 MAGIC* xmg_magic; /* linked list of magicalness */
277 HV* xmg_stash; /* class package */
281 char * xpv_pv; /* pointer to malloced string */
282 STRLEN xpv_cur; /* length of xpv_pv as a C string */
283 STRLEN xpv_len; /* allocated size */
284 IV xiv_iv; /* integer value or pv offset */
285 NV xnv_nv; /* numeric value, if any */
286 MAGIC* xmg_magic; /* linked list of magicalness */
287 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 */
312 char * xpv_pv; /* pointer to malloced string */
313 STRLEN xpv_cur; /* length of xpv_pv as a C string */
314 STRLEN xpv_len; /* allocated size */
315 IV xiv_iv; /* integer value or pv offset */
316 NV xnv_nv; /* numeric value, if any */
317 MAGIC* xmg_magic; /* linked list of magicalness */
318 HV* xmg_stash; /* class package */
320 I32 xbm_useful; /* is this constant pattern being useful? */
321 U16 xbm_previous; /* how many characters in string before rare? */
322 U8 xbm_rare; /* rarest character in string */
325 /* This structure much match XPVCV in cv.h */
327 typedef U16 cv_flags_t;
330 char * xpv_pv; /* pointer to malloced string */
331 STRLEN xpv_cur; /* length of xpv_pv as a C string */
332 STRLEN xpv_len; /* allocated size */
333 IV xiv_iv; /* integer value or pv offset */
334 NV xnv_nv; /* numeric value, if any */
335 MAGIC* xmg_magic; /* linked list of magicalness */
336 HV* xmg_stash; /* class package */
341 void (*xcv_xsub)(pTHX_ CV*);
345 long xcv_depth; /* >= 2 indicates recursive call */
348 #ifdef USE_5005THREADS
349 perl_mutex *xcv_mutexp; /* protects xcv_owner */
350 struct perl_thread *xcv_owner; /* current owner thread */
351 #endif /* USE_5005THREADS */
352 cv_flags_t xcv_flags;
358 char * xpv_pv; /* pointer to malloced string */
359 STRLEN xpv_cur; /* length of xpv_pv as a C string */
360 STRLEN xpv_len; /* allocated size */
361 IV xiv_iv; /* integer value or pv offset */
362 NV xnv_nv; /* numeric value, if any */
363 MAGIC* xmg_magic; /* linked list of magicalness */
364 HV* xmg_stash; /* class package */
366 PerlIO * xio_ifp; /* ifp and ofp are normally the same */
367 PerlIO * xio_ofp; /* but sockets need separate streams */
368 /* Cray addresses everything by word boundaries (64 bits) and
369 * code and data pointers cannot be mixed (which is exactly what
370 * Perl_filter_add() tries to do with the dirp), hence the following
371 * union trick (as suggested by Gurusamy Sarathy).
372 * For further information see Geir Johansen's problem report titled
373 [ID 20000612.002] Perl problem on Cray system
374 * The any pointer (known as IoANY()) will also be a good place
375 * to hang any IO disciplines to.
378 DIR * xiou_dirp; /* for opendir, readdir, etc */
379 void * xiou_any; /* for alignment */
381 long xio_lines; /* $. */
382 long xio_page; /* $% */
383 long xio_page_len; /* $= */
384 long xio_lines_left; /* $- */
385 char * xio_top_name; /* $^ */
386 GV * xio_top_gv; /* $^ */
387 char * xio_fmt_name; /* $~ */
388 GV * xio_fmt_gv; /* $~ */
389 char * xio_bottom_name;/* $^B */
390 GV * xio_bottom_gv; /* $^B */
391 short xio_subprocess; /* -| or |- */
395 #define xio_dirp xio_dirpu.xiou_dirp
396 #define xio_any xio_dirpu.xiou_any
398 #define IOf_ARGV 1 /* this fp iterates over ARGV */
399 #define IOf_START 2 /* check for null ARGV and substitute '-' */
400 #define IOf_FLUSH 4 /* this fp wants a flush after write op */
401 #define IOf_DIDTOP 8 /* just did top of form */
402 #define IOf_UNTAINT 16 /* consider this fp (and its data) "safe" */
403 #define IOf_NOLINE 32 /* slurped a pseudo-line from empty file */
404 #define IOf_FAKE_DIRP 64 /* xio_dirp is fake (source filters kludge) */
406 /* The following macros define implementation-independent predicates on SVs. */
409 =for apidoc Am|bool|SvNIOK|SV* sv
410 Returns a boolean indicating whether the SV contains a number, integer or
413 =for apidoc Am|bool|SvNIOKp|SV* sv
414 Returns a boolean indicating whether the SV contains a number, integer or
415 double. Checks the B<private> setting. Use C<SvNIOK>.
417 =for apidoc Am|void|SvNIOK_off|SV* sv
418 Unsets the NV/IV status of an SV.
420 =for apidoc Am|bool|SvOK|SV* sv
421 Returns a boolean indicating whether the value is an SV.
423 =for apidoc Am|bool|SvIOKp|SV* sv
424 Returns a boolean indicating whether the SV contains an integer. Checks
425 the B<private> setting. Use C<SvIOK>.
427 =for apidoc Am|bool|SvNOKp|SV* sv
428 Returns a boolean indicating whether the SV contains a double. Checks the
429 B<private> setting. Use C<SvNOK>.
431 =for apidoc Am|bool|SvPOKp|SV* sv
432 Returns a boolean indicating whether the SV contains a character string.
433 Checks the B<private> setting. Use C<SvPOK>.
435 =for apidoc Am|bool|SvIOK|SV* sv
436 Returns a boolean indicating whether the SV contains an integer.
438 =for apidoc Am|void|SvIOK_on|SV* sv
439 Tells an SV that it is an integer.
441 =for apidoc Am|void|SvIOK_off|SV* sv
442 Unsets the IV status of an SV.
444 =for apidoc Am|void|SvIOK_only|SV* sv
445 Tells an SV that it is an integer and disables all other OK bits.
447 =for apidoc Am|void|SvIOK_only_UV|SV* sv
448 Tells and SV that it is an unsigned integer and disables all other OK bits.
450 =for apidoc Am|void|SvIOK_UV|SV* sv
451 Returns a boolean indicating whether the SV contains an unsigned integer.
453 =for apidoc Am|void|SvUOK|SV* sv
454 Returns a boolean indicating whether the SV contains an unsigned integer.
456 =for apidoc Am|void|SvIOK_notUV|SV* sv
457 Returns a boolean indicating whether the SV contains an signed integer.
459 =for apidoc Am|bool|SvNOK|SV* sv
460 Returns a boolean indicating whether the SV contains a double.
462 =for apidoc Am|void|SvNOK_on|SV* sv
463 Tells an SV that it is a double.
465 =for apidoc Am|void|SvNOK_off|SV* sv
466 Unsets the NV status of an SV.
468 =for apidoc Am|void|SvNOK_only|SV* sv
469 Tells an SV that it is a double and disables all other OK bits.
471 =for apidoc Am|bool|SvPOK|SV* sv
472 Returns a boolean indicating whether the SV contains a character
475 =for apidoc Am|void|SvPOK_on|SV* sv
476 Tells an SV that it is a string.
478 =for apidoc Am|void|SvPOK_off|SV* sv
479 Unsets the PV status of an SV.
481 =for apidoc Am|void|SvPOK_only|SV* sv
482 Tells an SV that it is a string and disables all other OK bits.
483 Will also turn off the UTF8 status.
485 =for apidoc Am|bool|SvOOK|SV* sv
486 Returns a boolean indicating whether the SvIVX is a valid offset value for
487 the SvPVX. This hack is used internally to speed up removal of characters
488 from the beginning of a SvPV. When SvOOK is true, then the start of the
489 allocated string buffer is really (SvPVX - SvIVX).
491 =for apidoc Am|bool|SvROK|SV* sv
492 Tests if the SV is an RV.
494 =for apidoc Am|void|SvROK_on|SV* sv
495 Tells an SV that it is an RV.
497 =for apidoc Am|void|SvROK_off|SV* sv
498 Unsets the RV status of an SV.
500 =for apidoc Am|SV*|SvRV|SV* sv
501 Dereferences an RV to return the SV.
503 =for apidoc Am|IV|SvIVX|SV* sv
504 Returns the raw value in the SV's IV slot, without checks or conversions.
505 Only use when you are sure SvIOK is true. See also C<SvIV()>.
507 =for apidoc Am|UV|SvUVX|SV* sv
508 Returns the raw value in the SV's UV slot, without checks or conversions.
509 Only use when you are sure SvIOK is true. See also C<SvUV()>.
511 =for apidoc Am|NV|SvNVX|SV* sv
512 Returns the raw value in the SV's NV slot, without checks or conversions.
513 Only use when you are sure SvNOK is true. See also C<SvNV()>.
515 =for apidoc Am|char*|SvPVX|SV* sv
516 Returns a pointer to the physical string in the SV. The SV must contain a
519 =for apidoc Am|STRLEN|SvCUR|SV* sv
520 Returns the length of the string which is in the SV. See C<SvLEN>.
522 =for apidoc Am|STRLEN|SvLEN|SV* sv
523 Returns the size of the string buffer in the SV, not including any part
524 attributable to C<SvOOK>. See C<SvCUR>.
526 =for apidoc Am|char*|SvEND|SV* sv
527 Returns a pointer to the last character in the string which is in the SV.
528 See C<SvCUR>. Access the character as *(SvEND(sv)).
530 =for apidoc Am|HV*|SvSTASH|SV* sv
531 Returns the stash of the SV.
533 =for apidoc Am|void|SvCUR_set|SV* sv|STRLEN len
534 Set the length of the string which is in the SV. See C<SvCUR>.
539 #define SvNIOK(sv) (SvFLAGS(sv) & (SVf_IOK|SVf_NOK))
540 #define SvNIOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK))
541 #define SvNIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK| \
542 SVp_IOK|SVp_NOK|SVf_IVisUV))
544 #define SvOK(sv) (SvFLAGS(sv) & SVf_OK)
545 #define SvOK_off(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC| \
546 SVf_IVisUV|SVf_UTF8), \
548 #define SvOK_off_exc_UV(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC| \
552 #define SvOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK))
553 #define SvIOKp(sv) (SvFLAGS(sv) & SVp_IOK)
554 #define SvIOKp_on(sv) ((void)SvOOK_off(sv), SvFLAGS(sv) |= SVp_IOK)
555 #define SvNOKp(sv) (SvFLAGS(sv) & SVp_NOK)
556 #define SvNOKp_on(sv) (SvFLAGS(sv) |= SVp_NOK)
557 #define SvPOKp(sv) (SvFLAGS(sv) & SVp_POK)
558 #define SvPOKp_on(sv) (SvFLAGS(sv) |= SVp_POK)
560 #define SvIOK(sv) (SvFLAGS(sv) & SVf_IOK)
561 #define SvIOK_on(sv) ((void)SvOOK_off(sv), \
562 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
563 #define SvIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVp_IOK|SVf_IVisUV))
564 #define SvIOK_only(sv) ((void)SvOK_off(sv), \
565 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
566 #define SvIOK_only_UV(sv) ((void)SvOK_off_exc_UV(sv), \
567 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
569 #define SvIOK_UV(sv) ((SvFLAGS(sv) & (SVf_IOK|SVf_IVisUV)) \
570 == (SVf_IOK|SVf_IVisUV))
571 #define SvUOK(sv) SvIOK_UV(sv)
572 #define SvIOK_notUV(sv) ((SvFLAGS(sv) & (SVf_IOK|SVf_IVisUV)) \
575 #define SvIsUV(sv) (SvFLAGS(sv) & SVf_IVisUV)
576 #define SvIsUV_on(sv) (SvFLAGS(sv) |= SVf_IVisUV)
577 #define SvIsUV_off(sv) (SvFLAGS(sv) &= ~SVf_IVisUV)
579 #define SvNOK(sv) (SvFLAGS(sv) & SVf_NOK)
580 #define SvNOK_on(sv) (SvFLAGS(sv) |= (SVf_NOK|SVp_NOK))
581 #define SvNOK_off(sv) (SvFLAGS(sv) &= ~(SVf_NOK|SVp_NOK))
582 #define SvNOK_only(sv) ((void)SvOK_off(sv), \
583 SvFLAGS(sv) |= (SVf_NOK|SVp_NOK))
586 =for apidoc Am|void|SvUTF8|SV* sv
587 Returns a boolean indicating whether the SV contains UTF-8 encoded data.
589 =for apidoc Am|void|SvUTF8_on|SV *sv
590 Turn on the UTF8 status of an SV (the data is not changed, just the flag).
591 Do not use frivolously.
593 =for apidoc Am|void|SvUTF8_off|SV *sv
594 Unsets the UTF8 status of an SV.
596 =for apidoc Am|void|SvPOK_only_UTF8|SV* sv
597 Tells an SV that it is a string and disables all other OK bits,
598 and leaves the UTF8 status as it was.
603 #define SvUTF8(sv) (SvFLAGS(sv) & SVf_UTF8)
604 #define SvUTF8_on(sv) (SvFLAGS(sv) |= (SVf_UTF8))
605 #define SvUTF8_off(sv) (SvFLAGS(sv) &= ~(SVf_UTF8))
607 #define SvPOK(sv) (SvFLAGS(sv) & SVf_POK)
608 #define SvPOK_on(sv) (SvFLAGS(sv) |= (SVf_POK|SVp_POK))
609 #define SvPOK_off(sv) (SvFLAGS(sv) &= ~(SVf_POK|SVp_POK))
610 #define SvPOK_only(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC| \
611 SVf_IVisUV|SVf_UTF8), \
612 SvFLAGS(sv) |= (SVf_POK|SVp_POK))
613 #define SvPOK_only_UTF8(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC| \
615 SvFLAGS(sv) |= (SVf_POK|SVp_POK))
617 #define SvOOK(sv) (SvFLAGS(sv) & SVf_OOK)
618 #define SvOOK_on(sv) ((void)SvIOK_off(sv), SvFLAGS(sv) |= SVf_OOK)
619 #define SvOOK_off(sv) (SvOOK(sv) && sv_backoff(sv))
621 #define SvFAKE(sv) (SvFLAGS(sv) & SVf_FAKE)
622 #define SvFAKE_on(sv) (SvFLAGS(sv) |= SVf_FAKE)
623 #define SvFAKE_off(sv) (SvFLAGS(sv) &= ~SVf_FAKE)
625 #define SvROK(sv) (SvFLAGS(sv) & SVf_ROK)
626 #define SvROK_on(sv) (SvFLAGS(sv) |= SVf_ROK)
627 #define SvROK_off(sv) (SvFLAGS(sv) &= ~(SVf_ROK|SVf_AMAGIC))
629 #define SvMAGICAL(sv) (SvFLAGS(sv) & (SVs_GMG|SVs_SMG|SVs_RMG))
630 #define SvMAGICAL_on(sv) (SvFLAGS(sv) |= (SVs_GMG|SVs_SMG|SVs_RMG))
631 #define SvMAGICAL_off(sv) (SvFLAGS(sv) &= ~(SVs_GMG|SVs_SMG|SVs_RMG))
633 #define SvGMAGICAL(sv) (SvFLAGS(sv) & SVs_GMG)
634 #define SvGMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_GMG)
635 #define SvGMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_GMG)
637 #define SvSMAGICAL(sv) (SvFLAGS(sv) & SVs_SMG)
638 #define SvSMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_SMG)
639 #define SvSMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_SMG)
641 #define SvRMAGICAL(sv) (SvFLAGS(sv) & SVs_RMG)
642 #define SvRMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_RMG)
643 #define SvRMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_RMG)
645 #define SvAMAGIC(sv) (SvFLAGS(sv) & SVf_AMAGIC)
646 #define SvAMAGIC_on(sv) (SvFLAGS(sv) |= SVf_AMAGIC)
647 #define SvAMAGIC_off(sv) (SvFLAGS(sv) &= ~SVf_AMAGIC)
649 #define SvGAMAGIC(sv) (SvFLAGS(sv) & (SVs_GMG|SVf_AMAGIC))
652 #define Gv_AMG(stash) \
653 (HV_AMAGICmb(stash) && \
654 ((!HV_AMAGICbad(stash) && HV_AMAGIC(stash)) || Gv_AMupdate(stash)))
656 #define Gv_AMG(stash) (PL_amagic_generation && Gv_AMupdate(stash))
658 #define SvWEAKREF(sv) ((SvFLAGS(sv) & (SVf_ROK|SVprv_WEAKREF)) \
659 == (SVf_ROK|SVprv_WEAKREF))
660 #define SvWEAKREF_on(sv) (SvFLAGS(sv) |= (SVf_ROK|SVprv_WEAKREF))
661 #define SvWEAKREF_off(sv) (SvFLAGS(sv) &= ~(SVf_ROK|SVprv_WEAKREF))
663 #define SvTHINKFIRST(sv) (SvFLAGS(sv) & SVf_THINKFIRST)
665 #define SvPADBUSY(sv) (SvFLAGS(sv) & SVs_PADBUSY)
667 #define SvPADTMP(sv) (SvFLAGS(sv) & SVs_PADTMP)
668 #define SvPADTMP_on(sv) (SvFLAGS(sv) |= SVs_PADTMP|SVs_PADBUSY)
669 #define SvPADTMP_off(sv) (SvFLAGS(sv) &= ~SVs_PADTMP)
671 #define SvPADMY(sv) (SvFLAGS(sv) & SVs_PADMY)
672 #define SvPADMY_on(sv) (SvFLAGS(sv) |= SVs_PADMY|SVs_PADBUSY)
674 #define SvTEMP(sv) (SvFLAGS(sv) & SVs_TEMP)
675 #define SvTEMP_on(sv) (SvFLAGS(sv) |= SVs_TEMP)
676 #define SvTEMP_off(sv) (SvFLAGS(sv) &= ~SVs_TEMP)
678 #define SvOBJECT(sv) (SvFLAGS(sv) & SVs_OBJECT)
679 #define SvOBJECT_on(sv) (SvFLAGS(sv) |= SVs_OBJECT)
680 #define SvOBJECT_off(sv) (SvFLAGS(sv) &= ~SVs_OBJECT)
682 #define SvREADONLY(sv) (SvFLAGS(sv) & SVf_READONLY)
683 #define SvREADONLY_on(sv) (SvFLAGS(sv) |= SVf_READONLY)
684 #define SvREADONLY_off(sv) (SvFLAGS(sv) &= ~SVf_READONLY)
686 #define SvSCREAM(sv) (SvFLAGS(sv) & SVp_SCREAM)
687 #define SvSCREAM_on(sv) (SvFLAGS(sv) |= SVp_SCREAM)
688 #define SvSCREAM_off(sv) (SvFLAGS(sv) &= ~SVp_SCREAM)
690 #define SvCOMPILED(sv) (SvFLAGS(sv) & SVpfm_COMPILED)
691 #define SvCOMPILED_on(sv) (SvFLAGS(sv) |= SVpfm_COMPILED)
692 #define SvCOMPILED_off(sv) (SvFLAGS(sv) &= ~SVpfm_COMPILED)
694 #define SvEVALED(sv) (SvFLAGS(sv) & SVrepl_EVAL)
695 #define SvEVALED_on(sv) (SvFLAGS(sv) |= SVrepl_EVAL)
696 #define SvEVALED_off(sv) (SvFLAGS(sv) &= ~SVrepl_EVAL)
698 #define SvTAIL(sv) (SvFLAGS(sv) & SVpbm_TAIL)
699 #define SvTAIL_on(sv) (SvFLAGS(sv) |= SVpbm_TAIL)
700 #define SvTAIL_off(sv) (SvFLAGS(sv) &= ~SVpbm_TAIL)
702 #define SvVALID(sv) (SvFLAGS(sv) & SVpbm_VALID)
703 #define SvVALID_on(sv) (SvFLAGS(sv) |= SVpbm_VALID)
704 #define SvVALID_off(sv) (SvFLAGS(sv) &= ~SVpbm_VALID)
707 /* The following uses the FAKE flag to show that a regex pointer is infact
708 its own offset in the regexpad for ithreads */
709 #define SvREPADTMP(sv) (SvFLAGS(sv) & SVf_FAKE)
710 #define SvREPADTMP_on(sv) (SvFLAGS(sv) |= SVf_FAKE)
711 #define SvREPADTMP_off(sv) (SvFLAGS(sv) &= ~SVf_FAKE)
714 #define SvRV(sv) ((XRV*) SvANY(sv))->xrv_rv
715 #define SvRVx(sv) SvRV(sv)
717 #define SvIVX(sv) ((XPVIV*) SvANY(sv))->xiv_iv
718 #define SvIVXx(sv) SvIVX(sv)
719 #define SvUVX(sv) ((XPVUV*) SvANY(sv))->xuv_uv
720 #define SvUVXx(sv) SvUVX(sv)
721 #define SvNVX(sv) ((XPVNV*)SvANY(sv))->xnv_nv
722 #define SvNVXx(sv) SvNVX(sv)
723 #define SvPVX(sv) ((XPV*) SvANY(sv))->xpv_pv
724 #define SvPVXx(sv) SvPVX(sv)
725 #define SvCUR(sv) ((XPV*) SvANY(sv))->xpv_cur
726 #define SvLEN(sv) ((XPV*) SvANY(sv))->xpv_len
727 #define SvLENx(sv) SvLEN(sv)
728 #define SvEND(sv)(((XPV*) SvANY(sv))->xpv_pv + ((XPV*)SvANY(sv))->xpv_cur)
729 #define SvENDx(sv) ((PL_Sv = (sv)), SvEND(PL_Sv))
730 #define SvMAGIC(sv) ((XPVMG*) SvANY(sv))->xmg_magic
731 #define SvSTASH(sv) ((XPVMG*) SvANY(sv))->xmg_stash
733 /* Ask a scalar nicely to try to become an IV, if possible.
734 Not guaranteed to stay returning void */
735 /* Macro won't actually call sv_2iv if already IOK */
736 #define SvIV_please(sv) \
737 STMT_START {if (!SvIOKp(sv) && (SvNOK(sv) || SvPOK(sv))) \
738 (void) SvIV(sv); } STMT_END
739 #define SvIV_set(sv, val) \
740 STMT_START { assert(SvTYPE(sv) == SVt_IV || SvTYPE(sv) >= SVt_PVIV); \
741 (((XPVIV*) SvANY(sv))->xiv_iv = val); } STMT_END
742 #define SvNV_set(sv, val) \
743 STMT_START { assert(SvTYPE(sv) == SVt_NV || SvTYPE(sv) >= SVt_PVNV); \
744 (((XPVNV*) SvANY(sv))->xnv_nv = val); } STMT_END
745 #define SvPV_set(sv, val) \
746 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
747 (((XPV*) SvANY(sv))->xpv_pv = val); } STMT_END
748 #define SvCUR_set(sv, val) \
749 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
750 (((XPV*) SvANY(sv))->xpv_cur = val); } STMT_END
751 #define SvLEN_set(sv, val) \
752 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
753 (((XPV*) SvANY(sv))->xpv_len = val); } STMT_END
754 #define SvEND_set(sv, val) \
755 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
756 (((XPV*) SvANY(sv))->xpv_cur = val - SvPVX(sv)); } STMT_END
758 #define BmRARE(sv) ((XPVBM*) SvANY(sv))->xbm_rare
759 #define BmUSEFUL(sv) ((XPVBM*) SvANY(sv))->xbm_useful
760 #define BmPREVIOUS(sv) ((XPVBM*) SvANY(sv))->xbm_previous
762 #define FmLINES(sv) ((XPVFM*) SvANY(sv))->xfm_lines
764 #define LvTYPE(sv) ((XPVLV*) SvANY(sv))->xlv_type
765 #define LvTARG(sv) ((XPVLV*) SvANY(sv))->xlv_targ
766 #define LvTARGOFF(sv) ((XPVLV*) SvANY(sv))->xlv_targoff
767 #define LvTARGLEN(sv) ((XPVLV*) SvANY(sv))->xlv_targlen
769 #define IoIFP(sv) ((XPVIO*) SvANY(sv))->xio_ifp
770 #define IoOFP(sv) ((XPVIO*) SvANY(sv))->xio_ofp
771 #define IoDIRP(sv) ((XPVIO*) SvANY(sv))->xio_dirp
772 #define IoANY(sv) ((XPVIO*) SvANY(sv))->xio_any
773 #define IoLINES(sv) ((XPVIO*) SvANY(sv))->xio_lines
774 #define IoPAGE(sv) ((XPVIO*) SvANY(sv))->xio_page
775 #define IoPAGE_LEN(sv) ((XPVIO*) SvANY(sv))->xio_page_len
776 #define IoLINES_LEFT(sv)((XPVIO*) SvANY(sv))->xio_lines_left
777 #define IoTOP_NAME(sv) ((XPVIO*) SvANY(sv))->xio_top_name
778 #define IoTOP_GV(sv) ((XPVIO*) SvANY(sv))->xio_top_gv
779 #define IoFMT_NAME(sv) ((XPVIO*) SvANY(sv))->xio_fmt_name
780 #define IoFMT_GV(sv) ((XPVIO*) SvANY(sv))->xio_fmt_gv
781 #define IoBOTTOM_NAME(sv)((XPVIO*) SvANY(sv))->xio_bottom_name
782 #define IoBOTTOM_GV(sv) ((XPVIO*) SvANY(sv))->xio_bottom_gv
783 #define IoSUBPROCESS(sv)((XPVIO*) SvANY(sv))->xio_subprocess
784 #define IoTYPE(sv) ((XPVIO*) SvANY(sv))->xio_type
785 #define IoFLAGS(sv) ((XPVIO*) SvANY(sv))->xio_flags
787 /* IoTYPE(sv) is a single character telling the type of I/O connection. */
788 #define IoTYPE_RDONLY '<'
789 #define IoTYPE_WRONLY '>'
790 #define IoTYPE_RDWR '+'
791 #define IoTYPE_APPEND 'a'
792 #define IoTYPE_PIPE '|'
793 #define IoTYPE_STD '-' /* stdin or stdout */
794 #define IoTYPE_SOCKET 's'
795 #define IoTYPE_CLOSED ' '
798 =for apidoc Am|bool|SvTAINTED|SV* sv
799 Checks to see if an SV is tainted. Returns TRUE if it is, FALSE if
802 =for apidoc Am|void|SvTAINTED_on|SV* sv
803 Marks an SV as tainted.
805 =for apidoc Am|void|SvTAINTED_off|SV* sv
806 Untaints an SV. Be I<very> careful with this routine, as it short-circuits
807 some of Perl's fundamental security features. XS module authors should not
808 use this function unless they fully understand all the implications of
809 unconditionally untainting the value. Untainting should be done in the
810 standard perl fashion, via a carefully crafted regexp, rather than directly
811 untainting variables.
813 =for apidoc Am|void|SvTAINT|SV* sv
814 Taints an SV if tainting is enabled
819 #define SvTAINTED(sv) (SvMAGICAL(sv) && sv_tainted(sv))
820 #define SvTAINTED_on(sv) STMT_START{ if(PL_tainting){sv_taint(sv);} }STMT_END
821 #define SvTAINTED_off(sv) STMT_START{ if(PL_tainting){sv_untaint(sv);} }STMT_END
823 #define SvTAINT(sv) \
832 =for apidoc Am|char*|SvPV_force|SV* sv|STRLEN len
833 Like <SvPV> but will force the SV into becoming a string (SvPOK). You want
834 force if you are going to update the SvPVX directly.
836 =for apidoc Am|char*|SvPV_force_nomg|SV* sv|STRLEN len
837 Like <SvPV> but will force the SV into becoming a string (SvPOK). You want
838 force if you are going to update the SvPVX directly. Doesn't process magic.
840 =for apidoc Am|char*|SvPV|SV* sv|STRLEN len
841 Returns a pointer to the string in the SV, or a stringified form of the SV
842 if the SV does not contain a string. Handles 'get' magic. See also
843 C<SvPVx> for a version which guarantees to evaluate sv only once.
845 =for apidoc Am|char*|SvPVx|SV* sv|STRLEN len
846 A version of C<SvPV> which guarantees to evaluate sv only once.
848 =for apidoc Am|char*|SvPV_nolen|SV* sv
849 Returns a pointer to the string in the SV, or a stringified form of the SV
850 if the SV does not contain a string. Handles 'get' magic.
852 =for apidoc Am|IV|SvIV|SV* sv
853 Coerces the given SV to an integer and returns it. See C<SvIVx> for a
854 version which guarantees to evaluate sv only once.
856 =for apidoc Am|IV|SvIVx|SV* sv
857 Coerces the given SV to an integer and returns it. Guarantees to evaluate
858 sv only once. Use the more efficent C<SvIV> otherwise.
860 =for apidoc Am|NV|SvNV|SV* sv
861 Coerce the given SV to a double and return it. See C<SvNVx> for a version
862 which guarantees to evaluate sv only once.
864 =for apidoc Am|NV|SvNVx|SV* sv
865 Coerces the given SV to a double and returns it. Guarantees to evaluate
866 sv only once. Use the more efficent C<SvNV> otherwise.
868 =for apidoc Am|UV|SvUV|SV* sv
869 Coerces the given SV to an unsigned integer and returns it. See C<SvUVx>
870 for a version which guarantees to evaluate sv only once.
872 =for apidoc Am|UV|SvUVx|SV* sv
873 Coerces the given SV to an unsigned integer and returns it. Guarantees to
874 evaluate sv only once. Use the more efficent C<SvUV> otherwise.
876 =for apidoc Am|bool|SvTRUE|SV* sv
877 Returns a boolean indicating whether Perl would evaluate the SV as true or
878 false, defined or undefined. Does not handle 'get' magic.
880 =for apidoc Am|char*|SvPVutf8_force|SV* sv|STRLEN len
881 Like C<SvPV_force>, but converts sv to uft8 first if necessary.
883 =for apidoc Am|char*|SvPVutf8|SV* sv|STRLEN len
884 Like C<SvPV>, but converts sv to uft8 first if necessary.
886 =for apidoc Am|char*|SvPVutf8_nolen|SV* sv|STRLEN len
887 Like C<SvPV_nolen>, but converts sv to uft8 first if necessary.
889 =for apidoc Am|char*|SvPVbyte_force|SV* sv|STRLEN len
890 Like C<SvPV_force>, but converts sv to byte representation first if necessary.
892 =for apidoc Am|char*|SvPVbyte|SV* sv|STRLEN len
893 Like C<SvPV>, but converts sv to byte representation first if necessary.
895 =for apidoc Am|char*|SvPVbyte_nolen|SV* sv|STRLEN len
896 Like C<SvPV_nolen>, but converts sv to byte representation first if necessary.
898 =for apidoc Am|char*|SvPVutf8x_force|SV* sv|STRLEN len
899 Like C<SvPV_force>, but converts sv to uft8 first if necessary.
900 Guarantees to evalute sv only once; use the more efficient C<SvPVutf8_force>
903 =for apidoc Am|char*|SvPVutf8x|SV* sv|STRLEN len
904 Like C<SvPV>, but converts sv to uft8 first if necessary.
905 Guarantees to evalute sv only once; use the more efficient C<SvPVutf8>
908 =for apidoc Am|char*|SvPVbytex_force|SV* sv|STRLEN len
909 Like C<SvPV_force>, but converts sv to byte representation first if necessary.
910 Guarantees to evalute sv only once; use the more efficient C<SvPVbyte_force>
913 =for apidoc Am|char*|SvPVbytex|SV* sv|STRLEN len
914 Like C<SvPV>, but converts sv to byte representation first if necessary.
915 Guarantees to evalute sv only once; use the more efficient C<SvPVbyte>
922 #define SvPV_force(sv, lp) sv_pvn_force(sv, &lp)
923 #define SvPV(sv, lp) sv_pvn(sv, &lp)
924 #define SvPV_nolen(sv) sv_pv(sv)
925 #define SvPV_nomg(sv, lp) sv_pvn_nomg(sv, &lp)
926 #define SvPV_force_flags(sv, lp, flags) sv_pvn_force_flags(sv, &lp, flags)
928 #define SvPVutf8_force(sv, lp) sv_pvutf8n_force(sv, &lp)
929 #define SvPVutf8(sv, lp) sv_pvutf8n(sv, &lp)
930 #define SvPVutf8_nolen(sv) sv_pvutf8(sv)
932 #define SvPVbyte_force(sv, lp) sv_pvbyte_force(sv, &lp)
933 #define SvPVbyte(sv, lp) sv_pvbyten(sv, &lp)
934 #define SvPVbyte_nolen(sv) sv_pvbyte(sv)
936 #define SvPVx(sv, lp) sv_pvn(sv, &lp)
937 #define SvPVx_force(sv, lp) sv_pvn_force(sv, &lp)
938 #define SvPVutf8x(sv, lp) sv_pvutf8n(sv, &lp)
939 #define SvPVutf8x_force(sv, lp) sv_pvutf8n_force(sv, &lp)
940 #define SvPVbytex(sv, lp) sv_pvbyten(sv, &lp)
941 #define SvPVbytex_force(sv, lp) sv_pvbyten_force(sv, &lp)
943 #define SvIVx(sv) sv_iv(sv)
944 #define SvUVx(sv) sv_uv(sv)
945 #define SvNVx(sv) sv_nv(sv)
947 #define SvTRUEx(sv) sv_true(sv)
949 #define SvIV(sv) SvIVx(sv)
950 #define SvNV(sv) SvNVx(sv)
951 #define SvUV(sv) SvUVx(sv)
952 #define SvTRUE(sv) SvTRUEx(sv)
954 /* flag values for sv_*_flags functions */
955 #define SV_IMMEDIATE_UNREF 1
958 #define sv_pvn_force_nomg(sv, lp) sv_pvn_force_flags(sv, lp, 0)
959 #define sv_utf8_upgrade_nomg(sv) sv_utf8_upgrade_flags(sv, 0)
960 #define sv_catpvn_nomg(dsv, sstr, slen) sv_catpvn_flags(dsv, sstr, slen, 0)
963 /* redefine some things to more efficient inlined versions */
965 /* Let us hope that bitmaps for UV and IV are the same */
967 #define SvIV(sv) (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv))
970 #define SvUV(sv) (SvIOK(sv) ? SvUVX(sv) : sv_2uv(sv))
973 #define SvNV(sv) (SvNOK(sv) ? SvNVX(sv) : sv_2nv(sv))
975 #define sv_setsv_macro(dsv, ssv) sv_setsv_flags(dsv, ssv, SV_GMAGIC)
976 #define sv_setsv_nomg(dsv, ssv) sv_setsv_flags(dsv, ssv, 0)
977 #define sv_catsv_macro(dsv, ssv) sv_catsv_flags(dsv, ssv, SV_GMAGIC)
978 #define sv_catsv_nomg(dsv, ssv) sv_catsv_flags(dsv, ssv, 0)
979 #define sv_catpvn_macro(dsv, sstr, slen) sv_catpvn_flags(dsv, sstr, slen, SV_GMAGIC)
980 #define sv_2pv_macro(sv, lp) sv_2pv_flags(sv, lp, SV_GMAGIC)
981 #define sv_2pv_nomg(sv, lp) sv_2pv_flags(sv, lp, 0)
982 #define sv_pvn_force_macro(sv, lp) sv_pvn_force_flags(sv, lp, SV_GMAGIC)
983 #define sv_utf8_upgrade_macro(sv) sv_utf8_upgrade_flags(sv, SV_GMAGIC)
985 /* function style also available for sourcecompat */
987 #define sv_setsv(dsv, ssv) sv_setsv_macro(dsv, ssv)
989 #define sv_catsv(dsv, ssv) sv_catsv_macro(dsv, ssv)
991 #define sv_catpvn(dsv, sstr, slen) sv_catpvn_macro(dsv, sstr, slen)
993 #define sv_2pv(sv, lp) sv_2pv_macro(sv, lp)
995 #define sv_pvn_force(sv, lp) sv_pvn_force_macro(sv, lp)
996 #undef sv_utf8_upgrade
997 #define sv_utf8_upgrade(sv) sv_utf8_upgrade_macro(sv)
1000 #define SvPV(sv, lp) SvPV_flags(sv, lp, SV_GMAGIC)
1003 #define SvPV_nomg(sv, lp) SvPV_flags(sv, lp, 0)
1006 #define SvPV_flags(sv, lp, flags) \
1007 ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
1008 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pv_flags(sv, &lp, flags))
1011 #define SvPV_force(sv, lp) SvPV_force_flags(sv, lp, SV_GMAGIC)
1012 #undef SvPV_force_nomg
1013 #define SvPV_force_nomg(sv, lp) SvPV_force_flags(sv, lp, 0)
1015 #undef SvPV_force_flags
1016 #define SvPV_force_flags(sv, lp, flags) \
1017 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \
1018 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvn_force_flags(sv, &lp, flags))
1021 #define SvPV_nolen(sv) \
1022 ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
1023 ? SvPVX(sv) : sv_2pv_nolen(sv))
1026 #define SvPVutf8(sv, lp) \
1027 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8) \
1028 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvutf8(sv, &lp))
1030 #undef SvPVutf8_force
1031 #define SvPVutf8_force(sv, lp) \
1032 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == (SVf_POK|SVf_UTF8) \
1033 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvutf8n_force(sv, &lp))
1035 #undef SvPVutf8_nolen
1036 #define SvPVutf8_nolen(sv) \
1037 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8)\
1038 ? SvPVX(sv) : sv_2pvutf8_nolen(sv))
1041 #define SvPVutf8(sv, lp) \
1042 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8) \
1043 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvutf8(sv, &lp))
1045 #undef SvPVutf8_force
1046 #define SvPVutf8_force(sv, lp) \
1047 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == (SVf_POK|SVf_UTF8) \
1048 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvutf8n_force(sv, &lp))
1050 #undef SvPVutf8_nolen
1051 #define SvPVutf8_nolen(sv) \
1052 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8)\
1053 ? SvPVX(sv) : sv_2pvutf8_nolen(sv))
1056 #define SvPVbyte(sv, lp) \
1057 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK) \
1058 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvbyte(sv, &lp))
1060 #undef SvPVbyte_force
1061 #define SvPVbyte_force(sv, lp) \
1062 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8|SVf_THINKFIRST)) == (SVf_POK) \
1063 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvbyte_force(sv, &lp))
1065 #undef SvPVbyte_nolen
1066 #define SvPVbyte_nolen(sv) \
1067 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK)\
1068 ? SvPVX(sv) : sv_2pvbyte_nolen(sv))
1080 # define SvIVx(sv) ({SV *nsv = (SV*)(sv); SvIV(nsv); })
1081 # define SvUVx(sv) ({SV *nsv = (SV*)(sv); SvUV(nsv); })
1082 # define SvNVx(sv) ({SV *nsv = (SV*)(sv); SvNV(nsv); })
1083 # define SvPVx(sv, lp) ({SV *nsv = (sv); SvPV(nsv, lp); })
1084 # define SvPVutf8x(sv, lp) ({SV *nsv = (sv); SvPVutf8(nsv, lp); })
1085 # define SvPVbytex(sv, lp) ({SV *nsv = (sv); SvPVbyte(nsv, lp); })
1086 # define SvTRUE(sv) ( \
1090 ? (({XPV *nxpv = (XPV*)SvANY(sv); \
1092 (nxpv->xpv_cur > 1 || \
1093 (nxpv->xpv_cur && *nxpv->xpv_pv != '0')); }) \
1100 ? SvNVX(sv) != 0.0 \
1102 # define SvTRUEx(sv) ({SV *nsv = (sv); SvTRUE(nsv); })
1103 #else /* __GNUC__ */
1104 #ifndef USE_5005THREADS
1105 /* These inlined macros use globals, which will require a thread
1106 * declaration in user code, so we avoid them under threads */
1116 # define SvIVx(sv) ((PL_Sv = (sv)), SvIV(PL_Sv))
1117 # define SvUVx(sv) ((PL_Sv = (sv)), SvUV(PL_Sv))
1118 # define SvNVx(sv) ((PL_Sv = (sv)), SvNV(PL_Sv))
1119 # define SvPVx(sv, lp) ((PL_Sv = (sv)), SvPV(PL_Sv, lp))
1120 # define SvPVutf8x(sv, lp) ((PL_Sv = (sv)), SvPVutf8(PL_Sv, lp))
1121 # define SvPVbytex(sv, lp) ((PL_Sv = (sv)), SvPVbyte(PL_Sv, lp))
1122 # define SvTRUE(sv) ( \
1126 ? ((PL_Xpv = (XPV*)SvANY(sv)) && \
1127 (PL_Xpv->xpv_cur > 1 || \
1128 (PL_Xpv->xpv_cur && *PL_Xpv->xpv_pv != '0')) \
1135 ? SvNVX(sv) != 0.0 \
1137 # define SvTRUEx(sv) ((PL_Sv = (sv)), SvTRUE(PL_Sv))
1138 #endif /* !USE_5005THREADS */
1139 #endif /* !__GNU__ */
1140 #endif /* !CRIPPLED_CC */
1143 =for apidoc Am|SV*|newRV_inc|SV* sv
1145 Creates an RV wrapper for an SV. The reference count for the original SV is
1151 #define newRV_inc(sv) newRV(sv)
1153 /* the following macros update any magic values this sv is associated with */
1156 =for apidoc Am|void|SvGETMAGIC|SV* sv
1157 Invokes C<mg_get> on an SV if it has 'get' magic. This macro evaluates its
1158 argument more than once.
1160 =for apidoc Am|void|SvSETMAGIC|SV* sv
1161 Invokes C<mg_set> on an SV if it has 'set' magic. This macro evaluates its
1162 argument more than once.
1164 =for apidoc Am|void|SvSetSV|SV* dsb|SV* ssv
1165 Calls C<sv_setsv> if dsv is not the same as ssv. May evaluate arguments
1168 =for apidoc Am|void|SvSetSV_nosteal|SV* dsv|SV* ssv
1169 Calls a non-destructive version of C<sv_setsv> if dsv is not the same as
1170 ssv. May evaluate arguments more than once.
1172 =for apidoc Am|void|SvSetMagicSV|SV* dsb|SV* ssv
1173 Like C<SvSetSV>, but does any set magic required afterwards.
1175 =for apidoc Am|void|SvSetMagicSV_nosteal|SV* dsv|SV* ssv
1176 Like C<SvSetMagicSV>, but does any set magic required afterwards.
1178 =for apidoc Am|char *|SvGROW|SV* sv|STRLEN len
1179 Expands the character buffer in the SV so that it has room for the
1180 indicated number of bytes (remember to reserve space for an extra trailing
1181 NUL character). Calls C<sv_grow> to perform the expansion if necessary.
1182 Returns a pointer to the character buffer.
1187 #define SvGETMAGIC(x) STMT_START { if (SvGMAGICAL(x)) mg_get(x); } STMT_END
1188 #define SvSETMAGIC(x) STMT_START { if (SvSMAGICAL(x)) mg_set(x); } STMT_END
1190 #define SvSetSV_and(dst,src,finally) \
1192 if ((dst) != (src)) { \
1193 sv_setsv(dst, src); \
1197 #define SvSetSV_nosteal_and(dst,src,finally) \
1199 if ((dst) != (src)) { \
1200 U32 tMpF = SvFLAGS(src) & SVs_TEMP; \
1202 sv_setsv(dst, src); \
1203 SvFLAGS(src) |= tMpF; \
1208 #define SvSetSV(dst,src) \
1209 SvSetSV_and(dst,src,/*nothing*/;)
1210 #define SvSetSV_nosteal(dst,src) \
1211 SvSetSV_nosteal_and(dst,src,/*nothing*/;)
1213 #define SvSetMagicSV(dst,src) \
1214 SvSetSV_and(dst,src,SvSETMAGIC(dst))
1215 #define SvSetMagicSV_nosteal(dst,src) \
1216 SvSetSV_nosteal_and(dst,src,SvSETMAGIC(dst))
1219 #define SvPEEK(sv) sv_peek(sv)
1221 #define SvPEEK(sv) ""
1224 #define SvIMMORTAL(sv) ((sv)==&PL_sv_undef || (sv)==&PL_sv_yes || (sv)==&PL_sv_no)
1226 #define boolSV(b) ((b) ? &PL_sv_yes : &PL_sv_no)
1228 #define isGV(sv) (SvTYPE(sv) == SVt_PVGV)
1230 #define SvGROW(sv,len) (SvLEN(sv) < (len) ? sv_grow(sv,len) : SvPVX(sv))
1231 #define Sv_Grow sv_grow
1233 #define CLONEf_COPY_STACKS 1
1234 #define CLONEf_KEEP_PTR_TABLE 2
1235 #define CLONEf_CLONE_HOST 4