mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-07 18:04:46 +00:00
Bug 1145051: Replace uses of NS_ATTR_MALLOC with new MOZ_ALLOCATOR from mfbt/Attributes.h. r=glandium
--HG-- extra : rebase_source : 294215445f084687ed7fa51b88e7a22e586447a2
This commit is contained in:
parent
9f8de4bfd5
commit
a778e9f970
15
configure.in
15
configure.in
@ -3436,13 +3436,6 @@ AC_CACHE_CHECK(for __attribute__((always_inline)),
|
||||
ac_cv_attribute_always_inline=yes,
|
||||
ac_cv_attribute_always_inline=no)])
|
||||
|
||||
AC_CACHE_CHECK(for __attribute__((malloc)),
|
||||
ac_cv_attribute_malloc,
|
||||
[AC_TRY_COMPILE([void* f(int) __attribute__((malloc));],
|
||||
[],
|
||||
ac_cv_attribute_malloc=yes,
|
||||
ac_cv_attribute_malloc=no)])
|
||||
|
||||
AC_CACHE_CHECK(for __attribute__((warn_unused_result)),
|
||||
ac_cv_attribute_warn_unused,
|
||||
[AC_TRY_COMPILE([int f(void) __attribute__((warn_unused_result));],
|
||||
@ -3486,14 +3479,6 @@ dnl ========================================================
|
||||
dnl The macros used for command line options
|
||||
dnl are defined in build/autoconf/altoptions.m4.
|
||||
|
||||
dnl If the compiler supports these attributes, define them as
|
||||
dnl convenience macros.
|
||||
if test "$ac_cv_attribute_malloc" = yes ; then
|
||||
AC_DEFINE(NS_ATTR_MALLOC, [__attribute__((malloc))])
|
||||
else
|
||||
AC_DEFINE(NS_ATTR_MALLOC,)
|
||||
fi
|
||||
|
||||
if test "$ac_cv_attribute_warn_unused" = yes ; then
|
||||
AC_DEFINE(NS_WARN_UNUSED_RESULT, [__attribute__((warn_unused_result))])
|
||||
else
|
||||
|
@ -2659,13 +2659,6 @@ AC_CACHE_CHECK(for __attribute__((always_inline)),
|
||||
ac_cv_attribute_always_inline=yes,
|
||||
ac_cv_attribute_always_inline=no)])
|
||||
|
||||
AC_CACHE_CHECK(for __attribute__((malloc)),
|
||||
ac_cv_attribute_malloc,
|
||||
[AC_TRY_COMPILE([void* f(int) __attribute__((malloc));],
|
||||
[],
|
||||
ac_cv_attribute_malloc=yes,
|
||||
ac_cv_attribute_malloc=no)])
|
||||
|
||||
AC_CACHE_CHECK(for __attribute__((warn_unused_result)),
|
||||
ac_cv_attribute_warn_unused,
|
||||
[AC_TRY_COMPILE([int f(void) __attribute__((warn_unused_result));],
|
||||
@ -2708,14 +2701,6 @@ dnl ========================================================
|
||||
dnl The macros used for command line options
|
||||
dnl are defined in build/autoconf/altoptions.m4.
|
||||
|
||||
dnl If the compiler supports these attributes, define them as
|
||||
dnl convenience macros.
|
||||
if test "$ac_cv_attribute_malloc" = yes ; then
|
||||
AC_DEFINE(NS_ATTR_MALLOC, [__attribute__((malloc))])
|
||||
else
|
||||
AC_DEFINE(NS_ATTR_MALLOC,)
|
||||
fi
|
||||
|
||||
if test "$ac_cv_attribute_warn_unused" = yes ; then
|
||||
AC_DEFINE(NS_WARN_UNUSED_RESULT, [__attribute__((warn_unused_result))])
|
||||
else
|
||||
|
@ -40,8 +40,8 @@
|
||||
#if defined(__SUNPRO_C) || defined(__SUNPRO_CC)
|
||||
# undef NS_WARN_UNUSED_RESULT
|
||||
# define NS_WARN_UNUSED_RESULT
|
||||
# undef NS_ATTR_MALLOC
|
||||
# define NS_ATTR_MALLOC
|
||||
# undef MOZ_ALLOCATOR
|
||||
# define MOZ_ALLOCATOR
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
@ -76,16 +76,16 @@ extern "C" {
|
||||
*/
|
||||
|
||||
MFBT_API void* moz_xmalloc(size_t size)
|
||||
NS_ATTR_MALLOC NS_WARN_UNUSED_RESULT;
|
||||
MOZ_ALLOCATOR;
|
||||
|
||||
MFBT_API void* moz_xcalloc(size_t nmemb, size_t size)
|
||||
NS_ATTR_MALLOC NS_WARN_UNUSED_RESULT;
|
||||
MOZ_ALLOCATOR;
|
||||
|
||||
MFBT_API void* moz_xrealloc(void* ptr, size_t size)
|
||||
NS_ATTR_MALLOC NS_WARN_UNUSED_RESULT;
|
||||
MOZ_ALLOCATOR;
|
||||
|
||||
MFBT_API char* moz_xstrdup(const char* str)
|
||||
NS_ATTR_MALLOC NS_WARN_UNUSED_RESULT;
|
||||
MOZ_ALLOCATOR;
|
||||
|
||||
MFBT_API size_t moz_malloc_usable_size(void *ptr);
|
||||
|
||||
@ -93,7 +93,7 @@ MFBT_API size_t moz_malloc_size_of(const void *ptr);
|
||||
|
||||
#if defined(HAVE_STRNDUP)
|
||||
MFBT_API char* moz_xstrndup(const char* str, size_t strsize)
|
||||
NS_ATTR_MALLOC NS_WARN_UNUSED_RESULT;
|
||||
MOZ_ALLOCATOR;
|
||||
#endif /* if defined(HAVE_STRNDUP) */
|
||||
|
||||
|
||||
@ -108,13 +108,13 @@ MFBT_API int moz_posix_memalign(void **ptr, size_t alignment, size_t size)
|
||||
|
||||
#if defined(HAVE_MEMALIGN)
|
||||
MFBT_API void* moz_xmemalign(size_t boundary, size_t size)
|
||||
NS_ATTR_MALLOC NS_WARN_UNUSED_RESULT;
|
||||
MOZ_ALLOCATOR;
|
||||
#endif /* if defined(HAVE_MEMALIGN) */
|
||||
|
||||
|
||||
#if defined(HAVE_VALLOC)
|
||||
MFBT_API void* moz_xvalloc(size_t size)
|
||||
NS_ATTR_MALLOC NS_WARN_UNUSED_RESULT;
|
||||
MOZ_ALLOCATOR;
|
||||
#endif /* if defined(HAVE_VALLOC) */
|
||||
|
||||
|
||||
|
@ -283,6 +283,35 @@
|
||||
# define MOZ_TSAN_BLACKLIST /* nothing */
|
||||
#endif
|
||||
|
||||
/**
|
||||
* MOZ_ALLOCATOR tells the compiler that the function it marks returns either a
|
||||
* "fresh", "pointer-free" block of memory, or nullptr. "Fresh" means that the
|
||||
* block is not pointed to by any other reachable pointer in the program.
|
||||
* "Pointer-free" means that the block contains no pointers to any valid object
|
||||
* in the program. It may be initialized with other (non-pointer) values.
|
||||
*
|
||||
* Placing this attribute on appropriate functions helps GCC analyze pointer
|
||||
* aliasing more accurately in their callers.
|
||||
*
|
||||
* GCC warns if a caller ignores the value returned by a function marked with
|
||||
* MOZ_ALLOCATOR: it is hard to imagine cases where dropping the value returned
|
||||
* by a function that meets the criteria above would be intentional.
|
||||
*
|
||||
* Place this attribute after the argument list and 'this' qualifiers of a
|
||||
* function definition. For example, write
|
||||
*
|
||||
* void *my_allocator(size_t) MOZ_ALLOCATOR;
|
||||
*
|
||||
* or
|
||||
*
|
||||
* void *my_allocator(size_t bytes) MOZ_ALLOCATOR { ... }
|
||||
*/
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
# define MOZ_ALLOCATOR __attribute__ ((malloc, warn_unused_result))
|
||||
#else
|
||||
# define MOZ_ALLOCATOR
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
/**
|
||||
|
@ -18,9 +18,6 @@
|
||||
/* Define if a dyanmic_cast to void* gives the most derived object */
|
||||
#undef HAVE_CPP_DYNAMIC_CAST_TO_VOID_PTR
|
||||
|
||||
/* Define to either __attribute__((malloc)) or nothing */
|
||||
#undef NS_ATTR_MALLOC
|
||||
|
||||
/* Define to either __attribute__((warn_unused_result)) or nothing */
|
||||
#undef NS_WARN_UNUSED_RESULT
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user