From aaf96507a15196145d903764dc905d8d6e7df7b0 Mon Sep 17 00:00:00 2001
From: Nat Goodspeed <nat@lindenlab.com>
Date: Fri, 16 Nov 2012 18:08:40 -0500
Subject: [PATCH] Some Mac header #defines macros like check and equivalent --
 gack!! Given that third-party libraries (such as Boost) can and do use those
 names, properly namespace-scoped, it's unpardonable to break any such
 innocent usage with a macro. Given the pervasiveness of the need, introduce a
 header file with the requisite #undef directives.

---
 indra/llcommon/CMakeLists.txt    |  1 +
 indra/llcommon/fix_macros.h      | 25 +++++++++++++++++++++++++
 indra/llcorehttp/_refcounted.h   |  1 +
 indra/llvfs/lldiriterator.cpp    |  1 +
 indra/llwindow/llwindowmacosx.h  |  2 +-
 indra/llwindow/llwindowsdl.h     |  2 +-
 indra/newview/lldirpicker.h      |  2 +-
 indra/newview/llfilepicker.h     |  2 +-
 indra/newview/lllocalbitmaps.cpp |  4 +---
 indra/newview/macutil_Prefix.h   |  2 +-
 10 files changed, 34 insertions(+), 8 deletions(-)
 create mode 100644 indra/llcommon/fix_macros.h

diff --git a/indra/llcommon/CMakeLists.txt b/indra/llcommon/CMakeLists.txt
index 36a8319189c..66e2bc90950 100644
--- a/indra/llcommon/CMakeLists.txt
+++ b/indra/llcommon/CMakeLists.txt
@@ -116,6 +116,7 @@ set(llcommon_HEADER_FILES
     bitpack.h
     ctype_workaround.h
     doublelinkedlist.h
+    fix_macros.h
     imageids.h
     indra_constants.h
     linden_common.h
diff --git a/indra/llcommon/fix_macros.h b/indra/llcommon/fix_macros.h
new file mode 100644
index 00000000000..ef959decffe
--- /dev/null
+++ b/indra/llcommon/fix_macros.h
@@ -0,0 +1,25 @@
+/**
+ * @file   fix_macros.h
+ * @author Nat Goodspeed
+ * @date   2012-11-16
+ * @brief  The Mac system headers seem to #define macros with obnoxiously
+ *         generic names, preventing any library from using those names. We've
+ *         had to fix these in so many places that it's worth making a header
+ *         file to handle it.
+ * 
+ * $LicenseInfo:firstyear=2012&license=viewerlgpl$
+ * Copyright (c) 2012, Linden Research, Inc.
+ * $/LicenseInfo$
+ */
+
+// DON'T use an #include guard: every time we encounter this header, #undef
+// these macros all over again.
+
+// who injects MACROS with such generic names?! Grr.
+#ifdef equivalent
+#undef equivalent
+#endif 
+
+#ifdef check
+#undef check
+#endif
diff --git a/indra/llcorehttp/_refcounted.h b/indra/llcorehttp/_refcounted.h
index a96c65fb6b9..21a916b13b1 100644
--- a/indra/llcorehttp/_refcounted.h
+++ b/indra/llcorehttp/_refcounted.h
@@ -30,6 +30,7 @@
 
 #include "linden_common.h"
 
+#include "fix_macros.h"
 #include <boost/thread.hpp>
 
 #include "llapr.h"
diff --git a/indra/llvfs/lldiriterator.cpp b/indra/llvfs/lldiriterator.cpp
index fa806bf23eb..460d2a8b4fb 100644
--- a/indra/llvfs/lldiriterator.cpp
+++ b/indra/llvfs/lldiriterator.cpp
@@ -26,6 +26,7 @@
 
 #include "lldiriterator.h"
 
+#include "fix_macros.h"
 #include <boost/filesystem.hpp>
 #include <boost/regex.hpp>
 
diff --git a/indra/llwindow/llwindowmacosx.h b/indra/llwindow/llwindowmacosx.h
index 52ba8b3bf3e..af83b500976 100644
--- a/indra/llwindow/llwindowmacosx.h
+++ b/indra/llwindow/llwindowmacosx.h
@@ -36,8 +36,8 @@
 #include <AGL/agl.h>
 
 // AssertMacros.h does bad things.
+#include "fix_macros.h"
 #undef verify
-#undef check
 #undef require
 
 
diff --git a/indra/llwindow/llwindowsdl.h b/indra/llwindow/llwindowsdl.h
index 4e2a269ea33..c5ce892a042 100644
--- a/indra/llwindow/llwindowsdl.h
+++ b/indra/llwindow/llwindowsdl.h
@@ -41,8 +41,8 @@
 #endif
 
 // AssertMacros.h does bad things.
+#include "fix_macros.h"
 #undef verify
-#undef check
 #undef require
 
 
diff --git a/indra/newview/lldirpicker.h b/indra/newview/lldirpicker.h
index 2188b7edd04..682f9d64769 100644
--- a/indra/newview/lldirpicker.h
+++ b/indra/newview/lldirpicker.h
@@ -37,8 +37,8 @@
 #include <Carbon/Carbon.h>
 
 // AssertMacros.h does bad things.
+#include "fix_macros.h"
 #undef verify
-#undef check
 #undef require
 
 #include <vector>
diff --git a/indra/newview/llfilepicker.h b/indra/newview/llfilepicker.h
index 55c665b9c76..4f602f63f13 100644
--- a/indra/newview/llfilepicker.h
+++ b/indra/newview/llfilepicker.h
@@ -39,8 +39,8 @@
 #include <Carbon/Carbon.h>
 
 // AssertMacros.h does bad things.
+#include "fix_macros.h"
 #undef verify
-#undef check
 #undef require
 
 #include <vector>
diff --git a/indra/newview/lllocalbitmaps.cpp b/indra/newview/lllocalbitmaps.cpp
index 459e52c4f4e..97ba5b634a1 100644
--- a/indra/newview/lllocalbitmaps.cpp
+++ b/indra/newview/lllocalbitmaps.cpp
@@ -32,9 +32,7 @@
 #include "lllocalbitmaps.h"
 
 /* boost: will not compile unless equivalent is undef'd, beware. */
-#ifdef equivalent
-#undef equivalent
-#endif 
+#include "fix_macros.h"
 #include <boost/filesystem.hpp>
 
 /* image compression headers. */
diff --git a/indra/newview/macutil_Prefix.h b/indra/newview/macutil_Prefix.h
index fd8e927a086..b54a764a624 100644
--- a/indra/newview/macutil_Prefix.h
+++ b/indra/newview/macutil_Prefix.h
@@ -33,7 +33,7 @@
  */
 
 #include <Carbon/Carbon.h>
+#include "fix_macros.h"
 
-#undef check
 #undef verify
 #undef require
-- 
GitLab