[HB] Assorted compiler macros

This commit is contained in:
Behdad Esfahbod 2009-08-01 20:46:02 -04:00
parent ba8d94ce33
commit df66028781
2 changed files with 70 additions and 22 deletions

View File

@ -215,8 +215,8 @@ struct Null <Type> \
private: char v[BYTES]; \
}; \
ASSERT_SIZE (NAME, BYTES)
#define DEFINE_INT_TYPE0(NAME, type, b) DEFINE_INT_TYPE1 (NAME, type, hb_be_##type, b)
#define DEFINE_INT_TYPE(NAME, u, w) DEFINE_INT_TYPE0 (NAME, u##int##w##_t, (w / 8))
#define DEFINE_INT_TYPE0(NAME, type, b) DEFINE_INT_TYPE1 (NAME, type##_t, hb_be_##type, b)
#define DEFINE_INT_TYPE(NAME, u, w) DEFINE_INT_TYPE0 (NAME, u##int##w, (w / 8))
DEFINE_INT_TYPE (USHORT, u, 16); /* 16-bit unsigned integer. */

View File

@ -27,31 +27,29 @@
#ifndef HB_PRIVATE_H
#define HB_PRIVATE_H
#include "hb-common.h"
#include <glib.h>
/* Macros to convert to/from BigEndian */
#define hb_be_uint8_t
#define hb_be_int8_t
#define hb_be_uint16_t GUINT16_TO_BE
#define hb_be_int16_t GINT16_TO_BE
#define hb_be_uint32_t GUINT32_TO_BE
#define hb_be_int32_t GINT32_TO_BE
#define hb_be_uint64_t GUINT64_TO_BE
#define hb_be_int64_t GINT64_TO_BE
#define HB_LIKELY G_LIKELY
#define HB_UNLIKELY G_UNLIKELY
#define HB_UNUSED(arg) ((arg) = (arg))
#define HB_GNUC_UNUSED G_GNUC_UNUSED
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <stdio.h> /* XXX */
#include <string.h>
#include <assert.h>
#include "hb-common.h"
#include <glib.h>
/* Macros to convert to/from BigEndian */
#define hb_be_uint8
#define hb_be_int8
#define hb_be_uint16 GUINT16_TO_BE
#define hb_be_int16 GINT16_TO_BE
#define hb_be_uint32 GUINT32_TO_BE
#define hb_be_int32 GINT32_TO_BE
#define hb_be_uint64 GUINT64_TO_BE
#define hb_be_int64 GINT64_TO_BE
/* Basics */
#undef MIN
@ -83,6 +81,54 @@
#define ASSERT_SIZE(_type, _size) ASSERT_STATIC (sizeof (_type) == (_size))
#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
#define _CAIRO_BOOLEAN_EXPR(expr) \
__extension__ ({ \
int _cairo_boolean_var_; \
if (expr) \
_cairo_boolean_var_ = 1; \
else \
_cairo_boolean_var_ = 0; \
_cairo_boolean_var_; \
})
#define HB_LIKELY(expr) (__builtin_expect (_CAIRO_BOOLEAN_EXPR(expr), 1))
#define HB_UNLIKELY(expr) (__builtin_expect (_CAIRO_BOOLEAN_EXPR(expr), 0))
#else
#define HB_LIKELY(expr) (expr)
#define HB_UNLIKELY(expr) (expr)
#endif
#ifndef __GNUC__
#undef __attribute__
#define __attribute__(x)
#endif
#if __GNUC__ >= 3
#define HB_GNUC_UNUSED __attribute__((unused))
#define HB_GNUC_PURE __attribute__((pure))
#define HB_GNUC_CONST __attribute__((const))
#else
#define HB_GNUC_UNUSED
#define HB_GNUC_PURE
#define HB_GNUC_CONST
#endif
#if (defined(__WIN32__) && !defined(__WINE__)) || defined(_MSC_VER)
#define snprintf _snprintf
#endif
#ifdef _MSC_VER
#undef inline
#define inline __inline
#endif
#ifdef __STRICT_ANSI__
#undef inline
#define inline __inline__
#endif
/* Return the number of 1 bits in mask.
*
* GCC 3.4 supports a "population count" builtin, which on many targets is
@ -90,7 +136,7 @@
* in libgcc in case a target does not have one, which should be just as
* good as the open-coded solution below, (which is "HACKMEM 169").
*/
static inline unsigned int
static HB_GNUC_UNUSED inline unsigned int
_hb_popcount32 (uint32_t mask)
{
#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
@ -104,6 +150,8 @@ _hb_popcount32 (uint32_t mask)
#endif
}
#include "hb-object-private.h"
#endif /* HB_PRIVATE_H */