diff --git a/memory/build/malloc_decls.h b/memory/build/malloc_decls.h index 2910851bd0d8..088a2096926f 100644 --- a/memory/build/malloc_decls.h +++ b/memory/build/malloc_decls.h @@ -34,18 +34,31 @@ #endif #ifdef MALLOC_DECL +// NOTHROW_MALLOC_DECL is intended for functions where the standard library +// declares the functions in question as `throw()`. Not all platforms +// consistent declare certain functions as `throw()`, though. + +// Bionic and OS X don't seem to care about `throw()`ness. +# if defined(ANDROID) || defined(XP_DARWIN) +# undef NOTHROW_MALLOC_DECL +# define NOTHROW_MALLOC_DECL MALLOC_DECL +// Some places don't care about the distinction. +# elif !defined(NOTHROW_MALLOC_DECL) +# define NOTHROW_MALLOC_DECL MALLOC_DECL +# endif + # if MALLOC_FUNCS & MALLOC_FUNCS_MALLOC_BASE MALLOC_DECL(malloc, void*, size_t) MALLOC_DECL(calloc, void*, size_t, size_t) MALLOC_DECL(realloc, void*, void*, size_t) -MALLOC_DECL(free, void, void*) -MALLOC_DECL(memalign, void*, size_t, size_t) +NOTHROW_MALLOC_DECL(free, void, void*) +NOTHROW_MALLOC_DECL(memalign, void*, size_t, size_t) # endif # if MALLOC_FUNCS & MALLOC_FUNCS_MALLOC_EXTRA -MALLOC_DECL(posix_memalign, int, void**, size_t, size_t) -MALLOC_DECL(aligned_alloc, void*, size_t, size_t) -MALLOC_DECL(valloc, void*, size_t) -MALLOC_DECL(malloc_usable_size, size_t, usable_ptr_t) +NOTHROW_MALLOC_DECL(posix_memalign, int, void**, size_t, size_t) +NOTHROW_MALLOC_DECL(aligned_alloc, void*, size_t, size_t) +NOTHROW_MALLOC_DECL(valloc, void*, size_t) +NOTHROW_MALLOC_DECL(malloc_usable_size, size_t, usable_ptr_t) MALLOC_DECL(malloc_good_size, size_t, size_t) # endif # if MALLOC_FUNCS & MALLOC_FUNCS_JEMALLOC @@ -122,5 +135,6 @@ MALLOC_DECL(moz_arena_memalign, void*, arena_id_t, size_t, size_t) #endif // MALLOC_DECL +#undef NOTHROW_MALLOC_DECL #undef MALLOC_DECL #undef MALLOC_FUNCS diff --git a/memory/build/mozjemalloc.cpp b/memory/build/mozjemalloc.cpp index 91dbb09e73e8..a60044cb4e23 100644 --- a/memory/build/mozjemalloc.cpp +++ b/memory/build/mozjemalloc.cpp @@ -4683,31 +4683,33 @@ static void replace_malloc_init_funcs(malloc_table_t* table) { return_type name(ARGS_HELPER(TYPED_ARGS, ##__VA_ARGS__)) \ __attribute__((alias(MOZ_STRINGIFY(name_impl)))); -#define GENERIC_MALLOC_DECL2(name, name_impl, return_type, ...) \ - return_type name_impl(ARGS_HELPER(TYPED_ARGS, ##__VA_ARGS__)) { \ +#define GENERIC_MALLOC_DECL2(attributes, name, name_impl, return_type, ...) \ + return_type name_impl(ARGS_HELPER(TYPED_ARGS, ##__VA_ARGS__)) attributes { \ return DefaultMalloc::name(ARGS_HELPER(ARGS, ##__VA_ARGS__)); \ } #ifndef __MINGW32__ -# define GENERIC_MALLOC_DECL(name, return_type, ...) \ - GENERIC_MALLOC_DECL2(name, name##_impl, return_type, ##__VA_ARGS__) +# define GENERIC_MALLOC_DECL(attributes, name, return_type, ...) \ + GENERIC_MALLOC_DECL2(attributes, name, name##_impl, return_type, ##__VA_ARGS__) #else -# define GENERIC_MALLOC_DECL(name, return_type, ...) \ - GENERIC_MALLOC_DECL2(name, name##_impl, return_type, ##__VA_ARGS__) \ +# define GENERIC_MALLOC_DECL(attributes, name, return_type, ...) \ + GENERIC_MALLOC_DECL2(attributes, name, name##_impl, return_type, ##__VA_ARGS__) \ GENERIC_MALLOC_DECL2_MINGW(name, name##_impl, return_type, ##__VA_ARGS__) #endif +#define NOTHROW_MALLOC_DECL(...) \ + MOZ_MEMORY_API MACRO_CALL(GENERIC_MALLOC_DECL, (noexcept(true), __VA_ARGS__)) #define MALLOC_DECL(...) \ - MOZ_MEMORY_API MACRO_CALL(GENERIC_MALLOC_DECL, (__VA_ARGS__)) + MOZ_MEMORY_API MACRO_CALL(GENERIC_MALLOC_DECL, (, __VA_ARGS__)) #define MALLOC_FUNCS MALLOC_FUNCS_MALLOC #include "malloc_decls.h" #undef GENERIC_MALLOC_DECL -#define GENERIC_MALLOC_DECL(name, return_type, ...) \ - GENERIC_MALLOC_DECL2(name, name, return_type, ##__VA_ARGS__) +#define GENERIC_MALLOC_DECL(attributes, name, return_type, ...) \ + GENERIC_MALLOC_DECL2(attributes, name, name, return_type, ##__VA_ARGS__) #define MALLOC_DECL(...) \ - MOZ_JEMALLOC_API MACRO_CALL(GENERIC_MALLOC_DECL, (__VA_ARGS__)) + MOZ_JEMALLOC_API MACRO_CALL(GENERIC_MALLOC_DECL, (, __VA_ARGS__)) #define MALLOC_FUNCS (MALLOC_FUNCS_JEMALLOC | MALLOC_FUNCS_ARENA) #include "malloc_decls.h" // *************************************************************************** diff --git a/memory/build/mozmemory.h b/memory/build/mozmemory.h index 6b75c5b45c3a..63bb735932fc 100644 --- a/memory/build/mozmemory.h +++ b/memory/build/mozmemory.h @@ -50,6 +50,8 @@ static inline size_t _malloc_good_size(size_t size) { #endif +#define NOTHROW_MALLOC_DECL(name, return_type, ...) \ + MOZ_JEMALLOC_API return_type name(__VA_ARGS__) noexcept(true); #define MALLOC_DECL(name, return_type, ...) \ MOZ_JEMALLOC_API return_type name(__VA_ARGS__); #define MALLOC_FUNCS MALLOC_FUNCS_ARENA diff --git a/memory/build/mozmemory_wrap.cpp b/memory/build/mozmemory_wrap.cpp index 7896df974cef..c13a4b19cf4a 100644 --- a/memory/build/mozmemory_wrap.cpp +++ b/memory/build/mozmemory_wrap.cpp @@ -10,6 +10,8 @@ // Declare malloc implementation functions with the right return and // argument types. +#define NOTHROW_MALLOC_DECL(name, return_type, ...) \ + MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__) noexcept(true); #define MALLOC_DECL(name, return_type, ...) \ MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__); #define MALLOC_FUNCS MALLOC_FUNCS_MALLOC diff --git a/memory/mozalloc/mozalloc.h b/memory/mozalloc/mozalloc.h index 7bce8a88587f..a80afbd5b0eb 100644 --- a/memory/mozalloc/mozalloc.h +++ b/memory/mozalloc/mozalloc.h @@ -16,6 +16,8 @@ // need to use _impl suffixes, which is becoming cumbersome. We'll have to use // something like a malloc.h wrapper and allow the use of the functions without // a _impl suffix. In the meanwhile, this is enough to get by for C++ code. +# define NOTHROW_MALLOC_DECL(name, return_type, ...) \ + MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__) noexcept(true); # define MALLOC_DECL(name, return_type, ...) \ MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__); # include "malloc_decls.h"