Bug 1365194 - Make `extern "C"` part of MOZ_MEMORY_API and MOZ_JEMALLOC_API. r=njn
authorMike Hommey <mh+mozilla@glandium.org>
Tue, 16 May 2017 18:46:02 +0900
changeset 407042 3284fc12e07d089d7e79475e5e821bce00a3175c
parent 407041 75dad4ff5874feff7fdaf98d08c3368a6bee441b
child 407043 5d681afa6b7af2f51012c0ba9c70c54761cf1591
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs1365194
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1365194 - Make `extern "C"` part of MOZ_MEMORY_API and MOZ_JEMALLOC_API. r=njn This avoids many additions of `extern "C"` in C++ code and will avoid having to do the same to mozjemalloc once built as C++.
memory/build/mozmemory.h
memory/build/mozmemory_wrap.h
memory/mozalloc/mozalloc.cpp
memory/mozalloc/winheap.cpp
mozglue/build/WindowsDllBlocklist.cpp
--- a/memory/build/mozmemory.h
+++ b/memory/build/mozmemory.h
@@ -19,18 +19,16 @@
 #  error Should not include mozmemory.h when MOZ_MEMORY is not set
 #endif
 
 #include "mozmemory_wrap.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/Types.h"
 #include "jemalloc_types.h"
 
-MOZ_BEGIN_EXTERN_C
-
 /*
  * On OSX, malloc/malloc.h contains the declaration for malloc_good_size,
  * which will call back in jemalloc, through the zone allocator so just use it.
  */
 #ifdef XP_DARWIN
 #  include <malloc/malloc.h>
 #else
 MOZ_MEMORY_API size_t malloc_good_size_impl(size_t size);
@@ -84,11 +82,9 @@ MOZ_JEMALLOC_API void jemalloc_purge_fre
  * down subsequent allocations so it is recommended to use it only when
  * memory needs to be reclaimed at all costs (see bug 805855). This function
  * provides functionality similar to mallctl("arenas.purge") in jemalloc 3.
  */
 MOZ_JEMALLOC_API void jemalloc_free_dirty_pages();
 
 MOZ_JEMALLOC_API void jemalloc_thread_local_arena(jemalloc_bool enabled);
 
-MOZ_END_EXTERN_C
-
 #endif /* mozmemory_h */
--- a/memory/build/mozmemory_wrap.h
+++ b/memory/build/mozmemory_wrap.h
@@ -115,54 +115,62 @@
 #  ifdef MFBT_API /* mozilla/Types.h was already included */
 #    error mozmemory_wrap.h has to be included before mozilla/Types.h when MOZ_MEMORY_IMPL is set and IMPL_MFBT is not.
 #  endif
 #  define IMPL_MFBT
 #endif
 
 #include "mozilla/Types.h"
 
+#ifndef MOZ_EXTERN_C
+#ifdef __cplusplus
+#define MOZ_EXTERN_C extern "C"
+#else
+#define MOZ_EXTERN_C
+#endif
+#endif
+
 #ifdef MOZ_MEMORY_IMPL
 #  if defined(MOZ_JEMALLOC_IMPL) && defined(MOZ_REPLACE_MALLOC) && !defined(MOZ_REPLACE_JEMALLOC)
 #    define mozmem_malloc_impl(a)     je_ ## a
 #    define mozmem_jemalloc_impl(a)   je_ ## a
 #  else
-#    define MOZ_JEMALLOC_API MFBT_API
+#    define MOZ_JEMALLOC_API MOZ_EXTERN_C MFBT_API
 #    ifdef MOZ_REPLACE_JEMALLOC
-#      define MOZ_MEMORY_API MFBT_API
+#      define MOZ_MEMORY_API MOZ_EXTERN_C MFBT_API
 #      define mozmem_malloc_impl(a)     replace_ ## a
 #      define mozmem_jemalloc_impl(a)   replace_ ## a
 #    elif (defined(XP_WIN) || defined(XP_DARWIN))
 #      if defined(MOZ_REPLACE_MALLOC)
 #        define mozmem_malloc_impl(a)   a ## _impl
 #      else
 #        define mozmem_malloc_impl(a)   je_ ## a
 #      endif
 #    else
-#      define MOZ_MEMORY_API MFBT_API
+#      define MOZ_MEMORY_API MOZ_EXTERN_C MFBT_API
 #      if defined(MOZ_WIDGET_ANDROID) || defined(MOZ_WIDGET_GONK)
 #        define MOZ_WRAP_NEW_DELETE
 #      endif
 #    endif
 #  endif
 #  ifdef XP_WIN
 #    define mozmem_dup_impl(a)      wrap_ ## a
 #  endif
 #endif
 
 #if !defined(MOZ_MEMORY_IMPL)
