[HarfBuzz] harfbuzz: Branch 'master' - 2 commits

Behdad Esfahbod behdad at kemper.freedesktop.org
Sat Dec 1 18:14:58 UTC 2018


 src/hb-dsalgs.hh    |   16 ++++++++++------
 src/hb-open-type.hh |   12 ++++++++++--
 2 files changed, 20 insertions(+), 8 deletions(-)

New commits:
commit 11d2f49af8f53340134c844173f4d8655b00dea3
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Sat Dec 1 13:12:21 2018 -0500

    New approach to change BigEndian casts to be int-sized
    
    Fixes spurious warnings like:
    Fixes https://github.com/harfbuzz/harfbuzz/issues/1436

diff --git a/src/hb-open-type.hh b/src/hb-open-type.hh
index ee76d7ed..0038ad8b 100644
--- a/src/hb-open-type.hh
+++ b/src/hb-open-type.hh
@@ -52,13 +52,19 @@ namespace OT {
  * Int types
  */
 
+template <bool is_signed> struct hb_signedness_int;
+template <> struct hb_signedness_int<false> { typedef unsigned int value; };
+template <> struct hb_signedness_int<true>  { typedef   signed int value; };
+
 /* Integer types in big-endian order and no alignment requirement */
 template <typename Type, unsigned int Size>
 struct IntType
 {
   typedef Type type;
-  inline void set (Type i) { v.set (i); }
-  inline operator Type (void) const { return v; }
+  typedef typename hb_signedness_int<hb_is_signed<Type>::value>::value wide_type;
+
+  inline void set (wide_type i) { v.set (i); }
+  inline operator wide_type (void) const { return v; }
   inline bool operator == (const IntType<Type,Size> &o) const { return (Type) v == (Type) o.v; }
   inline bool operator != (const IntType<Type,Size> &o) const { return !(*this == o); }
   static inline int cmp (const IntType<Type,Size> *a, const IntType<Type,Size> *b) { return b->cmp (*a); }
@@ -88,6 +94,8 @@ typedef IntType<uint16_t, 2> HBUINT16;	/* 16-bit unsigned integer. */
 typedef IntType<int16_t,  2> HBINT16;	/* 16-bit signed integer. */
 typedef IntType<uint32_t, 4> HBUINT32;	/* 32-bit unsigned integer. */
 typedef IntType<int32_t,  4> HBINT32;	/* 32-bit signed integer. */
+/* Note: we cannot defined a signed HBINT24 because there's no corresponding C type.
+ * Works for unsigned, but not signed, since we rely on compiler for sign-extension. */
 typedef IntType<uint32_t, 3> HBUINT24;	/* 24-bit unsigned integer. */
 
 /* 16-bit signed integer (HBINT16) that describes a quantity in FUnits. */
commit 50e0273ab18acd2fbb21bcf18ad487092e890b4e
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Sat Dec 1 13:03:52 2018 -0500

    Change hb_assert_unsigned_t<> to hb_is_signed<>

diff --git a/src/hb-dsalgs.hh b/src/hb-dsalgs.hh
index 9c920fc8..dccca3cf 100644
--- a/src/hb-dsalgs.hh
+++ b/src/hb-dsalgs.hh
@@ -287,11 +287,15 @@ hb_ceil_to_4 (unsigned int v)
   return ((v - 1) | 3) + 1;
 }
 
-template <typename T> class hb_assert_unsigned_t;
-template <> class hb_assert_unsigned_t<unsigned char> {};
-template <> class hb_assert_unsigned_t<unsigned short> {};
-template <> class hb_assert_unsigned_t<unsigned int> {};
-template <> class hb_assert_unsigned_t<unsigned long> {};
+template <typename T> struct hb_is_signed;
+template <> struct hb_is_signed<signed char> { enum { value = true }; };
+template <> struct hb_is_signed<signed short> { enum { value = true }; };
+template <> struct hb_is_signed<signed int> { enum { value = true }; };
+template <> struct hb_is_signed<signed long> { enum { value = true }; };
+template <> struct hb_is_signed<unsigned char> { enum { value = false }; };
+template <> struct hb_is_signed<unsigned short> { enum { value = false }; };
+template <> struct hb_is_signed<unsigned int> { enum { value = false }; };
+template <> struct hb_is_signed<unsigned long> { enum { value = false }; };
 
 template <typename T> static inline bool
 hb_in_range (T u, T lo, T hi)
@@ -301,7 +305,7 @@ hb_in_range (T u, T lo, T hi)
    * one right now.  Declaring a variable won't work as HB_UNUSED
    * is unusable on some platforms and unused types are less likely
    * to generate a warning than unused variables. */
-  static_assert ((sizeof (hb_assert_unsigned_t<T>) >= 0), "");
+  static_assert (!hb_is_signed<T>::value, "");
 
   /* The casts below are important as if T is smaller than int,
    * the subtract results will become a signed int! */


More information about the HarfBuzz mailing list