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 | f60282c | 2019-01-24 16:29:09 +0100 | [diff] [blame] | 32 | #ifndef HB_NO_PRAGMA_GCC_DIAGNOSTIC |
Behdad Esfahbod | 51b5848 | 2019-01-28 14:09:45 -0500 | [diff] [blame] | 33 | #if defined(_MSC_VER) |
| 34 | #pragma warning( disable: 4068 ) /* Unknown pragma */ |
| 35 | #endif |
Behdad Esfahbod | f13b678 | 2019-01-18 14:53:54 -0500 | [diff] [blame] | 36 | #if defined(__GNUC__) || defined(__clang__) |
Behdad Esfahbod | 1077e40 | 2019-01-17 18:36:10 -0500 | [diff] [blame] | 37 | /* Rules: |
Behdad Esfahbod | 7a634d7 | 2019-01-18 09:49:14 -0500 | [diff] [blame] | 38 | * |
| 39 | * - All pragmas are declared GCC even if they are clang ones. Otherwise GCC |
| 40 | * nags, even though we instruct it to ignore -Wunknown-pragmas. ¯\_(ツ)_/¯ |
| 41 | * |
Behdad Esfahbod | 1077e40 | 2019-01-17 18:36:10 -0500 | [diff] [blame] | 42 | * - Within each category, keep sorted. |
Behdad Esfahbod | 7a634d7 | 2019-01-18 09:49:14 -0500 | [diff] [blame] | 43 | * |
Behdad Esfahbod | 2bd530d | 2019-01-18 09:28:22 -0500 | [diff] [blame] | 44 | * - Warnings whose scope can be expanded in future compiler versions shall |
| 45 | * be declared as "warning". Otherwise, either ignored or error. |
Behdad Esfahbod | 1077e40 | 2019-01-17 18:36:10 -0500 | [diff] [blame] | 46 | */ |
Behdad Esfahbod | 16e5ba8 | 2019-01-18 09:46:17 -0500 | [diff] [blame] | 47 | |
Behdad Esfahbod | 7a634d7 | 2019-01-18 09:49:14 -0500 | [diff] [blame] | 48 | /* Setup. Don't sort order within this category. */ |
Behdad Esfahbod | f60282c | 2019-01-24 16:29:09 +0100 | [diff] [blame] | 49 | #ifndef HB_NO_PRAGMA_GCC_DIAGNOSTIC_WARNING |
Behdad Esfahbod | 7a634d7 | 2019-01-18 09:49:14 -0500 | [diff] [blame] | 50 | #pragma GCC diagnostic warning "-Wall" |
| 51 | #pragma GCC diagnostic warning "-Wextra" |
Behdad Esfahbod | f60282c | 2019-01-24 16:29:09 +0100 | [diff] [blame] | 52 | #endif |
| 53 | #ifndef HB_NO_PRAGMA_GCC_DIAGNOSTIC_IGNORED |
Behdad Esfahbod | 7a634d7 | 2019-01-18 09:49:14 -0500 | [diff] [blame] | 54 | #pragma GCC diagnostic ignored "-Wpragmas" |
| 55 | #pragma GCC diagnostic ignored "-Wunknown-pragmas" |
| 56 | #pragma GCC diagnostic ignored "-Wunknown-warning-option" |
Behdad Esfahbod | f60282c | 2019-01-24 16:29:09 +0100 | [diff] [blame] | 57 | #endif |
| 58 | #ifndef HB_NO_PRAGMA_GCC_DIAGNOSTIC_WARNING |
Behdad Esfahbod | 7a634d7 | 2019-01-18 09:49:14 -0500 | [diff] [blame] | 59 | //#pragma GCC diagnostic warning "-Weverything" |
Behdad Esfahbod | f60282c | 2019-01-24 16:29:09 +0100 | [diff] [blame] | 60 | #endif |
Behdad Esfahbod | 16e5ba8 | 2019-01-18 09:46:17 -0500 | [diff] [blame] | 61 | |
Behdad Esfahbod | 2bd530d | 2019-01-18 09:28:22 -0500 | [diff] [blame] | 62 | /* Error. Should never happen. */ |
Behdad Esfahbod | f60282c | 2019-01-24 16:29:09 +0100 | [diff] [blame] | 63 | #ifndef HB_NO_PRAGMA_GCC_DIAGNOSTIC_ERROR |
Behdad Esfahbod | 7a634d7 | 2019-01-18 09:49:14 -0500 | [diff] [blame] | 64 | #pragma GCC diagnostic error "-Wc++11-narrowing" |
| 65 | #pragma GCC diagnostic error "-Wcast-align" |
Behdad Esfahbod | 60022ec | 2019-01-26 14:04:51 +0100 | [diff] [blame] | 66 | #pragma GCC diagnostic error "-Wcast-function-type" |
Behdad Esfahbod | 9b4e51b | 2019-01-18 12:23:02 -0500 | [diff] [blame] | 67 | #pragma GCC diagnostic error "-Wdelete-non-virtual-dtor" |
Behdad Esfahbod | 7a634d7 | 2019-01-18 09:49:14 -0500 | [diff] [blame] | 68 | #pragma GCC diagnostic error "-Wformat-security" |
| 69 | #pragma GCC diagnostic error "-Wimplicit-function-declaration" |
| 70 | #pragma GCC diagnostic error "-Winit-self" |
Behdad Esfahbod | f35e7ea | 2019-01-26 22:50:00 +0100 | [diff] [blame] | 71 | #pragma GCC diagnostic error "-Winjected-class-name" |
Behdad Esfahbod | 7a634d7 | 2019-01-18 09:49:14 -0500 | [diff] [blame] | 72 | #pragma GCC diagnostic error "-Wmissing-braces" |
| 73 | #pragma GCC diagnostic error "-Wmissing-declarations" |
| 74 | #pragma GCC diagnostic error "-Wmissing-prototypes" |
| 75 | #pragma GCC diagnostic error "-Wnested-externs" |
| 76 | #pragma GCC diagnostic error "-Wold-style-definition" |
| 77 | #pragma GCC diagnostic error "-Wpointer-arith" |
| 78 | #pragma GCC diagnostic error "-Wredundant-decls" |
Behdad Esfahbod | a25174a | 2019-01-18 09:59:36 -0500 | [diff] [blame] | 79 | #pragma GCC diagnostic error "-Wreorder" |
Behdad Esfahbod | 9077272 | 2019-01-22 12:40:18 +0100 | [diff] [blame] | 80 | #pragma GCC diagnostic error "-Wsign-compare" |
Behdad Esfahbod | 7a634d7 | 2019-01-18 09:49:14 -0500 | [diff] [blame] | 81 | #pragma GCC diagnostic error "-Wstrict-prototypes" |
| 82 | #pragma GCC diagnostic error "-Wstring-conversion" |
| 83 | #pragma GCC diagnostic error "-Wswitch-enum" |
| 84 | #pragma GCC diagnostic error "-Wtautological-overlap-compare" |
| 85 | #pragma GCC diagnostic error "-Wunneeded-internal-declaration" |
| 86 | #pragma GCC diagnostic error "-Wunused" |
| 87 | #pragma GCC diagnostic error "-Wunused-local-typedefs" |
| 88 | #pragma GCC diagnostic error "-Wunused-value" |
| 89 | #pragma GCC diagnostic error "-Wunused-variable" |
Behdad Esfahbod | c81f02f | 2019-01-22 12:00:44 +0100 | [diff] [blame] | 90 | #pragma GCC diagnostic error "-Wvla" |
Behdad Esfahbod | 7a634d7 | 2019-01-18 09:49:14 -0500 | [diff] [blame] | 91 | #pragma GCC diagnostic error "-Wwrite-strings" |
Behdad Esfahbod | f60282c | 2019-01-24 16:29:09 +0100 | [diff] [blame] | 92 | #endif |
Behdad Esfahbod | 16e5ba8 | 2019-01-18 09:46:17 -0500 | [diff] [blame] | 93 | |
Behdad Esfahbod | 2bd530d | 2019-01-18 09:28:22 -0500 | [diff] [blame] | 94 | /* Warning. To be investigated if happens. */ |
Behdad Esfahbod | f60282c | 2019-01-24 16:29:09 +0100 | [diff] [blame] | 95 | #ifndef HB_NO_PRAGMA_GCC_DIAGNOSTIC_WARNING |
Behdad Esfahbod | 7a634d7 | 2019-01-18 09:49:14 -0500 | [diff] [blame] | 96 | #pragma GCC diagnostic warning "-Wbuiltin-macro-redefined" |
| 97 | #pragma GCC diagnostic warning "-Wdisabled-optimization" |
| 98 | #pragma GCC diagnostic warning "-Wformat=2" |
| 99 | #pragma GCC diagnostic warning "-Wignored-pragma-optimize" |
| 100 | #pragma GCC diagnostic warning "-Wlogical-op" |
Behdad Esfahbod | 4660090 | 2019-01-18 09:53:16 -0500 | [diff] [blame] | 101 | #pragma GCC diagnostic warning "-Wmaybe-uninitialized" |
Behdad Esfahbod | 7a634d7 | 2019-01-18 09:49:14 -0500 | [diff] [blame] | 102 | #pragma GCC diagnostic warning "-Wmissing-format-attribute" |
Behdad Esfahbod | 7a634d7 | 2019-01-18 09:49:14 -0500 | [diff] [blame] | 103 | #pragma GCC diagnostic warning "-Wundef" |
Behdad Esfahbod | f60282c | 2019-01-24 16:29:09 +0100 | [diff] [blame] | 104 | #endif |
Behdad Esfahbod | 16e5ba8 | 2019-01-18 09:46:17 -0500 | [diff] [blame] | 105 | |
Behdad Esfahbod | 2bd530d | 2019-01-18 09:28:22 -0500 | [diff] [blame] | 106 | /* Ignored currently, but should be fixed at some point. */ |
Behdad Esfahbod | f60282c | 2019-01-24 16:29:09 +0100 | [diff] [blame] | 107 | #ifndef HB_NO_PRAGMA_GCC_DIAGNOSTIC_IGNORED |
Behdad Esfahbod | 7a634d7 | 2019-01-18 09:49:14 -0500 | [diff] [blame] | 108 | #pragma GCC diagnostic ignored "-Wconversion" // TODO fix |
| 109 | #pragma GCC diagnostic ignored "-Wformat-signedness" // TODO fix |
| 110 | #pragma GCC diagnostic ignored "-Wshadow" // TODO fix |
| 111 | #pragma GCC diagnostic ignored "-Wunsafe-loop-optimizations" // TODO fix |
| 112 | #pragma GCC diagnostic ignored "-Wunused-parameter" // TODO fix |
Behdad Esfahbod | f60282c | 2019-01-24 16:29:09 +0100 | [diff] [blame] | 113 | #endif |
Behdad Esfahbod | 16e5ba8 | 2019-01-18 09:46:17 -0500 | [diff] [blame] | 114 | |
Behdad Esfahbod | 2bd530d | 2019-01-18 09:28:22 -0500 | [diff] [blame] | 115 | /* Ignored intentionally. */ |
Behdad Esfahbod | f60282c | 2019-01-24 16:29:09 +0100 | [diff] [blame] | 116 | #ifndef HB_NO_PRAGMA_GCC_DIAGNOSTIC_IGNORED |
Behdad Esfahbod | 7a634d7 | 2019-01-18 09:49:14 -0500 | [diff] [blame] | 117 | #pragma GCC diagnostic ignored "-Wclass-memaccess" |
| 118 | #pragma GCC diagnostic ignored "-Wformat-nonliteral" |
| 119 | #pragma GCC diagnostic ignored "-Wformat-zero-length" |
| 120 | #pragma GCC diagnostic ignored "-Wmissing-field-initializers" |
| 121 | #pragma GCC diagnostic ignored "-Wpacked" // Erratic impl in clang |
| 122 | #pragma GCC diagnostic ignored "-Wstrict-aliasing" |
| 123 | #pragma GCC diagnostic ignored "-Wtype-limits" |
Behdad Esfahbod | f60282c | 2019-01-24 16:29:09 +0100 | [diff] [blame] | 124 | #endif |
Behdad Esfahbod | f13b678 | 2019-01-18 14:53:54 -0500 | [diff] [blame] | 125 | |
| 126 | #endif |
Behdad Esfahbod | 868b0c0 | 2019-01-17 15:08:36 -0500 | [diff] [blame] | 127 | #endif |
| 128 | |
Behdad Esfahbod | 5ddd9cc | 2011-09-16 16:40:44 -0400 | [diff] [blame] | 129 | #ifdef HAVE_CONFIG_H |
Behdad Esfahbod | df66028 | 2009-08-01 20:46:02 -0400 | [diff] [blame] | 130 | #include "config.h" |
| 131 | #endif |
Behdad Esfahbod | 12360f7 | 2008-01-23 15:50:38 -0500 | [diff] [blame] | 132 | |
Behdad Esfahbod | 49334f9 | 2018-12-17 18:27:36 -0500 | [diff] [blame] | 133 | /* |
| 134 | * Following added based on what AC_USE_SYSTEM_EXTENSIONS adds to |
| 135 | * config.h.in. Copied here for the convenience of those embedding |
| 136 | * HarfBuzz and not using our build system. |
| 137 | */ |
| 138 | /* Enable extensions on AIX 3, Interix. */ |
| 139 | #ifndef _ALL_SOURCE |
| 140 | # define _ALL_SOURCE 1 |
| 141 | #endif |
| 142 | /* Enable GNU extensions on systems that have them. */ |
| 143 | #ifndef _GNU_SOURCE |
| 144 | # define _GNU_SOURCE 1 |
| 145 | #endif |
| 146 | /* Enable threading extensions on Solaris. */ |
| 147 | #ifndef _POSIX_PTHREAD_SEMANTICS |
| 148 | # define _POSIX_PTHREAD_SEMANTICS 1 |
| 149 | #endif |
| 150 | /* Enable extensions on HP NonStop. */ |
| 151 | #ifndef _TANDEM_SOURCE |
| 152 | # define _TANDEM_SOURCE 1 |
| 153 | #endif |
| 154 | /* Enable general extensions on Solaris. */ |
| 155 | #ifndef __EXTENSIONS__ |
| 156 | # define __EXTENSIONS__ 1 |
| 157 | #endif |
| 158 | |
Chun-wei Fan | 8e4ad1d | 2018-07-25 18:12:34 +0800 | [diff] [blame] | 159 | #if defined (_MSC_VER) && defined (HB_DLL_EXPORT) |
| 160 | #define HB_EXTERN __declspec (dllexport) extern |
| 161 | #endif |
| 162 | |
Behdad Esfahbod | d1c9eb4 | 2012-04-12 13:17:44 -0400 | [diff] [blame] | 163 | #include "hb.h" |
Behdad Esfahbod | d1c9eb4 | 2012-04-12 13:17:44 -0400 | [diff] [blame] | 164 | #define HB_H_IN |
Behdad Esfahbod | 3e32cd9 | 2012-04-23 13:20:52 -0400 | [diff] [blame] | 165 | #include "hb-ot.h" |
Behdad Esfahbod | d1c9eb4 | 2012-04-12 13:17:44 -0400 | [diff] [blame] | 166 | #define HB_OT_H_IN |
Behdad Esfahbod | b206133 | 2018-11-23 14:05:11 -0500 | [diff] [blame] | 167 | #include "hb-aat.h" |
| 168 | #define HB_AAT_H_IN |
Behdad Esfahbod | b28815c | 2009-08-04 22:35:36 -0400 | [diff] [blame] | 169 | |
Ebrahim Byagowi | a8726cb | 2018-11-17 14:23:11 +0330 | [diff] [blame] | 170 | #include "hb-aat.h" |
| 171 | |
Behdad Esfahbod | 7cdd6ab | 2018-01-10 04:33:08 +0100 | [diff] [blame] | 172 | #include <math.h> |
Behdad Esfahbod | c7d457a | 2009-05-21 12:46:29 -0400 | [diff] [blame] | 173 | #include <stdlib.h> |
Behdad Esfahbod | b65c060 | 2011-07-28 16:48:43 -0400 | [diff] [blame] | 174 | #include <stddef.h> |
Behdad Esfahbod | f0954d1 | 2009-07-30 15:33:57 -0400 | [diff] [blame] | 175 | #include <string.h> |
| 176 | #include <assert.h> |
Behdad Esfahbod | 7acb389 | 2009-08-05 15:20:34 -0400 | [diff] [blame] | 177 | #include <errno.h> |
Behdad Esfahbod | 40ec3bb | 2017-11-03 16:57:30 -0400 | [diff] [blame] | 178 | #include <stdio.h> |
Behdad Esfahbod | cc06c24 | 2011-07-25 20:25:44 -0400 | [diff] [blame] | 179 | #include <stdarg.h> |
Behdad Esfahbod | c7d457a | 2009-05-21 12:46:29 -0400 | [diff] [blame] | 180 | |
Tor Andersson | 8f4c123 | 2018-04-13 23:01:54 +0430 | [diff] [blame] | 181 | #if (defined(_MSC_VER) && _MSC_VER >= 1500) || defined(__MINGW32__) |
Arkady Shapkin | 6c10328 | 2018-02-15 23:17:46 +0300 | [diff] [blame] | 182 | #include <intrin.h> |
| 183 | #endif |
Behdad Esfahbod | acdba3f | 2010-07-23 15:11:18 -0400 | [diff] [blame] | 184 | |
Behdad Esfahbod | 2a74968 | 2017-10-26 19:48:33 -0600 | [diff] [blame] | 185 | #define HB_PASTE1(a,b) a##b |
| 186 | #define HB_PASTE(a,b) HB_PASTE1(a,b) |
| 187 | |
Behdad Esfahbod | 83ea277 | 2018-07-10 13:17:27 +0200 | [diff] [blame] | 188 | |
Behdad Esfahbod | 52b4185 | 2015-10-03 13:20:55 +0100 | [diff] [blame] | 189 | /* Compile-time custom allocator support. */ |
| 190 | |
| 191 | #if defined(hb_malloc_impl) \ |
| 192 | && defined(hb_calloc_impl) \ |
| 193 | && defined(hb_realloc_impl) \ |
| 194 | && defined(hb_free_impl) |
Behdad Esfahbod | cc6ea30 | 2015-10-12 17:21:52 -0400 | [diff] [blame] | 195 | extern "C" void* hb_malloc_impl(size_t size); |
| 196 | extern "C" void* hb_calloc_impl(size_t nmemb, size_t size); |
| 197 | extern "C" void* hb_realloc_impl(void *ptr, size_t size); |
| 198 | extern "C" void hb_free_impl(void *ptr); |
Behdad Esfahbod | 52b4185 | 2015-10-03 13:20:55 +0100 | [diff] [blame] | 199 | #define malloc hb_malloc_impl |
| 200 | #define calloc hb_calloc_impl |
| 201 | #define realloc hb_realloc_impl |
| 202 | #define free hb_free_impl |
Behdad Esfahbod | 83ea277 | 2018-07-10 13:17:27 +0200 | [diff] [blame] | 203 | |
Behdad Esfahbod | 763f878 | 2018-07-10 13:47:41 +0200 | [diff] [blame] | 204 | #if defined(hb_memalign_impl) |
Behdad Esfahbod | 83ea277 | 2018-07-10 13:17:27 +0200 | [diff] [blame] | 205 | extern "C" int hb_memalign_impl(void **memptr, size_t alignment, size_t size); |
| 206 | #define posix_memalign hb_memalign_impl |
| 207 | #else |
| 208 | #undef HAVE_POSIX_MEMALIGN |
| 209 | #endif |
| 210 | |
Behdad Esfahbod | 52b4185 | 2015-10-03 13:20:55 +0100 | [diff] [blame] | 211 | #endif |
| 212 | |
| 213 | |
Behdad Esfahbod | 2aae617 | 2018-07-11 17:27:23 +0200 | [diff] [blame] | 214 | /* |
| 215 | * Compiler attributes |
Behdad Esfahbod | 37be774 | 2018-08-06 04:51:38 -0700 | [diff] [blame] | 216 | */ |
Behdad Esfahbod | 292c100 | 2018-07-10 13:16:52 +0200 | [diff] [blame] | 217 | |
Ebrahim Byagowi | 76c4873 | 2017-06-02 21:53:10 +0430 | [diff] [blame] | 218 | #if (defined(__GNUC__) || defined(__clang__)) && defined(__OPTIMIZE__) |
| 219 | #define likely(expr) (__builtin_expect (!!(expr), 1)) |
| 220 | #define unlikely(expr) (__builtin_expect (!!(expr), 0)) |
Behdad Esfahbod | ae2b854 | 2014-06-03 16:59:09 -0400 | [diff] [blame] | 221 | #else |
| 222 | #define likely(expr) (expr) |
| 223 | #define unlikely(expr) (expr) |
Behdad Esfahbod | bc20045 | 2010-04-29 01:40:26 -0400 | [diff] [blame] | 224 | #endif |
| 225 | |
Steve Lhomme | 0b8f3ab | 2016-07-11 21:57:26 +0200 | [diff] [blame] | 226 | #if !defined(__GNUC__) && !defined(__clang__) |
Behdad Esfahbod | ae2b854 | 2014-06-03 16:59:09 -0400 | [diff] [blame] | 227 | #undef __attribute__ |
| 228 | #define __attribute__(x) |
| 229 | #endif |
Behdad Esfahbod | a794ebf | 2009-08-06 12:32:35 -0400 | [diff] [blame] | 230 | |
Behdad Esfahbod | d9f6be3 | 2019-01-18 12:48:01 -0500 | [diff] [blame] | 231 | #if defined(__GNUC__) && (__GNUC__ >= 3) |
Behdad Esfahbod | ae2b854 | 2014-06-03 16:59:09 -0400 | [diff] [blame] | 232 | #define HB_PURE_FUNC __attribute__((pure)) |
| 233 | #define HB_CONST_FUNC __attribute__((const)) |
| 234 | #define HB_PRINTF_FUNC(format_idx, arg_idx) __attribute__((__format__ (__printf__, format_idx, arg_idx))) |
| 235 | #else |
| 236 | #define HB_PURE_FUNC |
| 237 | #define HB_CONST_FUNC |
| 238 | #define HB_PRINTF_FUNC(format_idx, arg_idx) |
| 239 | #endif |
Behdad Esfahbod | d9f6be3 | 2019-01-18 12:48:01 -0500 | [diff] [blame] | 240 | #if defined(__GNUC__) && (__GNUC__ >= 4) |
Behdad Esfahbod | ae2b854 | 2014-06-03 16:59:09 -0400 | [diff] [blame] | 241 | #define HB_UNUSED __attribute__((unused)) |
Behdad Esfahbod | be59f3c | 2017-12-05 09:01:28 -0800 | [diff] [blame] | 242 | #elif defined(_MSC_VER) /* https://github.com/harfbuzz/harfbuzz/issues/635 */ |
| 243 | #define HB_UNUSED __pragma(warning(suppress: 4100 4101)) |
Behdad Esfahbod | ae2b854 | 2014-06-03 16:59:09 -0400 | [diff] [blame] | 244 | #else |
| 245 | #define HB_UNUSED |
| 246 | #endif |
| 247 | |
| 248 | #ifndef HB_INTERNAL |
Behdad Esfahbod | 90d1c74 | 2018-02-11 19:08:59 -0800 | [diff] [blame] | 249 | # 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] | 250 | # define HB_INTERNAL __attribute__((__visibility__("hidden"))) |
Behdad Esfahbod | 94759d4 | 2018-07-23 15:01:39 -0700 | [diff] [blame] | 251 | # elif defined(__MINGW32__) |
Chun-wei Fan | 8e4ad1d | 2018-07-25 18:12:34 +0800 | [diff] [blame] | 252 | /* We use -export-symbols on mingw32, since it does not support visibility attributes. */ |
| 253 | # define HB_INTERNAL |
| 254 | # elif defined (_MSC_VER) && defined (HB_DLL_EXPORT) |
| 255 | /* We do not try to export internal symbols on Visual Studio */ |
Behdad Esfahbod | 94759d4 | 2018-07-23 15:01:39 -0700 | [diff] [blame] | 256 | # define HB_INTERNAL |
| 257 | #else |
Behdad Esfahbod | ae2b854 | 2014-06-03 16:59:09 -0400 | [diff] [blame] | 258 | # define HB_INTERNAL |
Behdad Esfahbod | b87cbe2 | 2018-02-07 14:11:26 -0500 | [diff] [blame] | 259 | # define HB_NO_VISIBILITY 1 |
Behdad Esfahbod | ae2b854 | 2014-06-03 16:59:09 -0400 | [diff] [blame] | 260 | # endif |
| 261 | #endif |
| 262 | |
Behdad Esfahbod | d9f6be3 | 2019-01-18 12:48:01 -0500 | [diff] [blame] | 263 | #if defined(__GNUC__) && (__GNUC__ >= 3) |
Behdad Esfahbod | ae2b854 | 2014-06-03 16:59:09 -0400 | [diff] [blame] | 264 | #define HB_FUNC __PRETTY_FUNCTION__ |
| 265 | #elif defined(_MSC_VER) |
| 266 | #define HB_FUNC __FUNCSIG__ |
| 267 | #else |
| 268 | #define HB_FUNC __func__ |
| 269 | #endif |
| 270 | |
prrace | 498e437 | 2018-06-09 16:04:28 -0700 | [diff] [blame] | 271 | #if defined(__SUNPRO_CC) && (__SUNPRO_CC < 0x5140) |
Behdad Esfahbod | 8cef3a6 | 2018-02-09 16:04:23 -0600 | [diff] [blame] | 272 | /* https://github.com/harfbuzz/harfbuzz/issues/630 */ |
| 273 | #define __restrict |
| 274 | #endif |
| 275 | |
Behdad Esfahbod | 305d2fb | 2015-10-21 11:04:28 -0200 | [diff] [blame] | 276 | /* |
| 277 | * Borrowed from https://bugzilla.mozilla.org/show_bug.cgi?id=1215411 |
| 278 | * HB_FALLTHROUGH is an annotation to suppress compiler warnings about switch |
| 279 | * cases that fall through without a break or return statement. HB_FALLTHROUGH |
| 280 | * is only needed on cases that have code: |
| 281 | * |
| 282 | * switch (foo) { |
| 283 | * case 1: // These cases have no code. No fallthrough annotations are needed. |
| 284 | * case 2: |
| 285 | * case 3: |
| 286 | * foo = 4; // This case has code, so a fallthrough annotation is needed: |
| 287 | * HB_FALLTHROUGH; |
| 288 | * default: |
| 289 | * return foo; |
| 290 | * } |
| 291 | */ |
| 292 | #if defined(__clang__) && __cplusplus >= 201103L |
| 293 | /* clang's fallthrough annotations are only available starting in C++11. */ |
| 294 | # define HB_FALLTHROUGH [[clang::fallthrough]] |
Behdad Esfahbod | d9f6be3 | 2019-01-18 12:48:01 -0500 | [diff] [blame] | 295 | #elif defined(__GNUC__) && (__GNUC__ >= 7) |
Behdad Esfahbod | f41b921 | 2018-02-05 19:51:09 -0500 | [diff] [blame] | 296 | /* GNU fallthrough attribute is available from GCC7 */ |
| 297 | # define HB_FALLTHROUGH __attribute__((fallthrough)) |
Behdad Esfahbod | 305d2fb | 2015-10-21 11:04:28 -0200 | [diff] [blame] | 298 | #elif defined(_MSC_VER) |
| 299 | /* |
| 300 | * MSVC's __fallthrough annotations are checked by /analyze (Code Analysis): |
| 301 | * https://msdn.microsoft.com/en-us/library/ms235402%28VS.80%29.aspx |
| 302 | */ |
| 303 | # include <sal.h> |
| 304 | # define HB_FALLTHROUGH __fallthrough |
| 305 | #else |
| 306 | # define HB_FALLTHROUGH /* FALLTHROUGH */ |
| 307 | #endif |
| 308 | |
Behdad Esfahbod | 62376a7 | 2018-10-14 15:20:50 -0700 | [diff] [blame] | 309 | #if defined(__clang__) |
| 310 | /* Disable certain sanitizer errors. */ |
| 311 | /* https://github.com/harfbuzz/harfbuzz/issues/1247 */ |
| 312 | #define HB_NO_SANITIZE_SIGNED_INTEGER_OVERFLOW __attribute__((no_sanitize("signed-integer-overflow"))) |
| 313 | #else |
| 314 | #define HB_NO_SANITIZE_SIGNED_INTEGER_OVERFLOW |
| 315 | #endif |
| 316 | |
| 317 | |
Ken Brown | eee5b5e | 2018-11-12 21:05:39 -0500 | [diff] [blame] | 318 | #ifdef _WIN32 |
Behdad Esfahbod | db30828 | 2014-07-19 16:32:04 -0400 | [diff] [blame] | 319 | /* We need Windows Vista for both Uniscribe backend and for |
| 320 | * MemoryBarrier. We don't support compiling on Windows XP, |
| 321 | * though we run on it fine. */ |
| 322 | # if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0600 |
| 323 | # undef _WIN32_WINNT |
| 324 | # endif |
| 325 | # ifndef _WIN32_WINNT |
Matt Oliver | 24dd6c1 | 2018-09-23 18:08:30 +1000 | [diff] [blame] | 326 | # if !defined(WINAPI_FAMILY) || !(WINAPI_FAMILY==WINAPI_FAMILY_PC_APP || WINAPI_FAMILY==WINAPI_FAMILY_PHONE_APP) |
| 327 | # define _WIN32_WINNT 0x0600 |
| 328 | # endif |
Behdad Esfahbod | db30828 | 2014-07-19 16:32:04 -0400 | [diff] [blame] | 329 | # endif |
Behdad Esfahbod | 270971a | 2014-08-15 14:28:04 -0400 | [diff] [blame] | 330 | # ifndef WIN32_LEAN_AND_MEAN |
| 331 | # define WIN32_LEAN_AND_MEAN 1 |
| 332 | # endif |
| 333 | # ifndef STRICT |
| 334 | # define STRICT 1 |
| 335 | # endif |
Behdad Esfahbod | dabe698 | 2012-11-23 14:21:35 -0500 | [diff] [blame] | 336 | |
Konstantin Ritt | f3537b6 | 2015-01-25 09:50:51 +0400 | [diff] [blame] | 337 | # if defined(_WIN32_WCE) |
| 338 | /* Some things not defined on Windows CE. */ |
Konstantin Ritt | 5069062 | 2016-04-26 12:02:26 +0400 | [diff] [blame] | 339 | # define vsnprintf _vsnprintf |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 340 | # define getenv(Name) nullptr |
Konstantin Ritt | 855a5d7 | 2015-04-10 17:18:01 +0400 | [diff] [blame] | 341 | # if _WIN32_WCE < 0x800 |
| 342 | # define setlocale(Category, Locale) "C" |
Behdad Esfahbod | 26a963b | 2014-08-10 18:04:50 -0400 | [diff] [blame] | 343 | static int errno = 0; /* Use something better? */ |
Konstantin Ritt | 855a5d7 | 2015-04-10 17:18:01 +0400 | [diff] [blame] | 344 | # endif |
Konstantin Ritt | f3537b6 | 2015-01-25 09:50:51 +0400 | [diff] [blame] | 345 | # 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] | 346 | # define getenv(Name) nullptr |
Konstantin Ritt | f3537b6 | 2015-01-25 09:50:51 +0400 | [diff] [blame] | 347 | # endif |
Behdad Esfahbod | ce01ad7 | 2015-04-01 11:05:59 -0700 | [diff] [blame] | 348 | # if defined(_MSC_VER) && _MSC_VER < 1900 |
Konstantin Ritt | f3537b6 | 2015-01-25 09:50:51 +0400 | [diff] [blame] | 349 | # define snprintf _snprintf |
Konstantin Ritt | f3537b6 | 2015-01-25 09:50:51 +0400 | [diff] [blame] | 350 | # endif |
Behdad Esfahbod | 26a963b | 2014-08-10 18:04:50 -0400 | [diff] [blame] | 351 | #endif |
| 352 | |
Behdad Esfahbod | b89c7fd | 2018-11-21 12:32:48 -0500 | [diff] [blame] | 353 | #if defined(HAVE_ATEXIT) && !defined(HB_USE_ATEXIT) |
Behdad Esfahbod | 38fb30d | 2014-08-06 13:34:49 -0400 | [diff] [blame] | 354 | /* atexit() is only safe to be called from shared libraries on certain |
| 355 | * platforms. Whitelist. |
| 356 | * https://bugs.freedesktop.org/show_bug.cgi?id=82246 */ |
| 357 | # if defined(__linux) && defined(__GLIBC_PREREQ) |
| 358 | # if __GLIBC_PREREQ(2,3) |
| 359 | /* From atexit() manpage, it's safe with glibc 2.2.3 on Linux. */ |
| 360 | # define HB_USE_ATEXIT 1 |
| 361 | # endif |
| 362 | # elif defined(_MSC_VER) || defined(__MINGW32__) |
| 363 | /* For MSVC: |
Ebrahim Byagowi | f24b0b9 | 2018-04-12 13:40:45 +0430 | [diff] [blame] | 364 | * https://msdn.microsoft.com/en-us/library/tze57ck3.aspx |
| 365 | * https://msdn.microsoft.com/en-us/library/zk17ww08.aspx |
Behdad Esfahbod | 38fb30d | 2014-08-06 13:34:49 -0400 | [diff] [blame] | 366 | * mingw32 headers say atexit is safe to use in shared libraries. |
| 367 | */ |
| 368 | # define HB_USE_ATEXIT 1 |
Ebrahim Byagowi | 632713b | 2018-04-12 14:17:03 +0430 | [diff] [blame] | 369 | # elif defined(__ANDROID__) |
| 370 | /* This is available since Android NKD r8 or r8b: |
| 371 | * https://issuetracker.google.com/code/p/android/issues/detail?id=6455 |
Behdad Esfahbod | 38fb30d | 2014-08-06 13:34:49 -0400 | [diff] [blame] | 372 | */ |
| 373 | # define HB_USE_ATEXIT 1 |
Bruce Mitchener | e8859fc | 2018-02-04 01:26:57 +0700 | [diff] [blame] | 374 | # elif defined(__APPLE__) |
| 375 | /* For macOS and related platforms, the atexit man page indicates |
| 376 | * that it will be invoked when the library is unloaded, not only |
| 377 | * at application exit. |
| 378 | */ |
| 379 | # define HB_USE_ATEXIT 1 |
Behdad Esfahbod | 38fb30d | 2014-08-06 13:34:49 -0400 | [diff] [blame] | 380 | # endif |
| 381 | #endif |
Behdad Esfahbod | c14b24f | 2018-03-26 10:44:54 -0700 | [diff] [blame] | 382 | #ifdef HB_NO_ATEXIT |
| 383 | # undef HB_USE_ATEXIT |
| 384 | #endif |
Behdad Esfahbod | b89c7fd | 2018-11-21 12:32:48 -0500 | [diff] [blame] | 385 | #ifndef HB_USE_ATEXIT |
| 386 | # define HB_USE_ATEXIT 0 |
| 387 | #endif |
Behdad Esfahbod | dabe698 | 2012-11-23 14:21:35 -0500 | [diff] [blame] | 388 | |
Behdad Esfahbod | 35a7383 | 2009-08-01 19:30:31 -0400 | [diff] [blame] | 389 | #define HB_STMT_START do |
| 390 | #define HB_STMT_END while (0) |
Behdad Esfahbod | 5b3f770 | 2006-12-28 06:42:37 -0500 | [diff] [blame] | 391 | |
Behdad Esfahbod | 19e0091 | 2018-08-06 04:54:31 -0700 | [diff] [blame] | 392 | /* Static-assert as expression. */ |
Behdad Esfahbod | 76dcbf8 | 2017-10-15 11:24:35 +0200 | [diff] [blame] | 393 | template <unsigned int cond> class hb_assert_constant_t; |
| 394 | template <> class hb_assert_constant_t<1> {}; |
Behdad Esfahbod | 672ca3b | 2015-10-26 14:05:05 -0700 | [diff] [blame] | 395 | #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] | 396 | |
Behdad Esfahbod | 6fd5364 | 2011-04-11 11:47:14 -0400 | [diff] [blame] | 397 | /* Lets assert int types. Saves trouble down the road. */ |
Behdad Esfahbod | 606bf57 | 2018-09-16 19:33:48 +0200 | [diff] [blame] | 398 | static_assert ((sizeof (int8_t) == 1), ""); |
| 399 | static_assert ((sizeof (uint8_t) == 1), ""); |
| 400 | static_assert ((sizeof (int16_t) == 2), ""); |
| 401 | static_assert ((sizeof (uint16_t) == 2), ""); |
| 402 | static_assert ((sizeof (int32_t) == 4), ""); |
| 403 | static_assert ((sizeof (uint32_t) == 4), ""); |
| 404 | static_assert ((sizeof (int64_t) == 8), ""); |
| 405 | static_assert ((sizeof (uint64_t) == 8), ""); |
| 406 | static_assert ((sizeof (hb_codepoint_t) == 4), ""); |
| 407 | static_assert ((sizeof (hb_position_t) == 4), ""); |
| 408 | static_assert ((sizeof (hb_mask_t) == 4), ""); |
| 409 | static_assert ((sizeof (hb_var_int_t) == 4), ""); |
Behdad Esfahbod | 6fd5364 | 2011-04-11 11:47:14 -0400 | [diff] [blame] | 410 | |
Behdad Esfahbod | 824fd34 | 2019-04-11 11:16:01 -0400 | [diff] [blame] | 411 | #define HB_DELETE_COPY_ASSIGN(TypeName) \ |
Behdad Esfahbod | baf1e79 | 2019-04-11 11:18:04 -0400 | [diff] [blame^] | 412 | TypeName(const TypeName&) = delete; \ |
| 413 | void operator=(const TypeName&) = delete |
Behdad Esfahbod | 824fd34 | 2019-04-11 11:16:01 -0400 | [diff] [blame] | 414 | #define HB_DELETE_COPY_ASSIGN_TEMPLATE(TypeName, T) \ |
Behdad Esfahbod | baf1e79 | 2019-04-11 11:18:04 -0400 | [diff] [blame^] | 415 | TypeName(const TypeName<T>&) = delete; \ |
| 416 | void operator=(const TypeName<T>&) = delete |
Behdad Esfahbod | 824fd34 | 2019-04-11 11:16:01 -0400 | [diff] [blame] | 417 | #define HB_DELETE_COPY_ASSIGN_TEMPLATE2(TypeName, T1, T2) \ |
Behdad Esfahbod | baf1e79 | 2019-04-11 11:18:04 -0400 | [diff] [blame^] | 418 | TypeName(const TypeName<T1, T2>&) = delete; \ |
| 419 | void operator=(const TypeName<T1, T2>&) = delete |
Behdad Esfahbod | 824fd34 | 2019-04-11 11:16:01 -0400 | [diff] [blame] | 420 | #define HB_DELETE_CREATE_COPY_ASSIGN(TypeName) \ |
Behdad Esfahbod | baf1e79 | 2019-04-11 11:18:04 -0400 | [diff] [blame^] | 421 | TypeName() = delete; \ |
| 422 | TypeName(const TypeName&) = delete; \ |
| 423 | void operator=(const TypeName&) = delete |
Behdad Esfahbod | 824fd34 | 2019-04-11 11:16:01 -0400 | [diff] [blame] | 424 | #define HB_DELETE_CREATE_COPY_ASSIGN_TEMPLATE(TypeName, T) \ |
Behdad Esfahbod | baf1e79 | 2019-04-11 11:18:04 -0400 | [diff] [blame^] | 425 | TypeName() = delete; \ |
| 426 | TypeName(const TypeName<T>&) = delete; \ |
| 427 | void operator=(const TypeName<T>&) = delete |
Behdad Esfahbod | 824fd34 | 2019-04-11 11:16:01 -0400 | [diff] [blame] | 428 | #define HB_DELETE_CREATE_COPY_ASSIGN_TEMPLATE2(TypeName, T1, T2) \ |
Behdad Esfahbod | baf1e79 | 2019-04-11 11:18:04 -0400 | [diff] [blame^] | 429 | TypeName() = delete; \ |
| 430 | TypeName(const TypeName<T1, T2>&) = delete; \ |
| 431 | void operator=(const TypeName<T1, T2>&) = delete |
Behdad Esfahbod | c7c5df9 | 2018-10-29 15:16:52 -0700 | [diff] [blame] | 432 | |
Behdad Esfahbod | 44999f8 | 2018-07-11 17:00:59 +0200 | [diff] [blame] | 433 | |
| 434 | /* |
| 435 | * Compiler-assisted vectorization parameters. |
| 436 | */ |
| 437 | |
| 438 | /* |
| 439 | * Disable vectorization for now. To correctly use them, we should |
| 440 | * use posix_memalign() to allocate in hb_vector_t. Otherwise, can |
| 441 | * cause misaligned access. |
| 442 | * |
| 443 | * https://bugs.chromium.org/p/chromium/issues/detail?id=860184 |
| 444 | */ |
| 445 | #if !defined(HB_VECTOR_SIZE) |
| 446 | # define HB_VECTOR_SIZE 0 |
| 447 | #endif |
| 448 | |
| 449 | /* The `vector_size' attribute was introduced in gcc 3.1. */ |
| 450 | #if !defined(HB_VECTOR_SIZE) |
| 451 | # if defined( __GNUC__ ) && ( __GNUC__ >= 4 ) |
| 452 | # define HB_VECTOR_SIZE 128 |
| 453 | # else |
| 454 | # define HB_VECTOR_SIZE 0 |
| 455 | # endif |
| 456 | #endif |
Behdad Esfahbod | 606bf57 | 2018-09-16 19:33:48 +0200 | [diff] [blame] | 457 | static_assert (0 == (HB_VECTOR_SIZE & (HB_VECTOR_SIZE - 1)), "HB_VECTOR_SIZE is not power of 2."); |
| 458 | 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] | 459 | #if HB_VECTOR_SIZE |
| 460 | typedef uint64_t hb_vector_size_impl_t __attribute__((vector_size (HB_VECTOR_SIZE / 8))); |
| 461 | #else |
| 462 | typedef uint64_t hb_vector_size_impl_t; |
| 463 | #endif |
| 464 | |
| 465 | |
Behdad Esfahbod | 91dd115 | 2016-02-25 13:56:47 +0900 | [diff] [blame] | 466 | /* HB_NDEBUG disables some sanity checks that are very safe to disable and |
| 467 | * should be disabled in production systems. If NDEBUG is defined, enable |
| 468 | * HB_NDEBUG; but if it's desirable that normal assert()s (which are very |
| 469 | * light-weight) to be enabled, then HB_DEBUG can be defined to disable |
| 470 | * the costlier checks. */ |
| 471 | #ifdef NDEBUG |
Behdad Esfahbod | bd021a6 | 2018-05-08 01:50:30 -0700 | [diff] [blame] | 472 | #define HB_NDEBUG 1 |
Behdad Esfahbod | 91dd115 | 2016-02-25 13:56:47 +0900 | [diff] [blame] | 473 | #endif |
| 474 | |
Behdad Esfahbod | cc06c24 | 2011-07-25 20:25:44 -0400 | [diff] [blame] | 475 | |
Behdad Esfahbod | be336da | 2018-08-06 04:32:51 -0700 | [diff] [blame] | 476 | /* Flags */ |
Behdad Esfahbod | 8f0b64f | 2011-07-29 17:02:48 -0400 | [diff] [blame] | 477 | |
Behdad Esfahbod | aa7044d | 2015-11-04 16:25:57 -0800 | [diff] [blame] | 478 | /* Enable bitwise ops on enums marked as flags_t */ |
Behdad Esfahbod | 6986208 | 2015-11-04 18:46:22 -0800 | [diff] [blame] | 479 | /* To my surprise, looks like the function resolver is happy to silently cast |
| 480 | * 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] | 481 | * originally had in mind... :(. |
| 482 | * |
ebraminio | 7c6937e | 2017-11-20 14:49:22 -0500 | [diff] [blame] | 483 | * For MSVC warnings, see: https://github.com/harfbuzz/harfbuzz/pull/163 |
Behdad Esfahbod | e0082ae | 2015-11-17 18:42:13 -0800 | [diff] [blame] | 484 | */ |
| 485 | #ifdef _MSC_VER |
| 486 | # pragma warning(disable:4200) |
| 487 | # pragma warning(disable:4800) |
Chun-wei Fan | 167c327 | 2015-11-09 17:17:56 +0800 | [diff] [blame] | 488 | #endif |
Behdad Esfahbod | 1dc32ea | 2015-11-20 13:24:19 -0800 | [diff] [blame] | 489 | #define HB_MARK_AS_FLAG_T(T) \ |
| 490 | extern "C++" { \ |
| 491 | static inline T operator | (T l, T r) { return T ((unsigned) l | (unsigned) r); } \ |
| 492 | static inline T operator & (T l, T r) { return T ((unsigned) l & (unsigned) r); } \ |
| 493 | static inline T operator ^ (T l, T r) { return T ((unsigned) l ^ (unsigned) r); } \ |
| 494 | static inline T operator ~ (T r) { return T (~(unsigned int) r); } \ |
| 495 | static inline T& operator |= (T &l, T r) { l = l | r; return l; } \ |
| 496 | static inline T& operator &= (T& l, T r) { l = l & r; return l; } \ |
| 497 | 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] | 498 | } \ |
| 499 | static_assert (true, "") |
Behdad Esfahbod | aa7044d | 2015-11-04 16:25:57 -0800 | [diff] [blame] | 500 | |
Behdad Esfahbod | 45d6f29 | 2011-07-30 14:44:30 -0400 | [diff] [blame] | 501 | /* Useful for set-operations on small enums. |
| 502 | * For example, for testing "x ∈ {x1, x2, x3}" use: |
Behdad Esfahbod | 6058f98 | 2017-10-19 11:39:52 -0700 | [diff] [blame] | 503 | * (FLAG_UNSAFE(x) & (FLAG(x1) | FLAG(x2) | FLAG(x3))) |
Behdad Esfahbod | 45d6f29 | 2011-07-30 14:44:30 -0400 | [diff] [blame] | 504 | */ |
Behdad Esfahbod | 3d2b98e | 2018-11-23 10:45:44 -0500 | [diff] [blame] | 505 | #define FLAG(x) (ASSERT_STATIC_EXPR_ZERO ((unsigned)(x) < 32) + (((uint32_t) 1U) << (unsigned)(x))) |
| 506 | #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] | 507 | #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] | 508 | #define FLAG64(x) (ASSERT_STATIC_EXPR_ZERO ((unsigned)(x) < 64) + (((uint64_t) 1ULL) << (unsigned)(x))) |
| 509 | #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] | 510 | |
Behdad Esfahbod | 8f0b64f | 2011-07-29 17:02:48 -0400 | [diff] [blame] | 511 | |
Steven R. Loomis | a13b023 | 2015-12-11 10:21:27 -0800 | [diff] [blame] | 512 | /* Size signifying variable-sized array */ |
| 513 | #define VAR 1 |
Behdad Esfahbod | bab02d3 | 2013-02-12 15:26:45 -0500 | [diff] [blame] | 514 | |
Behdad Esfahbod | e1a37f3 | 2017-10-30 11:42:28 -0600 | [diff] [blame] | 515 | |
Chun-wei Fan | 19256be | 2018-03-12 13:33:03 +0800 | [diff] [blame] | 516 | /* fallback for round() */ |
Chun-wei Fan | 19256be | 2018-03-12 13:33:03 +0800 | [diff] [blame] | 517 | static inline double |
Behdad Esfahbod | 01dff1e | 2018-06-26 18:00:58 -0400 | [diff] [blame] | 518 | _hb_round (double x) |
Chun-wei Fan | 19256be | 2018-03-12 13:33:03 +0800 | [diff] [blame] | 519 | { |
| 520 | if (x >= 0) |
| 521 | return floor (x + 0.5); |
| 522 | else |
| 523 | return ceil (x - 0.5); |
| 524 | } |
Behdad Esfahbod | 292c100 | 2018-07-10 13:16:52 +0200 | [diff] [blame] | 525 | #if !defined (HAVE_ROUND) && !defined (HAVE_DECL_ROUND) |
Behdad Esfahbod | 01dff1e | 2018-06-26 18:00:58 -0400 | [diff] [blame] | 526 | #define round(x) _hb_round(x) |
Chun-wei Fan | 19256be | 2018-03-12 13:33:03 +0800 | [diff] [blame] | 527 | #endif |
| 528 | |
| 529 | |
Behdad Esfahbod | 83ea277 | 2018-07-10 13:17:27 +0200 | [diff] [blame] | 530 | /* fallback for posix_memalign() */ |
| 531 | static inline int |
| 532 | _hb_memalign(void **memptr, size_t alignment, size_t size) |
| 533 | { |
Behdad Esfahbod | 491d93b | 2018-07-10 16:03:31 +0200 | [diff] [blame] | 534 | if (unlikely (0 != (alignment & (alignment - 1)) || |
Behdad Esfahbod | 83ea277 | 2018-07-10 13:17:27 +0200 | [diff] [blame] | 535 | !alignment || |
| 536 | 0 != (alignment & (sizeof (void *) - 1)))) |
| 537 | return EINVAL; |
| 538 | |
| 539 | char *p = (char *) malloc (size + alignment - 1); |
| 540 | if (unlikely (!p)) |
| 541 | return ENOMEM; |
| 542 | |
| 543 | size_t off = (size_t) p & (alignment - 1); |
| 544 | if (off) |
| 545 | p += alignment - off; |
| 546 | |
| 547 | *memptr = (void *) p; |
| 548 | |
| 549 | return 0; |
| 550 | } |
| 551 | #if !defined(posix_memalign) && !defined(HAVE_POSIX_MEMALIGN) |
| 552 | #define posix_memalign _hb_memalign |
| 553 | #endif |
| 554 | |
| 555 | |
Behdad Esfahbod | bdb53ca | 2018-10-11 20:20:00 -0400 | [diff] [blame] | 556 | /* |
Behdad Esfahbod | 17f0cfa | 2019-03-31 21:34:19 -0700 | [diff] [blame] | 557 | * Big-endian integers. Here because fundamental. |
| 558 | */ |
| 559 | |
| 560 | template <typename Type, int Bytes> struct BEInt; |
| 561 | |
| 562 | template <typename Type> |
| 563 | struct BEInt<Type, 1> |
| 564 | { |
| 565 | public: |
| 566 | BEInt<Type, 1>& operator = (Type V) |
| 567 | { |
| 568 | v = V; |
| 569 | return *this; |
| 570 | } |
| 571 | operator Type () const { return v; } |
| 572 | private: uint8_t v; |
| 573 | }; |
| 574 | template <typename Type> |
| 575 | struct BEInt<Type, 2> |
| 576 | { |
| 577 | public: |
| 578 | BEInt<Type, 2>& operator = (Type V) |
| 579 | { |
| 580 | v[0] = (V >> 8) & 0xFF; |
| 581 | v[1] = (V ) & 0xFF; |
| 582 | return *this; |
| 583 | } |
| 584 | operator Type () const |
| 585 | { |
| 586 | #if ((defined(__GNUC__) && __GNUC__ >= 5) || defined(__clang__)) && \ |
| 587 | defined(__BYTE_ORDER) && \ |
| 588 | (__BYTE_ORDER == __LITTLE_ENDIAN || __BYTE_ORDER == __BIG_ENDIAN) |
| 589 | /* Spoon-feed the compiler a big-endian integer with alignment 1. |
| 590 | * https://github.com/harfbuzz/harfbuzz/pull/1398 */ |
| 591 | struct __attribute__((packed)) packed_uint16_t { uint16_t v; }; |
| 592 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
| 593 | return __builtin_bswap16 (((packed_uint16_t *) this)->v); |
| 594 | #else /* __BYTE_ORDER == __BIG_ENDIAN */ |
| 595 | return ((packed_uint16_t *) this)->v; |
| 596 | #endif |
| 597 | #endif |
| 598 | return (v[0] << 8) |
| 599 | + (v[1] ); |
| 600 | } |
| 601 | private: uint8_t v[2]; |
| 602 | }; |
| 603 | template <typename Type> |
| 604 | struct BEInt<Type, 3> |
| 605 | { |
| 606 | public: |
| 607 | BEInt<Type, 3>& operator = (Type V) |
| 608 | { |
| 609 | v[0] = (V >> 16) & 0xFF; |
| 610 | v[1] = (V >> 8) & 0xFF; |
| 611 | v[2] = (V ) & 0xFF; |
| 612 | return *this; |
| 613 | } |
| 614 | operator Type () const |
| 615 | { |
| 616 | return (v[0] << 16) |
| 617 | + (v[1] << 8) |
| 618 | + (v[2] ); |
| 619 | } |
| 620 | private: uint8_t v[3]; |
| 621 | }; |
| 622 | template <typename Type> |
| 623 | struct BEInt<Type, 4> |
| 624 | { |
| 625 | public: |
| 626 | BEInt<Type, 4>& operator = (Type V) |
| 627 | { |
| 628 | v[0] = (V >> 24) & 0xFF; |
| 629 | v[1] = (V >> 16) & 0xFF; |
| 630 | v[2] = (V >> 8) & 0xFF; |
| 631 | v[3] = (V ) & 0xFF; |
| 632 | return *this; |
| 633 | } |
| 634 | operator Type () const |
| 635 | { |
| 636 | return (v[0] << 24) |
| 637 | + (v[1] << 16) |
| 638 | + (v[2] << 8) |
| 639 | + (v[3] ); |
| 640 | } |
| 641 | private: uint8_t v[4]; |
| 642 | }; |
| 643 | |
| 644 | |
| 645 | /* |
Behdad Esfahbod | bdb53ca | 2018-10-11 20:20:00 -0400 | [diff] [blame] | 646 | * For lack of a better place, put Zawgyi script hack here. |
| 647 | * https://github.com/harfbuzz/harfbuzz/issues/1162 |
| 648 | */ |
| 649 | |
| 650 | #define HB_SCRIPT_MYANMAR_ZAWGYI ((hb_script_t) HB_TAG ('Q','a','a','g')) |
| 651 | |
| 652 | |
Behdad Esfahbod | 865deeb | 2018-12-21 17:35:58 -0500 | [diff] [blame] | 653 | /* Headers we include for everyone. Keep topologically sorted by dependency. |
| 654 | * They express dependency amongst themselves, but no other file should include |
| 655 | * them directly.*/ |
Behdad Esfahbod | e76a3ca | 2018-12-27 17:23:12 -0500 | [diff] [blame] | 656 | #include "hb-meta.hh" |
Behdad Esfahbod | c77ae40 | 2018-08-25 22:36:36 -0700 | [diff] [blame] | 657 | #include "hb-mutex.hh" |
Behdad Esfahbod | f64ea8f | 2018-12-30 18:49:34 -0500 | [diff] [blame] | 658 | #include "hb-atomic.hh" // Requires: hb-meta |
Behdad Esfahbod | 8c6cbbd | 2018-12-28 14:29:09 -0500 | [diff] [blame] | 659 | #include "hb-null.hh" // Requires: hb-meta |
Behdad Esfahbod | bdd5a9c | 2019-03-28 21:58:07 -0700 | [diff] [blame] | 660 | #include "hb-algs.hh" // Requires: hb-meta hb-null |
Behdad Esfahbod | e75b220 | 2019-01-28 21:26:23 -0500 | [diff] [blame] | 661 | #include "hb-iter.hh" // Requires: hb-meta |
Behdad Esfahbod | 6e3ad65 | 2019-01-09 09:05:01 -0800 | [diff] [blame] | 662 | #include "hb-debug.hh" // Requires: hb-algs hb-atomic |
| 663 | #include "hb-array.hh" // Requires: hb-algs hb-iter hb-null |
Behdad Esfahbod | 865deeb | 2018-12-21 17:35:58 -0500 | [diff] [blame] | 664 | #include "hb-vector.hh" // Requires: hb-array hb-null |
| 665 | #include "hb-object.hh" // Requires: hb-atomic hb-mutex hb-vector |
Behdad Esfahbod | 83ea277 | 2018-07-10 13:17:27 +0200 | [diff] [blame] | 666 | |
Behdad Esfahbod | c77ae40 | 2018-08-25 22:36:36 -0700 | [diff] [blame] | 667 | #endif /* HB_HH */ |