-#  define MOZ_MEMORY_API MFBT_API
-#  define MOZ_JEMALLOC_API MFBT_API
+#  define MOZ_MEMORY_API MOZ_EXTERN_C MFBT_API
+#  define MOZ_JEMALLOC_API MOZ_EXTERN_C MFBT_API
 #endif
 
 #ifndef MOZ_MEMORY_API
-#  define MOZ_MEMORY_API
+#  define MOZ_MEMORY_API MOZ_EXTERN_C
 #endif
 #ifndef MOZ_JEMALLOC_API
-#  define MOZ_JEMALLOC_API
+#  define MOZ_JEMALLOC_API MOZ_EXTERN_C
 #endif
 
 #ifndef mozmem_malloc_impl
 #  define mozmem_malloc_impl(a)   a
 #endif
 #ifndef mozmem_dup_impl
 #  define mozmem_dup_impl(a)      a
 #endif
--- a/memory/mozalloc/mozalloc.cpp
+++ b/memory/mozalloc/mozalloc.cpp
@@ -23,22 +23,22 @@
 #include <malloc/malloc.h> // for malloc_size
 #endif
 
 // See mozmemory_wrap.h for more details. This file is part of libmozglue, so
 // it needs to use _impl suffixes. However, with libmozglue growing, this is
 // becoming cumbersome, so we will likely use a malloc.h wrapper of some sort
 // and allow the use of the functions without a _impl suffix.
 #define MALLOC_DECL(name, return_type, ...) \
-  extern "C" MOZ_MEMORY_API return_type name ## _impl(__VA_ARGS__);
+  MOZ_MEMORY_API return_type name ## _impl(__VA_ARGS__);
 #define MALLOC_FUNCS MALLOC_FUNCS_MALLOC
 #include "malloc_decls.h"
 
-extern "C" MOZ_MEMORY_API char *strdup_impl(const char *);
-extern "C" MOZ_MEMORY_API char *strndup_impl(const char *, size_t);
+MOZ_MEMORY_API char *strdup_impl(const char *);
+MOZ_MEMORY_API char *strndup_impl(const char *, size_t);
 
 #else
 // When jemalloc is disabled, or when building the static runtime variant,
 // we need not to use the suffixes.
 
 #if defined(MALLOC_H)
 #  include MALLOC_H             // for memalign, valloc, malloc_size, malloc_us
 #endif // if defined(MALLOC_H)
--- a/memory/mozalloc/winheap.cpp
+++ b/memory/mozalloc/winheap.cpp
@@ -20,17 +20,17 @@
 #define MOZ_MEMORY_IMPL
 #include "mozmemory_wrap.h"
 
 // See mozmemory_wrap.h for more details. This file is part of libmozglue, so
 // it needs to use _impl suffixes. However, with libmozglue growing, this is
 // becoming cumbersome, so we will likely use a malloc.h wrapper of some sort
 // and allow the use of the functions without a _impl suffix.
 #define MALLOC_DECL(name, return_type, ...) \
-  extern "C" MOZ_MEMORY_API return_type name ## _impl(__VA_ARGS__);
+  MOZ_MEMORY_API return_type name ## _impl(__VA_ARGS__);
 #define MALLOC_FUNCS MALLOC_FUNCS_MALLOC
 #include "malloc_decls.h"
 
 // Warning: C4273: 'HeapAlloc': inconsistent dll linkage
 // The Windows headers define HeapAlloc as dllimport, but we define it as
 // dllexport, which is a voluntary inconsistency.
 #pragma warning(disable: 4273)
 
--- a/mozglue/build/WindowsDllBlocklist.cpp
+++ b/mozglue/build/WindowsDllBlocklist.cpp
@@ -5,17 +5,17 @@
 
 #ifdef MOZ_MEMORY
 #define MOZ_MEMORY_IMPL
 #include "mozmemory_wrap.h"
 #define MALLOC_FUNCS MALLOC_FUNCS_MALLOC
 // See mozmemory_wrap.h for more details. This file is part of libmozglue, so
 // it needs to use _impl suffixes.
 #define MALLOC_DECL(name, return_type, ...) \
-  extern "C" MOZ_MEMORY_API return_type name ## _impl(__VA_ARGS__);
+  MOZ_MEMORY_API return_type name ## _impl(__VA_ARGS__);
 #include "malloc_decls.h"
 #endif
 
 #include <windows.h>
 #include <winternl.h>
 #include <io.h>
 
 #pragma warning( push )