diff options
Diffstat (limited to 'third_party/harfbuzz-ng')
37 files changed, 704 insertions, 444 deletions
diff --git a/third_party/harfbuzz-ng/README.chromium b/third_party/harfbuzz-ng/README.chromium index f66a274..3ad1a17 100644 --- a/third_party/harfbuzz-ng/README.chromium +++ b/third_party/harfbuzz-ng/README.chromium @@ -2,8 +2,8 @@ Name: harfbuzz-ng Short Name: harfbuzz-ng URL: http://freedesktop.org/wiki/Software/HarfBuzz Version: unknown -Date: 20120604 -Revision: 3b8fd9c48f4bde368bf2d465c148b9743a9216ee +Date: 20120608 +Revision: 0bb0f5d41976ae27c5c7a51cbb82144b48315a4b Security Critical: yes Description: diff --git a/third_party/harfbuzz-ng/harfbuzz.gyp b/third_party/harfbuzz-ng/harfbuzz.gyp index 6a69487..f76d606 100644 --- a/third_party/harfbuzz-ng/harfbuzz.gyp +++ b/third_party/harfbuzz-ng/harfbuzz.gyp @@ -64,22 +64,24 @@ 'src/hb-ot-shape-complex-indic.cc', 'src/hb-ot-shape-complex-misc.cc', 'src/hb-ot-shape-complex-private.hh', - 'src/hb-ot-shape-normalize.cc', 'src/hb-ot-shape-normalize-private.hh', + 'src/hb-ot-shape-normalize.cc', 'src/hb-ot-shape-private.hh', 'src/hb-ot-shape.cc', 'src/hb-ot-tag.cc', 'src/hb-ot-tag.h', 'src/hb-ot.h', 'src/hb-private.hh', - 'src/hb-set.cc', 'src/hb-set-private.hh', + 'src/hb-set.cc', + 'src/hb-set.h', 'src/hb-shape.cc', 'src/hb-shape.h', 'src/hb-tt-font.cc', 'src/hb-unicode-private.hh', 'src/hb-unicode.cc', 'src/hb-unicode.h', + 'src/hb-uniscribe-private.hh', 'src/hb-version.h', 'src/hb-warning.cc', 'src/hb.h', diff --git a/third_party/harfbuzz-ng/src/hb-atomic-private.hh b/third_party/harfbuzz-ng/src/hb-atomic-private.hh index d6bd1c9..c543a8d 100644 --- a/third_party/harfbuzz-ng/src/hb-atomic-private.hh +++ b/third_party/harfbuzz-ng/src/hb-atomic-private.hh @@ -45,35 +45,68 @@ #elif !defined(HB_NO_MT) && defined(_MSC_VER) && _MSC_VER >= 1600 #include <intrin.h> +#pragma intrinsic(_InterlockedExchangeAdd, _InterlockedCompareExchangePointer) + typedef long hb_atomic_int_t; #define hb_atomic_int_add(AI, V) _InterlockedExchangeAdd (&(AI), (V)) +#define hb_atomic_ptr_get(P) (MemoryBarrier (), (void *) *(P)) +#define hb_atomic_ptr_cmpexch(P,O,N) (_InterlockedCompareExchangePointer ((void **) (P), (void *) (N), (void *) (O)) == (void *) (O)) + #elif !defined(HB_NO_MT) && defined(__APPLE__) #include <libkern/OSAtomic.h> + typedef int32_t hb_atomic_int_t; #define hb_atomic_int_add(AI, V) (OSAtomicAdd32Barrier ((V), &(AI)) - (V)) +#define hb_atomic_ptr_get(P) (OSMemoryBarrier (), (void *) *(P)) +#define hb_atomic_ptr_cmpexch(P,O,N) OSAtomicCompareAndSwapPtrBarrier ((void *) (O), (void *) (N), (void **) (P)) + + +#elif !defined(HB_NO_MT) && defined(HAVE_INTEL_ATOMIC_PRIMITIVES) && !defined(__MINGW32__) + +typedef int hb_atomic_int_t; +#define hb_atomic_int_add(AI, V) __sync_fetch_and_add (&(AI), (V)) + +#define hb_atomic_ptr_get(P) (void *) (__sync_synchronize (), *(P)) +#define hb_atomic_ptr_cmpexch(P,O,N) __sync_bool_compare_and_swap ((P), (O), (N)) #elif !defined(HB_NO_MT) && defined(HAVE_GLIB) #include <glib.h> -typedef volatile int hb_atomic_int_t; +typedef int hb_atomic_int_t; #if GLIB_CHECK_VERSION(2,29,5) #define hb_atomic_int_add(AI, V) g_atomic_int_add (&(AI), (V)) #else #define hb_atomic_int_add(AI, V) g_atomic_int_exchange_and_add (&(AI), (V)) #endif +#define hb_atomic_ptr_get(P) g_atomic_pointer_get (P) +#define hb_atomic_ptr_cmpexch(P,O,N) g_atomic_pointer_compare_and_exchange ((void **) (P), (void *) (O), (void *) (N)) -#else -#define HB_ATOMIC_INT_NIL 1 +#elif !defined(HB_NO_MT) + +#define HB_ATOMIC_INT_NIL 1 /* Warn that fallback implementation is in use. */ typedef volatile int hb_atomic_int_t; #define hb_atomic_int_add(AI, V) (((AI) += (V)) - (V)) +#define hb_atomic_ptr_get(P) ((void *) *(P)) +#define hb_atomic_ptr_cmpexch(P,O,N) (* (void * volatile *) (P) == (void *) (O) ? (* (void * volatile *) (P) = (void *) (N), true) : false) + + +#else /* HB_NO_MT */ + +typedef int hb_atomic_int_t; +#define hb_atomic_int_add(AI, V) (((AI) += (V)) - (V)) + +#define hb_atomic_ptr_get(P) ((void *) *(P)) +#define hb_atomic_ptr_cmpexch(P,O,N) (* (void **) (P) == (void *) (O) ? (* (void **) (P) = (void *) (N), true) : false) + #endif +/* TODO Add tracing. */ #endif /* HB_ATOMIC_PRIVATE_HH */ diff --git a/third_party/harfbuzz-ng/src/hb-blob.cc b/third_party/harfbuzz-ng/src/hb-blob.cc index ee997ad..3cc2d9d 100644 --- a/third_party/harfbuzz-ng/src/hb-blob.cc +++ b/third_party/harfbuzz-ng/src/hb-blob.cc @@ -48,6 +48,7 @@ struct _hb_blob_t { hb_object_header_t header; + ASSERT_POD (); bool immutable; @@ -59,19 +60,6 @@ struct _hb_blob_t { hb_destroy_func_t destroy; }; -static hb_blob_t _hb_blob_nil = { - HB_OBJECT_HEADER_STATIC, - - TRUE, /* immutable */ - - NULL, /* data */ - 0, /* length */ - HB_MEMORY_MODE_READONLY, /* mode */ - - NULL, /* user_data */ - NULL /* destroy */ -}; - static bool _try_writable (hb_blob_t *blob); @@ -97,7 +85,7 @@ hb_blob_create (const char *data, if (!length || !(blob = hb_object_create<hb_blob_t> ())) { if (destroy) destroy (user_data); - return &_hb_blob_nil; + return hb_blob_get_empty (); } blob->data = data; @@ -111,7 +99,7 @@ hb_blob_create (const char *data, blob->mode = HB_MEMORY_MODE_READONLY; if (!_try_writable (blob)) { hb_blob_destroy (blob); - return &_hb_blob_nil; + return hb_blob_get_empty (); } } @@ -126,7 +114,7 @@ hb_blob_create_sub_blob (hb_blob_t *parent, hb_blob_t *blob; if (!length || offset >= parent->length) - return &_hb_blob_nil; + return hb_blob_get_empty (); hb_blob_make_immutable (parent); @@ -142,7 +130,20 @@ hb_blob_create_sub_blob (hb_blob_t *parent, hb_blob_t * hb_blob_get_empty (void) { - return &_hb_blob_nil; + static const hb_blob_t _hb_blob_nil = { + HB_OBJECT_HEADER_STATIC, + + true, /* immutable */ + + NULL, /* data */ + 0, /* length */ + HB_MEMORY_MODE_READONLY, /* mode */ + + NULL, /* user_data */ + NULL /* destroy */ + }; + + return const_cast<hb_blob_t *> (&_hb_blob_nil); } hb_blob_t * @@ -185,7 +186,7 @@ hb_blob_make_immutable (hb_blob_t *blob) if (hb_object_is_inert (blob)) return; - blob->immutable = TRUE; + blob->immutable = true; } hb_bool_t @@ -244,7 +245,7 @@ _try_make_writable_inplace_unix (hb_blob_t *blob) if ((uintptr_t) -1L == pagesize) { DEBUG_MSG_FUNC (BLOB, blob, "failed to get pagesize: %s", strerror (errno)); - return FALSE; + return false; } DEBUG_MSG_FUNC (BLOB, blob, "pagesize is %lu", (unsigned long) pagesize); @@ -256,7 +257,7 @@ _try_make_writable_inplace_unix (hb_blob_t *blob) addr, addr+length, (unsigned long) length); if (-1 == mprotect ((void *) addr, length, PROT_READ | PROT_WRITE)) { DEBUG_MSG_FUNC (BLOB, blob, "mprotect failed: %s", strerror (errno)); - return FALSE; + return false; } blob->mode = HB_MEMORY_MODE_WRITABLE; @@ -264,9 +265,9 @@ _try_make_writable_inplace_unix (hb_blob_t *blob) DEBUG_MSG_FUNC (BLOB, blob, "successfully made [%p..%p] (%lu bytes) writable\n", addr, addr+length, (unsigned long) length); - return TRUE; + return true; #else - return FALSE; + return false; #endif } @@ -276,29 +277,29 @@ _try_writable_inplace (hb_blob_t *blob) DEBUG_MSG_FUNC (BLOB, blob, "making writable inplace\n"); if (_try_make_writable_inplace_unix (blob)) - return TRUE; + return true; DEBUG_MSG_FUNC (BLOB, blob, "making writable -> FAILED\n"); /* Failed to make writable inplace, mark that */ blob->mode = HB_MEMORY_MODE_READONLY; - return FALSE; + return false; } static bool _try_writable (hb_blob_t *blob) { if (blob->immutable) - return FALSE; + return false; if (blob->mode == HB_MEMORY_MODE_WRITABLE) - return TRUE; + return true; if (blob->mode == HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE && _try_writable_inplace (blob)) - return TRUE; + return true; if (blob->mode == HB_MEMORY_MODE_WRITABLE) - return TRUE; + return true; DEBUG_MSG_FUNC (BLOB, blob, "current data is -> %p\n", blob->data); @@ -307,7 +308,7 @@ _try_writable (hb_blob_t *blob) new_data = (char *) malloc (blob->length); if (unlikely (!new_data)) - return FALSE; + return false; DEBUG_MSG_FUNC (BLOB, blob, "dupped successfully -> %p\n", blob->data); @@ -318,7 +319,7 @@ _try_writable (hb_blob_t *blob) blob->user_data = new_data; blob->destroy = free; - return TRUE; + return true; } diff --git a/third_party/harfbuzz-ng/src/hb-buffer-private.hh b/third_party/harfbuzz-ng/src/hb-buffer-private.hh index e9e0f82..4077bb3 100644 --- a/third_party/harfbuzz-ng/src/hb-buffer-private.hh +++ b/third_party/harfbuzz-ng/src/hb-buffer-private.hh @@ -44,11 +44,13 @@ typedef struct _hb_segment_properties_t { hb_direction_t direction; hb_script_t script; hb_language_t language; + ASSERT_POD (); } hb_segment_properties_t; struct _hb_buffer_t { hb_object_header_t header; + ASSERT_POD (); /* Information about how the text in the buffer should be treated */ @@ -110,7 +112,7 @@ struct _hb_buffer_t { HB_INTERNAL void clear_positions (void); HB_INTERNAL void replace_glyphs_be16 (unsigned int num_in, unsigned int num_out, - const uint16_t *glyph_data_be); + const char *glyph_data_be); HB_INTERNAL void replace_glyphs (unsigned int num_in, unsigned int num_out, const hb_codepoint_t *glyph_data); @@ -149,7 +151,7 @@ struct _hb_buffer_t { HB_INTERNAL bool enlarge (unsigned int size); inline bool ensure (unsigned int size) - { return likely (size <= allocated) ? TRUE : enlarge (size); } + { return likely (size <= allocated) ? true : enlarge (size); } HB_INTERNAL bool make_room_for (unsigned int num_in, unsigned int num_out); diff --git a/third_party/harfbuzz-ng/src/hb-buffer.cc b/third_party/harfbuzz-ng/src/hb-buffer.cc index c566a4a..9c9b32e 100644 --- a/third_party/harfbuzz-ng/src/hb-buffer.cc +++ b/third_party/harfbuzz-ng/src/hb-buffer.cc @@ -37,21 +37,8 @@ #define HB_DEBUG_BUFFER (HB_DEBUG+0) #endif - -static hb_buffer_t _hb_buffer_nil = { - HB_OBJECT_HEADER_STATIC, - - &_hb_unicode_funcs_default, - { - HB_DIRECTION_INVALID, - HB_SCRIPT_INVALID, - NULL, - }, - - TRUE, /* in_error */ - TRUE, /* have_output */ - TRUE /* have_positions */ -}; +#define _HB_BUFFER_UNICODE_FUNCS_DEFAULT (const_cast<hb_unicode_funcs_t *> (&_hb_unicode_funcs_default)) +#define _HB_BUFFER_PROPS_DEFAULT { HB_DIRECTION_INVALID, HB_SCRIPT_INVALID, HB_LANGUAGE_INVALID } /* Here is how the buffer works internally: * @@ -79,7 +66,7 @@ bool hb_buffer_t::enlarge (unsigned int size) { if (unlikely (in_error)) - return FALSE; + return false; unsigned int new_allocated = allocated; hb_glyph_position_t *new_pos = NULL; @@ -101,7 +88,7 @@ hb_buffer_t::enlarge (unsigned int size) done: if (unlikely (!new_pos || !new_info)) - in_error = TRUE; + in_error = true; if (likely (new_pos)) pos = new_pos; @@ -120,7 +107,7 @@ bool hb_buffer_t::make_room_for (unsigned int num_in, unsigned int num_out) { - if (unlikely (!ensure (out_len + num_out))) return FALSE; + if (unlikely (!ensure (out_len + num_out))) return false; if (out_info == info && out_len + num_out > idx + num_in) @@ -131,14 +118,14 @@ hb_buffer_t::make_room_for (unsigned int num_in, memcpy (out_info, info, out_len * sizeof (out_info[0])); } - return TRUE; + return true; } void * hb_buffer_t::get_scratch_buffer (unsigned int *size) { - have_output = FALSE; - have_positions = FALSE; + have_output = false; + have_positions = false; out_len = 0; *size = allocated * sizeof (pos[0]); return pos; @@ -154,13 +141,14 @@ hb_buffer_t::reset (void) return; hb_unicode_funcs_destroy (unicode); - unicode = _hb_buffer_nil.unicode; + unicode = _HB_BUFFER_UNICODE_FUNCS_DEFAULT; - props = _hb_buffer_nil.props; + hb_segment_properties_t default_props = _HB_BUFFER_PROPS_DEFAULT; + props = default_props; - in_error = FALSE; - have_output = FALSE; - have_positions = FALSE; + in_error = false; + have_output = false; + have_positions = false; idx = 0; len = 0; @@ -198,8 +186,8 @@ hb_buffer_t::clear_output (void) if (unlikely (hb_object_is_inert (this))) return; - have_output = TRUE; - have_positions = FALSE; + have_output = true; + have_positions = false; out_len = 0; out_info = info; @@ -211,8 +199,8 @@ hb_buffer_t::clear_positions (void) if (unlikely (hb_object_is_inert (this))) return; - have_output = FALSE; - have_positions = TRUE; + have_output = false; + have_positions = true; memset (pos, 0, sizeof (pos[0]) * len); } @@ -223,7 +211,7 @@ hb_buffer_t::swap_buffers (void) if (unlikely (in_error)) return; assert (have_output); - have_output = FALSE; + have_output = false; if (out_info != info) { @@ -245,7 +233,7 @@ hb_buffer_t::swap_buffers (void) void hb_buffer_t::replace_glyphs_be16 (unsigned int num_in, unsigned int num_out, - const uint16_t *glyph_data_be) + const char *glyph_data_be) { if (!make_room_for (num_in, num_out)) return; @@ -257,10 +245,11 @@ hb_buffer_t::replace_glyphs_be16 (unsigned int num_in, } hb_glyph_info_t *pinfo = &out_info[out_len]; + const unsigned char *data = (const unsigned char *) glyph_data_be; for (unsigned int i = 0; i < num_out; i++) { *pinfo = orig_info; - pinfo->codepoint = hb_be_uint16 (glyph_data_be[i]); + pinfo->codepoint = (data[2*i] << 8) | data[2*i+1]; pinfo++; } @@ -543,7 +532,7 @@ hb_buffer_create () hb_buffer_t *buffer; if (!(buffer = hb_object_create<hb_buffer_t> ())) - return &_hb_buffer_nil; + return hb_buffer_get_empty (); buffer->reset (); @@ -553,7 +542,18 @@ hb_buffer_create () hb_buffer_t * hb_buffer_get_empty (void) { - return &_hb_buffer_nil; + static const hb_buffer_t _hb_buffer_nil = { + HB_OBJECT_HEADER_STATIC, + + _HB_BUFFER_UNICODE_FUNCS_DEFAULT, + _HB_BUFFER_PROPS_DEFAULT, + + true, /* in_error */ + true, /* have_output */ + true /* have_positions */ + }; + + return const_cast<hb_buffer_t *> (&_hb_buffer_nil); } hb_buffer_t * @@ -601,7 +601,7 @@ hb_buffer_set_unicode_funcs (hb_buffer_t *buffer, return; if (!unicode) - unicode = _hb_buffer_nil.unicode; + unicode = _HB_BUFFER_UNICODE_FUNCS_DEFAULT; hb_unicode_funcs_reference (unicode); hb_unicode_funcs_destroy (buffer->unicode); @@ -695,8 +695,11 @@ hb_bool_t hb_buffer_set_length (hb_buffer_t *buffer, unsigned int length) { + if (unlikely (hb_object_is_inert (buffer))) + return length == 0; + if (!buffer->ensure (length)) - return FALSE; + return false; /* Wipe the new space */ if (length > buffer->len) { @@ -706,7 +709,7 @@ hb_buffer_set_length (hb_buffer_t *buffer, } buffer->len = length; - return TRUE; + return true; } unsigned int diff --git a/third_party/harfbuzz-ng/src/hb-buffer.h b/third_party/harfbuzz-ng/src/hb-buffer.h index ca1bbf4..fe53197 100644 --- a/third_party/harfbuzz-ng/src/hb-buffer.h +++ b/third_party/harfbuzz-ng/src/hb-buffer.h @@ -121,13 +121,13 @@ hb_buffer_get_language (hb_buffer_t *buffer); void hb_buffer_reset (hb_buffer_t *buffer); -/* Returns FALSE if allocation failed */ +/* Returns false if allocation failed */ hb_bool_t hb_buffer_pre_allocate (hb_buffer_t *buffer, unsigned int size); -/* Returns FALSE if allocation has failed before */ +/* Returns false if allocation has failed before */ hb_bool_t hb_buffer_allocation_successful (hb_buffer_t *buffer); diff --git a/third_party/harfbuzz-ng/src/hb-common.cc b/third_party/harfbuzz-ng/src/hb-common.cc index bfbba65..331d255 100644 --- a/third_party/harfbuzz-ng/src/hb-common.cc +++ b/third_party/harfbuzz-ng/src/hb-common.cc @@ -114,18 +114,16 @@ static const char canon_map[256] = { }; static hb_bool_t -lang_equal (const void *v1, - const void *v2) +lang_equal (hb_language_t v1, + const void *v2) { const unsigned char *p1 = (const unsigned char *) v1; const unsigned char *p2 = (const unsigned char *) v2; - while (canon_map[*p1] && canon_map[*p1] == canon_map[*p2]) - { - p1++, p2++; - } + while (*p1 && *p1 == canon_map[*p2]) + p1++, p2++; - return (canon_map[*p1] == canon_map[*p2]); + return *p1 == canon_map[*p2]; } #if 0 @@ -147,6 +145,7 @@ lang_hash (const void *key) struct hb_language_item_t { + struct hb_language_item_t *next; hb_language_t lang; inline bool operator == (const char *s) const { @@ -164,10 +163,52 @@ struct hb_language_item_t { void finish (void) { free (lang); } }; -static struct hb_static_lang_set_t : hb_lockable_set_t<hb_language_item_t, hb_static_mutex_t> { - ~hb_static_lang_set_t (void) { this->finish (lock); } - hb_static_mutex_t lock; -} langs; + +/* Thread-safe lock-free language list */ + +static hb_language_item_t *langs; + +static +void free_langs (void) +{ + while (langs) { + hb_language_item_t *next = langs->next; + langs->finish (); + free (langs); + langs = next; + } +} + +static hb_language_item_t * +lang_find_or_insert (const char *key) +{ +retry: + hb_language_item_t *first_lang = (hb_language_item_t *) hb_atomic_ptr_get (&langs); + + for (hb_language_item_t *lang = first_lang; lang; lang = lang->next) + if (*lang == key) + return lang; + + /* Not found; allocate one. */ + hb_language_item_t *lang = (hb_language_item_t *) calloc (1, sizeof (hb_language_item_t)); + if (unlikely (!lang)) + return NULL; + lang->next = first_lang; + *lang = key; + + if (!hb_atomic_ptr_cmpexch (&langs, first_lang, lang)) { + free (lang); + goto retry; + } + +#ifdef HAVE_ATEXIT + if (!first_lang) + atexit (free_langs); /* First person registers atexit() callback. */ +#endif + + return lang; +} + hb_language_t hb_language_from_string (const char *str, int len) @@ -182,7 +223,7 @@ hb_language_from_string (const char *str, int len) strbuf[len] = '\0'; } - hb_language_item_t *item = langs.find_or_insert (str, langs.lock); + hb_language_item_t *item = lang_find_or_insert (str); return likely (item) ? item->lang : HB_LANGUAGE_INVALID; } @@ -314,47 +355,41 @@ hb_script_get_horizontal_direction (hb_script_t script) /* hb_user_data_array_t */ - -/* NOTE: Currently we use a global lock for user_data access - * threadsafety. If one day we add a mutex to any object, we - * should switch to using that insted for these too. - */ - -static hb_static_mutex_t user_data_lock; - bool hb_user_data_array_t::set (hb_user_data_key_t *key, void * data, hb_destroy_func_t destroy, - hb_bool_t replace) + hb_bool_t replace, + hb_mutex_t &lock) { if (!key) return false; if (replace) { if (!data && !destroy) { - items.remove (key, user_data_lock); + items.remove (key, lock); return true; } } hb_user_data_item_t item = {key, data, destroy}; - bool ret = !!items.replace_or_insert (item, user_data_lock, replace); + bool ret = !!items.replace_or_insert (item, lock, replace); return ret; } void * -hb_user_data_array_t::get (hb_user_data_key_t *key) +hb_user_data_array_t::get (hb_user_data_key_t *key, + hb_mutex_t &lock) { hb_user_data_item_t item = {NULL }; - return items.find (key, &item, user_data_lock) ? item.data : NULL; + return items.find (key, &item, lock) ? item.data : NULL; } void -hb_user_data_array_t::finish (void) +hb_user_data_array_t::finish (hb_mutex_t &lock) { - items.finish (user_data_lock); + items.finish (lock); } diff --git a/third_party/harfbuzz-ng/src/hb-fallback-shape.cc b/third_party/harfbuzz-ng/src/hb-fallback-shape.cc index 20ea43e..5939887 100644 --- a/third_party/harfbuzz-ng/src/hb-fallback-shape.cc +++ b/third_party/harfbuzz-ng/src/hb-fallback-shape.cc @@ -57,5 +57,5 @@ _hb_fallback_shape (hb_font_t *font, if (HB_DIRECTION_IS_BACKWARD (buffer->props.direction)) hb_buffer_reverse (buffer); - return TRUE; + return true; } diff --git a/third_party/harfbuzz-ng/src/hb-font-private.hh b/third_party/harfbuzz-ng/src/hb-font-private.hh index e10e105..91a4304 100644 --- a/third_party/harfbuzz-ng/src/hb-font-private.hh +++ b/third_party/harfbuzz-ng/src/hb-font-private.hh @@ -56,6 +56,7 @@ struct _hb_font_funcs_t { hb_object_header_t header; + ASSERT_POD (); hb_bool_t immutable; @@ -87,6 +88,7 @@ struct _hb_font_funcs_t { struct _hb_face_t { hb_object_header_t header; + ASSERT_POD (); hb_bool_t immutable; @@ -107,6 +109,7 @@ struct _hb_face_t { struct _hb_font_t { hb_object_header_t header; + ASSERT_POD (); hb_bool_t immutable; diff --git a/third_party/harfbuzz-ng/src/hb-font.cc b/third_party/harfbuzz-ng/src/hb-font.cc index 1862ac3..109caff 100644 --- a/third_party/harfbuzz-ng/src/hb-font.cc +++ b/third_party/harfbuzz-ng/src/hb-font.cc @@ -55,7 +55,7 @@ hb_font_get_glyph_nil (hb_font_t *font, return hb_font_get_glyph (font->parent, unicode, variation_selector, glyph); *glyph = 0; - return FALSE; + return false; } static hb_position_t @@ -98,7 +98,7 @@ hb_font_get_glyph_h_origin_nil (hb_font_t *font, } *x = *y = 0; - return FALSE; + return false; } static hb_bool_t @@ -117,7 +117,7 @@ hb_font_get_glyph_v_origin_nil (hb_font_t *font, } *x = *y = 0; - return FALSE; + return false; } static hb_position_t @@ -165,7 +165,7 @@ hb_font_get_glyph_extents_nil (hb_font_t *font, } memset (extents, 0, sizeof (*extents)); - return FALSE; + return false; } static hb_bool_t @@ -185,7 +185,7 @@ hb_font_get_glyph_contour_point_nil (hb_font_t *font, } *x = *y = 0; - return FALSE; + return false; } static hb_bool_t @@ -199,7 +199,7 @@ hb_font_get_glyph_name_nil (hb_font_t *font, return hb_font_get_glyph_name (font->parent, glyph, name, size); snprintf (name, size, "gid%u", glyph); - return FALSE; + return false; } static hb_bool_t @@ -213,14 +213,14 @@ hb_font_get_glyph_from_name_nil (hb_font_t *font, return hb_font_get_glyph_from_name (font->parent, name, len, glyph); *glyph = 0; - return FALSE; + return false; } -static hb_font_funcs_t _hb_font_funcs_nil = { +static const hb_font_funcs_t _hb_font_funcs_nil = { HB_OBJECT_HEADER_STATIC, - TRUE, /* immutable */ + true, /* immutable */ { #define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_nil, @@ -236,7 +236,7 @@ hb_font_funcs_create (void) hb_font_funcs_t *ffuncs; if (!(ffuncs = hb_object_create<hb_font_funcs_t> ())) - return &_hb_font_funcs_nil; + return hb_font_funcs_get_empty (); ffuncs->get = _hb_font_funcs_nil.get; @@ -246,7 +246,7 @@ hb_font_funcs_create (void) hb_font_funcs_t * hb_font_funcs_get_empty (void) { - return &_hb_font_funcs_nil; + return const_cast<hb_font_funcs_t *> (&_hb_font_funcs_nil); } hb_font_funcs_t * @@ -292,7 +292,7 @@ hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs) if (hb_object_is_inert (ffuncs)) return; - ffuncs->immutable = TRUE; + ffuncs->immutable = true; } hb_bool_t @@ -578,10 +578,10 @@ hb_font_get_glyph_contour_point_for_origin (hb_font_t *font, * hb_face_t */ -static hb_face_t _hb_face_nil = { +static const hb_face_t _hb_face_nil = { HB_OBJECT_HEADER_STATIC, - TRUE, /* immutable */ + true, /* immutable */ NULL, /* reference_table */ NULL, /* user_data */ @@ -604,7 +604,7 @@ hb_face_create_for_tables (hb_reference_table_func_t reference_table, if (!reference_table || !(face = hb_object_create<hb_face_t> ())) { if (destroy) destroy (user_data); - return &_hb_face_nil; + return hb_face_get_empty (); } face->reference_table = reference_table; @@ -671,12 +671,12 @@ hb_face_create (hb_blob_t *blob, hb_face_t *face; if (unlikely (!blob || !hb_blob_get_length (blob))) - return &_hb_face_nil; + return hb_face_get_empty (); hb_face_for_data_closure_t *closure = _hb_face_for_data_closure_create (Sanitizer<OpenTypeFontFile>::sanitize (hb_blob_reference (blob)), index); if (unlikely (!closure)) - return &_hb_face_nil; + return hb_face_get_empty (); face = hb_face_create_for_tables (_hb_face_for_data_reference_table, closure, @@ -690,7 +690,7 @@ hb_face_create (hb_blob_t *blob, hb_face_t * hb_face_get_empty (void) { - return &_hb_face_nil; + return const_cast<hb_face_t *> (&_hb_face_nil); } @@ -811,40 +811,21 @@ hb_face_get_upem (hb_face_t *face) * hb_font_t */ -static hb_font_t _hb_font_nil = { - HB_OBJECT_HEADER_STATIC, - - TRUE, /* immutable */ - - NULL, /* parent */ - &_hb_face_nil, - - 0, /* x_scale */ - 0, /* y_scale */ - - 0, /* x_ppem */ - 0, /* y_ppem */ - - &_hb_font_funcs_nil, /* klass */ - NULL, /* user_data */ - NULL /* destroy */ -}; - hb_font_t * hb_font_create (hb_face_t *face) { hb_font_t *font; if (unlikely (!face)) - face = &_hb_face_nil; + face = hb_face_get_empty (); if (unlikely (hb_object_is_inert (face))) - return &_hb_font_nil; + return hb_font_get_empty (); if (!(font = hb_object_create<hb_font_t> ())) - return &_hb_font_nil; + return hb_font_get_empty (); hb_face_make_immutable (face); font->face = hb_face_reference (face); - font->klass = &_hb_font_funcs_nil; + font->klass = hb_font_funcs_get_empty (); return font; } @@ -853,7 +834,7 @@ hb_font_t * hb_font_create_sub_font (hb_font_t *parent) { if (unlikely (!parent)) - return &_hb_font_nil; + return hb_font_get_empty (); hb_font_t *font = hb_font_create (parent->face); @@ -868,15 +849,32 @@ hb_font_create_sub_font (hb_font_t *parent) font->x_ppem = parent->x_ppem; font->y_ppem = parent->y_ppem; - font->klass = &_hb_font_funcs_nil; - return font; } hb_font_t * hb_font_get_empty (void) { - return &_hb_font_nil; + static const hb_font_t _hb_font_nil = { + HB_OBJECT_HEADER_STATIC, + + true, /* immutable */ + + NULL, /* parent */ + const_cast<hb_face_t *> (&_hb_face_nil), + + 0, /* x_scale */ + 0, /* y_scale */ + + 0, /* x_ppem */ + 0, /* y_ppem */ + + const_cast<hb_font_funcs_t *> (&_hb_font_funcs_nil), /* klass */ + NULL, /* user_data */ + NULL /* destroy */ + }; + + return const_cast<hb_font_t *> (&_hb_font_nil); } hb_font_t * @@ -960,7 +958,7 @@ hb_font_set_funcs (hb_font_t *font, font->destroy (font->user_data); if (!klass) - klass = &_hb_font_funcs_nil; + klass = hb_font_funcs_get_empty (); hb_font_funcs_reference (klass); hb_font_funcs_destroy (font->klass); diff --git a/third_party/harfbuzz-ng/src/hb-ft.cc b/third_party/harfbuzz-ng/src/hb-ft.cc index 90adc0d..0589c9e 100644 --- a/third_party/harfbuzz-ng/src/hb-ft.cc +++ b/third_party/harfbuzz-ng/src/hb-ft.cc @@ -81,7 +81,7 @@ hb_ft_get_glyph (hb_font_t *font HB_UNUSED, if (unlikely (variation_selector)) { *glyph = FT_Face_GetCharVariantIndex (ft_face, unicode, variation_selector); if (*glyph) - return TRUE; + return true; } #endif @@ -132,7 +132,7 @@ hb_ft_get_glyph_h_origin (hb_font_t *font HB_UNUSED, void *user_data HB_UNUSED) { /* We always work in the horizontal coordinates. */ - return TRUE; + return true; } static hb_bool_t @@ -147,14 +147,14 @@ hb_ft_get_glyph_v_origin (hb_font_t *font HB_UNUSED, int load_flags = FT_LOAD_DEFAULT; if (unlikely (FT_Load_Glyph (ft_face, glyph, load_flags))) - return FALSE; + return false; /* Note: FreeType's vertical metrics grows downward while other FreeType coordinates * have a Y growing upward. Hence the extra negation. */ *x = ft_face->glyph->metrics.horiBearingX - ft_face->glyph->metrics.vertBearingX; *y = ft_face->glyph->metrics.horiBearingY - (-ft_face->glyph->metrics.vertBearingY); - return TRUE; + return true; } static hb_position_t @@ -195,13 +195,13 @@ hb_ft_get_glyph_extents (hb_font_t *font HB_UNUSED, int load_flags = FT_LOAD_DEFAULT; if (unlikely (FT_Load_Glyph (ft_face, glyph, load_flags))) - return FALSE; + return false; extents->x_bearing = ft_face->glyph->metrics.horiBearingX; extents->y_bearing = ft_face->glyph->metrics.horiBearingY; extents->width = ft_face->glyph->metrics.width; extents->height = ft_face->glyph->metrics.height; - return TRUE; + return true; } static hb_bool_t @@ -217,18 +217,18 @@ hb_ft_get_glyph_contour_point (hb_font_t *font HB_UNUSED, int load_flags = FT_LOAD_DEFAULT; if (unlikely (FT_Load_Glyph (ft_face, glyph, load_flags))) - return FALSE; + return false; if (unlikely (ft_face->glyph->format != FT_GLYPH_FORMAT_OUTLINE)) - return FALSE; + return false; if (unlikely (point_index >= (unsigned int) ft_face->glyph->outline.n_points)) - return FALSE; + return false; *x = ft_face->glyph->outline.points[point_index].x; *y = ft_face->glyph->outline.points[point_index].y; - return TRUE; + return true; } static hb_bool_t @@ -271,22 +271,22 @@ hb_ft_get_glyph_from_name (hb_font_t *font, } -static hb_font_funcs_t ft_ffuncs = { - HB_OBJECT_HEADER_STATIC, +static hb_font_funcs_t * +_hb_ft_get_font_funcs (void) +{ + static const hb_font_funcs_t ft_ffuncs = { + HB_OBJECT_HEADER_STATIC, - TRUE, /* immutable */ + true, /* immutable */ - { + { #define HB_FONT_FUNC_IMPLEMENT(name) hb_ft_get_##name, - HB_FONT_FUNCS_IMPLEMENT_CALLBACKS + HB_FONT_FUNCS_IMPLEMENT_CALLBACKS #undef HB_FONT_FUNC_IMPLEMENT - } -}; + } + }; -static hb_font_funcs_t * -_hb_ft_get_font_funcs (void) -{ - return &ft_ffuncs; + return const_cast<hb_font_funcs_t *> (&ft_ffuncs); } @@ -398,26 +398,39 @@ hb_ft_font_create (FT_Face ft_face, } - +/* Thread-safe, lock-free, FT_Library */ static FT_Library ft_library; -static hb_bool_t ft_library_initialized; -static struct ft_library_destructor { - ~ft_library_destructor (void) { - if (ft_library) - FT_Done_FreeType (ft_library); - } -} static_ft_library_destructor; + +static +void free_ft_library (void) +{ + FT_Done_FreeType (ft_library); +} static FT_Library -_get_ft_library (void) +get_ft_library (void) { - if (unlikely (!ft_library_initialized)) { - FT_Init_FreeType (&ft_library); - ft_library_initialized = TRUE; +retry: + FT_Library library = (FT_Library) hb_atomic_ptr_get (&ft_library); + + if (unlikely (!library)) + { + /* Not found; allocate one. */ + if (FT_Init_FreeType (&library)) + return NULL; + + if (!hb_atomic_ptr_cmpexch (&ft_library, NULL, library)) { + FT_Done_FreeType (library); + goto retry; + } + +#ifdef HAVE_ATEXIT + atexit (free_ft_library); /* First person registers atexit() callback. */ +#endif } - return ft_library; + return library; } static void @@ -436,7 +449,7 @@ hb_ft_font_set_funcs (hb_font_t *font) DEBUG_MSG (FT, font, "Font face has empty blob"); FT_Face ft_face = NULL; - FT_Error err = FT_New_Memory_Face (_get_ft_library (), + FT_Error err = FT_New_Memory_Face (get_ft_library (), (const FT_Byte *) blob_data, blob_length, hb_face_get_index (font->face), diff --git a/third_party/harfbuzz-ng/src/hb-glib.cc b/third_party/harfbuzz-ng/src/hb-glib.cc index 26d40a3..6b655dd 100644 --- a/third_party/harfbuzz-ng/src/hb-glib.cc +++ b/third_party/harfbuzz-ng/src/hb-glib.cc @@ -251,7 +251,7 @@ hb_glib_unicode_compose (hb_unicode_funcs_t *ufuncs HB_UNUSED, * sees it and makes sure it's compilable. */ if (!a || !b) - return FALSE; + return false; gchar utf8[12]; gchar *normalized; @@ -263,13 +263,13 @@ hb_glib_unicode_compose (hb_unicode_funcs_t *ufuncs HB_UNUSED, normalized = g_utf8_normalize (utf8, len, G_NORMALIZE_NFC); len = g_utf8_strlen (normalized, -1); if (unlikely (!len)) - return FALSE; + return false; if (len == 1) { *ab = g_utf8_get_char (normalized); - ret = TRUE; + ret = true; } else { - ret = FALSE; + ret = false; } g_free (normalized); @@ -299,7 +299,7 @@ hb_glib_unicode_decompose (hb_unicode_funcs_t *ufuncs HB_UNUSED, normalized = g_utf8_normalize (utf8, len, G_NORMALIZE_NFD); len = g_utf8_strlen (normalized, -1); if (unlikely (!len)) - return FALSE; + return false; if (len == 1) { *a = g_utf8_get_char (normalized); @@ -318,7 +318,7 @@ hb_glib_unicode_decompose (hb_unicode_funcs_t *ufuncs HB_UNUSED, *b = 0; } g_free (recomposed); - ret = TRUE; + ret = true; } else { /* If decomposed to more than two characters, take the last one, * and recompose the rest to get the first component. */ @@ -329,7 +329,7 @@ hb_glib_unicode_decompose (hb_unicode_funcs_t *ufuncs HB_UNUSED, /* We expect that recomposed has exactly one character now. */ *a = g_utf8_get_char (recomposed); g_free (recomposed); - ret = TRUE; + ret = true; } g_free (normalized); @@ -337,12 +337,12 @@ hb_glib_unicode_decompose (hb_unicode_funcs_t *ufuncs HB_UNUSED, } -extern HB_INTERNAL hb_unicode_funcs_t _hb_unicode_funcs_glib; -hb_unicode_funcs_t _hb_glib_unicode_funcs = { +extern HB_INTERNAL const hb_unicode_funcs_t _hb_glib_unicode_funcs; +const hb_unicode_funcs_t _hb_glib_unicode_funcs = { HB_OBJECT_HEADER_STATIC, NULL, /* parent */ - TRUE, /* immutable */ + true, /* immutable */ { #define HB_UNICODE_FUNC_IMPLEMENT(name) hb_glib_unicode_##name, HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS @@ -353,6 +353,6 @@ hb_unicode_funcs_t _hb_glib_unicode_funcs = { hb_unicode_funcs_t * hb_glib_get_unicode_funcs (void) { - return &_hb_glib_unicode_funcs; + return const_cast<hb_unicode_funcs_t *> (&_hb_glib_unicode_funcs); } diff --git a/third_party/harfbuzz-ng/src/hb-graphite2.cc b/third_party/harfbuzz-ng/src/hb-graphite2.cc index eab2eae..3fa9f79 100644 --- a/third_party/harfbuzz-ng/src/hb-graphite2.cc +++ b/third_party/harfbuzz-ng/src/hb-graphite2.cc @@ -159,7 +159,7 @@ _hb_gr_face_get_data (hb_face_t *face) if (unlikely (!hb_face_set_user_data (face, &hb_gr_data_key, data, (hb_destroy_func_t) _hb_gr_face_data_destroy, - FALSE))) + false))) { _hb_gr_face_data_destroy (data); data = (hb_gr_face_data_t *) hb_face_get_user_data (face, &hb_gr_data_key); @@ -198,7 +198,7 @@ _hb_gr_font_get_data (hb_font_t *font) if (unlikely (!hb_font_set_user_data (font, &hb_gr_data_key, data, (hb_destroy_func_t) _hb_gr_font_data_destroy, - FALSE))) + false))) { _hb_gr_font_data_destroy (data); data = (hb_gr_font_data_t *) hb_font_get_user_data (font, &hb_gr_data_key); @@ -225,14 +225,14 @@ _hb_graphite_shape (hb_font_t *font, * is not graphite! Shouldn't do. */ hb_gr_font_data_t *data = _hb_gr_font_get_data (font); - if (!data->grface) return FALSE; + if (!data->grface) return false; unsigned int charlen; hb_glyph_info_t *bufferi = hb_buffer_get_glyph_infos (buffer, &charlen); int success = 0; - if (!charlen) return TRUE; + if (!charlen) return true; const char *lang = hb_language_to_string (hb_buffer_get_language (buffer)); const char *lang_end = strchr (lang, '-'); diff --git a/third_party/harfbuzz-ng/src/hb-icu.cc b/third_party/harfbuzz-ng/src/hb-icu.cc index 5cd0143..491c1c8 100644 --- a/third_party/harfbuzz-ng/src/hb-icu.cc +++ b/third_party/harfbuzz-ng/src/hb-icu.cc @@ -172,7 +172,7 @@ hb_icu_unicode_compose (hb_unicode_funcs_t *ufuncs HB_UNUSED, void *user_data HB_UNUSED) { if (!a || !b) - return FALSE; + return false; UChar utf16[4], normalized[5]; int len; @@ -180,21 +180,21 @@ hb_icu_unicode_compose (hb_unicode_funcs_t *ufuncs HB_UNUSED, UErrorCode icu_err; len = 0; - err = FALSE; + err = false; U16_APPEND (utf16, len, ARRAY_LENGTH (utf16), a, err); - if (err) return FALSE; + if (err) return false; U16_APPEND (utf16, len, ARRAY_LENGTH (utf16), b, err); - if (err) return FALSE; + if (err) return false; icu_err = U_ZERO_ERROR; len = unorm_normalize (utf16, len, UNORM_NFC, 0, normalized, ARRAY_LENGTH (normalized), &icu_err); if (U_FAILURE (icu_err)) - return FALSE; + return false; if (u_countChar32 (normalized, len) == 1) { U16_GET_UNSAFE (normalized, 0, *ab); - ret = TRUE; + ret = true; } else { - ret = FALSE; + ret = false; } return ret; @@ -217,14 +217,14 @@ hb_icu_unicode_decompose (hb_unicode_funcs_t *ufuncs HB_UNUSED, /* Watchout for the dragons. Err, watchout for macros changing len. */ len = 0; - err = FALSE; + err = false; U16_APPEND (utf16, len, ARRAY_LENGTH (utf16), ab, err); - if (err) return FALSE; + if (err) return false; icu_err = U_ZERO_ERROR; len = unorm_normalize (utf16, len, UNORM_NFD, 0, normalized, ARRAY_LENGTH (normalized), &icu_err); if (U_FAILURE (icu_err)) - return FALSE; + return false; len = u_countChar32 (normalized, len); @@ -244,37 +244,40 @@ hb_icu_unicode_decompose (hb_unicode_funcs_t *ufuncs HB_UNUSED, icu_err = U_ZERO_ERROR; unorm_normalize (normalized, len, UNORM_NFC, 0, recomposed, ARRAY_LENGTH (recomposed), &icu_err); if (U_FAILURE (icu_err)) - return FALSE; + return false; hb_codepoint_t c; U16_GET_UNSAFE (recomposed, 0, c); if (c != *a && c != ab) { *a = c; *b = 0; } - ret = TRUE; + ret = true; } else { /* If decomposed to more than two characters, take the last one, * and recompose the rest to get the first component. */ - U16_PREV_UNSAFE (normalized, len, *b); - UChar recomposed[20]; + U16_PREV_UNSAFE (normalized, len, *b); /* Changes len in-place. */ + UChar recomposed[18 * 2]; icu_err = U_ZERO_ERROR; len = unorm_normalize (normalized, len, UNORM_NFC, 0, recomposed, ARRAY_LENGTH (recomposed), &icu_err); if (U_FAILURE (icu_err)) - return FALSE; + return false; /* We expect that recomposed has exactly one character now. */ + if (unlikely (u_countChar32 (recomposed, len) != 1)) + return false; U16_GET_UNSAFE (recomposed, 0, *a); - ret = TRUE; + ret = true; } return ret; } -extern HB_INTERNAL hb_unicode_funcs_t _hb_unicode_funcs_icu; -hb_unicode_funcs_t _hb_icu_unicode_funcs = { + +extern HB_INTERNAL const hb_unicode_funcs_t _hb_icu_unicode_funcs; +const hb_unicode_funcs_t _hb_icu_unicode_funcs = { HB_OBJECT_HEADER_STATIC, NULL, /* parent */ - TRUE, /* immutable */ + true, /* immutable */ { #define HB_UNICODE_FUNC_IMPLEMENT(name) hb_icu_unicode_##name, HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS @@ -285,7 +288,7 @@ hb_unicode_funcs_t _hb_icu_unicode_funcs = { hb_unicode_funcs_t * hb_icu_get_unicode_funcs (void) { - return &_hb_icu_unicode_funcs; + return const_cast<hb_unicode_funcs_t *> (&_hb_icu_unicode_funcs); } diff --git a/third_party/harfbuzz-ng/src/hb-mutex-private.hh b/third_party/harfbuzz-ng/src/hb-mutex-private.hh index 44b48df..f9bd679 100644 --- a/third_party/harfbuzz-ng/src/hb-mutex-private.hh +++ b/third_party/harfbuzz-ng/src/hb-mutex-private.hh @@ -1,7 +1,7 @@ /* * Copyright © 2007 Chris Wilson * Copyright © 2009,2010 Red Hat, Inc. - * Copyright © 2011 Google, Inc. + * Copyright © 2011,2012 Google, Inc. * * This is part of HarfBuzz, a text shaping library. * @@ -50,10 +50,10 @@ typedef CRITICAL_SECTION hb_mutex_impl_t; #define hb_mutex_impl_init(M) InitializeCriticalSection (M) #define hb_mutex_impl_lock(M) EnterCriticalSection (M) #define hb_mutex_impl_unlock(M) LeaveCriticalSection (M) -#define hb_mutex_impl_free(M) DeleteCriticalSection (M) +#define hb_mutex_impl_finish(M) DeleteCriticalSection (M) -#elif !defined(HB_NO_MT) && defined(__APPLE__) +#elif !defined(HB_NO_MT) && (defined(HAVE_PTHREAD) || defined(__APPLE__)) #include <pthread.h> typedef pthread_mutex_t hb_mutex_impl_t; @@ -61,7 +61,7 @@ typedef pthread_mutex_t hb_mutex_impl_t; #define hb_mutex_impl_init(M) pthread_mutex_init (M, NULL) #define hb_mutex_impl_lock(M) pthread_mutex_lock (M) #define hb_mutex_impl_unlock(M) pthread_mutex_unlock (M) -#define hb_mutex_impl_free(M) pthread_mutex_destroy (M) +#define hb_mutex_impl_finish(M) pthread_mutex_destroy (M) #elif !defined(HB_NO_MT) && defined(HAVE_GLIB) @@ -72,48 +72,69 @@ typedef GStaticMutex hb_mutex_impl_t; #define hb_mutex_impl_init(M) g_static_mutex_init (M) #define hb_mutex_impl_lock(M) g_static_mutex_lock (M) #define hb_mutex_impl_unlock(M) g_static_mutex_unlock (M) -#define hb_mutex_impl_free(M) g_static_mutex_free (M) +#define hb_mutex_impl_finish(M) g_static_mutex_free (M) +#elif !defined(HB_NO_MT) && defined(HAVE_INTEL_ATOMIC_PRIMITIVES) + +#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_YIELD) +# include <sched.h> +# define HB_SCHED_YIELD() sched_yield () +#else +# define HB_SCHED_YIELD() HB_STMT_START {} HB_STMT_END +#endif + +/* This actually is not a totally awful implementation. */ +typedef volatile int hb_mutex_impl_t; +#define HB_MUTEX_IMPL_INIT 0 +#define hb_mutex_impl_init(M) *(M) = 0 +#define hb_mutex_impl_lock(M) HB_STMT_START { while (__sync_lock_test_and_set((M), 1)) HB_SCHED_YIELD (); } HB_STMT_END +#define hb_mutex_impl_unlock(M) __sync_lock_release (M) +#define hb_mutex_impl_finish(M) HB_STMT_START {} HB_STMT_END + + +#elif !defined(HB_NO_MT) + +#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_YIELD) +# include <sched.h> +# define HB_SCHED_YIELD() sched_yield () #else +# define HB_SCHED_YIELD() HB_STMT_START {} HB_STMT_END +#endif -#define HB_MUTEX_IMPL_NIL 1 +#define HB_MUTEX_INT_NIL 1 /* Warn that fallback implementation is in use. */ typedef volatile int hb_mutex_impl_t; #define HB_MUTEX_IMPL_INIT 0 -#define hb_mutex_impl_init(M) ((void) (*(M) = 0)) -#define hb_mutex_impl_lock(M) ((void) (*(M) = 1)) -#define hb_mutex_impl_unlock(M) ((void) (*(M) = 0)) -#define hb_mutex_impl_free(M) ((void) (*(M) = 2)) +#define hb_mutex_impl_init(M) *(M) = 0 +#define hb_mutex_impl_lock(M) HB_STMT_START { while (*(M)) HB_SCHED_YIELD (); (*(M))++; } HB_STMT_END +#define hb_mutex_impl_unlock(M) (*(M))--; +#define hb_mutex_impl_finish(M) HB_STMT_START {} HB_STMT_END + + +#else /* HB_NO_MT */ + +typedef int hb_mutex_impl_t; +#define HB_MUTEX_IMPL_INIT 0 +#define hb_mutex_impl_init(M) HB_STMT_START {} HB_STMT_END +#define hb_mutex_impl_lock(M) HB_STMT_START {} HB_STMT_END +#define hb_mutex_impl_unlock(M) HB_STMT_START {} HB_STMT_END +#define hb_mutex_impl_finish(M) HB_STMT_START {} HB_STMT_END #endif +#define HB_MUTEX_INIT {HB_MUTEX_IMPL_INIT} struct hb_mutex_t { + /* TODO Add tracing. */ + hb_mutex_impl_t m; inline void init (void) { hb_mutex_impl_init (&m); } inline void lock (void) { hb_mutex_impl_lock (&m); } inline void unlock (void) { hb_mutex_impl_unlock (&m); } - inline void free (void) { hb_mutex_impl_free (&m); } -}; - -#define HB_MUTEX_INIT {HB_MUTEX_IMPL_INIT} -#define hb_mutex_init(M) (M)->init () -#define hb_mutex_lock(M) (M)->lock () -#define hb_mutex_unlock(M) (M)->unlock () -#define hb_mutex_free(M) (M)->free () - - -struct hb_static_mutex_t : hb_mutex_t -{ - hb_static_mutex_t (void) { this->init (); } - ~hb_static_mutex_t (void) { this->free (); } - - private: - NO_COPY (hb_static_mutex_t); + inline void finish (void) { hb_mutex_impl_finish (&m); } }; - #endif /* HB_MUTEX_PRIVATE_HH */ diff --git a/third_party/harfbuzz-ng/src/hb-object-private.hh b/third_party/harfbuzz-ng/src/hb-object-private.hh index e3c9d21..96d1bd3 100644 --- a/third_party/harfbuzz-ng/src/hb-object-private.hh +++ b/third_party/harfbuzz-ng/src/hb-object-private.hh @@ -1,7 +1,7 @@ /* * Copyright © 2007 Chris Wilson * Copyright © 2009,2010 Red Hat, Inc. - * Copyright © 2011 Google, Inc. + * Copyright © 2011,2012 Google, Inc. * * This is part of HarfBuzz, a text shaping library. * @@ -47,16 +47,16 @@ /* reference_count */ +#define HB_REFERENCE_COUNT_INVALID_VALUE ((hb_atomic_int_t) -1) +#define HB_REFERENCE_COUNT_INVALID {HB_REFERENCE_COUNT_INVALID_VALUE} struct hb_reference_count_t { hb_atomic_int_t ref_count; -#define HB_REFERENCE_COUNT_INVALID_VALUE ((hb_atomic_int_t) -1) -#define HB_REFERENCE_COUNT_INVALID {HB_REFERENCE_COUNT_INVALID_VALUE} - - inline void init (int v) { const_cast<hb_atomic_int_t &> (ref_count) = v; } + inline void init (int v) { ref_count = v; } inline int inc (void) { return hb_atomic_int_add (const_cast<hb_atomic_int_t &> (ref_count), 1); } inline int dec (void) { return hb_atomic_int_add (const_cast<hb_atomic_int_t &> (ref_count), -1); } + inline void finish (void) { ref_count = HB_REFERENCE_COUNT_INVALID_VALUE; } inline bool is_invalid (void) const { return ref_count == HB_REFERENCE_COUNT_INVALID_VALUE; } @@ -65,8 +65,11 @@ struct hb_reference_count_t /* user_data */ +#define HB_USER_DATA_ARRAY_INIT {HB_LOCKABLE_SET_INIT} struct hb_user_data_array_t { + /* TODO Add tracing. */ + struct hb_user_data_item_t { hb_user_data_key_t *key; void *data; @@ -78,16 +81,20 @@ struct hb_user_data_array_t void finish (void) { if (destroy) destroy (data); } }; - hb_lockable_set_t<hb_user_data_item_t, hb_static_mutex_t> items; + hb_lockable_set_t<hb_user_data_item_t, hb_mutex_t> items; + + inline void init (void) { items.init (); } HB_INTERNAL bool set (hb_user_data_key_t *key, void * data, hb_destroy_func_t destroy, - hb_bool_t replace); + hb_bool_t replace, + hb_mutex_t &lock); - HB_INTERNAL void *get (hb_user_data_key_t *key); + HB_INTERNAL void *get (hb_user_data_key_t *key, + hb_mutex_t &lock); - HB_INTERNAL void finish (void); + HB_INTERNAL void finish (hb_mutex_t &lock); }; @@ -96,9 +103,10 @@ struct hb_user_data_array_t struct hb_object_header_t { hb_reference_count_t ref_count; + hb_mutex_t lock; hb_user_data_array_t user_data; -#define HB_OBJECT_HEADER_STATIC {HB_REFERENCE_COUNT_INVALID} +#define HB_OBJECT_HEADER_STATIC {HB_REFERENCE_COUNT_INVALID, HB_MUTEX_INIT, HB_USER_DATA_ARRAY_INIT} static inline void *create (unsigned int size) { hb_object_header_t *obj = (hb_object_header_t *) calloc (1, size); @@ -111,6 +119,8 @@ struct hb_object_header_t inline void init (void) { ref_count.init (1); + lock.init (); + user_data.init (); } inline bool is_inert (void) const { @@ -129,9 +139,9 @@ struct hb_object_header_t if (ref_count.dec () != 1) return false; - ref_count.init (HB_REFERENCE_COUNT_INVALID_VALUE); - - user_data.finish (); + ref_count.finish (); /* Do this before user_data */ + user_data.finish (lock); + lock.finish (); return true; } @@ -143,11 +153,14 @@ struct hb_object_header_t if (unlikely (!this || this->is_inert ())) return false; - return user_data.set (key, data, destroy_func, replace); + return user_data.set (key, data, destroy_func, replace, lock); } inline void *get_user_data (hb_user_data_key_t *key) { - return user_data.get (key); + if (unlikely (!this || this->is_inert ())) + return NULL; + + return user_data.get (key, lock); } inline void trace (const char *function) const { @@ -160,6 +173,8 @@ struct hb_object_header_t this ? ref_count.ref_count : 0); } + private: + ASSERT_POD (); }; diff --git a/third_party/harfbuzz-ng/src/hb-open-type-private.hh b/third_party/harfbuzz-ng/src/hb-open-type-private.hh index f4a2ba9..5f097f0 100644 --- a/third_party/harfbuzz-ng/src/hb-open-type-private.hh +++ b/third_party/harfbuzz-ng/src/hb-open-type-private.hh @@ -80,17 +80,25 @@ inline Type& StructAfter(TObject &X) */ /* Check _assertion in a method environment */ -#define _DEFINE_SIZE_ASSERTION(_assertion) \ - inline void _size_assertion (void) const \ - { ASSERT_STATIC (_assertion); } +#define _DEFINE_INSTANCE_ASSERTION1(_line, _assertion) \ + inline void _instance_assertion_on_line_##_line (void) const \ + { \ + ASSERT_STATIC (_assertion); \ + ASSERT_INSTANCE_POD (*this); /* Make sure it's POD. */ \ + } +# define _DEFINE_INSTANCE_ASSERTION0(_line, _assertion) _DEFINE_INSTANCE_ASSERTION1 (_line, _assertion) +# define DEFINE_INSTANCE_ASSERTION(_assertion) _DEFINE_INSTANCE_ASSERTION0 (__LINE__, _assertion) + /* Check that _code compiles in a method environment */ -#define _DEFINE_COMPILES_ASSERTION(_code) \ - inline void _compiles_assertion (void) const \ +#define _DEFINE_COMPILES_ASSERTION1(_line, _code) \ + inline void _compiles_assertion_on_line_##_line (void) const \ { _code; } +# define _DEFINE_COMPILES_ASSERTION0(_line, _code) _DEFINE_COMPILES_ASSERTION1 (_line, _code) +# define DEFINE_COMPILES_ASSERTION(_code) _DEFINE_COMPILES_ASSERTION0 (__LINE__, _code) #define DEFINE_SIZE_STATIC(size) \ - _DEFINE_SIZE_ASSERTION (sizeof (*this) == (size)); \ + DEFINE_INSTANCE_ASSERTION (sizeof (*this) == (size)); \ static const unsigned int static_size = (size); \ static const unsigned int min_size = (size) @@ -98,21 +106,21 @@ inline Type& StructAfter(TObject &X) #define VAR 1 #define DEFINE_SIZE_UNION(size, _member) \ - _DEFINE_SIZE_ASSERTION (this->u._member.static_size == (size)); \ + DEFINE_INSTANCE_ASSERTION (this->u._member.static_size == (size)); \ static const unsigned int min_size = (size) #define DEFINE_SIZE_MIN(size) \ - _DEFINE_SIZE_ASSERTION (sizeof (*this) >= (size)); \ + DEFINE_INSTANCE_ASSERTION (sizeof (*this) >= (size)); \ static const unsigned int min_size = (size) #define DEFINE_SIZE_ARRAY(size, array) \ - _DEFINE_SIZE_ASSERTION (sizeof (*this) == (size) + sizeof (array[0])); \ - _DEFINE_COMPILES_ASSERTION ((void) array[0].static_size) \ + DEFINE_INSTANCE_ASSERTION (sizeof (*this) == (size) + sizeof (array[0])); \ + DEFINE_COMPILES_ASSERTION ((void) array[0].static_size) \ static const unsigned int min_size = (size) #define DEFINE_SIZE_ARRAY2(size, array1, array2) \ - _DEFINE_SIZE_ASSERTION (sizeof (*this) == (size) + sizeof (this->array1[0]) + sizeof (this->array2[0])); \ - _DEFINE_COMPILES_ASSERTION ((void) array1[0].static_size; (void) array2[0].static_size) \ + DEFINE_INSTANCE_ASSERTION (sizeof (*this) == (size) + sizeof (this->array1[0]) + sizeof (this->array2[0])); \ + DEFINE_COMPILES_ASSERTION ((void) array1[0].static_size; (void) array2[0].static_size) \ static const unsigned int min_size = (size) @@ -122,6 +130,7 @@ inline Type& StructAfter(TObject &X) */ /* Global nul-content Null pool. Enlarge as necessary. */ +/* TODO This really should be a extern HB_INTERNAL and defined somewhere... */ static const void *_NullPool[64 / sizeof (void *)]; /* Generic nul-content Null objects. */ diff --git a/third_party/harfbuzz-ng/src/hb-ot-layout-gsub-table.hh b/third_party/harfbuzz-ng/src/hb-ot-layout-gsub-table.hh index f6a7575..4229f32 100644 --- a/third_party/harfbuzz-ng/src/hb-ot-layout-gsub-table.hh +++ b/third_party/harfbuzz-ng/src/hb-ot-layout-gsub-table.hh @@ -213,7 +213,7 @@ struct Sequence if (unlikely (!substitute.len)) return TRACE_RETURN (false); unsigned int klass = c->property & HB_OT_LAYOUT_GLYPH_CLASS_LIGATURE ? HB_OT_LAYOUT_GLYPH_CLASS_BASE_GLYPH : 0; - c->replace_glyphs_be16 (1, substitute.len, (const uint16_t *) substitute.array, klass); + c->replace_glyphs_be16 (1, substitute.len, (const char *) substitute.array, klass); return TRACE_RETURN (true); } @@ -502,7 +502,7 @@ struct Ligature if (skippy_iter.idx < c->buffer->idx + count) /* No input glyphs skipped */ { - c->replace_glyphs_be16 (count, 1, (const uint16_t *) &ligGlyph, klass); + c->replace_glyphs_be16 (count, 1, (const char *) &ligGlyph, klass); } else { diff --git a/third_party/harfbuzz-ng/src/hb-ot-layout-gsubgpos-private.hh b/third_party/harfbuzz-ng/src/hb-ot-layout-gsubgpos-private.hh index a2e4b2f..e590e39 100644 --- a/third_party/harfbuzz-ng/src/hb-ot-layout-gsubgpos-private.hh +++ b/third_party/harfbuzz-ng/src/hb-ot-layout-gsubgpos-private.hh @@ -230,7 +230,7 @@ struct hb_apply_context_t } inline void replace_glyphs_be16 (unsigned int num_in, unsigned int num_out, - const uint16_t *glyph_data_be, + const char *glyph_data_be, unsigned int klass = 0) const { buffer->cur().props_cache() = klass; /* XXX if has gdef? */ diff --git a/third_party/harfbuzz-ng/src/hb-ot-layout.cc b/third_party/harfbuzz-ng/src/hb-ot-layout.cc index ded3dcc..0621f86 100644 --- a/third_party/harfbuzz-ng/src/hb-ot-layout.cc +++ b/third_party/harfbuzz-ng/src/hb-ot-layout.cc @@ -232,19 +232,19 @@ hb_ot_layout_table_find_script (hb_face_t *face, const GSUBGPOS &g = get_gsubgpos_table (face, table_tag); if (g.find_script_index (script_tag, script_index)) - return TRUE; + return true; /* try finding 'DFLT' */ if (g.find_script_index (HB_OT_TAG_DEFAULT_SCRIPT, script_index)) - return FALSE; + return false; /* try with 'dflt'; MS site has had typos and many fonts use it now :(. * including many versions of DejaVu Sans Mono! */ if (g.find_script_index (HB_OT_TAG_DEFAULT_LANGUAGE, script_index)) - return FALSE; + return false; if (script_index) *script_index = HB_OT_LAYOUT_NO_SCRIPT_INDEX; - return FALSE; + return false; } hb_bool_t @@ -262,7 +262,7 @@ hb_ot_layout_table_choose_script (hb_face_t *face, if (g.find_script_index (*script_tags, script_index)) { if (chosen_script) *chosen_script = *script_tags; - return TRUE; + return true; } script_tags++; } @@ -271,14 +271,14 @@ hb_ot_layout_table_choose_script (hb_face_t *face, if (g.find_script_index (HB_OT_TAG_DEFAULT_SCRIPT, script_index)) { if (chosen_script) *chosen_script = HB_OT_TAG_DEFAULT_SCRIPT; - return FALSE; + return false; } /* try with 'dflt'; MS site has had typos and many fonts use it now :( */ if (g.find_script_index (HB_OT_TAG_DEFAULT_LANGUAGE, script_index)) { if (chosen_script) *chosen_script = HB_OT_TAG_DEFAULT_LANGUAGE; - return FALSE; + return false; } /* try with 'latn'; some old fonts put their features there even though @@ -287,13 +287,13 @@ hb_ot_layout_table_choose_script (hb_face_t *face, if (g.find_script_index (HB_OT_TAG_LATIN_SCRIPT, script_index)) { if (chosen_script) *chosen_script = HB_OT_TAG_LATIN_SCRIPT; - return FALSE; + return false; } if (script_index) *script_index = HB_OT_LAYOUT_NO_SCRIPT_INDEX; if (chosen_script) *chosen_script = HB_OT_LAYOUT_NO_SCRIPT_INDEX; - return FALSE; + return false; } unsigned int @@ -333,14 +333,14 @@ hb_ot_layout_script_find_language (hb_face_t *face, const Script &s = get_gsubgpos_table (face, table_tag).get_script (script_index); if (s.find_lang_sys_index (language_tag, language_index)) - return TRUE; + return true; /* try with 'dflt'; MS site has had typos and many fonts use it now :( */ if (s.find_lang_sys_index (HB_OT_TAG_DEFAULT_LANGUAGE, language_index)) - return FALSE; + return false; if (language_index) *language_index = HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX; - return FALSE; + return false; } hb_bool_t @@ -415,12 +415,12 @@ hb_ot_layout_language_find_feature (hb_face_t *face, if (feature_tag == g.get_feature_tag (f_index)) { if (feature_index) *feature_index = f_index; - return TRUE; + return true; } } if (feature_index) *feature_index = HB_OT_LAYOUT_NO_FEATURE_INDEX; - return FALSE; + return false; } unsigned int diff --git a/third_party/harfbuzz-ng/src/hb-ot-shape-complex-indic.cc b/third_party/harfbuzz-ng/src/hb-ot-shape-complex-indic.cc index 0c5479e..f168fe1 100644 --- a/third_party/harfbuzz-ng/src/hb-ot-shape-complex-indic.cc +++ b/third_party/harfbuzz-ng/src/hb-ot-shape-complex-indic.cc @@ -27,16 +27,44 @@ #include "hb-ot-shape-complex-indic-private.hh" #include "hb-ot-shape-private.hh" -static const struct indic_options_t +struct indic_options_t { - indic_options_t (void) - { - char *c = getenv ("HB_OT_INDIC_OPTIONS"); - uniscribe_bug_compatible = c && strstr (c, "uniscribe-bug-compatible"); + int initialized : 1; + int uniscribe_bug_compatible : 1; +}; + +union indic_options_union_t { + int i; + indic_options_t opts; +}; +ASSERT_STATIC (sizeof (int) == sizeof (indic_options_union_t)); + +static indic_options_union_t +indic_options_init (void) +{ + indic_options_union_t u; + u.i = 0; + u.opts.initialized = 1; + + char *c = getenv ("HB_OT_INDIC_OPTIONS"); + u.opts.uniscribe_bug_compatible = c && strstr (c, "uniscribe-bug-compatible"); + + return u; +} + +inline indic_options_t +indic_options (void) +{ + static indic_options_union_t options; + + if (unlikely (!options.i)) { + /* This is idempotent and threadsafe. */ + options = indic_options_init (); } - bool uniscribe_bug_compatible; -} options; + return options.opts; +} + static int compare_codepoint (const void *pa, const void *pb) @@ -390,7 +418,7 @@ initial_reordering_consonant_syllable (const hb_ot_map_t *map, hb_buffer_t *buff } /* Attach ZWJ, ZWNJ, nukta, and halant to previous char to move with them. */ - if (!options.uniscribe_bug_compatible) + if (!indic_options ().uniscribe_bug_compatible) { /* Please update the Uniscribe branch when touching this! */ for (unsigned int i = start + 1; i < end; i++) @@ -487,7 +515,7 @@ initial_reordering_standalone_cluster (const hb_ot_map_t *map, /* We treat NBSP/dotted-circle as if they are consonants, so we should just chain. * Only if not in compatibility mode that is... */ - if (options.uniscribe_bug_compatible) + if (indic_options ().uniscribe_bug_compatible) { /* For dotted-circle, this is what Uniscribe does: * If dotted-circle is the last glyph, it just does nothing. @@ -617,7 +645,7 @@ final_reordering_syllable (hb_buffer_t *buffer, hb_mask_t *mask_array, REPH_BEFORE_SUBSCRIPT, REPH_AFTER_SUBSCRIPT, REPH_BEFORE_POSTSCRIPT, - REPH_AFTER_POSTSCRIPT, + REPH_AFTER_POSTSCRIPT } reph_pos; /* XXX Figure out old behavior too */ @@ -732,7 +760,7 @@ final_reordering_syllable (hb_buffer_t *buffer, hb_mask_t *mask_array, * Uniscribe doesn't do this. * TEST: U+0930,U+094D,U+0915,U+094B,U+094D */ - if (!options.uniscribe_bug_compatible && + if (!indic_options ().uniscribe_bug_compatible && unlikely (info[new_reph_pos].indic_category() == OT_H)) { for (unsigned int i = base + 1; i < new_reph_pos; i++) if (info[i].indic_category() == OT_M) { @@ -792,7 +820,7 @@ final_reordering_syllable (hb_buffer_t *buffer, hb_mask_t *mask_array, /* Finish off the clusters and go home! */ - if (!options.uniscribe_bug_compatible) + if (!indic_options ().uniscribe_bug_compatible) { /* This is what Uniscribe does. Ie. add cluster boundaries after Halant,ZWNJ. * This means, half forms are submerged into the main consonants cluster. diff --git a/third_party/harfbuzz-ng/src/hb-ot-shape-complex-private.hh b/third_party/harfbuzz-ng/src/hb-ot-shape-complex-private.hh index ba962b5..d2f7959 100644 --- a/third_party/harfbuzz-ng/src/hb-ot-shape-complex-private.hh +++ b/third_party/harfbuzz-ng/src/hb-ot-shape-complex-private.hh @@ -253,7 +253,7 @@ hb_ot_shape_complex_collect_features (hb_ot_complex_shaper_t shaper, * * Called during shape_execute(). * - * Shapers should return TRUE if it prefers decomposed (NFD) input rather than precomposed (NFC). + * Shapers should return true if it prefers decomposed (NFD) input rather than precomposed (NFC). */ typedef hb_ot_shape_normalization_mode_t hb_ot_shape_complex_normalization_preference_func_t (void); diff --git a/third_party/harfbuzz-ng/src/hb-ot-shape-normalize.cc b/third_party/harfbuzz-ng/src/hb-ot-shape-normalize.cc index a9019fb..562ba88 100644 --- a/third_party/harfbuzz-ng/src/hb-ot-shape-normalize.cc +++ b/third_party/harfbuzz-ng/src/hb-ot-shape-normalize.cc @@ -84,7 +84,7 @@ decompose (hb_font_t *font, hb_buffer_t *buffer, if (!hb_unicode_decompose (buffer->unicode, ab, &a, &b) || (b && !hb_font_get_glyph (font, b, 0, &glyph))) - return FALSE; + return false; bool has_a = hb_font_get_glyph (font, a, 0, &glyph); if (shortest && has_a) { @@ -92,23 +92,23 @@ decompose (hb_font_t *font, hb_buffer_t *buffer, output_glyph (buffer, a); if (b) output_glyph (buffer, b); - return TRUE; + return true; } if (decompose (font, buffer, shortest, a)) { if (b) output_glyph (buffer, b); - return TRUE; + return true; } if (has_a) { output_glyph (buffer, a); if (b) output_glyph (buffer, b); - return TRUE; + return true; } - return FALSE; + return false; } static void @@ -149,7 +149,7 @@ decompose_multi_char_cluster (hb_font_t *font, hb_buffer_t *buffer, } while (buffer->idx < end) - decompose_current_glyph (font, buffer, FALSE); + decompose_current_glyph (font, buffer, false); } static int @@ -166,7 +166,7 @@ _hb_ot_shape_normalize (hb_font_t *font, hb_buffer_t *buffer, hb_ot_shape_normalization_mode_t mode) { bool recompose = mode != HB_OT_SHAPE_NORMALIZATION_MODE_DECOMPOSED; - bool has_multichar_clusters = FALSE; + bool has_multichar_clusters = false; unsigned int count; /* We do a fairly straightforward yet custom normalization process in three @@ -191,7 +191,7 @@ _hb_ot_shape_normalize (hb_font_t *font, hb_buffer_t *buffer, decompose_single_char_cluster (font, buffer, recompose); else { decompose_multi_char_cluster (font, buffer, end); - has_multichar_clusters = TRUE; + has_multichar_clusters = true; } } buffer->swap_buffers (); diff --git a/third_party/harfbuzz-ng/src/hb-ot-shape.cc b/third_party/harfbuzz-ng/src/hb-ot-shape.cc index 8b1d670..19cf680 100644 --- a/third_party/harfbuzz-ng/src/hb-ot-shape.cc +++ b/third_party/harfbuzz-ng/src/hb-ot-shape.cc @@ -327,7 +327,7 @@ hb_ot_position_complex (hb_ot_shape_context_t *c) &c->buffer->pos[i].y_offset); } - c->applied_position_complex = TRUE; + c->applied_position_complex = true; } hb_ot_layout_position_finish (c->buffer); @@ -490,7 +490,7 @@ _hb_ot_shape (hb_font_t *font, hb_ot_shape_plan_internal (&plan, font->face, &buffer->props, features, num_features); hb_ot_shape_execute (&plan, font, buffer, features, num_features); - return TRUE; + return true; } diff --git a/third_party/harfbuzz-ng/src/hb-private.hh b/third_party/harfbuzz-ng/src/hb-private.hh index aa86072..0cb049e 100644 --- a/third_party/harfbuzz-ng/src/hb-private.hh +++ b/third_party/harfbuzz-ng/src/hb-private.hh @@ -61,12 +61,6 @@ # define NULL ((void *) 0) #endif -#undef FALSE -#define FALSE 0 - -#undef TRUE -#define TRUE 1 - /* Basics */ @@ -84,11 +78,11 @@ template <typename Type> static inline Type MAX (const Type &a, const Type &b) { #define HB_STMT_START do #define HB_STMT_END while (0) -#define _ASSERT_STATIC1(_line, _cond) typedef int _static_assert_on_line_##_line##_failed[(_cond)?1:-1] -#define _ASSERT_STATIC0(_line, _cond) _ASSERT_STATIC1 (_line, (_cond)) -#define ASSERT_STATIC(_cond) _ASSERT_STATIC0 (__LINE__, (_cond)) +#define _ASSERT_STATIC1(_line, _cond) typedef int _static_assert_on_line_##_line##_failed[(_cond)?1:-1] +#define _ASSERT_STATIC0(_line, _cond) _ASSERT_STATIC1 (_line, (_cond)) +#define ASSERT_STATIC(_cond) _ASSERT_STATIC0 (__LINE__, (_cond)) -#define ASSERT_STATIC_EXPR(_cond) ((void) sizeof (char[(_cond) ? 1 : -1])) +#define ASSERT_STATIC_EXPR(_cond)((void) sizeof (char[(_cond) ? 1 : -1])) #define ASSERT_STATIC_EXPR_ZERO(_cond) (0 * sizeof (char[(_cond) ? 1 : -1])) #define _PASTE1(a,b) a##b @@ -110,6 +104,34 @@ ASSERT_STATIC (sizeof (hb_position_t) == 4); ASSERT_STATIC (sizeof (hb_mask_t) == 4); ASSERT_STATIC (sizeof (hb_var_int_t) == 4); + +/* We like our types POD */ + +#define _ASSERT_TYPE_POD1(_line, _type) union _type_##_type##_on_line_##_line##_is_not_POD { _type instance; } +#define _ASSERT_TYPE_POD0(_line, _type) _ASSERT_TYPE_POD1 (_line, _type) +#define ASSERT_TYPE_POD(_type) _ASSERT_TYPE_POD0 (__LINE__, _type) + +#ifdef __GNUC__ +# define _ASSERT_INSTANCE_POD1(_line, _instance) \ + HB_STMT_START { \ + typedef __typeof__(_instance) _type_##_line; \ + _ASSERT_TYPE_POD1 (_line, _type_##_line); \ + } HB_STMT_END +#else +# define _ASSERT_INSTANCE_POD1(_line, _instance) typedef int _assertion_on_line_##_line##_not_tested +#endif +# define _ASSERT_INSTANCE_POD0(_line, _instance) _ASSERT_INSTANCE_POD1 (_line, _instance) +# define ASSERT_INSTANCE_POD(_instance) _ASSERT_INSTANCE_POD0 (__LINE__, _instance) + +/* Check _assertion in a method environment */ +#define _ASSERT_POD1(_line) \ + inline void _static_assertion_on_line_##_line (void) const \ + { _ASSERT_INSTANCE_POD1 (_line, *this); /* Make sure it's POD. */ } +# define _ASSERT_POD0(_line) _ASSERT_POD1 (_line) +# define ASSERT_POD() _ASSERT_POD0 (__LINE__) + + + /* Misc */ @@ -239,15 +261,16 @@ typedef int (*hb_compare_func_t) (const void *, const void *); /* arrays and maps */ +#define HB_PREALLOCED_ARRAY_INIT {0} template <typename Type, unsigned int StaticSize> -struct hb_prealloced_array_t { - +struct hb_prealloced_array_t +{ unsigned int len; unsigned int allocated; Type *array; Type static_array[StaticSize]; - hb_prealloced_array_t (void) { memset (this, 0, sizeof (*this)); } + void init (void) { memset (this, 0, sizeof (*this)); } inline Type& operator [] (unsigned int i) { return array[i]; } inline const Type& operator [] (unsigned int i) const { return array[i]; } @@ -342,14 +365,14 @@ struct hb_prealloced_array_t { } }; -template <typename Type> -struct hb_array_t : hb_prealloced_array_t<Type, 2> {}; - +#define HB_LOCKABLE_SET_INIT {HB_PREALLOCED_ARRAY_INIT} template <typename item_t, typename lock_t> struct hb_lockable_set_t { - hb_array_t <item_t> items; + hb_prealloced_array_t <item_t, 2> items; + + inline void init (void) { items.init (); } template <typename T> inline item_t *replace_or_insert (T v, lock_t &l, bool replace) @@ -600,9 +623,9 @@ _hb_debug_msg<0> (const char *what HB_UNUSED, const char *message HB_UNUSED, ...) {} -#define DEBUG_MSG_LEVEL(WHAT, OBJ, LEVEL, LEVEL_DIR, ...) _hb_debug_msg<HB_DEBUG_##WHAT> (#WHAT, (OBJ), NULL, TRUE, (LEVEL), (LEVEL_DIR), __VA_ARGS__) -#define DEBUG_MSG(WHAT, OBJ, ...) _hb_debug_msg<HB_DEBUG_##WHAT> (#WHAT, (OBJ), NULL, FALSE, 0, 0, __VA_ARGS__) -#define DEBUG_MSG_FUNC(WHAT, OBJ, ...) _hb_debug_msg<HB_DEBUG_##WHAT> (#WHAT, (OBJ), HB_FUNC, FALSE, 0, 0, __VA_ARGS__) +#define DEBUG_MSG_LEVEL(WHAT, OBJ, LEVEL, LEVEL_DIR, ...) _hb_debug_msg<HB_DEBUG_##WHAT> (#WHAT, (OBJ), NULL, true, (LEVEL), (LEVEL_DIR), __VA_ARGS__) +#define DEBUG_MSG(WHAT, OBJ, ...) _hb_debug_msg<HB_DEBUG_##WHAT> (#WHAT, (OBJ), NULL, false, 0, 0, __VA_ARGS__) +#define DEBUG_MSG_FUNC(WHAT, OBJ, ...) _hb_debug_msg<HB_DEBUG_##WHAT> (#WHAT, (OBJ), HB_FUNC, false, 0, 0, __VA_ARGS__) /* @@ -622,14 +645,14 @@ struct hb_auto_trace_t { va_list ap; va_start (ap, message); - _hb_debug_msg_va<max_level> (what, obj, func, TRUE, plevel ? *plevel : 0, +1, message, ap); + _hb_debug_msg_va<max_level> (what, obj, func, true, plevel ? *plevel : 0, +1, message, ap); va_end (ap); } inline ~hb_auto_trace_t (void) { if (unlikely (!returned)) { fprintf (stderr, "OUCH, returned with no call to TRACE_RETURN. This is a bug, please report. Level was %d.\n", plevel ? *plevel : -1); - _hb_debug_msg<max_level> (what, obj, NULL, TRUE, plevel ? *plevel : 1, -1, " "); + _hb_debug_msg<max_level> (what, obj, NULL, true, plevel ? *plevel : 1, -1, " "); return; } @@ -643,7 +666,7 @@ struct hb_auto_trace_t { return v; } - _hb_debug_msg<max_level> (what, obj, NULL, TRUE, plevel ? *plevel : 1, -1, "return %s", v ? "true" : "false"); + _hb_debug_msg<max_level> (what, obj, NULL, true, plevel ? *plevel : 1, -1, "return %s", v ? "true" : "false"); if (plevel) --*plevel; plevel = NULL; returned = true; diff --git a/third_party/harfbuzz-ng/src/hb-set-private.hh b/third_party/harfbuzz-ng/src/hb-set-private.hh index 9d8ba4a..5cdf8a0 100644 --- a/third_party/harfbuzz-ng/src/hb-set-private.hh +++ b/third_party/harfbuzz-ng/src/hb-set-private.hh @@ -36,7 +36,11 @@ struct _hb_set_t { + hb_object_header_t header; + ASSERT_POD (); + inline void init (void) { + header.init (); clear (); } inline void fini (void) { @@ -157,7 +161,6 @@ struct _hb_set_t elt_t elt (hb_codepoint_t g) const { return elts[g >> SHIFT]; } elt_t mask (hb_codepoint_t g) const { return elt_t (1) << (g & MASK); } - hb_object_header_t header; elt_t elts[ELTS]; /* XXX 8kb */ ASSERT_STATIC (sizeof (elt_t) * 8 == BITS); diff --git a/third_party/harfbuzz-ng/src/hb-set.cc b/third_party/harfbuzz-ng/src/hb-set.cc index 5045386..4225e3c 100644 --- a/third_party/harfbuzz-ng/src/hb-set.cc +++ b/third_party/harfbuzz-ng/src/hb-set.cc @@ -30,12 +30,6 @@ /* Public API */ -static hb_set_t _hb_set_nil = { - HB_OBJECT_HEADER_STATIC, - - {0} /* elts */ -}; - hb_set_t * hb_set_create () @@ -43,7 +37,7 @@ hb_set_create () hb_set_t *set; if (!(set = hb_object_create<hb_set_t> ())) - return &_hb_set_nil; + return hb_set_get_empty (); set->clear (); @@ -53,7 +47,13 @@ hb_set_create () hb_set_t * hb_set_get_empty (void) { - return &_hb_set_nil; + static const hb_set_t _hb_set_nil = { + HB_OBJECT_HEADER_STATIC, + + {0} /* elts */ + }; + + return const_cast<hb_set_t *> (&_hb_set_nil); } hb_set_t * @@ -93,7 +93,7 @@ hb_set_get_user_data (hb_set_t *set, hb_bool_t hb_set_allocation_successful (hb_set_t *set HB_UNUSED) { - return TRUE; + return true; } void diff --git a/third_party/harfbuzz-ng/src/hb-set.h b/third_party/harfbuzz-ng/src/hb-set.h index 97e68e4..9f849cf 100644 --- a/third_party/harfbuzz-ng/src/hb-set.h +++ b/third_party/harfbuzz-ng/src/hb-set.h @@ -63,7 +63,7 @@ hb_set_get_user_data (hb_set_t *set, hb_user_data_key_t *key); -/* Returns FALSE if allocation has failed before */ +/* Returns false if allocation has failed before */ hb_bool_t hb_set_allocation_successful (hb_set_t *set); diff --git a/third_party/harfbuzz-ng/src/hb-shape.cc b/third_party/harfbuzz-ng/src/hb-shape.cc index d97028e..56c9046 100644 --- a/third_party/harfbuzz-ng/src/hb-shape.cc +++ b/third_party/harfbuzz-ng/src/hb-shape.cc @@ -47,10 +47,10 @@ typedef hb_bool_t (*hb_shape_func_t) (hb_font_t *font, unsigned int num_features); #define HB_SHAPER_IMPLEMENT(name) {#name, _hb_##name##_shape} -static struct hb_shaper_pair_t { +static const struct hb_shaper_pair_t { char name[16]; hb_shape_func_t func; -} shapers[] = { +} all_shapers[] = { /* v--- Add new shapers in the right place here */ #ifdef HAVE_GRAPHITE HB_SHAPER_IMPLEMENT (graphite2), @@ -65,55 +65,120 @@ static struct hb_shaper_pair_t { }; #undef HB_SHAPER_IMPLEMENT -static struct static_shaper_list_t + +/* Thread-safe, lock-free, shapers */ + +static hb_shaper_pair_t *static_shapers; + +static +void free_static_shapers (void) +{ + if (unlikely (static_shapers != all_shapers)) + free (static_shapers); +} + +static const hb_shaper_pair_t * +get_shapers (void) { - static_shaper_list_t (void) +retry: + hb_shaper_pair_t *shapers = (hb_shaper_pair_t *) hb_atomic_ptr_get (&static_shapers); + + if (unlikely (!shapers)) { char *env = getenv ("HB_SHAPER_LIST"); - if (env && *env) - { - /* Reorder shaper list to prefer requested shaper list. */ - unsigned int i = 0; - char *end, *p = env; - for (;;) { - end = strchr (p, ','); - if (!end) - end = p + strlen (p); - - for (unsigned int j = i; j < ARRAY_LENGTH (shapers); j++) - if (end - p == (int) strlen (shapers[j].name) && - 0 == strncmp (shapers[j].name, p, end - p)) - { - /* Reorder this shaper to position i */ - struct hb_shaper_pair_t t = shapers[j]; - memmove (&shapers[i + 1], &shapers[i], sizeof (shapers[i]) * (j - i)); - shapers[i] = t; - i++; - } - - if (!*end) - break; - else - p = end + 1; - } + if (!env || !*env) { + (void) hb_atomic_ptr_cmpexch (&static_shapers, NULL, (const hb_shaper_pair_t *) all_shapers); + return (const hb_shaper_pair_t *) all_shapers; } - ASSERT_STATIC ((ARRAY_LENGTH (shapers) + 1) * sizeof (*shaper_list) <= sizeof (shaper_list)); - unsigned int i; - for (i = 0; i < ARRAY_LENGTH (shapers); i++) - shaper_list[i] = shapers[i].name; - shaper_list[i] = NULL; + /* Not found; allocate one. */ + shapers = (hb_shaper_pair_t *) malloc (sizeof (all_shapers)); + if (unlikely (!shapers)) + return (const hb_shaper_pair_t *) all_shapers; + memcpy (shapers, all_shapers, sizeof (all_shapers)); + + /* Reorder shaper list to prefer requested shapers. */ + unsigned int i = 0; + char *end, *p = env; + for (;;) { + end = strchr (p, ','); + if (!end) + end = p + strlen (p); + + for (unsigned int j = i; j < ARRAY_LENGTH (all_shapers); j++) + if (end - p == (int) strlen (shapers[j].name) && + 0 == strncmp (shapers[j].name, p, end - p)) + { + /* Reorder this shaper to position i */ + struct hb_shaper_pair_t t = shapers[j]; + memmove (&shapers[i + 1], &shapers[i], sizeof (shapers[i]) * (j - i)); + shapers[i] = t; + i++; + } + + if (!*end) + break; + else + p = end + 1; + } + + if (!hb_atomic_ptr_cmpexch (&static_shapers, NULL, shapers)) { + free (shapers); + goto retry; + } + +#ifdef HAVE_ATEXIT + atexit (free_static_shapers); /* First person registers atexit() callback. */ +#endif } - const char *shaper_list[ARRAY_LENGTH (shapers) + 1]; -} static_shaper_list; + return shapers; +} + + +static const char **static_shaper_list; + +static +void free_static_shaper_list (void) +{ + free (static_shaper_list); +} const char ** hb_shape_list_shapers (void) { - return static_shaper_list.shaper_list; +retry: + const char **shaper_list = (const char **) hb_atomic_ptr_get (&static_shaper_list); + + if (unlikely (!shaper_list)) + { + /* Not found; allocate one. */ + shaper_list = (const char **) calloc (1 + ARRAY_LENGTH (all_shapers), sizeof (const char *)); + if (unlikely (!shaper_list)) { + static const char *nil_shaper_list[] = {NULL}; + return nil_shaper_list; + } + + const hb_shaper_pair_t *shapers = get_shapers (); + unsigned int i; + for (i = 0; i < ARRAY_LENGTH (all_shapers); i++) + shaper_list[i] = shapers[i].name; + shaper_list[i] = NULL; + + if (!hb_atomic_ptr_cmpexch (&static_shaper_list, NULL, shaper_list)) { + free (shaper_list); + goto retry; + } + +#ifdef HAVE_ATEXIT + atexit (free_static_shaper_list); /* First person registers atexit() callback. */ +#endif + } + + return shaper_list; } + hb_bool_t hb_shape_full (hb_font_t *font, hb_buffer_t *buffer, @@ -124,21 +189,22 @@ hb_shape_full (hb_font_t *font, hb_font_make_immutable (font); /* So we can safely cache stuff on it */ if (likely (!shaper_list)) { - for (unsigned int i = 0; i < ARRAY_LENGTH (shapers); i++) + const hb_shaper_pair_t *shapers = get_shapers (); + for (unsigned int i = 0; i < ARRAY_LENGTH (all_shapers); i++) if (likely (shapers[i].func (font, buffer, features, num_features))) - return TRUE; + return true; } else { while (*shaper_list) { - for (unsigned int i = 0; i < ARRAY_LENGTH (shapers); i++) - if (0 == strcmp (*shaper_list, shapers[i].name)) { - if (likely (shapers[i].func (font, buffer, features, num_features))) - return TRUE; + for (unsigned int i = 0; i < ARRAY_LENGTH (all_shapers); i++) + if (0 == strcmp (*shaper_list, all_shapers[i].name)) { + if (likely (all_shapers[i].func (font, buffer, features, num_features))) + return true; break; } shaper_list++; } } - return FALSE; + return false; } void diff --git a/third_party/harfbuzz-ng/src/hb-tt-font.cc b/third_party/harfbuzz-ng/src/hb-tt-font.cc index b2f24f6..0055ae9 100644 --- a/third_party/harfbuzz-ng/src/hb-tt-font.cc +++ b/third_party/harfbuzz-ng/src/hb-tt-font.cc @@ -88,7 +88,7 @@ hb_font_get_glyph_nil (hb_font_t *font HB_UNUSED, return hb_font_get_glyph (font->parent, unicode, variation_selector, glyph); *glyph = 0; - return FALSE; + return false; } static hb_position_t @@ -133,7 +133,7 @@ hb_font_get_glyph_h_origin_nil (hb_font_t *font HB_UNUSED, } *x = *y = 0; - return FALSE; + return false; } static hb_bool_t @@ -154,7 +154,7 @@ hb_font_get_glyph_v_origin_nil (hb_font_t *font HB_UNUSED, } *x = *y = 0; - return FALSE; + return false; } static hb_position_t @@ -202,7 +202,7 @@ hb_font_get_glyph_extents_nil (hb_font_t *font HB_UNUSED, } memset (extents, 0, sizeof (*extents)); - return FALSE; + return false; } static hb_bool_t @@ -224,14 +224,14 @@ hb_font_get_glyph_contour_point_nil (hb_font_t *font HB_UNUSED, } *x = *y = 0; - return FALSE; + return false; } static hb_font_funcs_t _hb_font_funcs_nil = { HB_OBJECT_HEADER_STATIC, - TRUE, /* immutable */ + true, /* immutable */ { #define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_nil, diff --git a/third_party/harfbuzz-ng/src/hb-unicode-private.hh b/third_party/harfbuzz-ng/src/hb-unicode-private.hh index ddba1ac..8a34174 100644 --- a/third_party/harfbuzz-ng/src/hb-unicode-private.hh +++ b/third_party/harfbuzz-ng/src/hb-unicode-private.hh @@ -63,6 +63,7 @@ struct _hb_unicode_funcs_t { hb_object_header_t header; + ASSERT_POD (); hb_unicode_funcs_t *parent; @@ -91,14 +92,13 @@ struct _hb_unicode_funcs_t { #ifdef HAVE_GLIB -extern HB_INTERNAL hb_unicode_funcs_t _hb_glib_unicode_funcs; +extern HB_INTERNAL const hb_unicode_funcs_t _hb_glib_unicode_funcs; #define _hb_unicode_funcs_default _hb_glib_unicode_funcs #elif defined(HAVE_ICU) -extern HB_INTERNAL hb_unicode_funcs_t _hb_icu_unicode_funcs; +extern HB_INTERNAL const hb_unicode_funcs_t _hb_icu_unicode_funcs; #define _hb_unicode_funcs_default _hb_icu_unicode_funcs #else #define HB_UNICODE_FUNCS_NIL 1 -extern HB_INTERNAL hb_unicode_funcs_t _hb_unicode_funcs_nil; #define _hb_unicode_funcs_default _hb_unicode_funcs_nil #endif diff --git a/third_party/harfbuzz-ng/src/hb-unicode.cc b/third_party/harfbuzz-ng/src/hb-unicode.cc index f2fbebb..1d6eacb 100644 --- a/third_party/harfbuzz-ng/src/hb-unicode.cc +++ b/third_party/harfbuzz-ng/src/hb-unicode.cc @@ -85,7 +85,7 @@ hb_unicode_compose_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED, hb_codepoint_t *ab HB_UNUSED, void *user_data HB_UNUSED) { - return FALSE; + return false; } static hb_bool_t @@ -95,27 +95,15 @@ hb_unicode_decompose_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED, hb_codepoint_t *b HB_UNUSED, void *user_data HB_UNUSED) { - return FALSE; + return false; } -hb_unicode_funcs_t _hb_unicode_funcs_nil = { - HB_OBJECT_HEADER_STATIC, - - NULL, /* parent */ - TRUE, /* immutable */ - { -#define HB_UNICODE_FUNC_IMPLEMENT(name) hb_unicode_##name##_nil, - HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS -#undef HB_UNICODE_FUNC_IMPLEMENT - } -}; - hb_unicode_funcs_t * hb_unicode_funcs_get_default (void) { - return &_hb_unicode_funcs_default; + return const_cast<hb_unicode_funcs_t *> (&_hb_unicode_funcs_default); } hb_unicode_funcs_t * @@ -124,10 +112,10 @@ hb_unicode_funcs_create (hb_unicode_funcs_t *parent) hb_unicode_funcs_t *ufuncs; if (!(ufuncs = hb_object_create<hb_unicode_funcs_t> ())) - return &_hb_unicode_funcs_nil; + return hb_unicode_funcs_get_empty (); if (!parent) - parent = &_hb_unicode_funcs_nil; + parent = hb_unicode_funcs_get_empty (); hb_unicode_funcs_make_immutable (parent); ufuncs->parent = hb_unicode_funcs_reference (parent); @@ -142,10 +130,24 @@ hb_unicode_funcs_create (hb_unicode_funcs_t *parent) return ufuncs; } + +extern HB_INTERNAL const hb_unicode_funcs_t _hb_unicode_funcs_nil; +const hb_unicode_funcs_t _hb_unicode_funcs_nil = { + HB_OBJECT_HEADER_STATIC, + + NULL, /* parent */ + true, /* immutable */ + { +#define HB_UNICODE_FUNC_IMPLEMENT(name) hb_unicode_##name##_nil, + HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS +#undef HB_UNICODE_FUNC_IMPLEMENT + } +}; + hb_unicode_funcs_t * hb_unicode_funcs_get_empty (void) { - return &_hb_unicode_funcs_nil; + return const_cast<hb_unicode_funcs_t *> (&_hb_unicode_funcs_nil); } hb_unicode_funcs_t * @@ -193,7 +195,7 @@ hb_unicode_funcs_make_immutable (hb_unicode_funcs_t *ufuncs) if (hb_object_is_inert (ufuncs)) return; - ufuncs->immutable = TRUE; + ufuncs->immutable = true; } hb_bool_t @@ -205,7 +207,7 @@ hb_unicode_funcs_is_immutable (hb_unicode_funcs_t *ufuncs) hb_unicode_funcs_t * hb_unicode_funcs_get_parent (hb_unicode_funcs_t *ufuncs) { - return ufuncs->parent ? ufuncs->parent : &_hb_unicode_funcs_nil; + return ufuncs->parent ? ufuncs->parent : hb_unicode_funcs_get_empty (); } diff --git a/third_party/harfbuzz-ng/src/hb-uniscribe.cc b/third_party/harfbuzz-ng/src/hb-uniscribe.cc index 584d641..9f84a3c 100644 --- a/third_party/harfbuzz-ng/src/hb-uniscribe.cc +++ b/third_party/harfbuzz-ng/src/hb-uniscribe.cc @@ -77,18 +77,18 @@ populate_log_font (LOGFONTW *lf, if (unlikely (!len)) { DEBUG_MSG (UNISCRIBE, NULL, "Didn't find English name table entry"); - return FALSE; + return false; } if (unlikely (len >= LF_FACESIZE)) { DEBUG_MSG (UNISCRIBE, NULL, "Font name too long"); - return FALSE; + return false; } for (unsigned int i = 0; i < len; i++) lf->lfFaceName[i] = hb_be_uint16 (lf->lfFaceName[i]); lf->lfFaceName[len] = 0; - return TRUE; + return true; } @@ -133,7 +133,7 @@ _hb_uniscribe_face_get_data (hb_face_t *face) if (unlikely (!hb_face_set_user_data (face, &hb_uniscribe_data_key, data, (hb_destroy_func_t) _hb_uniscribe_face_data_destroy, - FALSE))) + false))) { _hb_uniscribe_face_data_destroy (data); data = (hb_uniscribe_face_data_t *) hb_face_get_user_data (face, &hb_uniscribe_data_key); @@ -190,7 +190,7 @@ _hb_uniscribe_font_get_data (hb_font_t *font) if (unlikely (!hb_font_set_user_data (font, &hb_uniscribe_data_key, data, (hb_destroy_func_t) _hb_uniscribe_font_data_destroy, - FALSE))) + false))) { _hb_uniscribe_font_data_destroy (data); data = (hb_uniscribe_font_data_t *) hb_font_get_user_data (font, &hb_uniscribe_data_key); @@ -233,7 +233,7 @@ _hb_uniscribe_shape (hb_font_t *font, #define FAIL(...) \ HB_STMT_START { \ DEBUG_MSG (UNISCRIBE, NULL, __VA_ARGS__); \ - return FALSE; \ + return false; \ } HB_STMT_END; hb_uniscribe_face_data_t *face_data = _hb_uniscribe_face_get_data (font->face); @@ -245,7 +245,7 @@ _hb_uniscribe_shape (hb_font_t *font, FAIL ("Couldn't get font font"); if (unlikely (!buffer->len)) - return TRUE; + return true; HRESULT hr; @@ -305,7 +305,7 @@ retry: int item_count; /* MinGW32 doesn't define fMergeNeutralItems, so we bruteforce */ - //bidi_control.fMergeNeutralItems = TRUE; + //bidi_control.fMergeNeutralItems = true; *(uint32_t*)&bidi_control |= 1<<24; bidi_state.uBidiLevel = HB_DIRECTION_IS_FORWARD (buffer->props.direction) ? 0 : 1; @@ -459,7 +459,7 @@ retry: } /* Wow, done! */ - return TRUE; + return true; } diff --git a/third_party/harfbuzz-ng/src/hb-warning.cc b/third_party/harfbuzz-ng/src/hb-warning.cc index c13731b..4f1f65f 100644 --- a/third_party/harfbuzz-ng/src/hb-warning.cc +++ b/third_party/harfbuzz-ng/src/hb-warning.cc @@ -28,23 +28,23 @@ #include "hb-mutex-private.hh" -#if !defined(HB_NO_MT) && defined(HB_ATOMIC_INT_NIL) +#if defined(HB_ATOMIC_INT_NIL) #ifdef _MSC_VER -#pragma message("Could not find any system to define atomic_int macros, library will NOT be thread-safe") +#pragma message("Could not find any system to define atomic_int macros, library may NOT be thread-safe") #else -#warning "Could not find any system to define atomic_int macros, library will NOT be thread-safe" +#warning "Could not find any system to define atomic_int macros, library may NOT be thread-safe" #endif #endif -#if !defined(HB_NO_MT) && defined(HB_MUTEX_IMPL_NIL) +#if defined(HB_MUTEX_IMPL_NIL) #ifdef _MSC_VER -#pragma message("Could not find any system to define mutex macros, library will NOT be thread-safe") +#pragma message("Could not find any system to define mutex macros, library may NOT be thread-safe") #else -#warning "Could not find any system to define mutex macros, library will NOT be thread-safe" +#warning "Could not find any system to define mutex macros, library may NOT be thread-safe" #endif #endif -#if !defined(HB_NO_MT) && (defined(HB_ATOMIC_INT_NIL) || defined(HB_MUTEX_IMPL_NIL)) +#if defined(HB_ATOMIC_INT_NIL) || defined(HB_MUTEX_IMPL_NIL) #ifdef _MSC_VER #pragma message("To suppress these warnings, define HB_NO_MT") #else diff --git a/third_party/harfbuzz-ng/src/indic.cc b/third_party/harfbuzz-ng/src/indic.cc index e00311d..3b44076 100644 --- a/third_party/harfbuzz-ng/src/indic.cc +++ b/third_party/harfbuzz-ng/src/indic.cc @@ -41,6 +41,6 @@ main (void) hb_codepoint_t a, b; if (!hb_unicode_decompose (funcs, u, &a, &b)) - printf ("U+%04X\n", u); + printf ("U+%04X %x %x\n", u, category, position); } } diff --git a/third_party/harfbuzz-ng/src/main.cc b/third_party/harfbuzz-ng/src/main.cc index 03b6e6c..07d3d69 100644 --- a/third_party/harfbuzz-ng/src/main.cc +++ b/third_party/harfbuzz-ng/src/main.cc @@ -49,7 +49,7 @@ main (int argc, char **argv) int len = 0; #ifdef HAVE_GLIB - GMappedFile *mf = g_mapped_file_new (argv[1], FALSE, NULL); + GMappedFile *mf = g_mapped_file_new (argv[1], false, NULL); font_data = g_mapped_file_get_contents (mf); len = g_mapped_file_get_length (mf); #else |