From d5e5f378329b6ce21944b79b568369ea7bc36cf3 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Wed, 5 Jun 2019 22:20:03 +0300 Subject: [PATCH] This makes minor changes to allow building HarfBuzz with mingw.org's MinGW. src/hb-algs.hh: Don't compile _BitScanForward and _BitScanReverse for GCC >= 4. mingw.org's MinGW doesn't have these functions. src/hb-atomic.hh: MemoryBarrier does exist in mingw.org's MinGW, but it is not a macro, it is an inline function. __MINGW32_VERSION is a macro that exists only in mingw.org's MinGW, so conditioning on it should not affect MinGW64, where MemoryBarrier is a macro. src/hb-uniscribe.cc: Define E_NOT_SUFFICIENT_BUFFER if it is not defined (mingw.org's MinGW doesn't). src/hb.hh: Don't include intrin.h for mingw.org's MinGW, since that header is not available; instead, include windows.h. Conditioned on __MINGW32_VERSION to avoid affecting MinGW64. --- src/hb-algs.hh | 4 ++-- src/hb-atomic.hh | 2 +- src/hb-uniscribe.cc | 4 ++++ src/hb.hh | 7 +++++++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/hb-algs.hh b/src/hb-algs.hh index 0b34f7106..fe716d0c0 100644 --- a/src/hb-algs.hh +++ b/src/hb-algs.hh @@ -400,7 +400,7 @@ hb_bit_storage (T v) return sizeof (unsigned long long) * 8 - __builtin_clzll (v); #endif -#if (defined(_MSC_VER) && _MSC_VER >= 1500) || defined(__MINGW32__) +#if (defined(_MSC_VER) && _MSC_VER >= 1500) || (defined(__MINGW32__) && (__GNUC__ < 4)) if (sizeof (T) <= sizeof (unsigned int)) { unsigned long where; @@ -474,7 +474,7 @@ hb_ctz (T v) return __builtin_ctzll (v); #endif -#if (defined(_MSC_VER) && _MSC_VER >= 1500) || defined(__MINGW32__) +#if (defined(_MSC_VER) && _MSC_VER >= 1500) || (defined(__MINGW32__) && (__GNUC__ < 4)) if (sizeof (T) <= sizeof (unsigned int)) { unsigned long where; diff --git a/src/hb-atomic.hh b/src/hb-atomic.hh index 45413d5e7..09d88937c 100644 --- a/src/hb-atomic.hh +++ b/src/hb-atomic.hh @@ -107,7 +107,7 @@ _hb_atomic_ptr_impl_cmplexch (const void **P, const void *O_, const void *N) static inline void _hb_memory_barrier () { -#ifndef MemoryBarrier +#if !defined(MemoryBarrier) && !defined(__MINGW32_VERSION) /* MinGW has a convoluted history of supporting MemoryBarrier. */ LONG dummy = 0; InterlockedExchange (&dummy, 1); diff --git a/src/hb-uniscribe.cc b/src/hb-uniscribe.cc index f97ed91fc..69a1ae7e4 100644 --- a/src/hb-uniscribe.cc +++ b/src/hb-uniscribe.cc @@ -31,6 +31,10 @@ #include #include +#ifndef E_NOT_SUFFICIENT_BUFFER +#define E_NOT_SUFFICIENT_BUFFER HRESULT_FROM_WIN32 (ERROR_INSUFFICIENT_BUFFER) +#endif + #include "hb-uniscribe.h" #include "hb-open-file.hh" diff --git a/src/hb.hh b/src/hb.hh index e6d22fe3b..afd9799ee 100644 --- a/src/hb.hh +++ b/src/hb.hh @@ -183,8 +183,15 @@ #include #if (defined(_MSC_VER) && _MSC_VER >= 1500) || defined(__MINGW32__) +#ifdef __MINGW32_VERSION +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN 1 +#endif +#include +#else #include #endif +#endif #define HB_PASTE1(a,b) a##b #define HB_PASTE(a,b) HB_PASTE1(a,b)