summaryrefslogtreecommitdiff
path: root/sv.h
diff options
context:
space:
mode:
authorPaul "LeoNerd" Evans <leonerd@leonerd.org.uk>2021-08-07 14:48:32 +0100
committerPaul Evans <leonerd@leonerd.org.uk>2021-09-10 20:08:40 +0100
commit1d0d673f78c5c03a0f3c97ceeb7686e9388e0611 (patch)
tree388abd531263b971a0bfa2762402a33a3c0148ca /sv.h
parent914bb57489325d34ddbb7c0557c53df7baa84d86 (diff)
downloadperl-1d0d673f78c5c03a0f3c97ceeb7686e9388e0611.tar.gz
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
Diffstat (limited to 'sv.h')
-rw-r--r--sv.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/sv.h b/sv.h
index 334176abbd..903279b96e 100644
--- a/sv.h
+++ b/sv.h
@@ -1052,6 +1052,17 @@ Remove any string offset.
((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
Returns true if the SV has get magic or
@@ -2334,6 +2345,21 @@ See also C<L</PL_sv_yes>> and C<L</PL_sv_no>>.
#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<sv_setbool_mg> handles 'set' magic; C<sv_setbool>
+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. */