develooper Front page | perl.perl5.changes | Postings from September 2019

[perl.git] branch blead updated. v5.31.4-28-g76d3ad4c24

From:
Karl Williamson
Date:
September 26, 2019 04:31
Subject:
[perl.git] branch blead updated. v5.31.4-28-g76d3ad4c24
Message ID:
E1iDLQV-0004UB-Nm@git.dc.perl.space
In perl.git, the branch blead has been updated

<https://perl5.git.perl.org/perl.git/commitdiff/76d3ad4c2443f94d2d636a40a01762c27bbf1c10?hp=f5a59698ee00a9f6abaf832459625e5f51700539>

- Log -----------------------------------------------------------------
commit 76d3ad4c2443f94d2d636a40a01762c27bbf1c10
Author: Karl Williamson <khw@cpan.org>
Date:   Wed Sep 25 22:23:55 2019 -0600

    handy.h: Avoid compiler warnings for withinCOUNT()
    
    If a parameter to this function is unsigned, gcc, at least, generates a
    comparison-always-true warning for the asserts on the parameters.
    Silence these by casting to an NV.  Any extra machine instructions will
    be gone from non-DEBUGGING builds.  The value in an NV won't necessarily
    be exact, but all the assertions care about is the sign, which is
    guaranteed by C11 standard 6.3.1.4 item 2.
    
    This technique was the idea of Tomasz Konojacki.

commit 1eaefa6ebf606d54de28b69d64510e8179c754ef
Author: Karl Williamson <khw@cpan.org>
Date:   Sat Sep 21 12:23:49 2019 -0600

    handy.h: Rmv duplicated assert in inRANGE()
    
    This assertion is done in the macro that is called to do the real work.

commit 45f4bb73962fcf38d8ded9b6067d2c73ff03a0ed
Author: Karl Williamson <khw@cpan.org>
Date:   Mon Sep 9 14:57:07 2019 -0600

    handy.h Fix withinCOUNT() for > 32 bit operands
    
    It needs to cast to unsigned in all circumstances; prior to this commit
    it failed to do so for oprands wider than 32 bits

-----------------------------------------------------------------------

Summary of changes:
 handy.h | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/handy.h b/handy.h
index d9cd92d567..26547fbd1d 100644
--- a/handy.h
+++ b/handy.h
@@ -1317,21 +1317,24 @@ or casts
 #define FITS_IN_8_BITS(c) (1)
 #endif
 
-/* Returns true if l <= c <= l + n, where 'l' and 'n' are non-negative
+/* Returns true if l <= c <= (l + n), where 'l' and 'n' are non-negative
  * Written this way so that after optimization, only one conditional test is
- * needed. */
-#define withinCOUNT(c, l, n) (__ASSERT_((l) >= 0) __ASSERT_((n) >= (0))        \
-   (((WIDEST_UTYPE) (((c) | 0) - ((l) | 0))) <= (((WIDEST_UTYPE) ((n) | 0)))))
+ * needed.  (The NV casts stop any warnings about comparison always being true
+ * if called with an unsigned.  The cast preserves the sign, which is all we
+ * care about.) */
+#define withinCOUNT(c, l, n) (__ASSERT_((NV) (l) >= 0)                         \
+                              __ASSERT_((NV) (n) >= 0)                         \
+   (((WIDEST_UTYPE) (((c)) - ((l) | 0))) <= (((WIDEST_UTYPE) ((n) | 0)))))
 
 /* Returns true if c is in the range l..u, where 'l' is non-negative
  * Written this way so that after optimization, only one conditional test is
  * needed. */
-#define inRANGE(c, l, u) (__ASSERT_((l) >= 0) __ASSERT_((u) >= (l))            \
+#define inRANGE(c, l, u) (__ASSERT_((u) >= (l))                                \
    (  (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)))  \
     : (__ASSERT_(sizeof(c) == sizeof(WIDEST_UTYPE))                            \
-                                   withinCOUNT((      (c)), (l), ((u) - (l))))))
+                          withinCOUNT(((WIDEST_UTYPE) (c)), (l), ((u) - (l))))))
 
 #ifdef EBCDIC
 #   ifndef _ALL_SOURCE

-- 
Perl5 Master Repository



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About