From 07386ea410af13e8fc844eb939a6c6e47c2adaf1 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 22 Oct 2018 21:18:27 -0700 Subject: [PATCH] Remove const and references when binding Null() Fixes https://github.com/harfbuzz/harfbuzz/issues/1299 Removes anomaly I was seeing in cpal table trying to use implicit Null(NameID). --- src/hb-atomic.hh | 5 +---- src/hb-common.cc | 2 +- src/hb-ft.cc | 2 +- src/hb-null.hh | 4 ++-- src/hb-open-type.hh | 6 ++---- src/hb-ot-color-cpal-table.hh | 8 ++------ src/hb-static.cc | 1 - src/hb.hh | 9 +++++++++ 8 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/hb-atomic.hh b/src/hb-atomic.hh index 5cb7ca5d5..697de19c5 100644 --- a/src/hb-atomic.hh +++ b/src/hb-atomic.hh @@ -278,14 +278,11 @@ struct hb_atomic_int_t }; -template struct hb_remove_ptr_t { typedef T value; }; -template struct hb_remove_ptr_t { typedef T value; }; - #define HB_ATOMIC_PTR_INIT(V) {V} template struct hb_atomic_ptr_t { - typedef typename hb_remove_ptr_t

::value T; + typedef typename hb_remove_pointer

