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++.
--- 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 )