mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 11:25:00 +00:00
Bug 1423114 - Remove moz_xposix_memalign and moz_xvalloc. r=njn
They are both infallible wrappers of posix_memalign and valloc. There is also moz_xmemalign, which wraps memalign, which is mostly always available as of bug 1402647. None of them are actually used, but it's still desirable to at least have one infallible variant, so keep moz_xmemalign and remove the other two. While here, we actually make both memalign and moz_xmemalign always available. --HG-- extra : rebase_source : 1c3ca4b3e3310543145f3181dfa4e764be1d6ff8
This commit is contained in:
parent
4c95537eeb
commit
3f1f5c9fc2
@ -9,9 +9,7 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifndef HAVE_MEMALIGN
|
||||
namespace {
|
||||
|
||||
inline void*
|
||||
MOZ_MEMORY_API void*
|
||||
memalign(size_t aAlignment, size_t aSize)
|
||||
{
|
||||
#ifdef XP_WIN
|
||||
@ -24,7 +22,6 @@ memalign(size_t aAlignment, size_t aSize)
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
struct SystemMalloc
|
||||
|
@ -34,20 +34,18 @@ MOZ_MEMORY_API char *strndup_impl(const char *, size_t);
|
||||
// we need not to use the suffixes.
|
||||
|
||||
#if defined(MALLOC_H)
|
||||
# include MALLOC_H // for memalign, valloc, malloc_size, malloc_us
|
||||
# include MALLOC_H // for memalign, malloc_size, malloc_us
|
||||
#endif // if defined(MALLOC_H)
|
||||
#include <stdlib.h> // for malloc, free
|
||||
#if defined(XP_UNIX)
|
||||
# include <unistd.h> // for valloc on *BSD
|
||||
# include <unistd.h>
|
||||
#endif //if defined(XP_UNIX)
|
||||
|
||||
#define malloc_impl malloc
|
||||
#define posix_memalign_impl posix_memalign
|
||||
#define calloc_impl calloc
|
||||
#define realloc_impl realloc
|
||||
#define free_impl free
|
||||
#define memalign_impl memalign
|
||||
#define valloc_impl valloc
|
||||
#define malloc_usable_size_impl malloc_usable_size
|
||||
#define strdup_impl strdup
|
||||
#define strndup_impl strndup
|
||||
@ -129,21 +127,12 @@ moz_xstrndup(const char* str, size_t strsize)
|
||||
}
|
||||
#endif // if defined(HAVE_STRNDUP)
|
||||
|
||||
#if defined(HAVE_POSIX_MEMALIGN)
|
||||
int
|
||||
moz_xposix_memalign(void **ptr, size_t alignment, size_t size)
|
||||
{
|
||||
int err = posix_memalign_impl(ptr, alignment, size);
|
||||
if (UNLIKELY(err && ENOMEM == err)) {
|
||||
mozalloc_handle_oom(size);
|
||||
return moz_xposix_memalign(ptr, alignment, size);
|
||||
}
|
||||
// else: (0 == err) or (EINVAL == err)
|
||||
return err;
|
||||
}
|
||||
#endif // if defined(HAVE_POSIX_MEMALIGN)
|
||||
#ifndef HAVE_MEMALIGN
|
||||
// We always have a definition of memalign, but system headers don't
|
||||
// necessarily come with a declaration.
|
||||
extern "C" void* memalign(size_t, size_t);
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_MEMALIGN)
|
||||
void*
|
||||
moz_xmemalign(size_t boundary, size_t size)
|
||||
{
|
||||
@ -155,20 +144,6 @@ moz_xmemalign(size_t boundary, size_t size)
|
||||
// non-NULL ptr or errno == EINVAL
|
||||
return ptr;
|
||||
}
|
||||
#endif // if defined(HAVE_MEMALIGN)
|
||||
|
||||
#if defined(HAVE_VALLOC)
|
||||
void*
|
||||
moz_xvalloc(size_t size)
|
||||
{
|
||||
void* ptr = valloc_impl(size);
|
||||
if (UNLIKELY(!ptr)) {
|
||||
mozalloc_handle_oom(size);
|
||||
return moz_xvalloc(size);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
#endif // if defined(HAVE_VALLOC)
|
||||
|
||||
size_t
|
||||
moz_malloc_usable_size(void *ptr)
|
||||
|
@ -97,24 +97,8 @@ MFBT_API char* moz_xstrndup(const char* str, size_t strsize)
|
||||
MOZ_ALLOCATOR;
|
||||
#endif /* if defined(HAVE_STRNDUP) */
|
||||
|
||||
|
||||
#if defined(HAVE_POSIX_MEMALIGN)
|
||||
MFBT_API MOZ_MUST_USE
|
||||
int moz_xposix_memalign(void **ptr, size_t alignment, size_t size);
|
||||
#endif /* if defined(HAVE_POSIX_MEMALIGN) */
|
||||
|
||||
|
||||
#if defined(HAVE_MEMALIGN)
|
||||
MFBT_API void* moz_xmemalign(size_t boundary, size_t size)
|
||||
MOZ_ALLOCATOR;
|
||||
#endif /* if defined(HAVE_MEMALIGN) */
|
||||
|
||||
|
||||
#if defined(HAVE_VALLOC)
|
||||
MFBT_API void* moz_xvalloc(size_t size)
|
||||
MOZ_ALLOCATOR;
|
||||
#endif /* if defined(HAVE_VALLOC) */
|
||||
|
||||
|
||||
MOZ_END_EXTERN_C
|
||||
|
||||
|
@ -34,7 +34,7 @@ allocatorFns = [
|
||||
'calloc',
|
||||
# Matches realloc, replace_realloc, moz_xrealloc, vpx_realloc, js_realloc, pod_realloc, pod_reallocCanGC.
|
||||
'realloc',
|
||||
# Matches memalign, posix_memalign, replace_memalign, replace_posix_memalign, moz_xmemalign, moz_xposix_memalign, vpx_memalign, malloc_zone_memalign.
|
||||
# Matches memalign, posix_memalign, replace_memalign, replace_posix_memalign, moz_xmemalign, vpx_memalign, malloc_zone_memalign.
|
||||
'memalign',
|
||||
'operator new(',
|
||||
'operator new[](',
|
||||
|
Loading…
Reference in New Issue
Block a user