diff options
author | Youngbok Shin <youngb.shin@samsung.com> | 2016-08-22 11:23:44 +0900 |
---|---|---|
committer | Youngbok Shin <youngb.shin@samsung.com> | 2016-08-22 11:23:44 +0900 |
commit | e684182ac634596bace621b0e84dfc98d2bc82c5 (patch) | |
tree | e6ce432188d6fe2b0b4bee6ddad34e7977c26a44 /src/hb-private.hh | |
parent | 087e8c5d58be057cb77192932cd7fa8f7aacf1a5 (diff) | |
download | harfbuzz-e684182ac634596bace621b0e84dfc98d2bc82c5.tar.gz harfbuzz-e684182ac634596bace621b0e84dfc98d2bc82c5.tar.bz2 harfbuzz-e684182ac634596bace621b0e84dfc98d2bc82c5.zip |
Revert "Imported Upstream version 1.2.7"
This reverts commit 087e8c5d58be057cb77192932cd7fa8f7aacf1a5.
Diffstat (limited to 'src/hb-private.hh')
-rw-r--r-- | src/hb-private.hh | 167 |
1 files changed, 43 insertions, 124 deletions
diff --git a/src/hb-private.hh b/src/hb-private.hh index d58a695..06b24a8 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -54,23 +54,6 @@ #include <stdarg.h> -/* Compile-time custom allocator support. */ - -#if defined(hb_malloc_impl) \ - && defined(hb_calloc_impl) \ - && defined(hb_realloc_impl) \ - && defined(hb_free_impl) -extern "C" void* hb_malloc_impl(size_t size); -extern "C" void* hb_calloc_impl(size_t nmemb, size_t size); -extern "C" void* hb_realloc_impl(void *ptr, size_t size); -extern "C" void hb_free_impl(void *ptr); -#define malloc hb_malloc_impl -#define calloc hb_calloc_impl -#define realloc hb_realloc_impl -#define free hb_free_impl -#endif - - /* Compiler attributes */ @@ -119,36 +102,6 @@ extern "C" void hb_free_impl(void *ptr); #define HB_FUNC __func__ #endif -/* - * Borrowed from https://bugzilla.mozilla.org/show_bug.cgi?id=1215411 - * HB_FALLTHROUGH is an annotation to suppress compiler warnings about switch - * cases that fall through without a break or return statement. HB_FALLTHROUGH - * is only needed on cases that have code: - * - * switch (foo) { - * case 1: // These cases have no code. No fallthrough annotations are needed. - * case 2: - * case 3: - * foo = 4; // This case has code, so a fallthrough annotation is needed: - * HB_FALLTHROUGH; - * default: - * return foo; - * } - */ -#if defined(__clang__) && __cplusplus >= 201103L - /* clang's fallthrough annotations are only available starting in C++11. */ -# define HB_FALLTHROUGH [[clang::fallthrough]] -#elif defined(_MSC_VER) - /* - * MSVC's __fallthrough annotations are checked by /analyze (Code Analysis): - * https://msdn.microsoft.com/en-us/library/ms235402%28VS.80%29.aspx - */ -# include <sal.h> -# define HB_FALLTHROUGH __fallthrough -#else -# define HB_FALLTHROUGH /* FALLTHROUGH */ -#endif - #if defined(_WIN32) || defined(__CYGWIN__) /* We need Windows Vista for both Uniscribe backend and for * MemoryBarrier. We don't support compiling on Windows XP, @@ -168,20 +121,15 @@ extern "C" void hb_free_impl(void *ptr); # if defined(_WIN32_WCE) /* Some things not defined on Windows CE. */ -# define strdup _strdup -# define vsnprintf _vsnprintf # define getenv(Name) NULL -# if _WIN32_WCE < 0x800 -# define setlocale(Category, Locale) "C" +# define setlocale(Category, Locale) "C" static int errno = 0; /* Use something better? */ -# endif # elif defined(WINAPI_FAMILY) && (WINAPI_FAMILY==WINAPI_FAMILY_PC_APP || WINAPI_FAMILY==WINAPI_FAMILY_PHONE_APP) # define getenv(Name) NULL # endif -# if defined(_MSC_VER) && _MSC_VER < 1900 +# if (defined(__WIN32__) && !defined(__WINE__)) || defined(_MSC_VER) # define snprintf _snprintf -# elif defined(_MSC_VER) && _MSC_VER >= 1900 -# /* Covers VC++ Error for strdup being a deprecated POSIX name and to instead use _strdup instead */ + /* Windows CE only has _strdup, while rest of Windows has both. */ # define strdup _strdup # endif #endif @@ -244,9 +192,8 @@ static inline unsigned int ARRAY_LENGTH (const Type (&)[n]) { return n; } #define _ASSERT_STATIC0(_line, _cond) _ASSERT_STATIC1 (_line, (_cond)) #define ASSERT_STATIC(_cond) _ASSERT_STATIC0 (__LINE__, (_cond)) -template <unsigned int cond> class hb_assert_constant_t {}; - -#define ASSERT_STATIC_EXPR_ZERO(_cond) (0 * (unsigned int) sizeof (hb_assert_constant_t<_cond>)) +#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 #define PASTE(a,b) _PASTE1(a,b) @@ -299,8 +246,8 @@ ASSERT_STATIC (sizeof (hb_var_int_t) == 4); /* Void! */ struct _hb_void_t {}; -typedef const _hb_void_t *hb_void_t; -#define HB_VOID ((const _hb_void_t *) NULL) +typedef const _hb_void_t &hb_void_t; +#define HB_VOID (* (const _hb_void_t *) NULL) /* Return the number of 1 bits in mask. */ static inline HB_CONST_FUNC unsigned int @@ -612,15 +559,6 @@ static inline unsigned char TOLOWER (unsigned char c) /* Debug */ -/* HB_NDEBUG disables some sanity checks that are very safe to disable and - * should be disabled in production systems. If NDEBUG is defined, enable - * HB_NDEBUG; but if it's desirable that normal assert()s (which are very - * light-weight) to be enabled, then HB_DEBUG can be defined to disable - * the costlier checks. */ -#ifdef NDEBUG -#define HB_NDEBUG -#endif - #ifndef HB_DEBUG #define HB_DEBUG 0 #endif @@ -800,7 +738,7 @@ template <typename T> static inline void _hb_warn_no_return (bool returned) { if (unlikely (!returned)) { - fprintf (stderr, "OUCH, returned with no call to return_trace(). This is a bug, please report.\n"); + fprintf (stderr, "OUCH, returned with no call to TRACE_RETURN. This is a bug, please report.\n"); } } template <> @@ -835,7 +773,7 @@ struct hb_auto_trace_t { inline ret_t ret (ret_t v, unsigned int line = 0) { if (unlikely (returned)) { - fprintf (stderr, "OUCH, double calls to return_trace(). This is a bug, please report.\n"); + fprintf (stderr, "OUCH, double calls to TRACE_RETURN. This is a bug, please report.\n"); return v; } @@ -866,7 +804,7 @@ struct hb_auto_trace_t<0, ret_t> { inline ret_t ret (ret_t v, unsigned int line HB_UNUSED = 0) { return v; } }; -#define return_trace(RET) return trace.ret (RET, __LINE__) +#define TRACE_RETURN(RET) trace.ret (RET, __LINE__) /* Misc */ @@ -904,68 +842,51 @@ hb_in_ranges (T u, T lo1, T hi1, T lo2, T hi2, T lo3, T hi3) } -/* Enable bitwise ops on enums marked as flags_t */ -/* To my surprise, looks like the function resolver is happy to silently cast - * one enum to another... So this doesn't provide the type-checking that I - * originally had in mind... :(. - * - * For MSVC warnings, see: https://github.com/behdad/harfbuzz/pull/163 - */ -#ifdef _MSC_VER -# pragma warning(disable:4200) -# pragma warning(disable:4800) -#endif -#define HB_MARK_AS_FLAG_T(T) \ - extern "C++" { \ - static inline T operator | (T l, T r) { return T ((unsigned) l | (unsigned) r); } \ - static inline T operator & (T l, T r) { return T ((unsigned) l & (unsigned) r); } \ - static inline T operator ^ (T l, T r) { return T ((unsigned) l ^ (unsigned) r); } \ - static inline T operator ~ (T r) { return T (~(unsigned int) r); } \ - static inline T& operator |= (T &l, T r) { l = l | r; return l; } \ - static inline T& operator &= (T& l, T r) { l = l & r; return l; } \ - static inline T& operator ^= (T& l, T r) { l = l ^ r; return l; } \ - } - - /* Useful for set-operations on small enums. * For example, for testing "x ∈ {x1, x2, x3}" use: - * (FLAG_SAFE(x) & (FLAG(x1) | FLAG(x2) | FLAG(x3))) + * (FLAG(x) & (FLAG(x1) | FLAG(x2) | FLAG(x3))) */ -#define FLAG(x) (ASSERT_STATIC_EXPR_ZERO ((x) < 32) + (1U << (x))) -#define FLAG_SAFE(x) (1U << (x)) -#define FLAG_UNSAFE(x) ((x) < 32 ? FLAG_SAFE(x) : 0) +#define FLAG(x) (1<<(x)) #define FLAG_RANGE(x,y) (ASSERT_STATIC_EXPR_ZERO ((x) < (y)) + FLAG(y+1) - FLAG(x)) template <typename T, typename T2> static inline void -hb_stable_sort (T *array, unsigned int len, int(*compar)(const T *, const T *), T2 *array2) +hb_bubble_sort (T *array, unsigned int len, int(*compar)(const T *, const T *), T2 *array2) { - for (unsigned int i = 1; i < len; i++) - { - unsigned int j = i; - while (j && compar (&array[j - 1], &array[i]) > 0) - j--; - if (i == j) - continue; - /* Move item i to occupy place for item j, shift what's in between. */ - { - T t = array[i]; - memmove (&array[j + 1], &array[j], (i - j) * sizeof (T)); - array[j] = t; - } - if (array2) - { - T2 t = array2[i]; - memmove (&array2[j + 1], &array2[j], (i - j) * sizeof (T2)); - array2[j] = t; - } - } + if (unlikely (!len)) + return; + + unsigned int k = len - 1; + do { + unsigned int new_k = 0; + + for (unsigned int j = 0; j < k; j++) + if (compar (&array[j], &array[j+1]) > 0) + { + { + T t; + t = array[j]; + array[j] = array[j + 1]; + array[j + 1] = t; + } + if (array2) + { + T2 t; + t = array2[j]; + array2[j] = array2[j + 1]; + array2[j + 1] = t; + } + + new_k = j; + } + k = new_k; + } while (k); } template <typename T> static inline void -hb_stable_sort (T *array, unsigned int len, int(*compar)(const T *, const T *)) +hb_bubble_sort (T *array, unsigned int len, int(*compar)(const T *, const T *)) { - hb_stable_sort (array, len, compar, (int *) NULL); + hb_bubble_sort (array, len, compar, (int *) NULL); } static inline hb_bool_t @@ -1015,7 +936,5 @@ hb_options (void) return _hb_options.opts; } -/* Size signifying variable-sized array */ -#define VAR 1 #endif /* HB_PRIVATE_HH */ |