From fff0089cdee6ca5d1c000e213f15bb3ea460a21f Mon Sep 17 00:00:00 2001 From: Yves Orton Date: Wed, 20 Apr 2022 12:24:25 +0200 Subject: 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. --- inline.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'inline.h') 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 -- cgit v1.2.1