::value T; inline void init (T* v_ = nullptr) { set_relaxed (v_); } inline void set_relaxed (T* v_) const { hb_atomic_ptr_impl_set_relaxed (&v, v_); } diff --git a/src/hb-common.cc b/src/hb-common.cc index ba48dd561..ccdb4dd94 100644 --- a/src/hb-common.cc +++ b/src/hb-common.cc @@ -761,7 +761,7 @@ parse_uint32 (const char **pp, const char *end, uint32_t *pv) static void free_static_C_locale (void); #endif -static struct hb_C_locale_lazy_loader_t : hb_lazy_loader_t::value, +static struct hb_C_locale_lazy_loader_t : hb_lazy_loader_t::value, hb_C_locale_lazy_loader_t> { static inline HB_LOCALE_T create (void) diff --git a/src/hb-ft.cc b/src/hb-ft.cc index 18fb72a73..fbf362688 100644 --- a/src/hb-ft.cc +++ b/src/hb-ft.cc @@ -737,7 +737,7 @@ hb_ft_font_create_referenced (FT_Face ft_face) static void free_static_ft_library (void); #endif -static struct hb_ft_library_lazy_loader_t : hb_lazy_loader_t::value, +static struct hb_ft_library_lazy_loader_t : hb_lazy_loader_t::value, hb_ft_library_lazy_loader_t> { static inline FT_Library create (void) diff --git a/src/hb-null.hh b/src/hb-null.hh index 87662265c..3d8a1ae6c 100644 --- a/src/hb-null.hh +++ b/src/hb-null.hh @@ -47,7 +47,7 @@ static inline Type const & Null (void) { static_assert (sizeof (Type) <= HB_NULL_POOL_SIZE, "Increase HB_NULL_POOL_SIZE."); return *reinterpret_cast (_hb_NullPool); } -#define Null(Type) Null() +#define Null(Type) Null::value>::value>() /* Specializations for arbitrary-content Null objects expressed in bytes. */ #define DECLARE_NULL_NAMESPACE_BYTES(Namespace, Type) \ @@ -90,7 +90,7 @@ static inline Type& Crap (void) { *obj = Null(Type); return *obj; } -#define Crap(Type) Crap() +#define Crap(Type) Crap::value>::value>() template struct CrapOrNull { diff --git a/src/hb-open-type.hh b/src/hb-open-type.hh index dc2f1f7c0..19081447f 100644 --- a/src/hb-open-type.hh +++ b/src/hb-open-type.hh @@ -149,16 +149,14 @@ struct Tag : HBUINT32 /* Glyph index number, same as uint16 (length = 16 bits) */ typedef HBUINT16 GlyphID; -/* Name-table index, same as uint16 (length = 16 bits) */ -struct NameID : HBUINT16 {}; -DECLARE_NULL_NAMESPACE_BYTES (OT, NameID); - /* Script/language-system/feature index */ struct Index : HBUINT16 { enum { NOT_FOUND_INDEX = 0xFFFFu }; }; DECLARE_NULL_NAMESPACE_BYTES (OT, Index); +typedef Index NameID; + /* Offset, Null offset = 0 */ template struct Offset : Type diff --git a/src/hb-ot-color-cpal-table.hh b/src/hb-ot-color-cpal-table.hh index 3f2165c46..7dd0c0f90 100644 --- a/src/hb-ot-color-cpal-table.hh +++ b/src/hb-ot-color-cpal-table.hh @@ -63,9 +63,7 @@ struct CPALV1Tail unsigned int palette_index, unsigned int palette_count) const { - /* XXX the Null(NameID) returned by hb_array_t is wrong. Figure out why - * and remove the explicit bound check. */ - if (!paletteLabelsZ || palette_index >= palette_count) return HB_NAME_ID_INVALID; + if (!paletteLabelsZ) return HB_NAME_ID_INVALID; return hb_array_t ((base+paletteLabelsZ).arrayZ, palette_count)[palette_index]; } @@ -74,9 +72,7 @@ struct CPALV1Tail unsigned int color_index, unsigned int color_count) const { - /* XXX the Null(NameID) returned by hb_array_t is wrong. Figure out why - * and remove the explicit bound check. */ - if (!colorLabelsZ || color_index >= color_count) return HB_NAME_ID_INVALID; + if (!colorLabelsZ) return HB_NAME_ID_INVALID; return hb_array_t ((base+colorLabelsZ).arrayZ, color_count)[color_index]; } diff --git a/src/hb-static.cc b/src/hb-static.cc index 53889a5a6..e5507960d 100644 --- a/src/hb-static.cc +++ b/src/hb-static.cc @@ -40,7 +40,6 @@ hb_vector_size_impl_t const _hb_NullPool[(HB_NULL_POOL_SIZE + sizeof (hb_vector_size_impl_t) - 1) / sizeof (hb_vector_size_impl_t)] = {}; /*thread_local*/ hb_vector_size_impl_t _hb_CrapPool[(HB_NULL_POOL_SIZE + sizeof (hb_vector_size_impl_t) - 1) / sizeof (hb_vector_size_impl_t)] = {}; -DEFINE_NULL_NAMESPACE_BYTES (OT, NameID) = {0xFF,0xFF}; DEFINE_NULL_NAMESPACE_BYTES (OT, Index) = {0xFF,0xFF}; DEFINE_NULL_NAMESPACE_BYTES (OT, LangSys) = {0x00,0x00, 0xFF,0xFF, 0x00,0x00}; DEFINE_NULL_NAMESPACE_BYTES (OT, RangeRecord) = {0x00,0x01, 0x00,0x00, 0x00, 0x00}; diff --git a/src/hb.hh b/src/hb.hh index 098b56604..ea474298f 100644 --- a/src/hb.hh +++ b/src/hb.hh @@ -495,6 +495,15 @@ _hb_memalign(void **memptr, size_t alignment, size_t size) #define HB_SCRIPT_MYANMAR_ZAWGYI ((hb_script_t) HB_TAG ('Q','a','a','g')) +/* Some really basic things everyone wants. */ +template struct hb_remove_const { typedef T value; }; +template struct hb_remove_const { typedef T value; }; +template struct hb_remove_reference { typedef T value; }; +template struct hb_remove_reference { typedef T value; }; +template struct hb_remove_pointer { typedef T value; }; +template struct hb_remove_pointer { typedef T value; }; + + /* Headers we include for everyone. Keep sorted. They express dependency amongst * themselves, but no other file should include them.*/ #include "hb-atomic.hh"