Behdad Esfahbod | 64aef3a | 2008-01-23 16:14:38 -0500 | [diff] [blame] | 1 | /* |
Behdad Esfahbod | 2409d5f | 2011-04-21 17:14:28 -0400 | [diff] [blame] | 2 | * Copyright © 2007,2008,2009 Red Hat, Inc. |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 3 | * Copyright © 2011,2012 Google, Inc. |
Behdad Esfahbod | 64aef3a | 2008-01-23 16:14:38 -0500 | [diff] [blame] | 4 | * |
Behdad Esfahbod | c755cb3 | 2010-04-22 00:11:43 -0400 | [diff] [blame] | 5 | * This is part of HarfBuzz, a text shaping library. |
Behdad Esfahbod | 64aef3a | 2008-01-23 16:14:38 -0500 | [diff] [blame] | 6 | * |
| 7 | * Permission is hereby granted, without written agreement and without |
| 8 | * license or royalty fees, to use, copy, modify, and distribute this |
| 9 | * software and its documentation for any purpose, provided that the |
| 10 | * above copyright notice and the following two paragraphs appear in |
| 11 | * all copies of this software. |
| 12 | * |
| 13 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR |
| 14 | * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
| 15 | * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN |
| 16 | * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
| 17 | * DAMAGE. |
| 18 | * |
| 19 | * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
| 20 | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 21 | * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |
| 22 | * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO |
| 23 | * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 24 | * |
| 25 | * Red Hat Author(s): Behdad Esfahbod |
Behdad Esfahbod | 2409d5f | 2011-04-21 17:14:28 -0400 | [diff] [blame] | 26 | * Google Author(s): Behdad Esfahbod |
Behdad Esfahbod | 64aef3a | 2008-01-23 16:14:38 -0500 | [diff] [blame] | 27 | */ |
| 28 | |
Behdad Esfahbod | c77ae40 | 2018-08-25 22:36:36 -0700 | [diff] [blame] | 29 | #ifndef HB_HH |
| 30 | #define HB_HH |
Behdad Esfahbod | 5b3f770 | 2006-12-28 06:42:37 -0500 | [diff] [blame] | 31 | |
Behdad Esfahbod | d6c5473 | 2019-01-17 15:22:46 -0500 | [diff] [blame] | 32 | #ifndef HB_NO_DIAGNOSTIC_PRAGMAS |
Behdad Esfahbod | 1077e40 | 2019-01-17 18:36:10 -0500 | [diff] [blame^] | 33 | /* Rules: |
| 34 | * - We set all pragmas under GCC, even clang-specific ones. Clang |
| 35 | * still reads them. |
| 36 | * - Within each category, keep sorted. |
| 37 | */ |
| 38 | /* Setup */ |
| 39 | #pragma GCC diagnostic ignored "-Wpragmas" // Must be first |
Behdad Esfahbod | a9946b7 | 2019-01-17 15:22:28 -0500 | [diff] [blame] | 40 | #pragma GCC diagnostic warning "-Wall" |
| 41 | #pragma GCC diagnostic warning "-Wextra" |
Behdad Esfahbod | 1077e40 | 2019-01-17 18:36:10 -0500 | [diff] [blame^] | 42 | //#pragma GCC diagnostic warning "-Weverything" |
| 43 | /* Error */ |
| 44 | #pragma GCC diagnostic error "-Wcast-align" |
| 45 | #pragma GCC diagnostic error "-Wunused" |
| 46 | /* Warning */ |
| 47 | /* Ignored */ |
| 48 | #pragma GCC diagnostic ignored "-Wconversion" // TODO fix |
Behdad Esfahbod | a9946b7 | 2019-01-17 15:22:28 -0500 | [diff] [blame] | 49 | #pragma GCC diagnostic ignored "-Wmissing-field-initializers" |
Behdad Esfahbod | 1077e40 | 2019-01-17 18:36:10 -0500 | [diff] [blame^] | 50 | #pragma GCC diagnostic ignored "-Wpacked" // Erratic impl in clang |
| 51 | #pragma GCC diagnostic ignored "-Wshadow" // TODO fix |
| 52 | #pragma GCC diagnostic ignored "-Wstrict-aliasing" |
Behdad Esfahbod | 14a560a | 2019-01-17 17:42:44 -0500 | [diff] [blame] | 53 | #pragma GCC diagnostic ignored "-Wtype-limits" |
Behdad Esfahbod | a9946b7 | 2019-01-17 15:22:28 -0500 | [diff] [blame] | 54 | #pragma GCC diagnostic ignored "-Wunused-parameter" // TODO Fix |
Behdad Esfahbod | 868b0c0 | 2019-01-17 15:08:36 -0500 | [diff] [blame] | 55 | #endif |
| 56 | |
Behdad Esfahbod | 5ddd9cc | 2011-09-16 16:40:44 -0400 | [diff] [blame] | 57 | #ifdef HAVE_CONFIG_H |
Behdad Esfahbod | df66028 | 2009-08-01 20:46:02 -0400 | [diff] [blame] | 58 | #include "config.h" |
| 59 | #endif |
Behdad Esfahbod | 12360f7 | 2008-01-23 15:50:38 -0500 | [diff] [blame] | 60 | |
Behdad Esfahbod | 49334f9 | 2018-12-17 18:27:36 -0500 | [diff] [blame] | 61 | /* |
| 62 | * Following added based on what AC_USE_SYSTEM_EXTENSIONS adds to |
| 63 | * config.h.in. Copied here for the convenience of those embedding |
| 64 | * HarfBuzz and not using our build system. |
| 65 | */ |
| 66 | /* Enable extensions on AIX 3, Interix. */ |
| 67 | #ifndef _ALL_SOURCE |
| 68 | # define _ALL_SOURCE 1 |
| 69 | #endif |
| 70 | /* Enable GNU extensions on systems that have them. */ |
| 71 | #ifndef _GNU_SOURCE |
| 72 | # define _GNU_SOURCE 1 |
| 73 | #endif |
| 74 | /* Enable threading extensions on Solaris. */ |
| 75 | #ifndef _POSIX_PTHREAD_SEMANTICS |
| 76 | # define _POSIX_PTHREAD_SEMANTICS 1 |
| 77 | #endif |
| 78 | /* Enable extensions on HP NonStop. */ |
| 79 | #ifndef _TANDEM_SOURCE |
| 80 | # define _TANDEM_SOURCE 1 |
| 81 | #endif |
| 82 | /* Enable general extensions on Solaris. */ |
| 83 | #ifndef __EXTENSIONS__ |
| 84 | # define __EXTENSIONS__ 1 |
| 85 | #endif |
| 86 | |
Chun-wei Fan | 8e4ad1d | 2018-07-25 18:12:34 +0800 | [diff] [blame] | 87 | #if defined (_MSC_VER) && defined (HB_DLL_EXPORT) |
| 88 | #define HB_EXTERN __declspec (dllexport) extern |
| 89 | #endif |
| 90 | |
Behdad Esfahbod | d1c9eb4 | 2012-04-12 13:17:44 -0400 | [diff] [blame] | 91 | #include "hb.h" |
Behdad Esfahbod | d1c9eb4 | 2012-04-12 13:17:44 -0400 | [diff] [blame] | 92 | #define HB_H_IN |
Behdad Esfahbod | 3e32cd9 | 2012-04-23 13:20:52 -0400 | [diff] [blame] | 93 | #include "hb-ot.h" |
Behdad Esfahbod | d1c9eb4 | 2012-04-12 13:17:44 -0400 | [diff] [blame] | 94 | #define HB_OT_H_IN |
Behdad Esfahbod | b206133 | 2018-11-23 14:05:11 -0500 | [diff] [blame] | 95 | #include "hb-aat.h" |
| 96 | #define HB_AAT_H_IN |
Behdad Esfahbod | b28815c | 2009-08-04 22:35:36 -0400 | [diff] [blame] | 97 | |
Ebrahim Byagowi | a8726cb | 2018-11-17 14:23:11 +0330 | [diff] [blame] | 98 | #include "hb-aat.h" |
| 99 | |
Behdad Esfahbod | 7cdd6ab | 2018-01-10 04:33:08 +0100 | [diff] [blame] | 100 | #include <math.h> |
Behdad Esfahbod | c7d457a | 2009-05-21 12:46:29 -0400 | [diff] [blame] | 101 | #include <stdlib.h> |
Behdad Esfahbod | b65c060 | 2011-07-28 16:48:43 -0400 | [diff] [blame] | 102 | #include <stddef.h> |
Behdad Esfahbod | f0954d1 | 2009-07-30 15:33:57 -0400 | [diff] [blame] | 103 | #include <string.h> |
| 104 | #include <assert.h> |
Behdad Esfahbod | 7acb389 | 2009-08-05 15:20:34 -0400 | [diff] [blame] | 105 | #include <errno.h> |
Behdad Esfahbod | 40ec3bb | 2017-11-03 16:57:30 -0400 | [diff] [blame] | 106 | #include <stdio.h> |
Behdad Esfahbod | cc06c24 | 2011-07-25 20:25:44 -0400 | [diff] [blame] | 107 | #include <stdarg.h> |
Behdad Esfahbod | c7d457a | 2009-05-21 12:46:29 -0400 | [diff] [blame] | 108 | |
Tor Andersson | 8f4c123 | 2018-04-13 23:01:54 +0430 | [diff] [blame] | 109 | #if (defined(_MSC_VER) && _MSC_VER >= 1500) || defined(__MINGW32__) |
Arkady Shapkin | 6c10328 | 2018-02-15 23:17:46 +0300 | [diff] [blame] | 110 | #include <intrin.h> |
| 111 | #endif |
Behdad Esfahbod | acdba3f | 2010-07-23 15:11:18 -0400 | [diff] [blame] | 112 | |
Behdad Esfahbod | 2a74968 | 2017-10-26 19:48:33 -0600 | [diff] [blame] | 113 | #define HB_PASTE1(a,b) a##b |
| 114 | #define HB_PASTE(a,b) HB_PASTE1(a,b) |
| 115 | |
Behdad Esfahbod | 83ea277 | 2018-07-10 13:17:27 +0200 | [diff] [blame] | 116 | |
Behdad Esfahbod | 52b4185 | 2015-10-03 13:20:55 +0100 | [diff] [blame] | 117 | /* Compile-time custom allocator support. */ |
| 118 | |
| 119 | #if defined(hb_malloc_impl) \ |
| 120 | && defined(hb_calloc_impl) \ |
| 121 | && defined(hb_realloc_impl) \ |
| 122 | && defined(hb_free_impl) |
Behdad Esfahbod | cc6ea30 | 2015-10-12 17:21:52 -0400 | [diff] [blame] | 123 | extern "C" void* hb_malloc_impl(size_t size); |
| 124 | extern "C" void* hb_calloc_impl(size_t nmemb, size_t size); |
| 125 | extern "C" void* hb_realloc_impl(void *ptr, size_t size); |
| 126 | extern "C" void hb_free_impl(void *ptr); |
Behdad Esfahbod | 52b4185 | 2015-10-03 13:20:55 +0100 | [diff] [blame] | 127 | #define malloc hb_malloc_impl |
| 128 | #define calloc hb_calloc_impl |
| 129 | #define realloc hb_realloc_impl |
| 130 | #define free hb_free_impl |
Behdad Esfahbod | 83ea277 | 2018-07-10 13:17:27 +0200 | [diff] [blame] | 131 | |
Behdad Esfahbod | 763f878 | 2018-07-10 13:47:41 +0200 | [diff] [blame] | 132 | #if defined(hb_memalign_impl) |
Behdad Esfahbod | 83ea277 | 2018-07-10 13:17:27 +0200 | [diff] [blame] | 133 | extern "C" int hb_memalign_impl(void **memptr, size_t alignment, size_t size); |
| 134 | #define posix_memalign hb_memalign_impl |
| 135 | #else |
| 136 | #undef HAVE_POSIX_MEMALIGN |
| 137 | #endif |
| 138 | |
Behdad Esfahbod | 52b4185 | 2015-10-03 13:20:55 +0100 | [diff] [blame] | 139 | #endif |
| 140 | |
| 141 | |
Behdad Esfahbod | 2aae617 | 2018-07-11 17:27:23 +0200 | [diff] [blame] | 142 | /* |
| 143 | * Compiler attributes |
Behdad Esfahbod | 37be774 | 2018-08-06 04:51:38 -0700 | [diff] [blame] | 144 | */ |
Behdad Esfahbod | 292c100 | 2018-07-10 13:16:52 +0200 | [diff] [blame] | 145 | |
Behdad Esfahbod | 76dcbf8 | 2017-10-15 11:24:35 +0200 | [diff] [blame] | 146 | #if __cplusplus < 201103L |
| 147 | |
Behdad Esfahbod | 62e312e | 2017-10-27 09:29:20 -0600 | [diff] [blame] | 148 | #ifndef nullptr |
| 149 | #define nullptr NULL |
| 150 | #endif |
Behdad Esfahbod | 76dcbf8 | 2017-10-15 11:24:35 +0200 | [diff] [blame] | 151 | |
Behdad Esfahbod | bca8361 | 2018-07-10 12:58:13 +0200 | [diff] [blame] | 152 | #ifndef constexpr |
| 153 | #define constexpr const |
| 154 | #endif |
| 155 | |
Behdad Esfahbod | 76dcbf8 | 2017-10-15 11:24:35 +0200 | [diff] [blame] | 156 | #ifndef static_assert |
Behdad Esfahbod | 606bf57 | 2018-09-16 19:33:48 +0200 | [diff] [blame] | 157 | #define static_assert(e, msg) \ |
Behdad Esfahbod | 6f08b12 | 2017-10-26 18:23:03 -0600 | [diff] [blame] | 158 | HB_UNUSED typedef int HB_PASTE(static_assertion_failed_at_line_, __LINE__) [(e) ? 1 : -1] |
Behdad Esfahbod | 76dcbf8 | 2017-10-15 11:24:35 +0200 | [diff] [blame] | 159 | #endif // static_assert |
| 160 | |
Behdad Esfahbod | f83e992 | 2018-05-24 11:46:57 -0700 | [diff] [blame] | 161 | #ifdef __GNUC__ |
| 162 | #if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 8)) |
| 163 | #define thread_local __thread |
| 164 | #endif |
| 165 | #else |
| 166 | #define thread_local |
| 167 | #endif |
| 168 | |
Behdad Esfahbod | 2aae617 | 2018-07-11 17:27:23 +0200 | [diff] [blame] | 169 | template <typename T> |
| 170 | struct _hb_alignof |
| 171 | { |
| 172 | struct s |
| 173 | { |
| 174 | char c; |
| 175 | T t; |
| 176 | }; |
| 177 | static constexpr size_t value = offsetof (s, t); |
| 178 | }; |
Behdad Esfahbod | bca8361 | 2018-07-10 12:58:13 +0200 | [diff] [blame] | 179 | #ifndef alignof |
Behdad Esfahbod | 27c5317 | 2018-07-10 13:03:42 +0200 | [diff] [blame] | 180 | #define alignof(x) (_hb_alignof<x>::value) |
Behdad Esfahbod | 37be774 | 2018-08-06 04:51:38 -0700 | [diff] [blame] | 181 | #endif |
Behdad Esfahbod | bca8361 | 2018-07-10 12:58:13 +0200 | [diff] [blame] | 182 | |
Behdad Esfahbod | f9a3eab | 2018-08-12 12:21:56 -0700 | [diff] [blame] | 183 | /* https://github.com/harfbuzz/harfbuzz/issues/1127 */ |
| 184 | #ifndef explicit_operator |
Behdad Esfahbod | 01d06e3 | 2018-12-16 14:27:43 -0500 | [diff] [blame] | 185 | #define explicit_operator operator |
Behdad Esfahbod | f9a3eab | 2018-08-12 12:21:56 -0700 | [diff] [blame] | 186 | #endif |
| 187 | |
| 188 | #else /* __cplusplus >= 201103L */ |
| 189 | |
| 190 | /* https://github.com/harfbuzz/harfbuzz/issues/1127 */ |
| 191 | #ifndef explicit_operator |
Behdad Esfahbod | 01d06e3 | 2018-12-16 14:27:43 -0500 | [diff] [blame] | 192 | #define explicit_operator explicit operator |
Behdad Esfahbod | f9a3eab | 2018-08-12 12:21:56 -0700 | [diff] [blame] | 193 | #endif |
| 194 | |
| 195 | #endif /* __cplusplus < 201103L */ |
| 196 | |
Behdad Esfahbod | 76dcbf8 | 2017-10-15 11:24:35 +0200 | [diff] [blame] | 197 | |
Ebrahim Byagowi | 76c4873 | 2017-06-02 21:53:10 +0430 | [diff] [blame] | 198 | #if (defined(__GNUC__) || defined(__clang__)) && defined(__OPTIMIZE__) |
| 199 | #define likely(expr) (__builtin_expect (!!(expr), 1)) |
| 200 | #define unlikely(expr) (__builtin_expect (!!(expr), 0)) |
Behdad Esfahbod | ae2b854 | 2014-06-03 16:59:09 -0400 | [diff] [blame] | 201 | #else |
| 202 | #define likely(expr) (expr) |
| 203 | #define unlikely(expr) (expr) |
Behdad Esfahbod | bc20045 | 2010-04-29 01:40:26 -0400 | [diff] [blame] | 204 | #endif |
| 205 | |
Steve Lhomme | 0b8f3ab | 2016-07-11 21:57:26 +0200 | [diff] [blame] | 206 | #if !defined(__GNUC__) && !defined(__clang__) |
Behdad Esfahbod | ae2b854 | 2014-06-03 16:59:09 -0400 | [diff] [blame] | 207 | #undef __attribute__ |
| 208 | #define __attribute__(x) |
| 209 | #endif |
Behdad Esfahbod | a794ebf | 2009-08-06 12:32:35 -0400 | [diff] [blame] | 210 | |
Behdad Esfahbod | ae2b854 | 2014-06-03 16:59:09 -0400 | [diff] [blame] | 211 | #if __GNUC__ >= 3 |
| 212 | #define HB_PURE_FUNC __attribute__((pure)) |
| 213 | #define HB_CONST_FUNC __attribute__((const)) |
| 214 | #define HB_PRINTF_FUNC(format_idx, arg_idx) __attribute__((__format__ (__printf__, format_idx, arg_idx))) |
| 215 | #else |
| 216 | #define HB_PURE_FUNC |
| 217 | #define HB_CONST_FUNC |
| 218 | #define HB_PRINTF_FUNC(format_idx, arg_idx) |
| 219 | #endif |
| 220 | #if __GNUC__ >= 4 |
| 221 | #define HB_UNUSED __attribute__((unused)) |
Behdad Esfahbod | be59f3c | 2017-12-05 09:01:28 -0800 | [diff] [blame] | 222 | #elif defined(_MSC_VER) /* https://github.com/harfbuzz/harfbuzz/issues/635 */ |
| 223 | #define HB_UNUSED __pragma(warning(suppress: 4100 4101)) |
Behdad Esfahbod | ae2b854 | 2014-06-03 16:59:09 -0400 | [diff] [blame] | 224 | #else |
| 225 | #define HB_UNUSED |
| 226 | #endif |
| 227 | |
| 228 | #ifndef HB_INTERNAL |
Behdad Esfahbod | 90d1c74 | 2018-02-11 19:08:59 -0800 | [diff] [blame] | 229 | # if !defined(HB_NO_VISIBILITY) && !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(_MSC_VER) && !defined(__SUNPRO_CC) |
Behdad Esfahbod | ae2b854 | 2014-06-03 16:59:09 -0400 | [diff] [blame] | 230 | # define HB_INTERNAL __attribute__((__visibility__("hidden"))) |
Behdad Esfahbod | 94759d4 | 2018-07-23 15:01:39 -0700 | [diff] [blame] | 231 | # elif defined(__MINGW32__) |
Chun-wei Fan | 8e4ad1d | 2018-07-25 18:12:34 +0800 | [diff] [blame] | 232 | /* We use -export-symbols on mingw32, since it does not support visibility attributes. */ |
| 233 | # define HB_INTERNAL |
| 234 | # elif defined (_MSC_VER) && defined (HB_DLL_EXPORT) |
| 235 | /* We do not try to export internal symbols on Visual Studio */ |
Behdad Esfahbod | 94759d4 | 2018-07-23 15:01:39 -0700 | [diff] [blame] | 236 | # define HB_INTERNAL |
| 237 | #else |
Behdad Esfahbod | ae2b854 | 2014-06-03 16:59:09 -0400 | [diff] [blame] | 238 | # define HB_INTERNAL |
Behdad Esfahbod | b87cbe2 | 2018-02-07 14:11:26 -0500 | [diff] [blame] | 239 | # define HB_NO_VISIBILITY 1 |
Behdad Esfahbod | ae2b854 | 2014-06-03 16:59:09 -0400 | [diff] [blame] | 240 | # endif |
| 241 | #endif |
| 242 | |
Behdad Esfahbod | ae2b854 | 2014-06-03 16:59:09 -0400 | [diff] [blame] | 243 | #if __GNUC__ >= 3 |
| 244 | #define HB_FUNC __PRETTY_FUNCTION__ |
| 245 | #elif defined(_MSC_VER) |
| 246 | #define HB_FUNC __FUNCSIG__ |
| 247 | #else |
| 248 | #define HB_FUNC __func__ |
| 249 | #endif |
| 250 | |
prrace | 498e437 | 2018-06-09 16:04:28 -0700 | [diff] [blame] | 251 | #if defined(__SUNPRO_CC) && (__SUNPRO_CC < 0x5140) |
Behdad Esfahbod | 8cef3a6 | 2018-02-09 16:04:23 -0600 | [diff] [blame] | 252 | /* https://github.com/harfbuzz/harfbuzz/issues/630 */ |
| 253 | #define __restrict |
| 254 | #endif |
| 255 | |
Behdad Esfahbod | 305d2fb | 2015-10-21 11:04:28 -0200 | [diff] [blame] | 256 | /* |
| 257 | * Borrowed from https://bugzilla.mozilla.org/show_bug.cgi?id=1215411 |
| 258 | * HB_FALLTHROUGH is an annotation to suppress compiler warnings about switch |
| 259 | * cases that fall through without a break or return statement. HB_FALLTHROUGH |
| 260 | * is only needed on cases that have code: |
| 261 | * |
| 262 | * switch (foo) { |
| 263 | * case 1: // These cases have no code. No fallthrough annotations are needed. |
| 264 | * case 2: |
| 265 | * case 3: |
| 266 | * foo = 4; // This case has code, so a fallthrough annotation is needed: |
| 267 | * HB_FALLTHROUGH; |
| 268 | * default: |
| 269 | * return foo; |
| 270 | * } |
| 271 | */ |
| 272 | #if defined(__clang__) && __cplusplus >= 201103L |
| 273 | /* clang's fallthrough annotations are only available starting in C++11. */ |
| 274 | # define HB_FALLTHROUGH [[clang::fallthrough]] |
Behdad Esfahbod | f41b921 | 2018-02-05 19:51:09 -0500 | [diff] [blame] | 275 | #elif __GNUC__ >= 7 |
| 276 | /* GNU fallthrough attribute is available from GCC7 */ |
| 277 | # define HB_FALLTHROUGH __attribute__((fallthrough)) |
Behdad Esfahbod | 305d2fb | 2015-10-21 11:04:28 -0200 | [diff] [blame] | 278 | #elif defined(_MSC_VER) |
| 279 | /* |
| 280 | * MSVC's __fallthrough annotations are checked by /analyze (Code Analysis): |
| 281 | * https://msdn.microsoft.com/en-us/library/ms235402%28VS.80%29.aspx |
| 282 | */ |
| 283 | # include <sal.h> |
| 284 | # define HB_FALLTHROUGH __fallthrough |
| 285 | #else |
| 286 | # define HB_FALLTHROUGH /* FALLTHROUGH */ |
| 287 | #endif |
| 288 | |
Behdad Esfahbod | 62376a7 | 2018-10-14 15:20:50 -0700 | [diff] [blame] | 289 | #if defined(__clang__) |
| 290 | /* Disable certain sanitizer errors. */ |
| 291 | /* https://github.com/harfbuzz/harfbuzz/issues/1247 */ |
| 292 | #define HB_NO_SANITIZE_SIGNED_INTEGER_OVERFLOW __attribute__((no_sanitize("signed-integer-overflow"))) |
| 293 | #else |
| 294 | #define HB_NO_SANITIZE_SIGNED_INTEGER_OVERFLOW |
| 295 | #endif |
| 296 | |
| 297 | |
Ken Brown | eee5b5e | 2018-11-12 21:05:39 -0500 | [diff] [blame] | 298 | #ifdef _WIN32 |
Behdad Esfahbod | db30828 | 2014-07-19 16:32:04 -0400 | [diff] [blame] | 299 | /* We need Windows Vista for both Uniscribe backend and for |
| 300 | * MemoryBarrier. We don't support compiling on Windows XP, |
| 301 | * though we run on it fine. */ |
| 302 | # if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0600 |
| 303 | # undef _WIN32_WINNT |
| 304 | # endif |
| 305 | # ifndef _WIN32_WINNT |
Matt Oliver | 24dd6c1 | 2018-09-23 18:08:30 +1000 | [diff] [blame] | 306 | # if !defined(WINAPI_FAMILY) || !(WINAPI_FAMILY==WINAPI_FAMILY_PC_APP || WINAPI_FAMILY==WINAPI_FAMILY_PHONE_APP) |
| 307 | # define _WIN32_WINNT 0x0600 |
| 308 | # endif |
Behdad Esfahbod | db30828 | 2014-07-19 16:32:04 -0400 | [diff] [blame] | 309 | # endif |
Behdad Esfahbod | 270971a | 2014-08-15 14:28:04 -0400 | [diff] [blame] | 310 | # ifndef WIN32_LEAN_AND_MEAN |
| 311 | # define WIN32_LEAN_AND_MEAN 1 |
| 312 | # endif |
| 313 | # ifndef STRICT |
| 314 | # define STRICT 1 |
| 315 | # endif |
Behdad Esfahbod | dabe698 | 2012-11-23 14:21:35 -0500 | [diff] [blame] | 316 | |
Konstantin Ritt | f3537b6 | 2015-01-25 09:50:51 +0400 | [diff] [blame] | 317 | # if defined(_WIN32_WCE) |
| 318 | /* Some things not defined on Windows CE. */ |
Konstantin Ritt | 5069062 | 2016-04-26 12:02:26 +0400 | [diff] [blame] | 319 | # define vsnprintf _vsnprintf |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 320 | # define getenv(Name) nullptr |
Konstantin Ritt | 855a5d7 | 2015-04-10 17:18:01 +0400 | [diff] [blame] | 321 | # if _WIN32_WCE < 0x800 |
| 322 | # define setlocale(Category, Locale) "C" |
Behdad Esfahbod | 26a963b | 2014-08-10 18:04:50 -0400 | [diff] [blame] | 323 | static int errno = 0; /* Use something better? */ |
Konstantin Ritt | 855a5d7 | 2015-04-10 17:18:01 +0400 | [diff] [blame] | 324 | # endif |
Konstantin Ritt | f3537b6 | 2015-01-25 09:50:51 +0400 | [diff] [blame] | 325 | # elif defined(WINAPI_FAMILY) && (WINAPI_FAMILY==WINAPI_FAMILY_PC_APP || WINAPI_FAMILY==WINAPI_FAMILY_PHONE_APP) |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 326 | # define getenv(Name) nullptr |
Konstantin Ritt | f3537b6 | 2015-01-25 09:50:51 +0400 | [diff] [blame] | 327 | # endif |
Behdad Esfahbod | ce01ad7 | 2015-04-01 11:05:59 -0700 | [diff] [blame] | 328 | # if defined(_MSC_VER) && _MSC_VER < 1900 |
Konstantin Ritt | f3537b6 | 2015-01-25 09:50:51 +0400 | [diff] [blame] | 329 | # define snprintf _snprintf |
Konstantin Ritt | f3537b6 | 2015-01-25 09:50:51 +0400 | [diff] [blame] | 330 | # endif |
Behdad Esfahbod | 26a963b | 2014-08-10 18:04:50 -0400 | [diff] [blame] | 331 | #endif |
| 332 | |
Behdad Esfahbod | b89c7fd | 2018-11-21 12:32:48 -0500 | [diff] [blame] | 333 | #if defined(HAVE_ATEXIT) && !defined(HB_USE_ATEXIT) |
Behdad Esfahbod | 38fb30d | 2014-08-06 13:34:49 -0400 | [diff] [blame] | 334 | /* atexit() is only safe to be called from shared libraries on certain |
| 335 | * platforms. Whitelist. |
| 336 | * https://bugs.freedesktop.org/show_bug.cgi?id=82246 */ |
| 337 | # if defined(__linux) && defined(__GLIBC_PREREQ) |
| 338 | # if __GLIBC_PREREQ(2,3) |
| 339 | /* From atexit() manpage, it's safe with glibc 2.2.3 on Linux. */ |
| 340 | # define HB_USE_ATEXIT 1 |
| 341 | # endif |
| 342 | # elif defined(_MSC_VER) || defined(__MINGW32__) |
| 343 | /* For MSVC: |
Ebrahim Byagowi | f24b0b9 | 2018-04-12 13:40:45 +0430 | [diff] [blame] | 344 | * https://msdn.microsoft.com/en-us/library/tze57ck3.aspx |
| 345 | * https://msdn.microsoft.com/en-us/library/zk17ww08.aspx |
Behdad Esfahbod | 38fb30d | 2014-08-06 13:34:49 -0400 | [diff] [blame] | 346 | * mingw32 headers say atexit is safe to use in shared libraries. |
| 347 | */ |
| 348 | # define HB_USE_ATEXIT 1 |
Ebrahim Byagowi | 632713b | 2018-04-12 14:17:03 +0430 | [diff] [blame] | 349 | # elif defined(__ANDROID__) |
| 350 | /* This is available since Android NKD r8 or r8b: |
| 351 | * https://issuetracker.google.com/code/p/android/issues/detail?id=6455 |
Behdad Esfahbod | 38fb30d | 2014-08-06 13:34:49 -0400 | [diff] [blame] | 352 | */ |
| 353 | # define HB_USE_ATEXIT 1 |
Bruce Mitchener | e8859fc | 2018-02-04 01:26:57 +0700 | [diff] [blame] | 354 | # elif defined(__APPLE__) |
| 355 | /* For macOS and related platforms, the atexit man page indicates |
| 356 | * that it will be invoked when the library is unloaded, not only |
| 357 | * at application exit. |
| 358 | */ |
| 359 | # define HB_USE_ATEXIT 1 |
Behdad Esfahbod | 38fb30d | 2014-08-06 13:34:49 -0400 | [diff] [blame] | 360 | # endif |
| 361 | #endif |
Behdad Esfahbod | c14b24f | 2018-03-26 10:44:54 -0700 | [diff] [blame] | 362 | #ifdef HB_NO_ATEXIT |
| 363 | # undef HB_USE_ATEXIT |
| 364 | #endif |
Behdad Esfahbod | b89c7fd | 2018-11-21 12:32:48 -0500 | [diff] [blame] | 365 | #ifndef HB_USE_ATEXIT |
| 366 | # define HB_USE_ATEXIT 0 |
| 367 | #endif |
Behdad Esfahbod | dabe698 | 2012-11-23 14:21:35 -0500 | [diff] [blame] | 368 | |
Behdad Esfahbod | 35a7383 | 2009-08-01 19:30:31 -0400 | [diff] [blame] | 369 | #define HB_STMT_START do |
| 370 | #define HB_STMT_END while (0) |
Behdad Esfahbod | 5b3f770 | 2006-12-28 06:42:37 -0500 | [diff] [blame] | 371 | |
Behdad Esfahbod | 19e0091 | 2018-08-06 04:54:31 -0700 | [diff] [blame] | 372 | /* Static-assert as expression. */ |
Behdad Esfahbod | 76dcbf8 | 2017-10-15 11:24:35 +0200 | [diff] [blame] | 373 | template <unsigned int cond> class hb_assert_constant_t; |
| 374 | template <> class hb_assert_constant_t<1> {}; |
Behdad Esfahbod | 672ca3b | 2015-10-26 14:05:05 -0700 | [diff] [blame] | 375 | #define ASSERT_STATIC_EXPR_ZERO(_cond) (0 * (unsigned int) sizeof (hb_assert_constant_t<_cond>)) |
Behdad Esfahbod | dcb7026 | 2011-04-21 16:34:22 -0400 | [diff] [blame] | 376 | |
Behdad Esfahbod | 6fd5364 | 2011-04-11 11:47:14 -0400 | [diff] [blame] | 377 | /* Lets assert int types. Saves trouble down the road. */ |
Behdad Esfahbod | 606bf57 | 2018-09-16 19:33:48 +0200 | [diff] [blame] | 378 | static_assert ((sizeof (int8_t) == 1), ""); |
| 379 | static_assert ((sizeof (uint8_t) == 1), ""); |
| 380 | static_assert ((sizeof (int16_t) == 2), ""); |
| 381 | static_assert ((sizeof (uint16_t) == 2), ""); |
| 382 | static_assert ((sizeof (int32_t) == 4), ""); |
| 383 | static_assert ((sizeof (uint32_t) == 4), ""); |
| 384 | static_assert ((sizeof (int64_t) == 8), ""); |
| 385 | static_assert ((sizeof (uint64_t) == 8), ""); |
| 386 | static_assert ((sizeof (hb_codepoint_t) == 4), ""); |
| 387 | static_assert ((sizeof (hb_position_t) == 4), ""); |
| 388 | static_assert ((sizeof (hb_mask_t) == 4), ""); |
| 389 | static_assert ((sizeof (hb_var_int_t) == 4), ""); |
Behdad Esfahbod | 6fd5364 | 2011-04-11 11:47:14 -0400 | [diff] [blame] | 390 | |
Behdad Esfahbod | a00a63b | 2012-06-06 03:07:01 -0400 | [diff] [blame] | 391 | |
Behdad Esfahbod | c7c5df9 | 2018-10-29 15:16:52 -0700 | [diff] [blame] | 392 | #if __cplusplus >= 201103L |
| 393 | |
Behdad Esfahbod | 67a22f3 | 2018-10-29 17:37:41 -0700 | [diff] [blame] | 394 | /* We only enable these with C++11 or later, since earlier language |
| 395 | * does not allow structs with constructors in unions, and we need |
| 396 | * those. */ |
| 397 | |
| 398 | #define HB_NO_COPY_ASSIGN(TypeName) \ |
| 399 | TypeName(const TypeName&); \ |
| 400 | void operator=(const TypeName&) |
Behdad Esfahbod | fa333e3 | 2018-12-27 17:56:22 -0500 | [diff] [blame] | 401 | #define HB_NO_COPY_ASSIGN_TEMPLATE(TypeName, T) \ |
| 402 | TypeName(const TypeName<T>&); \ |
| 403 | void operator=(const TypeName<T>&) |
Behdad Esfahbod | 67a22f3 | 2018-10-29 17:37:41 -0700 | [diff] [blame] | 404 | #define HB_NO_COPY_ASSIGN_TEMPLATE2(TypeName, T1, T2) \ |
| 405 | TypeName(const TypeName<T1, T2>&); \ |
| 406 | void operator=(const TypeName<T1, T2>&) |
Behdad Esfahbod | ea0e51d | 2018-10-29 16:00:23 -0700 | [diff] [blame] | 407 | #define HB_NO_CREATE_COPY_ASSIGN(TypeName) \ |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 408 | TypeName(); \ |
Behdad Esfahbod | fb07d1a | 2018-06-01 17:32:07 -0700 | [diff] [blame] | 409 | TypeName(const TypeName&); \ |
| 410 | void operator=(const TypeName&) |
Behdad Esfahbod | ea0e51d | 2018-10-29 16:00:23 -0700 | [diff] [blame] | 411 | #define HB_NO_CREATE_COPY_ASSIGN_TEMPLATE(TypeName, T) \ |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 412 | TypeName(); \ |
Behdad Esfahbod | a256a92 | 2018-10-29 11:25:35 -0700 | [diff] [blame] | 413 | TypeName(const TypeName<T>&); \ |
| 414 | void operator=(const TypeName<T>&) |
Behdad Esfahbod | ea0e51d | 2018-10-29 16:00:23 -0700 | [diff] [blame] | 415 | #define HB_NO_CREATE_COPY_ASSIGN_TEMPLATE2(TypeName, T1, T2) \ |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 416 | TypeName(); \ |
Behdad Esfahbod | a256a92 | 2018-10-29 11:25:35 -0700 | [diff] [blame] | 417 | TypeName(const TypeName<T1, T2>&); \ |
Ebrahim Byagowi | f7a08cd | 2018-10-30 11:29:09 +0330 | [diff] [blame] | 418 | void operator=(const TypeName<T1, T2>&) |
Behdad Esfahbod | c7c5df9 | 2018-10-29 15:16:52 -0700 | [diff] [blame] | 419 | |
| 420 | #else /* __cpluspplus >= 201103L */ |
| 421 | |
Behdad Esfahbod | 87ff65a | 2018-12-17 17:19:42 -0500 | [diff] [blame] | 422 | #define HB_NO_COPY_ASSIGN(TypeName) static_assert (true, "") |
Behdad Esfahbod | d092fb2 | 2018-12-30 01:53:03 -0500 | [diff] [blame] | 423 | #define HB_NO_COPY_ASSIGN_TEMPLATE(TypeName, T) static_assert (true, "") |
Behdad Esfahbod | ae9ad10 | 2018-11-03 21:41:50 -0400 | [diff] [blame] | 424 | #define HB_NO_COPY_ASSIGN_TEMPLATE2(TypeName, T1, T2) static_assert (true, "") |
| 425 | #define HB_NO_CREATE_COPY_ASSIGN(TypeName) static_assert (true, "") |
| 426 | #define HB_NO_CREATE_COPY_ASSIGN_TEMPLATE(TypeName, T) static_assert (true, "") |
| 427 | #define HB_NO_CREATE_COPY_ASSIGN_TEMPLATE2(TypeName, T1, T2) static_assert (true, "") |
Behdad Esfahbod | c7c5df9 | 2018-10-29 15:16:52 -0700 | [diff] [blame] | 428 | |
| 429 | #endif /* __cpluspplus >= 201103L */ |
Behdad Esfahbod | 6c22276 | 2018-05-25 16:21:27 -0700 | [diff] [blame] | 430 | |
Behdad Esfahbod | 44999f8 | 2018-07-11 17:00:59 +0200 | [diff] [blame] | 431 | |
| 432 | /* |
| 433 | * Compiler-assisted vectorization parameters. |
| 434 | */ |
| 435 | |
| 436 | /* |
| 437 | * Disable vectorization for now. To correctly use them, we should |
| 438 | * use posix_memalign() to allocate in hb_vector_t. Otherwise, can |
| 439 | * cause misaligned access. |
| 440 | * |
| 441 | * https://bugs.chromium.org/p/chromium/issues/detail?id=860184 |
| 442 | */ |
| 443 | #if !defined(HB_VECTOR_SIZE) |
| 444 | # define HB_VECTOR_SIZE 0 |
| 445 | #endif |
| 446 | |
| 447 | /* The `vector_size' attribute was introduced in gcc 3.1. */ |
| 448 | #if !defined(HB_VECTOR_SIZE) |
| 449 | # if defined( __GNUC__ ) && ( __GNUC__ >= 4 ) |
| 450 | # define HB_VECTOR_SIZE 128 |
| 451 | # else |
| 452 | # define HB_VECTOR_SIZE 0 |
| 453 | # endif |
| 454 | #endif |
Behdad Esfahbod | 606bf57 | 2018-09-16 19:33:48 +0200 | [diff] [blame] | 455 | static_assert (0 == (HB_VECTOR_SIZE & (HB_VECTOR_SIZE - 1)), "HB_VECTOR_SIZE is not power of 2."); |
| 456 | static_assert (0 == (HB_VECTOR_SIZE % 64), "HB_VECTOR_SIZE is not multiple of 64."); |
Behdad Esfahbod | 44999f8 | 2018-07-11 17:00:59 +0200 | [diff] [blame] | 457 | #if HB_VECTOR_SIZE |
| 458 | typedef uint64_t hb_vector_size_impl_t __attribute__((vector_size (HB_VECTOR_SIZE / 8))); |
| 459 | #else |
| 460 | typedef uint64_t hb_vector_size_impl_t; |
| 461 | #endif |
| 462 | |
| 463 | |
Behdad Esfahbod | 91dd115 | 2016-02-25 13:56:47 +0900 | [diff] [blame] | 464 | /* HB_NDEBUG disables some sanity checks that are very safe to disable and |
| 465 | * should be disabled in production systems. If NDEBUG is defined, enable |
| 466 | * HB_NDEBUG; but if it's desirable that normal assert()s (which are very |
| 467 | * light-weight) to be enabled, then HB_DEBUG can be defined to disable |
| 468 | * the costlier checks. */ |
| 469 | #ifdef NDEBUG |
Behdad Esfahbod | bd021a6 | 2018-05-08 01:50:30 -0700 | [diff] [blame] | 470 | #define HB_NDEBUG 1 |
Behdad Esfahbod | 91dd115 | 2016-02-25 13:56:47 +0900 | [diff] [blame] | 471 | #endif |
| 472 | |
Behdad Esfahbod | cc06c24 | 2011-07-25 20:25:44 -0400 | [diff] [blame] | 473 | |
Behdad Esfahbod | be336da | 2018-08-06 04:32:51 -0700 | [diff] [blame] | 474 | /* Flags */ |
Behdad Esfahbod | 8f0b64f | 2011-07-29 17:02:48 -0400 | [diff] [blame] | 475 | |
Behdad Esfahbod | aa7044d | 2015-11-04 16:25:57 -0800 | [diff] [blame] | 476 | /* Enable bitwise ops on enums marked as flags_t */ |
Behdad Esfahbod | 6986208 | 2015-11-04 18:46:22 -0800 | [diff] [blame] | 477 | /* To my surprise, looks like the function resolver is happy to silently cast |
| 478 | * one enum to another... So this doesn't provide the type-checking that I |
Behdad Esfahbod | e0082ae | 2015-11-17 18:42:13 -0800 | [diff] [blame] | 479 | * originally had in mind... :(. |
| 480 | * |
ebraminio | 7c6937e | 2017-11-20 14:49:22 -0500 | [diff] [blame] | 481 | * For MSVC warnings, see: https://github.com/harfbuzz/harfbuzz/pull/163 |
Behdad Esfahbod | e0082ae | 2015-11-17 18:42:13 -0800 | [diff] [blame] | 482 | */ |
| 483 | #ifdef _MSC_VER |
| 484 | # pragma warning(disable:4200) |
| 485 | # pragma warning(disable:4800) |
Chun-wei Fan | 167c327 | 2015-11-09 17:17:56 +0800 | [diff] [blame] | 486 | #endif |
Behdad Esfahbod | 1dc32ea | 2015-11-20 13:24:19 -0800 | [diff] [blame] | 487 | #define HB_MARK_AS_FLAG_T(T) \ |
| 488 | extern "C++" { \ |
| 489 | static inline T operator | (T l, T r) { return T ((unsigned) l | (unsigned) r); } \ |
| 490 | static inline T operator & (T l, T r) { return T ((unsigned) l & (unsigned) r); } \ |
| 491 | static inline T operator ^ (T l, T r) { return T ((unsigned) l ^ (unsigned) r); } \ |
| 492 | static inline T operator ~ (T r) { return T (~(unsigned int) r); } \ |
| 493 | static inline T& operator |= (T &l, T r) { l = l | r; return l; } \ |
| 494 | static inline T& operator &= (T& l, T r) { l = l & r; return l; } \ |
| 495 | static inline T& operator ^= (T& l, T r) { l = l ^ r; return l; } \ |
Behdad Esfahbod | d25a2f1 | 2018-12-23 20:19:52 -0500 | [diff] [blame] | 496 | } \ |
| 497 | static_assert (true, "") |
Behdad Esfahbod | aa7044d | 2015-11-04 16:25:57 -0800 | [diff] [blame] | 498 | |
Behdad Esfahbod | 45d6f29 | 2011-07-30 14:44:30 -0400 | [diff] [blame] | 499 | /* Useful for set-operations on small enums. |
| 500 | * For example, for testing "x ∈ {x1, x2, x3}" use: |
Behdad Esfahbod | 6058f98 | 2017-10-19 11:39:52 -0700 | [diff] [blame] | 501 | * (FLAG_UNSAFE(x) & (FLAG(x1) | FLAG(x2) | FLAG(x3))) |
Behdad Esfahbod | 45d6f29 | 2011-07-30 14:44:30 -0400 | [diff] [blame] | 502 | */ |
Behdad Esfahbod | 3d2b98e | 2018-11-23 10:45:44 -0500 | [diff] [blame] | 503 | #define FLAG(x) (ASSERT_STATIC_EXPR_ZERO ((unsigned)(x) < 32) + (((uint32_t) 1U) << (unsigned)(x))) |
| 504 | #define FLAG_UNSAFE(x) ((unsigned)(x) < 32 ? (((uint32_t) 1U) << (unsigned)(x)) : 0) |
Behdad Esfahbod | 2c372b8 | 2012-07-20 13:37:48 -0400 | [diff] [blame] | 505 | #define FLAG_RANGE(x,y) (ASSERT_STATIC_EXPR_ZERO ((x) < (y)) + FLAG(y+1) - FLAG(x)) |
Behdad Esfahbod | 3d2b98e | 2018-11-23 10:45:44 -0500 | [diff] [blame] | 506 | #define FLAG64(x) (ASSERT_STATIC_EXPR_ZERO ((unsigned)(x) < 64) + (((uint64_t) 1ULL) << (unsigned)(x))) |
| 507 | #define FLAG64_UNSAFE(x) ((unsigned)(x) < 64 ? (((uint64_t) 1ULL) << (unsigned)(x)) : 0) |
Behdad Esfahbod | 7b08b0a | 2011-07-20 23:59:07 -0400 | [diff] [blame] | 508 | |
Behdad Esfahbod | 8f0b64f | 2011-07-29 17:02:48 -0400 | [diff] [blame] | 509 | |
Steven R. Loomis | a13b023 | 2015-12-11 10:21:27 -0800 | [diff] [blame] | 510 | /* Size signifying variable-sized array */ |
| 511 | #define VAR 1 |
Behdad Esfahbod | bab02d3 | 2013-02-12 15:26:45 -0500 | [diff] [blame] | 512 | |
Behdad Esfahbod | e1a37f3 | 2017-10-30 11:42:28 -0600 | [diff] [blame] | 513 | |
Chun-wei Fan | 19256be | 2018-03-12 13:33:03 +0800 | [diff] [blame] | 514 | /* fallback for round() */ |
Chun-wei Fan | 19256be | 2018-03-12 13:33:03 +0800 | [diff] [blame] | 515 | static inline double |
Behdad Esfahbod | 01dff1e | 2018-06-26 18:00:58 -0400 | [diff] [blame] | 516 | _hb_round (double x) |
Chun-wei Fan | 19256be | 2018-03-12 13:33:03 +0800 | [diff] [blame] | 517 | { |
| 518 | if (x >= 0) |
| 519 | return floor (x + 0.5); |
| 520 | else |
| 521 | return ceil (x - 0.5); |
| 522 | } |
Behdad Esfahbod | 292c100 | 2018-07-10 13:16:52 +0200 | [diff] [blame] | 523 | #if !defined (HAVE_ROUND) && !defined (HAVE_DECL_ROUND) |
Behdad Esfahbod | 01dff1e | 2018-06-26 18:00:58 -0400 | [diff] [blame] | 524 | #define round(x) _hb_round(x) |
Chun-wei Fan | 19256be | 2018-03-12 13:33:03 +0800 | [diff] [blame] | 525 | #endif |
| 526 | |
| 527 | |
Behdad Esfahbod | 83ea277 | 2018-07-10 13:17:27 +0200 | [diff] [blame] | 528 | /* fallback for posix_memalign() */ |
| 529 | static inline int |
| 530 | _hb_memalign(void **memptr, size_t alignment, size_t size) |
| 531 | { |
Behdad Esfahbod | 491d93b | 2018-07-10 16:03:31 +0200 | [diff] [blame] | 532 | if (unlikely (0 != (alignment & (alignment - 1)) || |
Behdad Esfahbod | 83ea277 | 2018-07-10 13:17:27 +0200 | [diff] [blame] | 533 | !alignment || |
| 534 | 0 != (alignment & (sizeof (void *) - 1)))) |
| 535 | return EINVAL; |
| 536 | |
| 537 | char *p = (char *) malloc (size + alignment - 1); |
| 538 | if (unlikely (!p)) |
| 539 | return ENOMEM; |
| 540 | |
| 541 | size_t off = (size_t) p & (alignment - 1); |
| 542 | if (off) |
| 543 | p += alignment - off; |
| 544 | |
| 545 | *memptr = (void *) p; |
| 546 | |
| 547 | return 0; |
| 548 | } |
| 549 | #if !defined(posix_memalign) && !defined(HAVE_POSIX_MEMALIGN) |
| 550 | #define posix_memalign _hb_memalign |
| 551 | #endif |
| 552 | |
| 553 | |
Behdad Esfahbod | bdb53ca | 2018-10-11 20:20:00 -0400 | [diff] [blame] | 554 | /* |
| 555 | * For lack of a better place, put Zawgyi script hack here. |
| 556 | * https://github.com/harfbuzz/harfbuzz/issues/1162 |
| 557 | */ |
| 558 | |
| 559 | #define HB_SCRIPT_MYANMAR_ZAWGYI ((hb_script_t) HB_TAG ('Q','a','a','g')) |
| 560 | |
| 561 | |
Behdad Esfahbod | 07386ea | 2018-10-22 21:18:27 -0700 | [diff] [blame] | 562 | /* Some really basic things everyone wants. */ |
| 563 | template <typename T> struct hb_remove_const { typedef T value; }; |
| 564 | template <typename T> struct hb_remove_const<const T> { typedef T value; }; |
Behdad Esfahbod | f99abcc | 2018-11-24 00:22:21 -0500 | [diff] [blame] | 565 | #define hb_remove_const(T) hb_remove_const<T>::value |
Behdad Esfahbod | 07386ea | 2018-10-22 21:18:27 -0700 | [diff] [blame] | 566 | template <typename T> struct hb_remove_reference { typedef T value; }; |
| 567 | template <typename T> struct hb_remove_reference<T &> { typedef T value; }; |
Behdad Esfahbod | f99abcc | 2018-11-24 00:22:21 -0500 | [diff] [blame] | 568 | #define hb_remove_reference(T) hb_remove_reference<T>::value |
Behdad Esfahbod | 07386ea | 2018-10-22 21:18:27 -0700 | [diff] [blame] | 569 | template <typename T> struct hb_remove_pointer { typedef T value; }; |
| 570 | template <typename T> struct hb_remove_pointer<T *> { typedef T value; }; |
Behdad Esfahbod | f99abcc | 2018-11-24 00:22:21 -0500 | [diff] [blame] | 571 | #define hb_remove_pointer(T) hb_remove_pointer<T>::value |
Behdad Esfahbod | 07386ea | 2018-10-22 21:18:27 -0700 | [diff] [blame] | 572 | |
| 573 | |
Behdad Esfahbod | 865deeb | 2018-12-21 17:35:58 -0500 | [diff] [blame] | 574 | /* Headers we include for everyone. Keep topologically sorted by dependency. |
| 575 | * They express dependency amongst themselves, but no other file should include |
| 576 | * them directly.*/ |
Behdad Esfahbod | c77ae40 | 2018-08-25 22:36:36 -0700 | [diff] [blame] | 577 | #include "hb-atomic.hh" |
Behdad Esfahbod | c77ae40 | 2018-08-25 22:36:36 -0700 | [diff] [blame] | 578 | #include "hb-mutex.hh" |
Behdad Esfahbod | 25147ff | 2018-08-06 05:01:52 -0700 | [diff] [blame] | 579 | #include "hb-null.hh" |
Behdad Esfahbod | 865deeb | 2018-12-21 17:35:58 -0500 | [diff] [blame] | 580 | #include "hb-dsalgs.hh" // Requires: hb-null |
| 581 | #include "hb-iter.hh" // Requires: hb-null |
| 582 | #include "hb-debug.hh" // Requires: hb-atomic hb-dsalgs |
| 583 | #include "hb-array.hh" // Requires: hb-dsalgs hb-iter hb-null |
| 584 | #include "hb-vector.hh" // Requires: hb-array hb-null |
| 585 | #include "hb-object.hh" // Requires: hb-atomic hb-mutex hb-vector |
Behdad Esfahbod | 83ea277 | 2018-07-10 13:17:27 +0200 | [diff] [blame] | 586 | |
Behdad Esfahbod | c77ae40 | 2018-08-25 22:36:36 -0700 | [diff] [blame] | 587 | #endif /* HB_HH */ |