/*
=head1 SV Flags
-=for apidoc AmU||svtype
+=for apidoc AmnU||svtype
An enum of flags for Perl types. These are found in the file F<sv.h>
in the C<svtype> enum. Test these flags with the C<SvTYPE> macro.
C<SVt_PVNV> is similar. C<SVt_PVMG> can hold anything C<SVt_PVNV> can hold, but it
can, but does not have to, be blessed or magical.
-=for apidoc AmU||SVt_NULL
+=for apidoc AmnU||SVt_NULL
Type flag for scalars. See L</svtype>.
-=for apidoc AmU||SVt_IV
+=for apidoc AmnU||SVt_IV
Type flag for scalars. See L</svtype>.
-=for apidoc AmU||SVt_NV
+=for apidoc AmnU||SVt_NV
Type flag for scalars. See L</svtype>.
-=for apidoc AmU||SVt_PV
+=for apidoc AmnU||SVt_PV
Type flag for scalars. See L</svtype>.
-=for apidoc AmU||SVt_PVIV
+=for apidoc AmnU||SVt_PVIV
Type flag for scalars. See L</svtype>.
-=for apidoc AmU||SVt_PVNV
+=for apidoc AmnU||SVt_PVNV
Type flag for scalars. See L</svtype>.
-=for apidoc AmU||SVt_PVMG
+=for apidoc AmnU||SVt_PVMG
Type flag for scalars. See L</svtype>.
-=for apidoc AmU||SVt_INVLIST
-Type flag for scalars. See L</svtype>.
+=for apidoc CmnU||SVt_INVLIST
+Type flag for scalars. See L<perlapi/svtype>.
-=for apidoc AmU||SVt_REGEXP
+=for apidoc AmnU||SVt_REGEXP
Type flag for regular expressions. See L</svtype>.
-=for apidoc AmU||SVt_PVGV
+=for apidoc AmnU||SVt_PVGV
Type flag for typeglobs. See L</svtype>.
-=for apidoc AmU||SVt_PVLV
+=for apidoc AmnU||SVt_PVLV
Type flag for scalars. See L</svtype>.
-=for apidoc AmU||SVt_PVAV
+=for apidoc AmnU||SVt_PVAV
Type flag for arrays. See L</svtype>.
-=for apidoc AmU||SVt_PVHV
+=for apidoc AmnU||SVt_PVHV
Type flag for hashes. See L</svtype>.
-=for apidoc AmU||SVt_PVCV
+=for apidoc AmnU||SVt_PVCV
Type flag for subroutines. See L</svtype>.
-=for apidoc AmU||SVt_PVFM
+=for apidoc AmnU||SVt_PVFM
Type flag for formats. See L</svtype>.
-=for apidoc AmU||SVt_PVIO
+=for apidoc AmnU||SVt_PVIO
Type flag for I/O objects. See L</svtype>.
=cut
Returns the value of the object's reference count. Exposed
to perl code via Internals::SvREFCNT().
-=for apidoc Am|SV*|SvREFCNT_inc|SV* sv
+=for apidoc SvREFCNT_inc
Increments the reference count of the given SV, returning the SV.
-All of the following C<SvREFCNT_inc>* macros are optimized versions of
+All of the following C<SvREFCNT_inc>* are optimized versions of
C<SvREFCNT_inc>, and can be replaced with C<SvREFCNT_inc>.
-=for apidoc Am|SV*|SvREFCNT_inc_NN|SV* sv
+=for apidoc SvREFCNT_inc_NN
Same as C<SvREFCNT_inc>, but can only be used if you know C<sv>
is not C<NULL>. Since we don't have to check the NULLness, it's faster
and smaller.
-=for apidoc Am|void|SvREFCNT_inc_void|SV* sv
+=for apidoc SvREFCNT_inc_void
Same as C<SvREFCNT_inc>, but can only be used if you don't need the
return value. The macro doesn't need to return a meaningful value.
to return a meaningful value, or check for NULLness, so it's smaller
and faster.
-=for apidoc Am|void|SvREFCNT_dec|SV* sv
+=for apidoc SvREFCNT_dec
Decrements the reference count of the given SV. C<sv> may be C<NULL>.
-=for apidoc Am|void|SvREFCNT_dec_NN|SV* sv
+=for apidoc SvREFCNT_dec_NN
Same as C<SvREFCNT_dec>, but can only be used if you know C<sv>
is not C<NULL>. Since we don't have to check the NULLness, it's faster
and smaller.
#define SvFLAGS(sv) (sv)->sv_flags
#define SvREFCNT(sv) (sv)->sv_refcnt
-#define SvREFCNT_inc(sv) S_SvREFCNT_inc(MUTABLE_SV(sv))
+#define SvREFCNT_inc(sv) Perl_SvREFCNT_inc(MUTABLE_SV(sv))
#define SvREFCNT_inc_simple(sv) SvREFCNT_inc(sv)
-#define SvREFCNT_inc_NN(sv) S_SvREFCNT_inc_NN(MUTABLE_SV(sv))
-#define SvREFCNT_inc_void(sv) S_SvREFCNT_inc_void(MUTABLE_SV(sv))
+#define SvREFCNT_inc_NN(sv) Perl_SvREFCNT_inc_NN(MUTABLE_SV(sv))
+#define SvREFCNT_inc_void(sv) Perl_SvREFCNT_inc_void(MUTABLE_SV(sv))
/* These guys don't need the curly blocks */
#define SvREFCNT_inc_simple_void(sv) STMT_START { if (sv) SvREFCNT(sv)++; } STMT_END
#define SvREFCNT_inc_void_NN(sv) (void)(++SvREFCNT(MUTABLE_SV(sv)))
#define SvREFCNT_inc_simple_void_NN(sv) (void)(++SvREFCNT(MUTABLE_SV(sv)))
-#define SvREFCNT_dec(sv) S_SvREFCNT_dec(aTHX_ MUTABLE_SV(sv))
-#define SvREFCNT_dec_NN(sv) S_SvREFCNT_dec_NN(aTHX_ MUTABLE_SV(sv))
+#define SvREFCNT_dec(sv) Perl_SvREFCNT_dec(aTHX_ MUTABLE_SV(sv))
+#define SvREFCNT_dec_NN(sv) Perl_SvREFCNT_dec_NN(aTHX_ MUTABLE_SV(sv))
#define SVTYPEMASK 0xff
#define SvTYPE(sv) ((svtype)((sv)->sv_flags & SVTYPEMASK))
Returns the raw value in the SV's UV slot, without checks or conversions.
Only use when you are sure C<SvIOK> is true. See also C<L</SvUV>>.
+=for apidoc AmD|UV|SvUVXx|SV* sv
+This is an unnecessary synonym for L</SvUVX>
+
=for apidoc Am|NV|SvNVX|SV* sv
Returns the raw value in the SV's NV slot, without checks or conversions.
Only use when you are sure C<SvNOK> is true. See also C<L</SvNV>>.
#define SvPADTMP_on(sv) (SvFLAGS(sv) |= SVs_PADTMP)
#define SvPADTMP_off(sv) (SvFLAGS(sv) &= ~SVs_PADTMP)
-#define SvPADSTALE_on(sv) S_SvPADSTALE_on(MUTABLE_SV(sv))
-#define SvPADSTALE_off(sv) S_SvPADSTALE_off(MUTABLE_SV(sv))
+#define SvPADSTALE_on(sv) Perl_SvPADSTALE_on(MUTABLE_SV(sv))
+#define SvPADSTALE_off(sv) Perl_SvPADSTALE_off(MUTABLE_SV(sv))
#define SvTEMP(sv) (SvFLAGS(sv) & SVs_TEMP)
#define SvTEMP_on(sv) (SvFLAGS(sv) |= SVs_TEMP)
# define SvMAGIC(sv) (0 + *(assert_(SvTYPE(sv) >= SVt_PVMG) &((XPVMG*) SvANY(sv))->xmg_u.xmg_magic))
# define SvSTASH(sv) (0 + *(assert_(SvTYPE(sv) >= SVt_PVMG) &((XPVMG*) SvANY(sv))->xmg_stash))
#else
+# ifdef PERL_CORE
+# define SvLEN(sv) (0 + ((XPV*) SvANY(sv))->xpv_len)
+# else
# define SvLEN(sv) ((XPV*) SvANY(sv))->xpv_len
+# endif
# define SvEND(sv) ((sv)->sv_u.svu_pv + ((XPV*)SvANY(sv))->xpv_cur)
# if defined (DEBUGGING) && defined(__GNUC__) && !defined(PERL_GCC_BRACE_GROUPS_FORBIDDEN)
&& !(IoFLAGS(_svpvx) & IOf_FAKE_DIRP))); \
&((_svpvx)->sv_u.svu_pv); \
}))
+# ifdef PERL_CORE
+# define SvCUR(sv) \
+ ({ const SV *const _svcur = (const SV *)(sv); \
+ assert(PL_valid_types_PVX[SvTYPE(_svcur) & SVt_MASK]); \
+ assert(!isGV_with_GP(_svcur)); \
+ assert(!(SvTYPE(_svcur) == SVt_PVIO \
+ && !(IoFLAGS(_svcur) & IOf_FAKE_DIRP))); \
+ (((XPV*) MUTABLE_PTR(SvANY(_svcur)))->xpv_cur); \
+ })
+# else
# define SvCUR(sv) \
(*({ const SV *const _svcur = (const SV *)(sv); \
assert(PL_valid_types_PVX[SvTYPE(_svcur) & SVt_MASK]); \
&& !(IoFLAGS(_svcur) & IOf_FAKE_DIRP))); \
&(((XPV*) MUTABLE_PTR(SvANY(_svcur)))->xpv_cur); \
}))
+# endif
# define SvIVX(sv) \
(*({ const SV *const _svivx = (const SV *)(sv); \
assert(PL_valid_types_IVX[SvTYPE(_svivx) & SVt_MASK]); \
unless the scalar is already C<SvPOK>, C<SvIOK> or C<SvNOK> (the public, not the
private flags).
+See C<L</SvTRUEx>> for a version which guarantees to evaluate C<sv> only once.
+
=for apidoc Am|bool|SvTRUE_nomg|SV* sv
Returns a boolean indicating whether Perl would evaluate the SV as true or
false. See C<L</SvOK>> for a defined/undefined test. Does not handle 'get' magic.
+=for apidoc Am|bool|SvTRUEx|SV* sv
+Returns a boolean indicating whether Perl would evaluate the SV as true or
+false. See C<L</SvOK>> for a defined/undefined test. Handles 'get' magic
+unless the scalar is already C<SvPOK>, C<SvIOK> or C<SvNOK> (the public, not the
+private flags).
+
+This form guarantees to evaluate C<sv> only once. Only use this if C<sv> is an
+expression with side effects, otherwise use the more efficient C<SvTRUE>.
+
=for apidoc Am|char*|SvPVutf8_force|SV* sv|STRLEN len
Like C<SvPV_force>, but converts C<sv> to UTF-8 first if necessary.
=for apidoc Am|char*|SvPVutf8|SV* sv|STRLEN len
Like C<SvPV>, but converts C<sv> to UTF-8 first if necessary.
+=for apidoc Am|char*|SvPVutf8_nomg|SV* sv|STRLEN len
+Like C<SvPVutf8>, but does not process get magic.
+
+=for apidoc Am|char*|SvPVutf8_or_null|SV* sv|STRLEN len
+Like C<SvPVutf8>, but when C<sv> is undef, returns C<NULL>.
+
+=for apidoc Am|char*|SvPVutf8_or_null_nomg|SV* sv|STRLEN len
+Like C<SvPVutf8_or_null>, but does not process get magic.
+
=for apidoc Am|char*|SvPVutf8_nolen|SV* sv
Like C<SvPV_nolen>, but converts C<sv> to UTF-8 first if necessary.
=for apidoc Am|char*|SvPVbyte|SV* sv|STRLEN len
Like C<SvPV>, but converts C<sv> to byte representation first if necessary.
+=for apidoc Am|char*|SvPVbyte_nomg|SV* sv|STRLEN len
+Like C<SvPVbyte>, but does not process get magic.
+
+=for apidoc Am|char*|SvPVbyte_or_null|SV* sv|STRLEN len
+Like C<SvPVbyte>, but when C<sv> is undef, returns C<NULL>.
+
+=for apidoc Am|char*|SvPVbyte_or_null_nomg|SV* sv|STRLEN len
+Like C<SvPVbyte_or_null>, but does not process get magic.
+
=for apidoc Am|char*|SvPVbyte_nolen|SV* sv
Like C<SvPV_nolen>, but converts C<sv> to byte representation first if necessary.
(SvPOK_utf8_nog(sv) \
? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvutf8(sv, &lp))
+#define SvPVutf8_or_null(sv, lp) \
+ (SvPOK_utf8_nog(sv) \
+ ? ((lp = SvCUR(sv)), SvPVX(sv)) : (SvGETMAGIC(sv), SvOK(sv)) \
+ ? sv_2pvutf8_flags(sv, &lp, 0) : ((lp = 0), NULL))
+
+#define SvPVutf8_nomg(sv, lp) \
+ (SvPOK_utf8_nog(sv) \
+ ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvutf8_flags(sv, &lp, 0))
+
+#define SvPVutf8_or_null_nomg(sv, lp) \
+ (SvPOK_utf8_nog(sv) \
+ ? ((lp = SvCUR(sv)), SvPVX(sv)) : SvOK(sv) \
+ ? sv_2pvutf8_flags(sv, &lp, 0) : ((lp = 0), NULL))
+
#define SvPVutf8_force(sv, lp) \
(SvPOK_utf8_pure_nogthink(sv) \
? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvutf8n_force(sv, &lp))
(SvPOK_byte_nog(sv) \
? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvbyte(sv, &lp))
+#define SvPVbyte_or_null(sv, lp) \
+ (SvPOK_byte_nog(sv) \
+ ? ((lp = SvCUR(sv)), SvPVX(sv)) : (SvGETMAGIC(sv), SvOK(sv)) \
+ ? sv_2pvbyte_flags(sv, &lp, 0) : ((lp = 0), NULL))
+
+#define SvPVbyte_nomg(sv, lp) \
+ (SvPOK_byte_nog(sv) \
+ ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvbyte_flags(sv, &lp, 0))
+
+#define SvPVbyte_or_null_nomg(sv, lp) \
+ (SvPOK_utf8_nog(sv) \
+ ? ((lp = SvCUR(sv)), SvPVX(sv)) : SvOK(sv) \
+ ? sv_2pvbyte_flags(sv, &lp, 0) : ((lp = 0), NULL))
+
#define SvPVbyte_force(sv, lp) \
(SvPOK_byte_pure_nogthink(sv) \
? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvbyten_force(sv, &lp))
#define sv_pvn_force_nomg(sv, lp) sv_pvn_force_flags(sv, lp, 0)
#define sv_utf8_upgrade_flags(sv, flags) sv_utf8_upgrade_flags_grow(sv, flags, 0)
#define sv_utf8_upgrade_nomg(sv) sv_utf8_upgrade_flags(sv, 0)
+#define sv_utf8_downgrade(sv, fail_ok) sv_utf8_downgrade_flags(sv, fail_ok, SV_GMAGIC)
+#define sv_utf8_downgrade_nomg(sv, fail_ok) sv_utf8_downgrade_flags(sv, fail_ok, 0)
#define sv_catpvn_nomg(dsv, sstr, slen) sv_catpvn_flags(dsv, sstr, slen, 0)
#define sv_catpv_nomg(dsv, sstr) sv_catpv_flags(dsv, sstr, 0)
#define sv_setsv(dsv, ssv) \
#define sv_copypv_nomg(dsv, ssv) sv_copypv_flags(dsv, ssv, 0)
#define sv_2pv(sv, lp) sv_2pv_flags(sv, lp, SV_GMAGIC)
#define sv_2pv_nolen(sv) sv_2pv(sv, 0)
+#define sv_2pvbyte(sv, lp) sv_2pvbyte_flags(sv, lp, SV_GMAGIC)
#define sv_2pvbyte_nolen(sv) sv_2pvbyte(sv, 0)
+#define sv_2pvutf8(sv, lp) sv_2pvutf8_flags(sv, lp, SV_GMAGIC)
#define sv_2pvutf8_nolen(sv) sv_2pvutf8(sv, 0)
#define sv_2pv_nomg(sv, lp) sv_2pv_flags(sv, lp, 0)
#define sv_pvn_force(sv, lp) sv_pvn_force_flags(sv, lp, SV_GMAGIC)