blob: 723d7e7699e52c514cf75419bcb61b95d1d94426 [file] [log] [blame]
Behdad Esfahbod64aef3a2008-01-23 16:14:38 -05001/*
Behdad Esfahbod2409d5f2011-04-21 17:14:28 -04002 * Copyright © 2007,2008,2009 Red Hat, Inc.
Behdad Esfahbod0ab8c862012-05-11 01:25:34 +02003 * Copyright © 2011,2012 Google, Inc.
Behdad Esfahbod64aef3a2008-01-23 16:14:38 -05004 *
Behdad Esfahbodc755cb32010-04-22 00:11:43 -04005 * This is part of HarfBuzz, a text shaping library.
Behdad Esfahbod64aef3a2008-01-23 16:14:38 -05006 *
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 Esfahbod2409d5f2011-04-21 17:14:28 -040026 * Google Author(s): Behdad Esfahbod
Behdad Esfahbod64aef3a2008-01-23 16:14:38 -050027 */
28
Behdad Esfahbodc77ae402018-08-25 22:36:36 -070029#ifndef HB_HH
30#define HB_HH
Behdad Esfahbod5b3f7702006-12-28 06:42:37 -050031
Behdad Esfahbodf60282c2019-01-24 16:29:09 +010032#ifndef HB_NO_PRAGMA_GCC_DIAGNOSTIC
Behdad Esfahbod227d85e2019-05-10 23:15:58 -070033#ifdef _MSC_VER
Behdad Esfahbod51b58482019-01-28 14:09:45 -050034#pragma warning( disable: 4068 ) /* Unknown pragma */
35#endif
Behdad Esfahbodf13b6782019-01-18 14:53:54 -050036#if defined(__GNUC__) || defined(__clang__)
Behdad Esfahbod1077e402019-01-17 18:36:10 -050037/* Rules:
Behdad Esfahbod7a634d72019-01-18 09:49:14 -050038 *
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 Esfahbod1077e402019-01-17 18:36:10 -050042 * - Within each category, keep sorted.
Behdad Esfahbod7a634d72019-01-18 09:49:14 -050043 *
Behdad Esfahbod2bd530d2019-01-18 09:28:22 -050044 * - Warnings whose scope can be expanded in future compiler versions shall
45 * be declared as "warning". Otherwise, either ignored or error.
Behdad Esfahbod1077e402019-01-17 18:36:10 -050046 */
Behdad Esfahbod16e5ba82019-01-18 09:46:17 -050047
Behdad Esfahbod7a634d72019-01-18 09:49:14 -050048/* Setup. Don't sort order within this category. */
Behdad Esfahbodf60282c2019-01-24 16:29:09 +010049#ifndef HB_NO_PRAGMA_GCC_DIAGNOSTIC_WARNING
Behdad Esfahbod7a634d72019-01-18 09:49:14 -050050#pragma GCC diagnostic warning "-Wall"
51#pragma GCC diagnostic warning "-Wextra"
Behdad Esfahbodf60282c2019-01-24 16:29:09 +010052#endif
53#ifndef HB_NO_PRAGMA_GCC_DIAGNOSTIC_IGNORED
Behdad Esfahbod7a634d72019-01-18 09:49:14 -050054#pragma GCC diagnostic ignored "-Wpragmas"
55#pragma GCC diagnostic ignored "-Wunknown-pragmas"
56#pragma GCC diagnostic ignored "-Wunknown-warning-option"
Behdad Esfahbodf60282c2019-01-24 16:29:09 +010057#endif
58#ifndef HB_NO_PRAGMA_GCC_DIAGNOSTIC_WARNING
Behdad Esfahbod7a634d72019-01-18 09:49:14 -050059//#pragma GCC diagnostic warning "-Weverything"
Behdad Esfahbodf60282c2019-01-24 16:29:09 +010060#endif
Behdad Esfahbod16e5ba82019-01-18 09:46:17 -050061
Behdad Esfahbod2bd530d2019-01-18 09:28:22 -050062/* Error. Should never happen. */
Behdad Esfahbodf60282c2019-01-24 16:29:09 +010063#ifndef HB_NO_PRAGMA_GCC_DIAGNOSTIC_ERROR
Behdad Esfahbod9bd7ba52021-10-12 08:44:01 -070064#pragma GCC diagnostic error "-Wbitwise-instead-of-logical"
Behdad Esfahbod7a634d72019-01-18 09:49:14 -050065#pragma GCC diagnostic error "-Wcast-align"
Behdad Esfahbod60022ec2019-01-26 14:04:51 +010066#pragma GCC diagnostic error "-Wcast-function-type"
Behdad Esfahbode9c0a742022-06-15 16:57:16 -060067#pragma GCC diagnostic error "-Wcomma"
Behdad Esfahbod9b4e51b2019-01-18 12:23:02 -050068#pragma GCC diagnostic error "-Wdelete-non-virtual-dtor"
Behdad Esfahbod8e3cde62019-06-19 19:58:24 -070069#pragma GCC diagnostic error "-Wembedded-directive"
Behdad Esfahbode98f0dd2019-05-13 13:53:06 -070070#pragma GCC diagnostic error "-Wextra-semi-stmt"
Behdad Esfahbod7a634d72019-01-18 09:49:14 -050071#pragma GCC diagnostic error "-Wformat-security"
72#pragma GCC diagnostic error "-Wimplicit-function-declaration"
73#pragma GCC diagnostic error "-Winit-self"
Behdad Esfahbodf35e7ea2019-01-26 22:50:00 +010074#pragma GCC diagnostic error "-Winjected-class-name"
Behdad Esfahbod7a634d72019-01-18 09:49:14 -050075#pragma GCC diagnostic error "-Wmissing-braces"
76#pragma GCC diagnostic error "-Wmissing-declarations"
77#pragma GCC diagnostic error "-Wmissing-prototypes"
Behdad Esfahboda89d9f22021-02-20 15:35:28 -070078#pragma GCC diagnostic error "-Wnarrowing"
Behdad Esfahbod7a634d72019-01-18 09:49:14 -050079#pragma GCC diagnostic error "-Wnested-externs"
80#pragma GCC diagnostic error "-Wold-style-definition"
81#pragma GCC diagnostic error "-Wpointer-arith"
82#pragma GCC diagnostic error "-Wredundant-decls"
Behdad Esfahboda25174a2019-01-18 09:59:36 -050083#pragma GCC diagnostic error "-Wreorder"
Behdad Esfahbod90772722019-01-22 12:40:18 +010084#pragma GCC diagnostic error "-Wsign-compare"
Behdad Esfahbod7a634d72019-01-18 09:49:14 -050085#pragma GCC diagnostic error "-Wstrict-prototypes"
86#pragma GCC diagnostic error "-Wstring-conversion"
87#pragma GCC diagnostic error "-Wswitch-enum"
88#pragma GCC diagnostic error "-Wtautological-overlap-compare"
89#pragma GCC diagnostic error "-Wunneeded-internal-declaration"
90#pragma GCC diagnostic error "-Wunused"
91#pragma GCC diagnostic error "-Wunused-local-typedefs"
92#pragma GCC diagnostic error "-Wunused-value"
93#pragma GCC diagnostic error "-Wunused-variable"
Behdad Esfahbodc81f02f2019-01-22 12:00:44 +010094#pragma GCC diagnostic error "-Wvla"
Behdad Esfahbod7a634d72019-01-18 09:49:14 -050095#pragma GCC diagnostic error "-Wwrite-strings"
Behdad Esfahbodf60282c2019-01-24 16:29:09 +010096#endif
Behdad Esfahbod16e5ba82019-01-18 09:46:17 -050097
Behdad Esfahbod2bd530d2019-01-18 09:28:22 -050098/* Warning. To be investigated if happens. */
Behdad Esfahbodf60282c2019-01-24 16:29:09 +010099#ifndef HB_NO_PRAGMA_GCC_DIAGNOSTIC_WARNING
Behdad Esfahbod7a634d72019-01-18 09:49:14 -0500100#pragma GCC diagnostic warning "-Wbuiltin-macro-redefined"
Behdad Esfahbod45f5e562019-05-07 00:33:32 -0700101#pragma GCC diagnostic warning "-Wdeprecated"
Ebrahim Byagowi6a6bf7b2019-07-17 21:22:38 +0430102#pragma GCC diagnostic warning "-Wdeprecated-declarations"
Behdad Esfahbod7a634d72019-01-18 09:49:14 -0500103#pragma GCC diagnostic warning "-Wdisabled-optimization"
Behdad Esfahbod3c240bd2019-06-07 10:56:24 -0700104#pragma GCC diagnostic warning "-Wdouble-promotion"
Behdad Esfahbod7a634d72019-01-18 09:49:14 -0500105#pragma GCC diagnostic warning "-Wformat=2"
Behdad Esfahboded023f62023-01-12 17:04:24 -0700106#pragma GCC diagnostic warning "-Wformat-signedness"
Behdad Esfahbod7a634d72019-01-18 09:49:14 -0500107#pragma GCC diagnostic warning "-Wignored-pragma-optimize"
108#pragma GCC diagnostic warning "-Wlogical-op"
Behdad Esfahbod46600902019-01-18 09:53:16 -0500109#pragma GCC diagnostic warning "-Wmaybe-uninitialized"
Behdad Esfahbod7a634d72019-01-18 09:49:14 -0500110#pragma GCC diagnostic warning "-Wmissing-format-attribute"
Behdad Esfahbod7a634d72019-01-18 09:49:14 -0500111#pragma GCC diagnostic warning "-Wundef"
Behdad Esfahbod075fe332023-01-12 17:14:42 -0700112#pragma GCC diagnostic warning "-Wunsafe-loop-optimizations"
Ebrahim Byagowi0ca35572020-08-09 16:10:06 +0430113#pragma GCC diagnostic warning "-Wunused-but-set-variable"
Behdad Esfahbodf60282c2019-01-24 16:29:09 +0100114#endif
Behdad Esfahbod16e5ba82019-01-18 09:46:17 -0500115
Behdad Esfahbod2bd530d2019-01-18 09:28:22 -0500116/* Ignored currently, but should be fixed at some point. */
Behdad Esfahbodf60282c2019-01-24 16:29:09 +0100117#ifndef HB_NO_PRAGMA_GCC_DIAGNOSTIC_IGNORED
Behdad Esfahbod7a634d72019-01-18 09:49:14 -0500118#pragma GCC diagnostic ignored "-Wconversion" // TODO fix
Behdad Esfahbod7a634d72019-01-18 09:49:14 -0500119#pragma GCC diagnostic ignored "-Wshadow" // TODO fix
Behdad Esfahbod7a634d72019-01-18 09:49:14 -0500120#pragma GCC diagnostic ignored "-Wunused-parameter" // TODO fix
Behdad Esfahbod05e845c2021-03-29 16:02:10 -0700121#if defined(__GNUC__) && !defined(__clang__)
Behdad Esfahbodb5e40322021-03-29 15:54:40 -0700122#pragma GCC diagnostic ignored "-Wunused-result" // TODO fix
Behdad Esfahbodf60282c2019-01-24 16:29:09 +0100123#endif
Behdad Esfahbod05e845c2021-03-29 16:02:10 -0700124#endif
Behdad Esfahbod16e5ba82019-01-18 09:46:17 -0500125
Behdad Esfahbod2bd530d2019-01-18 09:28:22 -0500126/* Ignored intentionally. */
Behdad Esfahbodf60282c2019-01-24 16:29:09 +0100127#ifndef HB_NO_PRAGMA_GCC_DIAGNOSTIC_IGNORED
Behdad Esfahbod7a634d72019-01-18 09:49:14 -0500128#pragma GCC diagnostic ignored "-Wclass-memaccess"
Behdad Esfahbod60c6b772022-10-28 14:19:39 -0600129#pragma GCC diagnostic ignored "-Wcast-function-type-strict" // https://github.com/harfbuzz/harfbuzz/pull/3859#issuecomment-1295409126
Behdad Esfahbod7a634d72019-01-18 09:49:14 -0500130#pragma GCC diagnostic ignored "-Wformat-nonliteral"
131#pragma GCC diagnostic ignored "-Wformat-zero-length"
132#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
133#pragma GCC diagnostic ignored "-Wpacked" // Erratic impl in clang
Behdad Esfahbod86993c02021-02-19 17:09:33 -0700134#pragma GCC diagnostic ignored "-Wrange-loop-analysis" // https://github.com/harfbuzz/harfbuzz/issues/2834
Behdad Esfahbod7a634d72019-01-18 09:49:14 -0500135#pragma GCC diagnostic ignored "-Wstrict-aliasing"
136#pragma GCC diagnostic ignored "-Wtype-limits"
Ebrahim Byagowie261dc32019-05-07 01:24:55 +0430137#pragma GCC diagnostic ignored "-Wc++11-compat" // only gcc raises it
Behdad Esfahbodf60282c2019-01-24 16:29:09 +0100138#endif
Behdad Esfahbodf13b6782019-01-18 14:53:54 -0500139
140#endif
Behdad Esfahbod868b0c02019-01-17 15:08:36 -0500141#endif
142
Behdad Esfahbode6582de2019-05-10 23:53:38 -0700143
144#include "hb-config.hh"
Behdad Esfahbodae208962022-12-26 12:30:39 -0700145#include "hb-limits.hh"
Behdad Esfahbode6582de2019-05-10 23:53:38 -0700146
Behdad Esfahbod12360f72008-01-23 15:50:38 -0500147
Behdad Esfahbod49334f92018-12-17 18:27:36 -0500148/*
149 * Following added based on what AC_USE_SYSTEM_EXTENSIONS adds to
150 * config.h.in. Copied here for the convenience of those embedding
151 * HarfBuzz and not using our build system.
152 */
153/* Enable extensions on AIX 3, Interix. */
154#ifndef _ALL_SOURCE
155# define _ALL_SOURCE 1
156#endif
157/* Enable GNU extensions on systems that have them. */
158#ifndef _GNU_SOURCE
159# define _GNU_SOURCE 1
160#endif
161/* Enable threading extensions on Solaris. */
162#ifndef _POSIX_PTHREAD_SEMANTICS
163# define _POSIX_PTHREAD_SEMANTICS 1
164#endif
165/* Enable extensions on HP NonStop. */
166#ifndef _TANDEM_SOURCE
167# define _TANDEM_SOURCE 1
168#endif
169/* Enable general extensions on Solaris. */
170#ifndef __EXTENSIONS__
171# define __EXTENSIONS__ 1
172#endif
173
Chun-wei Fan8e4ad1d2018-07-25 18:12:34 +0800174#if defined (_MSC_VER) && defined (HB_DLL_EXPORT)
175#define HB_EXTERN __declspec (dllexport) extern
176#endif
177
Behdad Esfahbodd1c9eb42012-04-12 13:17:44 -0400178#include "hb.h"
Behdad Esfahbodd1c9eb42012-04-12 13:17:44 -0400179#define HB_H_IN
Behdad Esfahbod3e32cd92012-04-23 13:20:52 -0400180#include "hb-ot.h"
Behdad Esfahbodd1c9eb42012-04-12 13:17:44 -0400181#define HB_OT_H_IN
Behdad Esfahbodb2061332018-11-23 14:05:11 -0500182#include "hb-aat.h"
183#define HB_AAT_H_IN
Behdad Esfahbodb28815c2009-08-04 22:35:36 -0400184
Behdad Esfahbod7cb22ba2021-03-01 12:44:06 -0700185#include <cassert>
186#include <cfloat>
187#include <climits>
Ryan VanderMeulen1c0eeb72022-06-15 23:05:15 -0400188#if defined(_MSC_VER) && !defined(_USE_MATH_DEFINES)
Behdad Esfahbode0d5fe72021-09-17 08:27:03 -0400189# define _USE_MATH_DEFINES
190#endif
Behdad Esfahbod7cb22ba2021-03-01 12:44:06 -0700191#include <cmath>
192#include <cstdarg>
193#include <cstddef>
194#include <cstdio>
195#include <cstdlib>
196#include <cstring>
Behdad Esfahbodc7d457a2009-05-21 12:46:29 -0400197
Tor Andersson8f4c1232018-04-13 23:01:54 +0430198#if (defined(_MSC_VER) && _MSC_VER >= 1500) || defined(__MINGW32__)
Eli Zaretskiid5e5f372019-06-05 22:20:03 +0300199#ifdef __MINGW32_VERSION
200#ifndef WIN32_LEAN_AND_MEAN
201#define WIN32_LEAN_AND_MEAN 1
202#endif
Eli Zaretskiid5e5f372019-06-05 22:20:03 +0300203#else
Arkady Shapkin6c103282018-02-15 23:17:46 +0300204#include <intrin.h>
205#endif
Eli Zaretskiid5e5f372019-06-05 22:20:03 +0300206#endif
Behdad Esfahbodacdba3f2010-07-23 15:11:18 -0400207
Hugo Beauzée-Luyssen40ec1872020-04-24 14:01:07 +0200208#ifdef _WIN32
209#include <windows.h>
210#include <winapifamily.h>
211#endif
212
Behdad Esfahbod2a749682017-10-26 19:48:33 -0600213#define HB_PASTE1(a,b) a##b
214#define HB_PASTE(a,b) HB_PASTE1(a,b)
215
Behdad Esfahbod83ea2772018-07-10 13:17:27 +0200216
Behdad Esfahbod52b41852015-10-03 13:20:55 +0100217/* Compile-time custom allocator support. */
218
Ebrahim Byagowi7c433ff2020-07-15 09:38:12 +0430219#if !defined(HB_CUSTOM_MALLOC) \
220 && defined(hb_malloc_impl) \
221 && defined(hb_calloc_impl) \
222 && defined(hb_realloc_impl) \
223 && defined(hb_free_impl)
224#define HB_CUSTOM_MALLOC
225#endif
226
227#ifdef HB_CUSTOM_MALLOC
Behdad Esfahbodcc6ea302015-10-12 17:21:52 -0400228extern "C" void* hb_malloc_impl(size_t size);
229extern "C" void* hb_calloc_impl(size_t nmemb, size_t size);
230extern "C" void* hb_realloc_impl(void *ptr, size_t size);
231extern "C" void hb_free_impl(void *ptr);
Behdad Esfahbod2337f0d2021-07-08 10:58:50 -0600232#define hb_malloc hb_malloc_impl
233#define hb_calloc hb_calloc_impl
234#define hb_realloc hb_realloc_impl
235#define hb_free hb_free_impl
236#else
237#define hb_malloc malloc
238#define hb_calloc calloc
239#define hb_realloc realloc
240#define hb_free free
Behdad Esfahbod52b41852015-10-03 13:20:55 +0100241#endif
242
243
Behdad Esfahbod2aae6172018-07-11 17:27:23 +0200244/*
245 * Compiler attributes
Behdad Esfahbod37be7742018-08-06 04:51:38 -0700246 */
Behdad Esfahbod292c1002018-07-10 13:16:52 +0200247
Ebrahim Byagowi76c48732017-06-02 21:53:10 +0430248#if (defined(__GNUC__) || defined(__clang__)) && defined(__OPTIMIZE__)
249#define likely(expr) (__builtin_expect (!!(expr), 1))
250#define unlikely(expr) (__builtin_expect (!!(expr), 0))
Behdad Esfahbodae2b8542014-06-03 16:59:09 -0400251#else
252#define likely(expr) (expr)
253#define unlikely(expr) (expr)
Behdad Esfahbodbc200452010-04-29 01:40:26 -0400254#endif
255
Steve Lhomme0b8f3ab2016-07-11 21:57:26 +0200256#if !defined(__GNUC__) && !defined(__clang__)
Behdad Esfahbodae2b8542014-06-03 16:59:09 -0400257#undef __attribute__
258#define __attribute__(x)
259#endif
Behdad Esfahboda794ebf2009-08-06 12:32:35 -0400260
Behdad Esfahbodd9f6be32019-01-18 12:48:01 -0500261#if defined(__GNUC__) && (__GNUC__ >= 3)
Behdad Esfahbodae2b8542014-06-03 16:59:09 -0400262#define HB_PRINTF_FUNC(format_idx, arg_idx) __attribute__((__format__ (__printf__, format_idx, arg_idx)))
263#else
Behdad Esfahbodae2b8542014-06-03 16:59:09 -0400264#define HB_PRINTF_FUNC(format_idx, arg_idx)
265#endif
Iceflowerd6a83ab2019-09-26 11:42:11 +0200266#if defined(__GNUC__) && (__GNUC__ >= 4) || (__clang__)
Behdad Esfahbodae2b8542014-06-03 16:59:09 -0400267#define HB_UNUSED __attribute__((unused))
Behdad Esfahbodbe59f3c2017-12-05 09:01:28 -0800268#elif defined(_MSC_VER) /* https://github.com/harfbuzz/harfbuzz/issues/635 */
269#define HB_UNUSED __pragma(warning(suppress: 4100 4101))
Behdad Esfahbodae2b8542014-06-03 16:59:09 -0400270#else
271#define HB_UNUSED
272#endif
273
274#ifndef HB_INTERNAL
Behdad Esfahbod90d1c742018-02-11 19:08:59 -0800275# if !defined(HB_NO_VISIBILITY) && !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(_MSC_VER) && !defined(__SUNPRO_CC)
Behdad Esfahbodae2b8542014-06-03 16:59:09 -0400276# define HB_INTERNAL __attribute__((__visibility__("hidden")))
Behdad Esfahbod94759d42018-07-23 15:01:39 -0700277# elif defined(__MINGW32__)
Chun-wei Fan8e4ad1d2018-07-25 18:12:34 +0800278 /* We use -export-symbols on mingw32, since it does not support visibility attributes. */
279# define HB_INTERNAL
280# elif defined (_MSC_VER) && defined (HB_DLL_EXPORT)
281 /* We do not try to export internal symbols on Visual Studio */
Behdad Esfahbod94759d42018-07-23 15:01:39 -0700282# define HB_INTERNAL
283#else
Behdad Esfahbodae2b8542014-06-03 16:59:09 -0400284# define HB_INTERNAL
Behdad Esfahbodb87cbe22018-02-07 14:11:26 -0500285# define HB_NO_VISIBILITY 1
Behdad Esfahbodae2b8542014-06-03 16:59:09 -0400286# endif
287#endif
288
Behdad Esfahbod02d864a2019-04-15 15:39:03 -0400289/* https://github.com/harfbuzz/harfbuzz/issues/1651 */
290#if defined(__clang__) && __clang_major__ < 10
291#define static_const static
292#else
293#define static_const static const
294#endif
295
Behdad Esfahbodd9f6be32019-01-18 12:48:01 -0500296#if defined(__GNUC__) && (__GNUC__ >= 3)
Behdad Esfahbodae2b8542014-06-03 16:59:09 -0400297#define HB_FUNC __PRETTY_FUNCTION__
298#elif defined(_MSC_VER)
299#define HB_FUNC __FUNCSIG__
300#else
301#define HB_FUNC __func__
302#endif
303
prrace498e4372018-06-09 16:04:28 -0700304#if defined(__SUNPRO_CC) && (__SUNPRO_CC < 0x5140)
Behdad Esfahbod8cef3a62018-02-09 16:04:23 -0600305/* https://github.com/harfbuzz/harfbuzz/issues/630 */
306#define __restrict
307#endif
308
Behdad Esfahbod305d2fb2015-10-21 11:04:28 -0200309/*
310 * Borrowed from https://bugzilla.mozilla.org/show_bug.cgi?id=1215411
311 * HB_FALLTHROUGH is an annotation to suppress compiler warnings about switch
312 * cases that fall through without a break or return statement. HB_FALLTHROUGH
313 * is only needed on cases that have code:
314 *
315 * switch (foo) {
316 * case 1: // These cases have no code. No fallthrough annotations are needed.
317 * case 2:
318 * case 3:
319 * foo = 4; // This case has code, so a fallthrough annotation is needed:
320 * HB_FALLTHROUGH;
321 * default:
322 * return foo;
323 * }
324 */
325#if defined(__clang__) && __cplusplus >= 201103L
326 /* clang's fallthrough annotations are only available starting in C++11. */
327# define HB_FALLTHROUGH [[clang::fallthrough]]
Behdad Esfahbodd9f6be32019-01-18 12:48:01 -0500328#elif defined(__GNUC__) && (__GNUC__ >= 7)
Behdad Esfahbodf41b9212018-02-05 19:51:09 -0500329 /* GNU fallthrough attribute is available from GCC7 */
330# define HB_FALLTHROUGH __attribute__((fallthrough))
Behdad Esfahbod305d2fb2015-10-21 11:04:28 -0200331#elif defined(_MSC_VER)
332 /*
333 * MSVC's __fallthrough annotations are checked by /analyze (Code Analysis):
334 * https://msdn.microsoft.com/en-us/library/ms235402%28VS.80%29.aspx
335 */
336# include <sal.h>
337# define HB_FALLTHROUGH __fallthrough
338#else
339# define HB_FALLTHROUGH /* FALLTHROUGH */
340#endif
341
Ebrahim Byagowi385d64e2020-05-07 09:59:01 +0430342/* A tag to enforce use of return value for a function */
343#if __cplusplus >= 201703L
344# define HB_NODISCARD [[nodiscard]]
345#elif defined(__GNUC__) || defined(__clang__)
346# define HB_NODISCARD __attribute__((warn_unused_result))
347#elif defined(_MSC_VER)
348# define HB_NODISCARD _Check_return_
349#else
350# define HB_NODISCARD
351#endif
Ebrahim Byagowi385d64e2020-05-07 09:59:01 +0430352
Behdad Esfahbod89228cc2019-07-22 07:07:37 -0400353/* https://github.com/harfbuzz/harfbuzz/issues/1852 */
354#if defined(__clang__) && !(defined(_AIX) && (defined(__IBMCPP__) || defined(__ibmxl__)))
Behdad Esfahbod62376a72018-10-14 15:20:50 -0700355/* Disable certain sanitizer errors. */
356/* https://github.com/harfbuzz/harfbuzz/issues/1247 */
357#define HB_NO_SANITIZE_SIGNED_INTEGER_OVERFLOW __attribute__((no_sanitize("signed-integer-overflow")))
358#else
359#define HB_NO_SANITIZE_SIGNED_INTEGER_OVERFLOW
360#endif
361
362
Ken Browneee5b5e2018-11-12 21:05:39 -0500363#ifdef _WIN32
Behdad Esfahboddb308282014-07-19 16:32:04 -0400364 /* We need Windows Vista for both Uniscribe backend and for
365 * MemoryBarrier. We don't support compiling on Windows XP,
366 * though we run on it fine. */
367# if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0600
368# undef _WIN32_WINNT
369# endif
370# ifndef _WIN32_WINNT
Hugo Beauzée-Luyssen40ec1872020-04-24 14:01:07 +0200371# if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
Matt Oliver24dd6c12018-09-23 18:08:30 +1000372# define _WIN32_WINNT 0x0600
373# endif
Behdad Esfahboddb308282014-07-19 16:32:04 -0400374# endif
Behdad Esfahbod270971a2014-08-15 14:28:04 -0400375# ifndef WIN32_LEAN_AND_MEAN
376# define WIN32_LEAN_AND_MEAN 1
377# endif
378# ifndef STRICT
379# define STRICT 1
380# endif
Behdad Esfahboddabe6982012-11-23 14:21:35 -0500381
Konstantin Rittf3537b62015-01-25 09:50:51 +0400382# if defined(_WIN32_WCE)
383 /* Some things not defined on Windows CE. */
Konstantin Ritt50690622016-04-26 12:02:26 +0400384# define vsnprintf _vsnprintf
Cody Planteen72e3eba2019-05-02 13:03:15 -0600385# ifndef HB_NO_GETENV
386# define HB_NO_GETENV
387# endif
Konstantin Ritt855a5d72015-04-10 17:18:01 +0400388# if _WIN32_WCE < 0x800
Ebrahim Byagowia36ff942019-06-10 15:48:28 +0430389# define HB_NO_SETLOCALE
Ebrahim Byagowi412d6ca2019-09-16 13:50:11 +0430390# define HB_NO_ERRNO
Konstantin Ritt855a5d72015-04-10 17:18:01 +0400391# endif
Khaled Hosny791a1bf2021-07-27 15:22:13 +0200392# elif !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
Cody Planteen72e3eba2019-05-02 13:03:15 -0600393# ifndef HB_NO_GETENV
394# define HB_NO_GETENV
395# endif
Konstantin Rittf3537b62015-01-25 09:50:51 +0400396# endif
Behdad Esfahbodce01ad72015-04-01 11:05:59 -0700397# if defined(_MSC_VER) && _MSC_VER < 1900
Konstantin Rittf3537b62015-01-25 09:50:51 +0400398# define snprintf _snprintf
Konstantin Rittf3537b62015-01-25 09:50:51 +0400399# endif
Behdad Esfahbod26a963b2014-08-10 18:04:50 -0400400#endif
401
Cody Planteen72e3eba2019-05-02 13:03:15 -0600402#ifdef HB_NO_GETENV
403#define getenv(Name) nullptr
404#endif
405
Behdad Esfahbode832dc42019-10-28 17:02:40 -0700406#ifndef HB_NO_ERRNO
Behdad Esfahbod7cb22ba2021-03-01 12:44:06 -0700407# include <cerrno>
Ebrahim Byagowi412d6ca2019-09-16 13:50:11 +0430408#else
Behdad Esfahbodfd71c042019-10-28 17:06:53 -0700409static int HB_UNUSED _hb_errno = 0;
Behdad Esfahbode832dc42019-10-28 17:02:40 -0700410# undef errno
411# define errno _hb_errno
Ebrahim Byagowi412d6ca2019-09-16 13:50:11 +0430412#endif
413
Behdad Esfahboded116322021-09-14 07:09:54 -0400414#define HB_STMT_START do
415#define HB_STMT_END while (0)
416
Behdad Esfahbodb89c7fd2018-11-21 12:32:48 -0500417#if defined(HAVE_ATEXIT) && !defined(HB_USE_ATEXIT)
Behdad Esfahbod38fb30d2014-08-06 13:34:49 -0400418/* atexit() is only safe to be called from shared libraries on certain
419 * platforms. Whitelist.
420 * https://bugs.freedesktop.org/show_bug.cgi?id=82246 */
421# if defined(__linux) && defined(__GLIBC_PREREQ)
422# if __GLIBC_PREREQ(2,3)
423/* From atexit() manpage, it's safe with glibc 2.2.3 on Linux. */
424# define HB_USE_ATEXIT 1
425# endif
426# elif defined(_MSC_VER) || defined(__MINGW32__)
427/* For MSVC:
Ebrahim Byagowif24b0b92018-04-12 13:40:45 +0430428 * https://msdn.microsoft.com/en-us/library/tze57ck3.aspx
429 * https://msdn.microsoft.com/en-us/library/zk17ww08.aspx
Behdad Esfahbod38fb30d2014-08-06 13:34:49 -0400430 * mingw32 headers say atexit is safe to use in shared libraries.
431 */
432# define HB_USE_ATEXIT 1
Ebrahim Byagowi632713b2018-04-12 14:17:03 +0430433# elif defined(__ANDROID__)
434/* This is available since Android NKD r8 or r8b:
435 * https://issuetracker.google.com/code/p/android/issues/detail?id=6455
Behdad Esfahbod38fb30d2014-08-06 13:34:49 -0400436 */
437# define HB_USE_ATEXIT 1
Bruce Mitchenere8859fc2018-02-04 01:26:57 +0700438# elif defined(__APPLE__)
439/* For macOS and related platforms, the atexit man page indicates
440 * that it will be invoked when the library is unloaded, not only
441 * at application exit.
442 */
443# define HB_USE_ATEXIT 1
Behdad Esfahbod38fb30d2014-08-06 13:34:49 -0400444# endif
Behdad Esfahboded116322021-09-14 07:09:54 -0400445#endif /* defined(HAVE_ATEXIT) && !defined(HB_USE_ATEXIT) */
Behdad Esfahbodc14b24f2018-03-26 10:44:54 -0700446#ifdef HB_NO_ATEXIT
447# undef HB_USE_ATEXIT
448#endif
Behdad Esfahbodb89c7fd2018-11-21 12:32:48 -0500449#ifndef HB_USE_ATEXIT
450# define HB_USE_ATEXIT 0
451#endif
Behdad Esfahbod91779532022-02-04 12:38:45 -0600452#ifndef hb_atexit
Behdad Esfahboded116322021-09-14 07:09:54 -0400453#if !HB_USE_ATEXIT
454# define hb_atexit(_) HB_STMT_START { if (0) (_) (); } HB_STMT_END
455#else /* HB_USE_ATEXIT */
456# ifdef HAVE_ATEXIT
457# define hb_atexit atexit
458# else
Behdad Esfahbodbda32382021-09-14 08:12:48 -0400459 template <void (*function) (void)> struct hb_atexit_t { ~hb_atexit_t () { function (); } };
460# define hb_atexit(f) static hb_atexit_t<f> _hb_atexit_##__LINE__;
Behdad Esfahboded116322021-09-14 07:09:54 -0400461# endif
462#endif
Behdad Esfahbod91779532022-02-04 12:38:45 -0600463#endif
Behdad Esfahbod5b3f7702006-12-28 06:42:37 -0500464
Behdad Esfahbod6fd53642011-04-11 11:47:14 -0400465/* Lets assert int types. Saves trouble down the road. */
Behdad Esfahbod606bf572018-09-16 19:33:48 +0200466static_assert ((sizeof (hb_codepoint_t) == 4), "");
467static_assert ((sizeof (hb_position_t) == 4), "");
468static_assert ((sizeof (hb_mask_t) == 4), "");
469static_assert ((sizeof (hb_var_int_t) == 4), "");
Behdad Esfahbod6fd53642011-04-11 11:47:14 -0400470
Behdad Esfahbod44999f82018-07-11 17:00:59 +0200471
Behdad Esfahbod865deeb2018-12-21 17:35:58 -0500472/* Headers we include for everyone. Keep topologically sorted by dependency.
473 * They express dependency amongst themselves, but no other file should include
474 * them directly.*/
Behdad Esfahbod17c80032022-06-09 04:17:38 -0600475#include "hb-cplusplus.hh"
Behdad Esfahbode76a3ca2018-12-27 17:23:12 -0500476#include "hb-meta.hh"
Behdad Esfahbodc77ae402018-08-25 22:36:36 -0700477#include "hb-mutex.hh"
Ebrahim Byagowia77bb7e2019-09-03 14:49:14 +0430478#include "hb-number.hh"
Behdad Esfahbodf64ea8f2018-12-30 18:49:34 -0500479#include "hb-atomic.hh" // Requires: hb-meta
Behdad Esfahbod8c6cbbd2018-12-28 14:29:09 -0500480#include "hb-null.hh" // Requires: hb-meta
Ebrahim Byagowia77bb7e2019-09-03 14:49:14 +0430481#include "hb-algs.hh" // Requires: hb-meta hb-null hb-number
Behdad Esfahboda3fcb9a2019-04-16 10:45:20 -0400482#include "hb-iter.hh" // Requires: hb-algs hb-meta
Behdad Esfahbod6e3ad652019-01-09 09:05:01 -0800483#include "hb-debug.hh" // Requires: hb-algs hb-atomic
484#include "hb-array.hh" // Requires: hb-algs hb-iter hb-null
Behdad Esfahbod865deeb2018-12-21 17:35:58 -0500485#include "hb-vector.hh" // Requires: hb-array hb-null
486#include "hb-object.hh" // Requires: hb-atomic hb-mutex hb-vector
Behdad Esfahbod83ea2772018-07-10 13:17:27 +0200487
Behdad Esfahbodc77ae402018-08-25 22:36:36 -0700488#endif /* HB_HH */