Bug 550401: Do the __declspec import/export dance in mozalloc to avoid MSVC warnings. r=bsmedberg
authorChris Jones <jones.chris.g@gmail.com>
Thu, 08 Apr 2010 13:05:02 -0500
changeset 40598 bbbb2d668d0d0bce8d8256a5b2f1ad80cd2fc12f
parent 40597 47cee476df1623147b7f69765de43ad5414b2fd4
child 40599 2676cf045c7311ff1add554324ff7f2e9b1b8ce9
push idunknown
push userunknown
push dateunknown
reviewersbsmedberg
bugs550401
milestone1.9.3a5pre
Bug 550401: Do the __declspec import/export dance in mozalloc to avoid MSVC warnings. r=bsmedberg
memory/mozalloc/mozalloc.cpp
memory/mozalloc/mozalloc.h
memory/mozalloc/mozalloc_oom.cpp
memory/mozalloc/mozalloc_oom.h
xpcom/base/nscore.h
--- a/memory/mozalloc/mozalloc.cpp
+++ b/memory/mozalloc/mozalloc.cpp
@@ -43,16 +43,20 @@
 #include <string.h>
 
 #if defined(MALLOC_H)
 #  include MALLOC_H             // for memalign, valloc where available
 #endif // if defined(MALLOC_H)
 #include <stddef.h>             // for size_t
 #include <stdlib.h>             // for malloc, free
 
+#if defined(XP_WIN) || (defined(XP_OS2) && defined(__declspec))
+#  define MOZALLOC_EXPORT __declspec(dllexport)
+#endif
+
 // Make sure that "malloc" et al. resolve to their libc variants.
 #define MOZALLOC_DONT_DEFINE_MACRO_WRAPPERS
 #include "mozilla/mozalloc.h"
 #include "mozilla/mozalloc_oom.h"  // for mozalloc_handle_oom
 
 
 #if defined(__GNUC__) && (__GNUC__ > 2)
 #define LIKELY(x)    (__builtin_expect(!!(x), 1))
--- a/memory/mozalloc/mozalloc.h
+++ b/memory/mozalloc/mozalloc.h
@@ -49,18 +49,21 @@
 /* 
  * NB: this header depends on the symbols malloc(), free(), and
  * std::bad_alloc.  But because this header is used in situations
  * where malloc/free have different visibility, we rely on code
  * including this header to provide the declarations of malloc/free.
  * I.e., we don't #include <stdlib.h> or <new> on purpose.
  */
 
-#if defined(XP_WIN) || (defined(XP_OS2) && defined(__declspec))
-#  define MOZALLOC_EXPORT __declspec(dllexport)
+#if defined(MOZALLOC_EXPORT)
+// do nothing: it's been defined to __declspec(dllexport) by
+// mozalloc*.cpp on platforms where that's required
+#elif defined(XP_WIN) || (defined(XP_OS2) && defined(__declspec))
+#  define MOZALLOC_EXPORT __declspec(dllimport)
 #elif defined(HAVE_VISIBILITY_ATTRIBUTE)
 /* Make sure symbols are still exported even if we're wrapped in a
  * |visibility push(hidden)| blanket. */
 #  define MOZALLOC_EXPORT __attribute__ ((visibility ("default")))
 #else
 #  define MOZALLOC_EXPORT
 #endif
 
--- a/memory/mozalloc/mozalloc_oom.cpp
+++ b/memory/mozalloc/mozalloc_oom.cpp
@@ -41,16 +41,20 @@
 #include <stdlib.h>             // for abort()
 
 #if defined(_WIN32)
 #  include <signal.h>           // for raise
 #elif defined(XP_UNIX)
 #  include <unistd.h>           // for _exit
 #endif
 
+#if defined(XP_WIN) || (defined(XP_OS2) && defined(__declspec))
+#  define MOZALLOC_EXPORT __declspec(dllexport)
+#endif
+
 #include "mozilla/mozalloc_oom.h"
 
 static int gDummyCounter;
 
 void
 mozalloc_handle_oom()
 {
     // NB: this is handle_oom() stage 1, which simply aborts on OOM.
--- a/memory/mozalloc/mozalloc_oom.h
+++ b/memory/mozalloc/mozalloc_oom.h
@@ -36,19 +36,21 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef mozilla_mozalloc_oom_h
 #define mozilla_mozalloc_oom_h
 
-
-#if defined(XP_WIN) || (defined(XP_OS2) && defined(__declspec))
-#  define MOZALLOC_EXPORT __declspec(dllexport)
+#if defined(MOZALLOC_EXPORT)
+// do nothing: it's been defined to __declspec(dllexport) by
+// mozalloc*.cpp on platforms where that's required
+#elif defined(XP_WIN) || (defined(XP_OS2) && defined(__declspec))
+#  define MOZALLOC_EXPORT __declspec(dllimport)
 #elif defined(HAVE_VISIBILITY_ATTRIBUTE)
 /* Make sure symbols are still exported even if we're wrapped in a
  * |visibility push(hidden)| blanket. */
 #  define MOZALLOC_EXPORT __attribute__ ((visibility ("default")))
 #else
 #  define MOZALLOC_EXPORT
 #endif
 
--- a/xpcom/base/nscore.h
+++ b/xpcom/base/nscore.h
@@ -45,17 +45,20 @@
 #include "xpcom-config.h"
 #endif
 
 /* Definitions of functions and operators that allocate memory. */
 #if !defined(XPCOM_GLUE) && !defined(NS_NO_XPCOM) && !defined(MOZ_NO_MOZALLOC)
 #  if defined(__cplusplus)
 #    include NEW_H              /* to give mozalloc std::bad_alloc */
 #  endif
-#  include <stdlib.h>         /* to give mozalloc malloc/free decls */
+/* include these to avoid the macro wrappers causing these headers to
+ * declare system functions with moz_ prefixes */
+#  include <stdlib.h>
+#  include <string.h>
 #  include "mozilla/mozalloc.h"
 #  include "mozilla/mozalloc_macro_wrappers.h"
 #endif
 
 /**
  * Incorporate the core NSPR data types which XPCOM uses.
  */
 #include "prtypes.h"