Bug 1368932 - Add argument names to malloc implementation declarations in replace-malloc. r=njn
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 25 May 2017 16:04:46 +0900
changeset 409823 899d3cbc450c37b27b7f3def83cc6836a61df09c
parent 409822 2265602a89551359f9a31fee81887bd9a6360d53
child 409824 3d78fdcff608b2486ea7b75cb9b5fe31b75cc2ed
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
bugs1368932
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 1368932 - Add argument names to malloc implementation declarations in replace-malloc. r=njn This transforms the declarations from e.g.: void *realloc(void *, size_t); into: void *realloc(void *arg1, size_t arg2);
memory/build/replace_malloc.c
--- a/memory/build/replace_malloc.c
+++ b/memory/build/replace_malloc.c
@@ -13,16 +13,17 @@
 #include "mozmemory_wrap.h"
 
 /* Declare all je_* functions */
 #define MALLOC_DECL(name, return_type, ...) \
   return_type je_ ## name(__VA_ARGS__);
 #include "malloc_decls.h"
 
 #include "mozilla/Likely.h"
+#include "mozilla/MacroArgs.h"
 
 /*
  * Windows doesn't come with weak imports as they are possible with
  * LD_PRELOAD or DYLD_INSERT_LIBRARIES on Linux/OSX. On this platform,
  * the replacement functions are defined as variable pointers to the
  * function resolved with GetProcAddress() instead of weak definitions
  * of functions. On Android, the same needs to happen as well, because
  * the Android linker doesn't handle weak linking with non LD_PRELOADed
@@ -100,19 +101,29 @@ replace_malloc_init_funcs()
  * replacement functions if they exist.
  */
 
 /*
  * Malloc implementation functions are MOZ_MEMORY_API, and jemalloc
  * specific functions MOZ_JEMALLOC_API; see mozmemory_wrap.h
  */
 #define MACRO_CALL(a, b) a b
+/* Can't use macros recursively, so we need another one doing the same as above. */
+#define MACRO_CALL2(a, b) a b
+
+#define TYPED_ARGS(...) MACRO_CALL2( \
+  MOZ_PASTE_PREFIX_AND_ARG_COUNT(TYPED_ARGS, ##__VA_ARGS__), \
+  (__VA_ARGS__))
+#define TYPED_ARGS0()
+#define TYPED_ARGS1(t1) t1 arg1
+#define TYPED_ARGS2(t1, t2) TYPED_ARGS1(t1), t2 arg2
+#define TYPED_ARGS3(t1, t2, t3) TYPED_ARGS2(t1, t2), t3 arg3
 
 #define GENERIC_MALLOC_DECL_HELPER(name, return_type, ...) \
-  return_type name ## _impl(__VA_ARGS__);
+  return_type name ## _impl(TYPED_ARGS(__VA_ARGS__));
 
 #define GENERIC_MALLOC_DECL(name, return_type, ...) \
   GENERIC_MALLOC_DECL_HELPER(name, return_type, ##__VA_ARGS__)
 #define GENERIC_MALLOC_DECL_VOID(name, ...) \
   GENERIC_MALLOC_DECL_HELPER(name, void, ##__VA_ARGS__)
 
 #define MALLOC_DECL(...) MOZ_MEMORY_API MACRO_CALL(GENERIC_MALLOC_DECL, (__VA_ARGS__))
 #define MALLOC_DECL_VOID(...) MOZ_MEMORY_API MACRO_CALL(GENERIC_MALLOC_DECL_VOID, (__VA_ARGS__))