hb-private.hh revision 64d3fc8d0dada673245cc8c0b1c12cd849b30997
164aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod/*
26c78683c042250a7b5a6fc6ebae4717b03fadf9eBehdad Esfahbod * Copyright (C) 2007,2008,2009  Red Hat, Inc.
364aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod *
4c755cb3e3ac55156d0d2ec05adea7a650b97cc41Behdad Esfahbod *  This is part of HarfBuzz, a text shaping library.
564aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod *
664aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * Permission is hereby granted, without written agreement and without
764aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * license or royalty fees, to use, copy, modify, and distribute this
864aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * software and its documentation for any purpose, provided that the
964aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * above copyright notice and the following two paragraphs appear in
1064aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * all copies of this software.
1164aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod *
1264aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
1364aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
1464aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
1564aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
1664aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * DAMAGE.
1764aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod *
1864aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
1964aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
2064aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
2164aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
2264aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
2364aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod *
2464aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * Red Hat Author(s): Behdad Esfahbod
2564aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod */
2664aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod
278dd1c8b8d6797d899d0f5b0a8015886bf6520ca2Behdad Esfahbod#ifndef HB_PRIVATE_H
288dd1c8b8d6797d899d0f5b0a8015886bf6520ca2Behdad Esfahbod#define HB_PRIVATE_H
295b3f7702a64fe0513d08a67bdb72704e46fd7cd4Behdad Esfahbod
30df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#if HAVE_CONFIG_H
31df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#include "config.h"
32df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#endif
33c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod
34bc200457430c083914a64bf4b056153506749610Behdad Esfahbod#include "hb-common.h"
35b28815c1f6e46d38471cacbc31248ca6fda8c4d1Behdad Esfahbod
36c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod#include <stdlib.h>
37f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod#include <string.h>
38f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod#include <assert.h>
391d52151a19ed8ec776276aac5cc6ce3769e0d947Behdad Esfahbod
401d52151a19ed8ec776276aac5cc6ce3769e0d947Behdad Esfahbod/* We only use these two for debug output.  However, the debug code is
411d52151a19ed8ec776276aac5cc6ce3769e0d947Behdad Esfahbod * always seen by the compiler (and optimized out in non-debug builds.
421d52151a19ed8ec776276aac5cc6ce3769e0d947Behdad Esfahbod * If including these becomes a problem, we can start thinking about
431d52151a19ed8ec776276aac5cc6ce3769e0d947Behdad Esfahbod * someway around that. */
447acb389569cf99c6bae9db31a8ed7c7007fbb566Behdad Esfahbod#include <stdio.h>
457acb389569cf99c6bae9db31a8ed7c7007fbb566Behdad Esfahbod#include <errno.h>
46c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod
47bc200457430c083914a64bf4b056153506749610Behdad Esfahbod
48bc200457430c083914a64bf4b056153506749610Behdad Esfahbod/* Essentials */
49bc200457430c083914a64bf4b056153506749610Behdad Esfahbod
50bc200457430c083914a64bf4b056153506749610Behdad Esfahbod#ifndef NULL
51bc200457430c083914a64bf4b056153506749610Behdad Esfahbod# define NULL ((void *) 0)
52bc200457430c083914a64bf4b056153506749610Behdad Esfahbod#endif
53bc200457430c083914a64bf4b056153506749610Behdad Esfahbod
54bc200457430c083914a64bf4b056153506749610Behdad Esfahbod#undef FALSE
55bc200457430c083914a64bf4b056153506749610Behdad Esfahbod#define FALSE 0
56bc200457430c083914a64bf4b056153506749610Behdad Esfahbod
57bc200457430c083914a64bf4b056153506749610Behdad Esfahbod#undef TRUE
58bc200457430c083914a64bf4b056153506749610Behdad Esfahbod#define TRUE 1
59df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod
60a794ebf4be9896393f4badf02905a4007981a588Behdad Esfahbod
61c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod/* Basics */
62c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod
63c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod#undef MIN
64c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod#define MIN(a,b) ((a) < (b) ? (a) : (b))
657586089c6fa8185cad8387869d3703c637e5cbb1Behdad Esfahbod
668a3511ac6c795226699c2b36e03401ecdf88f5f8Behdad Esfahbod#undef MAX
678a3511ac6c795226699c2b36e03401ecdf88f5f8Behdad Esfahbod#define MAX(a,b) ((a) > (b) ? (a) : (b))
688a3511ac6c795226699c2b36e03401ecdf88f5f8Behdad Esfahbod
69c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod#ifndef HB_INTERNAL
70081819ea8b98c0a4b4dffe8d4aca3512f9798719Behdad Esfahbod# define HB_INTERNAL extern
71c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod#endif
72c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod
734591753ad4b5ec0224e3f1befdfe4fc5f6075562Behdad Esfahbod#undef  ARRAY_LENGTH
744591753ad4b5ec0224e3f1befdfe4fc5f6075562Behdad Esfahbod#define ARRAY_LENGTH(__array) ((signed int) (sizeof (__array) / sizeof (__array[0])))
7512360f7c159826ae72271b34486dee59d96aa8caBehdad Esfahbod
7635a7383c6138fd705560f0d4bb30659cbd1ab64cBehdad Esfahbod#define HB_STMT_START do
7735a7383c6138fd705560f0d4bb30659cbd1ab64cBehdad Esfahbod#define HB_STMT_END   while (0)
785b3f7702a64fe0513d08a67bdb72704e46fd7cd4Behdad Esfahbod
79303fe62824d4e99df554b6bfaacba05d068522fbBehdad Esfahbod#define _ASSERT_STATIC1(_line, _cond) typedef int _static_assert_on_line_##_line##_failed[(_cond)?1:-1]
80303fe62824d4e99df554b6bfaacba05d068522fbBehdad Esfahbod#define _ASSERT_STATIC0(_line, _cond) _ASSERT_STATIC1 (_line, (_cond))
81303fe62824d4e99df554b6bfaacba05d068522fbBehdad Esfahbod#define ASSERT_STATIC(_cond) _ASSERT_STATIC0 (__LINE__, (_cond))
82303fe62824d4e99df554b6bfaacba05d068522fbBehdad Esfahbod
83bc200457430c083914a64bf4b056153506749610Behdad Esfahbod
84bc200457430c083914a64bf4b056153506749610Behdad Esfahbod/* Misc */
85bc200457430c083914a64bf4b056153506749610Behdad Esfahbod
86303fe62824d4e99df554b6bfaacba05d068522fbBehdad Esfahbod#define ASSERT_SIZE(_type, _size) ASSERT_STATIC (sizeof (_type) == (_size))
87303fe62824d4e99df554b6bfaacba05d068522fbBehdad Esfahbod
88c65b26acf28bd1a5b346fd8f6f28bec1f7d17a2aBehdad Esfahbod/* Size signifying variable-sized array */
89c65b26acf28bd1a5b346fd8f6f28bec1f7d17a2aBehdad Esfahbod#define VAR 1
90c65b26acf28bd1a5b346fd8f6f28bec1f7d17a2aBehdad Esfahbod
91c65b26acf28bd1a5b346fd8f6f28bec1f7d17a2aBehdad Esfahbod#define VAR0 (VAR+0)
92d3480ba37fbb5d4be75b094060f5b2f1ce98fb53Behdad Esfahbod#define ASSERT_SIZE_VAR(_type, _size, _var_type) \
93c65b26acf28bd1a5b346fd8f6f28bec1f7d17a2aBehdad Esfahbod	ASSERT_STATIC (sizeof (_type) == (_size) + VAR0 * sizeof (_var_type))
94d3480ba37fbb5d4be75b094060f5b2f1ce98fb53Behdad Esfahbod#define ASSERT_SIZE_VAR2(_type, _size, _var_type1, _var_type2) \
95c65b26acf28bd1a5b346fd8f6f28bec1f7d17a2aBehdad Esfahbod	ASSERT_STATIC (sizeof (_type) == (_size) + VAR0 * sizeof (_var_type1) + VAR0 * sizeof (_var_type2))
96c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod
97df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
987951279b4a52b48f13631e7838dbc180c7249ea4Behdad Esfahbod#define _HB_BOOLEAN_EXPR(expr) \
997951279b4a52b48f13631e7838dbc180c7249ea4Behdad Esfahbod  __extension__ ({ \
1007951279b4a52b48f13631e7838dbc180c7249ea4Behdad Esfahbod     int _hb_boolean_var_; \
1017951279b4a52b48f13631e7838dbc180c7249ea4Behdad Esfahbod     if (expr) \
1027951279b4a52b48f13631e7838dbc180c7249ea4Behdad Esfahbod	_hb_boolean_var_ = 1; \
1037951279b4a52b48f13631e7838dbc180c7249ea4Behdad Esfahbod     else \
1047951279b4a52b48f13631e7838dbc180c7249ea4Behdad Esfahbod	_hb_boolean_var_ = 0; \
1057951279b4a52b48f13631e7838dbc180c7249ea4Behdad Esfahbod     _hb_boolean_var_; \
1067951279b4a52b48f13631e7838dbc180c7249ea4Behdad Esfahbod  })
10764d3fc8d0dada673245cc8c0b1c12cd849b30997Behdad Esfahbod#define likely(expr) (__builtin_expect (_HB_BOOLEAN_EXPR(expr), 1))
10864d3fc8d0dada673245cc8c0b1c12cd849b30997Behdad Esfahbod#define unlikely(expr) (__builtin_expect (_HB_BOOLEAN_EXPR(expr), 0))
109df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#else
11064d3fc8d0dada673245cc8c0b1c12cd849b30997Behdad Esfahbod#define likely(expr) (expr)
11164d3fc8d0dada673245cc8c0b1c12cd849b30997Behdad Esfahbod#define unlikely(expr) (expr)
112df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#endif
113df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod
114df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#ifndef __GNUC__
115df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#undef __attribute__
116df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#define __attribute__(x)
117df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#endif
118df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod
119df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#if __GNUC__ >= 3
12033d13fdda99acaeffa9600737e8870278d053ebeBehdad Esfahbod#define HB_PURE_FUNC	__attribute__((pure))
12133d13fdda99acaeffa9600737e8870278d053ebeBehdad Esfahbod#define HB_CONST_FUNC	__attribute__((const))
122df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#else
12333d13fdda99acaeffa9600737e8870278d053ebeBehdad Esfahbod#define HB_PURE_FUNC
12433d13fdda99acaeffa9600737e8870278d053ebeBehdad Esfahbod#define HB_CONST_FUNC
125df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#endif
126bc7830e4259755ce7549025c6f5bf750e78c2ff1Behdad Esfahbod#if __GNUC__ >= 4
12733d13fdda99acaeffa9600737e8870278d053ebeBehdad Esfahbod#define HB_UNUSED	__attribute__((unused))
128bc7830e4259755ce7549025c6f5bf750e78c2ff1Behdad Esfahbod#else
12933d13fdda99acaeffa9600737e8870278d053ebeBehdad Esfahbod#define HB_UNUSED
130bc7830e4259755ce7549025c6f5bf750e78c2ff1Behdad Esfahbod#endif
131df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod
132df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod
133df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#if (defined(__WIN32__) && !defined(__WINE__)) || defined(_MSC_VER)
134df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#define snprintf _snprintf
135df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#endif
136df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod
137df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#ifdef _MSC_VER
138df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#undef inline
139df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#define inline __inline
140df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#endif
141df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod
142df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#ifdef __STRICT_ANSI__
143df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#undef inline
144df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#define inline __inline__
145df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#endif
146df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod
147df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod
1487d3a126334f8e6f6441561c1bb592bd3fa7a2c5cBehdad Esfahbod#if __GNUC__ >= 3
1497d3a126334f8e6f6441561c1bb592bd3fa7a2c5cBehdad Esfahbod#define HB_FUNC __PRETTY_FUNCTION__
1507d3a126334f8e6f6441561c1bb592bd3fa7a2c5cBehdad Esfahbod#elif defined(_MSC_VER)
1517d3a126334f8e6f6441561c1bb592bd3fa7a2c5cBehdad Esfahbod#define HB_FUNC __FUNCSIG__
1527d3a126334f8e6f6441561c1bb592bd3fa7a2c5cBehdad Esfahbod#else
1537d3a126334f8e6f6441561c1bb592bd3fa7a2c5cBehdad Esfahbod#define HB_FUNC __func__
1547d3a126334f8e6f6441561c1bb592bd3fa7a2c5cBehdad Esfahbod#endif
1557d3a126334f8e6f6441561c1bb592bd3fa7a2c5cBehdad Esfahbod
1567d3a126334f8e6f6441561c1bb592bd3fa7a2c5cBehdad Esfahbod
157c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod/* Return the number of 1 bits in mask.
158c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod *
159c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod * GCC 3.4 supports a "population count" builtin, which on many targets is
160c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod * implemented with a single instruction. There is a fallback definition
161c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod * in libgcc in case a target does not have one, which should be just as
162c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod * good as the open-coded solution below, (which is "HACKMEM 169").
163c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod */
164eaf29edb8fa49390e5f48b78105dfd173aff445bJeff Muizelaarstatic inline unsigned int
165c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod_hb_popcount32 (uint32_t mask)
166c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod{
167c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
168c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod    return __builtin_popcount (mask);
169c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod#else
1709faee63034d3965735bd6362c0beeca1613bd771Behdad Esfahbod    register uint32_t y;
171c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod
172c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod    y = (mask >> 1) &033333333333;
173c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod    y = mask - y - ((y >>1) & 033333333333);
174c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod    return (((y + (y >> 3)) & 030707070707) % 077);
175c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod#endif
176c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod}
177c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod
178df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod
1793c69bd46e27069fac0bfdefdecf5492c17eb01dfBehdad Esfahbod/* Multiplies a 16dot16 value by another value, then truncates the result */
18006558d2a745b8f3af11a8d6dce956ae52187a7e5Behdad Esfahbod#define _hb_16dot16_mul_round(A,B) (((int64_t) (A) * (B) + 0x8000) / 0x10000)
1813c69bd46e27069fac0bfdefdecf5492c17eb01dfBehdad Esfahbod
182f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod
183f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod/* We need external help for these */
184f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod
185f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod#ifdef HAVE_GLIB
186f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod
187f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod#include <glib.h>
188f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod
189f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbodtypedef int hb_atomic_int_t;
190f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod#define hb_atomic_int_fetch_and_add(AI, V)	g_atomic_int_exchange_and_add (&(AI), V)
191f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod#define hb_atomic_int_get(AI)			g_atomic_int_get (&(AI))
192f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod#define hb_atomic_int_set(AI, V)		g_atomic_int_set (&(AI), V)
193f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod
194f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbodtypedef GStaticMutex hb_mutex_t;
195f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod#define HB_MUTEX_INIT			G_STATIC_MUTEX_INIT
196f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod#define hb_mutex_init(M)		g_static_mutex_init (&M)
197f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod#define hb_mutex_lock(M)		g_static_mutex_lock (&M)
198f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod#define hb_mutex_trylock(M)		g_static_mutex_trylock (&M)
199f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod#define hb_mutex_unlock(M)		g_static_mutex_unlock (&M)
200f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod
201f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod#else
202f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod
203f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod#ifdef _MSC_VER
204f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod#pragma message(__LOC__"Could not find any system to define platform macros, library will NOT be thread-safe")
205f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod#else
206f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod#warning "Could not find any system to define platform macros, library will NOT be thread-safe"
207f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod#endif
208f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod
209f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbodtypedef int hb_atomic_int_t;
210f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod#define hb_atomic_int_fetch_and_add(AI, V)	((AI) += (V), (AI) - (V))
211f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod#define hb_atomic_int_get(AI)			(AI)
212ffff7dc44cb2a35a60f92831165e9d3c3a61ce19Behdad Esfahbod#define hb_atomic_int_set(AI, V)		HB_STMT_START { (AI) = (V); } HB_STMT_END
213f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod
214f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbodtypedef int hb_mutex_t;
215ffff7dc44cb2a35a60f92831165e9d3c3a61ce19Behdad Esfahbod#define HB_MUTEX_INIT				0
216ffff7dc44cb2a35a60f92831165e9d3c3a61ce19Behdad Esfahbod#define hb_mutex_init(M)			HB_STMT_START { (M) = 0; } HB_STMT_END
217ffff7dc44cb2a35a60f92831165e9d3c3a61ce19Behdad Esfahbod#define hb_mutex_lock(M)			HB_STMT_START { (M) = 1; } HB_STMT_END
218ffff7dc44cb2a35a60f92831165e9d3c3a61ce19Behdad Esfahbod#define hb_mutex_trylock(M)			((M) = 1, 1)
219ffff7dc44cb2a35a60f92831165e9d3c3a61ce19Behdad Esfahbod#define hb_mutex_unlock(M)			HB_STMT_START { (M) = 0; } HB_STMT_END
220f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod
221f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod#endif
222f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod
223f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod
224f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod/* Big-endian handling */
225f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod
2267a52f281178867379adb6e6c6fb0022102f75d17Behdad Esfahbod#define hb_be_uint16(v)		((uint16_t) ((((const uint8_t *)&(v))[0] << 8) + (((const uint8_t *)&(v))[1])))
2277a52f281178867379adb6e6c6fb0022102f75d17Behdad Esfahbod
228e032ed9f75d4a0f365649a25706871bbb5ae6651Behdad Esfahbod#define hb_be_uint16_put(v,V)	HB_STMT_START { v[0] = (V>>8); v[1] = (V); } HB_STMT_END
2297a52f281178867379adb6e6c6fb0022102f75d17Behdad Esfahbod#define hb_be_uint16_get(v)	(uint16_t) ((v[0] << 8) + v[1])
2307a52f281178867379adb6e6c6fb0022102f75d17Behdad Esfahbod#define hb_be_uint16_cmp(a,b)	(a[0] == b[0] && a[1] == b[1])
2317a52f281178867379adb6e6c6fb0022102f75d17Behdad Esfahbod
232e032ed9f75d4a0f365649a25706871bbb5ae6651Behdad Esfahbod#define hb_be_uint32_put(v,V)	HB_STMT_START { v[0] = (V>>24); v[1] = (V>>16); v[2] = (V>>8); v[3] = (V); } HB_STMT_END
2337a52f281178867379adb6e6c6fb0022102f75d17Behdad Esfahbod#define hb_be_uint32_get(v)	(uint32_t) ((v[0] << 24) + (v[1] << 16) + (v[2] << 8) + v[3])
2347a52f281178867379adb6e6c6fb0022102f75d17Behdad Esfahbod#define hb_be_uint32_cmp(a,b)	(a[0] == b[0] && a[1] == b[1] && a[2] == b[2] && a[3] == b[3])
235f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod
236f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod
237bc200457430c083914a64bf4b056153506749610Behdad Esfahbod/* Debug */
238bc200457430c083914a64bf4b056153506749610Behdad Esfahbod
239bc200457430c083914a64bf4b056153506749610Behdad Esfahbod#ifndef HB_DEBUG
240bc200457430c083914a64bf4b056153506749610Behdad Esfahbod#define HB_DEBUG 0
241bc200457430c083914a64bf4b056153506749610Behdad Esfahbod#endif
242bc200457430c083914a64bf4b056153506749610Behdad Esfahbod
243eaf29edb8fa49390e5f48b78105dfd173aff445bJeff Muizelaarstatic inline hb_bool_t /* always returns TRUE */
244bc200457430c083914a64bf4b056153506749610Behdad Esfahbod_hb_trace (const char *what,
245bc200457430c083914a64bf4b056153506749610Behdad Esfahbod	   const char *function,
246bc200457430c083914a64bf4b056153506749610Behdad Esfahbod	   const void *obj,
247bc200457430c083914a64bf4b056153506749610Behdad Esfahbod	   unsigned int depth,
248bc200457430c083914a64bf4b056153506749610Behdad Esfahbod	   unsigned int max_depth)
249bc200457430c083914a64bf4b056153506749610Behdad Esfahbod{
250bc200457430c083914a64bf4b056153506749610Behdad Esfahbod  if (depth < max_depth)
251bc200457430c083914a64bf4b056153506749610Behdad Esfahbod    fprintf (stderr, "%s(%p) %-*d-> %s\n", what, obj, depth, depth, function);
252bc200457430c083914a64bf4b056153506749610Behdad Esfahbod  return TRUE;
253bc200457430c083914a64bf4b056153506749610Behdad Esfahbod}
254bc200457430c083914a64bf4b056153506749610Behdad Esfahbod
255f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod
256ba8d94ce3360bfaf2c530d01f2af69237018a531Behdad Esfahbod#include "hb-object-private.h"
257ba8d94ce3360bfaf2c530d01f2af69237018a531Behdad Esfahbod
2588dd1c8b8d6797d899d0f5b0a8015886bf6520ca2Behdad Esfahbod#endif /* HB_PRIVATE_H */
259