Skip to content

Commit

Permalink
Add SvIsBOOL() macro to test for SVs being boolean-intent
Browse files Browse the repository at this point in the history
These are identified as being static shared COW strings whose string
buffer points directly at PL_Yes / PL_No
  • Loading branch information
leonerd committed Aug 26, 2021
1 parent 676b7d4 commit 69908c6
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions sv.h
Expand Up @@ -1051,6 +1051,19 @@ 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) \
(SvIOK(sv) && SvPOK(sv) && SvIsCOW_static(sv) && \
(SvPVX(sv) == PL_Yes || SvPVX(sv) == PL_No))

/*
=for apidoc Am|U32|SvGAMAGIC|SV* sv
Expand Down

0 comments on commit 69908c6

Please sign in to comment.