This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
parts/inc/misc: Add withinCOUNT and inRANGE
authorKarl Williamson <khw@cpan.org>
Sun, 6 Oct 2019 03:36:27 +0000 (21:36 -0600)
committerNicolas R <atoomic@cpan.org>
Fri, 8 Nov 2019 19:01:12 +0000 (12:01 -0700)
These are too new to be in the public API, but their presence here helps
with backporting things, so provide them, but undocumented.

(cherry picked from commit eb85beedef0dfeca24cb5a011f17a893525cb098)
Signed-off-by: Nicolas R <atoomic@cpan.org>
dist/Devel-PPPort/parts/inc/misc

index a58e825..2bf73d8 100644 (file)
@@ -50,6 +50,15 @@ __UNDEFINED__ __ASSERT_(statement)  assert(statement),
 __UNDEFINED__ __ASSERT_(statement)
 #endif
 
+/* These could become provided when they become part of the public API */
+__UNDEF_NOT_PROVIDED__ withinCOUNT(c, l, n)                                 \
+   (((WIDEST_UTYPE) (((c)) - ((l) | 0))) <= (((WIDEST_UTYPE) ((n) | 0))))
+__UNDEF_NOT_PROVIDED__ inRANGE(c, l, u)                                    \
+   (  (sizeof(c) == sizeof(U8))  ? withinCOUNT(((U8)  (c)), (l), ((u) - (l)))  \
+    : (sizeof(c) == sizeof(U16)) ? withinCOUNT(((U16) (c)), (l), ((u) - (l)))  \
+    : (sizeof(c) == sizeof(U32)) ? withinCOUNT(((U32) (c)), (l), ((u) - (l)))  \
+    : (withinCOUNT(((WIDEST_UTYPE) (c)), (l), ((u) - (l)))))
+
 __UNDEFINED__ SvRX(rv) (SvROK((rv)) ? (SvMAGICAL(SvRV((rv))) ? (mg_find(SvRV((rv)), PERL_MAGIC_qr) ? mg_find(SvRV((rv)), PERL_MAGIC_qr)->mg_obj : NULL) : NULL) : NULL)
 __UNDEFINED__ SvRXOK(sv) (!!SvRX(sv))