115 #define HB_FUNC __PRETTY_FUNCTION__ |
115 #define HB_FUNC __PRETTY_FUNCTION__ |
116 #elif defined(_MSC_VER) |
116 #elif defined(_MSC_VER) |
117 #define HB_FUNC __FUNCSIG__ |
117 #define HB_FUNC __FUNCSIG__ |
118 #else |
118 #else |
119 #define HB_FUNC __func__ |
119 #define HB_FUNC __func__ |
|
120 #endif |
|
121 |
|
122 /* |
|
123 * Borrowed from https://bugzilla.mozilla.org/show_bug.cgi?id=1215411 |
|
124 * HB_FALLTHROUGH is an annotation to suppress compiler warnings about switch |
|
125 * cases that fall through without a break or return statement. HB_FALLTHROUGH |
|
126 * is only needed on cases that have code: |
|
127 * |
|
128 * switch (foo) { |
|
129 * case 1: // These cases have no code. No fallthrough annotations are needed. |
|
130 * case 2: |
|
131 * case 3: |
|
132 * foo = 4; // This case has code, so a fallthrough annotation is needed: |
|
133 * HB_FALLTHROUGH; |
|
134 * default: |
|
135 * return foo; |
|
136 * } |
|
137 */ |
|
138 #if defined(__clang__) && __cplusplus >= 201103L |
|
139 /* clang's fallthrough annotations are only available starting in C++11. */ |
|
140 # define HB_FALLTHROUGH [[clang::fallthrough]] |
|
141 #elif defined(_MSC_VER) |
|
142 /* |
|
143 * MSVC's __fallthrough annotations are checked by /analyze (Code Analysis): |
|
144 * https://msdn.microsoft.com/en-us/library/ms235402%28VS.80%29.aspx |
|
145 */ |
|
146 # include <sal.h> |
|
147 # define HB_FALLTHROUGH __fallthrough |
|
148 #else |
|
149 # define HB_FALLTHROUGH /* FALLTHROUGH */ |
120 #endif |
150 #endif |
121 |
151 |
122 #if defined(_WIN32) || defined(__CYGWIN__) |
152 #if defined(_WIN32) || defined(__CYGWIN__) |
123 /* We need Windows Vista for both Uniscribe backend and for |
153 /* We need Windows Vista for both Uniscribe backend and for |
124 * MemoryBarrier. We don't support compiling on Windows XP, |
154 * MemoryBarrier. We don't support compiling on Windows XP, |
137 # endif |
167 # endif |
138 |
168 |
139 # if defined(_WIN32_WCE) |
169 # if defined(_WIN32_WCE) |
140 /* Some things not defined on Windows CE. */ |
170 /* Some things not defined on Windows CE. */ |
141 # define strdup _strdup |
171 # define strdup _strdup |
|
172 # define vsnprintf _vsnprintf |
142 # define getenv(Name) NULL |
173 # define getenv(Name) NULL |
143 # if _WIN32_WCE < 0x800 |
174 # if _WIN32_WCE < 0x800 |
144 # define setlocale(Category, Locale) "C" |
175 # define setlocale(Category, Locale) "C" |
145 static int errno = 0; /* Use something better? */ |
176 static int errno = 0; /* Use something better? */ |
146 # endif |
177 # endif |
147 # elif defined(WINAPI_FAMILY) && (WINAPI_FAMILY==WINAPI_FAMILY_PC_APP || WINAPI_FAMILY==WINAPI_FAMILY_PHONE_APP) |
178 # elif defined(WINAPI_FAMILY) && (WINAPI_FAMILY==WINAPI_FAMILY_PC_APP || WINAPI_FAMILY==WINAPI_FAMILY_PHONE_APP) |
148 # define getenv(Name) NULL |
179 # define getenv(Name) NULL |
149 # endif |
180 # endif |
150 # if defined(_MSC_VER) && _MSC_VER < 1900 |
181 # if defined(_MSC_VER) && _MSC_VER < 1900 |
151 # define snprintf _snprintf |
182 # define snprintf _snprintf |
|
183 # elif defined(_MSC_VER) && _MSC_VER >= 1900 |
|
184 # /* Covers VC++ Error for strdup being a deprecated POSIX name and to instead use _strdup instead */ |
|
185 # define strdup _strdup |
152 # endif |
186 # endif |
153 #endif |
187 #endif |
154 |
188 |
155 #if HAVE_ATEXIT |
189 #if HAVE_ATEXIT |
156 /* atexit() is only safe to be called from shared libraries on certain |
190 /* atexit() is only safe to be called from shared libraries on certain |
208 |
242 |
209 #define _ASSERT_STATIC1(_line, _cond) HB_UNUSED typedef int _static_assert_on_line_##_line##_failed[(_cond)?1:-1] |
243 #define _ASSERT_STATIC1(_line, _cond) HB_UNUSED typedef int _static_assert_on_line_##_line##_failed[(_cond)?1:-1] |
210 #define _ASSERT_STATIC0(_line, _cond) _ASSERT_STATIC1 (_line, (_cond)) |
244 #define _ASSERT_STATIC0(_line, _cond) _ASSERT_STATIC1 (_line, (_cond)) |
211 #define ASSERT_STATIC(_cond) _ASSERT_STATIC0 (__LINE__, (_cond)) |
245 #define ASSERT_STATIC(_cond) _ASSERT_STATIC0 (__LINE__, (_cond)) |
212 |
246 |
213 /* Note: C++ allows sizeof() of variable-lengh arrays. So, if _cond is not |
247 template <unsigned int cond> class hb_assert_constant_t {}; |
214 * constant, it still compiles (ouch!), but at least we'll get a -Wvla warning. */ |
248 |
215 #define ASSERT_STATIC_EXPR_ZERO(_cond) (0 * sizeof (char[(_cond) ? 1 : -1])) |
249 #define ASSERT_STATIC_EXPR_ZERO(_cond) (0 * (unsigned int) sizeof (hb_assert_constant_t<_cond>)) |
216 |
250 |
217 #define _PASTE1(a,b) a##b |
251 #define _PASTE1(a,b) a##b |
218 #define PASTE(a,b) _PASTE1(a,b) |
252 #define PASTE(a,b) _PASTE1(a,b) |
219 |
253 |
220 /* Lets assert int types. Saves trouble down the road. */ |
254 /* Lets assert int types. Saves trouble down the road. */ |
859 { |
902 { |
860 return hb_in_range (u, lo1, hi1) || hb_in_range (u, lo2, hi2) || hb_in_range (u, lo3, hi3); |
903 return hb_in_range (u, lo1, hi1) || hb_in_range (u, lo2, hi2) || hb_in_range (u, lo3, hi3); |
861 } |
904 } |
862 |
905 |
863 |
906 |
|
907 /* Enable bitwise ops on enums marked as flags_t */ |
|
908 /* To my surprise, looks like the function resolver is happy to silently cast |
|
909 * one enum to another... So this doesn't provide the type-checking that I |
|
910 * originally had in mind... :(. |
|
911 * |
|
912 * For MSVC warnings, see: https://github.com/behdad/harfbuzz/pull/163 |
|
913 */ |
|
914 #ifdef _MSC_VER |
|
915 # pragma warning(disable:4200) |
|
916 # pragma warning(disable:4800) |
|
917 #endif |
|
918 #define HB_MARK_AS_FLAG_T(T) \ |
|
919 extern "C++" { \ |
|
920 static inline T operator | (T l, T r) { return T ((unsigned) l | (unsigned) r); } \ |
|
921 static inline T operator & (T l, T r) { return T ((unsigned) l & (unsigned) r); } \ |
|
922 static inline T operator ^ (T l, T r) { return T ((unsigned) l ^ (unsigned) r); } \ |
|
923 static inline T operator ~ (T r) { return T (~(unsigned int) r); } \ |
|
924 static inline T& operator |= (T &l, T r) { l = l | r; return l; } \ |
|
925 static inline T& operator &= (T& l, T r) { l = l & r; return l; } \ |
|
926 static inline T& operator ^= (T& l, T r) { l = l ^ r; return l; } \ |
|
927 } |
|
928 |
|
929 |
864 /* Useful for set-operations on small enums. |
930 /* Useful for set-operations on small enums. |
865 * For example, for testing "x ∈ {x1, x2, x3}" use: |
931 * For example, for testing "x ∈ {x1, x2, x3}" use: |
866 * (FLAG_SAFE(x) & (FLAG(x1) | FLAG(x2) | FLAG(x3))) |
932 * (FLAG_SAFE(x) & (FLAG(x1) | FLAG(x2) | FLAG(x3))) |
867 */ |
933 */ |
868 #define FLAG(x) (ASSERT_STATIC_EXPR_ZERO ((x) < 32) + (1U << (x))) |
934 #define FLAG(x) (ASSERT_STATIC_EXPR_ZERO ((x) < 32) + (1U << (x))) |