[HarfBuzz] harfbuzz: Branch 'master' - 2 commits
Behdad Esfahbod
behdad at kemper.freedesktop.org
Tue Jul 10 11:17:56 UTC 2018
configure.ac | 2 -
src/hb-private.hh | 63 ++++++++++++++++++++++++++++++++++++++++++++----------
2 files changed, 53 insertions(+), 12 deletions(-)
New commits:
commit 83ea277178544cd7e417bdfb7b600ede94910e13
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Tue Jul 10 13:17:27 2018 +0200
Add posix_memalign() fallback
diff --git a/configure.ac b/configure.ac
index d6c23e53..35de036b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -78,7 +78,7 @@ GTK_DOC_CHECK([1.15],[--flavour no-tmpl])
])
# Functions and headers
-AC_CHECK_FUNCS(atexit mprotect sysconf getpagesize mmap isatty newlocale strtod_l)
+AC_CHECK_FUNCS(atexit mprotect sysconf getpagesize mmap isatty newlocale strtod_l posix_memalign)
save_libs="$LIBS"
LIBS="$LIBS -lm"
diff --git a/src/hb-private.hh b/src/hb-private.hh
index 48a7db10..56606531 100644
--- a/src/hb-private.hh
+++ b/src/hb-private.hh
@@ -58,6 +58,7 @@
#define HB_PASTE1(a,b) a##b
#define HB_PASTE(a,b) HB_PASTE1(a,b)
+
/* Compile-time custom allocator support. */
#if defined(hb_malloc_impl) \
@@ -72,6 +73,14 @@ extern "C" void hb_free_impl(void *ptr);
#define calloc hb_calloc_impl
#define realloc hb_realloc_impl
#define free hb_free_impl
+
+#if defined(hb_memalign_impl
+extern "C" int hb_memalign_impl(void **memptr, size_t alignment, size_t size);
+#define posix_memalign hb_memalign_impl
+#else
+#undef HAVE_POSIX_MEMALIGN
+#endif
+
#endif
@@ -550,6 +559,10 @@ _hb_ceil_to_4 (unsigned int v)
return ((v - 1) | 3) + 1;
}
+static inline bool _hb_ispow2 (unsigned int v)
+{
+ return 0 == (v & (v - 1));
+}
/*
@@ -1272,4 +1285,31 @@ _hb_round (double x)
#endif
+/* fallback for posix_memalign() */
+static inline int
+_hb_memalign(void **memptr, size_t alignment, size_t size)
+{
+ if (unlikely (!_hb_ispow2 (alignment) ||
+ !alignment ||
+ 0 != (alignment & (sizeof (void *) - 1))))
+ return EINVAL;
+
+ char *p = (char *) malloc (size + alignment - 1);
+ if (unlikely (!p))
+ return ENOMEM;
+
+ size_t off = (size_t) p & (alignment - 1);
+ if (off)
+ p += alignment - off;
+
+ *memptr = (void *) p;
+
+ return 0;
+}
+#if !defined(posix_memalign) && !defined(HAVE_POSIX_MEMALIGN)
+#define posix_memalign _hb_memalign
+#endif
+
+
+
#endif /* HB_PRIVATE_HH */
commit 292c100d6141eb2e981fa632602d73768f748727
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Tue Jul 10 13:16:52 2018 +0200
Always compile (but not use) alignof() and round() fallback codes
Catches compile-errors in them better.
diff --git a/src/hb-private.hh b/src/hb-private.hh
index 8609e04a..48a7db10 100644
--- a/src/hb-private.hh
+++ b/src/hb-private.hh
@@ -78,6 +78,17 @@ extern "C" void hb_free_impl(void *ptr);
/* Compiler attributes */
+template <typename T>
+struct _hb_alignof
+{
+ struct s
+ {
+ char c;
+ T t;
+ };
+ static constexpr unsigned int value = offsetof (s, t);
+};
+
#if __cplusplus < 201103L
#ifndef nullptr
@@ -104,16 +115,6 @@ extern "C" void hb_free_impl(void *ptr);
#ifndef alignof
#define alignof(x) (_hb_alignof<x>::value)
-template <typename T>
-struct _hb_alignof
-{
- struct s
- {
- char c;
- T t;
- };
- static constexpr unsigned int value = offsetof (s, t);
-};
#endif // alignof
#endif // __cplusplus < 201103L
@@ -1258,7 +1259,6 @@ struct hb_bytes_t
/* fallback for round() */
-#if !defined (HAVE_ROUND) && !defined (HAVE_DECL_ROUND)
static inline double
_hb_round (double x)
{
@@ -1267,6 +1267,7 @@ _hb_round (double x)
else
return ceil (x - 0.5);
}
+#if !defined (HAVE_ROUND) && !defined (HAVE_DECL_ROUND)
#define round(x) _hb_round(x)
#endif
More information about the HarfBuzz
mailing list