summaryrefslogtreecommitdiff
path: root/inline.h
diff options
context:
space:
mode:
authorYves Orton <demerphq@gmail.com>2022-04-20 12:24:25 +0200
committerKarl Williamson <khw@cpan.org>2022-05-27 21:18:10 -0600
commitfff0089cdee6ca5d1c000e213f15bb3ea460a21f (patch)
treec47533083cf97aa9868483317367ec204972c060 /inline.h
parentfd1cd0c604ac258cf945c706768b80f03544f0fe (diff)
downloadperl-fff0089cdee6ca5d1c000e213f15bb3ea460a21f.tar.gz
sv.c - add new bool related utility functions and macros
The new bool "type" does not have the usual complement of utility functions and macros. It only has one encapsulating function, which is perfectly reasonable for most use cases where one wants to test if an SV* is a bool, but does a bit too much if one is working on a serialization tool which is likely to want to unroll a nice chunk of the logic. The new type also lacks the usual cohort of utility functions to create new bool SV's. This patch adds the following functions: newSVbool(const bool bool_val) newSV_true() newSV_false() sv_set_true(SV *sv) sv_set_false(SV *sv) sv_set_bool(SV *sv, const bool bool_val) And the following macros: SvIandPOK(sv) SvIandPOK_off(sv) SvIandPOK_on(sv) The following three are intended very specifically for writing serialization code like for Sereal, where it is reasonable to want to unroll the logic contained in Perl_sv_isbool() and SvTRUE(). They are documented as "you dont want to use this except under special circumstances". SvBoolFlagsOK(sv) BOOL_INTERNALS_sv_isbool(sv) BOOL_INTERNALS_sv_isbool_true(sv) BOOL_INTERNALS_sv_isbool_false(sv) SvBoolFlagsOK() is documented as being the same as SvIandPOK(), but this abstracts the intent from the implementation.
Diffstat (limited to 'inline.h')
-rw-r--r--inline.h3
1 files changed, 1 insertions, 2 deletions
diff --git a/inline.h b/inline.h
index 436f8eb3ac..72fe1d3cd4 100644
--- a/inline.h
+++ b/inline.h
@@ -3475,8 +3475,7 @@ Perl_mortal_getenv(const char * str)
PERL_STATIC_INLINE bool
Perl_sv_isbool(pTHX_ const SV *sv)
{
- return SvIOK(sv) && SvPOK(sv) && SvIsCOW_static(sv) &&
- (SvPVX_const(sv) == PL_Yes || SvPVX_const(sv) == PL_No);
+ return SvBoolFlagsOK(sv) && BOOL_INTERNALS_sv_isbool(sv);
}
#ifdef USE_ITHREADS