[HarfBuzz] build problem on windows with older MSVC

Jonathan Kew jonathan at jfkew.plus.com
Mon Oct 17 02:27:33 PDT 2011


Hi Behdad,

It seems that there's a problem with the use of <intrin.h> in some versions of MSVC - apparently some older SDK versions are buggy and it leads to a conflict with <windows.h>. I ran into this when things built fine for me locally, with VC2010, but failed on our tinderbox machines with an older compiler (2005? 2008?).

I don't know whether anyone is really relying on thread-safety at the moment. As a workaround, I'd suggest just disabling the use of the MS intrinsics when building with older tools. If someone really needs this, they could be encouraged to use the latest toolset.

So, suggested patch:

diff --git a/harfbuzz/src/hb-object-private.hh b/harfbuzz/src/hb-object-private.hh
--- a/harfbuzz/src/hb-object-private.hh
+++ b/harfbuzz/src/hb-object-private.hh
@@ -54,29 +54,33 @@
 #include <glib.h>
 
 typedef volatile int hb_atomic_int_t;
 #define hb_atomic_int_fetch_and_add(AI, V)	g_atomic_int_exchange_and_add (&(AI), V)
 #define hb_atomic_int_get(AI)			g_atomic_int_get (&(AI))
 #define hb_atomic_int_set(AI, V)		g_atomic_int_set (&(AI), V)
 
 
-#elif defined(_MSC_VER)
+#elif _MSC_VER >= 1600
 
 #include <intrin.h>
 
 typedef long hb_atomic_int_t;
 #define hb_atomic_int_fetch_and_add(AI, V)	_InterlockedExchangeAdd (&(AI), V)
 #define hb_atomic_int_get(AI)			(_ReadBarrier (), (AI))
 #define hb_atomic_int_set(AI, V)		((void) _InterlockedExchange (&(AI), (V)))
 
 
 #else
 
+#ifdef _MSC_VER
+#pragma message("Could not find any system to define atomic_int macros, library will NOT be thread-safe")
+#else
 #warning "Could not find any system to define atomic_int macros, library will NOT be thread-safe"
+#endif
 
 typedef volatile int hb_atomic_int_t;
 #define hb_atomic_int_fetch_and_add(AI, V)	((AI) += (V), (AI) - (V))
 #define hb_atomic_int_get(AI)			(AI)
 #define hb_atomic_int_set(AI, V)		((void) ((AI) = (V)))
 
 
 #endif

(Note that MSVC doesn't recognize #warning, so it's necessary to provide an alternative, as above.)

JK




More information about the HarfBuzz mailing list