From 1d0d673f78c5c03a0f3c97ceeb7686e9388e0611 Mon Sep 17 00:00:00 2001 From: "Paul \"LeoNerd\" Evans" Date: Sat, 7 Aug 2021 14:48:32 +0100 Subject: Add SvIsBOOL() macro to test for SVs being boolean-intent These are identified as being static shared COW strings whose string buffer points directly at PL_Yes / PL_No Define sv_setbool() and sv_setbool_mg() macros Use sv_setbool() where appropriate Have sv_dump() annotate when an SV's PV buffer is one of the PL_(Yes|No) special booleans --- sv.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'sv.h') diff --git a/sv.h b/sv.h index 334176abbd..903279b96e 100644 --- a/sv.h +++ b/sv.h @@ -1051,6 +1051,17 @@ Remove any string offset. #define SvPOK_byte_pure_nogthink(sv) \ ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8|SVf_IOK|SVf_NOK|SVf_ROK|SVpgv_GP|SVf_THINKFIRST|SVs_GMG)) == SVf_POK) +/* +=for apidoc Am|BOOL|SvIsBOOL|SV* sv + +Returns true if the SV is one of the special boolean constants (PL_sv_yes or +PL_sv_no), or is a regular SV whose last assignment stored a copy of one. + +=cut +*/ + +#define SvIsBOOL(sv) Perl_sv_isbool(aTHX_ sv) + /* =for apidoc Am|U32|SvGAMAGIC|SV* sv @@ -2334,6 +2345,21 @@ See also C> and C>. #define boolSV(b) ((b) ? &PL_sv_yes : &PL_sv_no) +/* +=for apidoc Am|void|sv_setbool|SV *sv|bool b +=for apidoc_item |void|sv_setbool_mg|SV *sv|bool b + +These set an SV to a true or false boolean value, upgrading first if necessary. + +They differ only in that C handles 'set' magic; C +does not. + +=cut +*/ + +#define sv_setbool(sv, b) sv_setsv(sv, boolSV(b)) +#define sv_setbool_mg(sv, b) sv_setsv_mg(sv, boolSV(b)) + #define isGV(sv) (SvTYPE(sv) == SVt_PVGV) /* If I give every macro argument a different name, then there won't be bugs where nested macros get confused. Been there, done that. */ -- cgit v1.2.1