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);
--- 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__))