Bug 550692: Wrap posix_memalign, memalign, and valloc if jemalloc provides them and the OS doesn't. r=bsmedberg

This commit is contained in:
Chris Jones 2010-04-21 23:41:40 -05:00
parent 67941217d5
commit 7af55eecbb
4 changed files with 13 additions and 23 deletions

View File

@ -89,12 +89,12 @@ void free(void *ptr);
int posix_memalign(void **memptr, size_t alignment, size_t size);
#endif /* MOZ_MEMORY_DARWIN, MOZ_MEMORY_LINUX */
/* Linux has memalign */
/* Linux has memalign and malloc_usable_size */
#if !defined(MOZ_MEMORY_LINUX)
void *memalign(size_t alignment, size_t size);
size_t malloc_usable_size(const void *ptr);
#endif /* MOZ_MEMORY_LINUX */
size_t malloc_usable_size(const void *ptr);
void jemalloc_stats(jemalloc_stats_t *stats);
#ifdef __cplusplus

View File

@ -51,6 +51,11 @@
# include <unistd.h> // for valloc on *BSD
#endif //if defined(XP_UNIX)
#if defined(MOZ_MEMORY)
// jemalloc.h doesn't redeclare symbols if they're provided by the OS
# include "jemalloc.h"
#endif
#if defined(XP_WIN) || (defined(XP_OS2) && defined(__declspec))
# define MOZALLOC_EXPORT __declspec(dllexport)
#endif
@ -158,7 +163,7 @@ moz_strndup(const char* str, size_t strsize)
}
#endif // if defined(HAVE_STRNDUP)
#if defined(HAVE_POSIX_MEMALIGN)
#if defined(HAVE_POSIX_MEMALIGN) || defined(HAVE_JEMALLOC_POSIX_MEMALIGN)
int
moz_xposix_memalign(void **ptr, size_t alignment, size_t size)
{
@ -177,7 +182,7 @@ moz_posix_memalign(void **ptr, size_t alignment, size_t size)
}
#endif // if defined(HAVE_POSIX_MEMALIGN)
#if defined(HAVE_MEMALIGN)
#if defined(HAVE_MEMALIGN) || defined(HAVE_JEMALLOC_MEMALIGN)
void*
moz_xmemalign(size_t boundary, size_t size)
{

View File

@ -87,21 +87,6 @@ extern "C" {
#endif /* ifdef __cplusplus */
/*
* If we don't have these system functions, but do have jemalloc
* replacements, go ahead and declare them independently of jemalloc.
* Trying to #include the jemalloc header causes redeclaration of some
* system functions with different visibility.
*/
/* FIXME/cjones: make something like the following work with jemalloc */
#if 0
#if !defined(HAVE_POSIX_MEMALIGN) && defined(HAVE_JEMALLOC_POSIX_MEMALIGN)
MOZALLOC_IMPORT int posix_memalign(void **, size_t, size_t)
NS_WARN_UNUSED_RESULT;
#endif
#endif
/*
* Each pair of declarations below is analogous to a "standard"
* allocation function, except that the out-of-memory handling is made
@ -156,7 +141,7 @@ MOZALLOC_EXPORT char* moz_strndup(const char* str, size_t strsize)
#endif /* if defined(HAVE_STRNDUP) */
#if defined(HAVE_POSIX_MEMALIGN)
#if defined(HAVE_POSIX_MEMALIGN) || defined(HAVE_JEMALLOC_POSIX_MEMALIGN)
MOZALLOC_EXPORT int moz_xposix_memalign(void **ptr, size_t alignment, size_t size)
NS_WARN_UNUSED_RESULT;
@ -165,7 +150,7 @@ MOZALLOC_EXPORT int moz_posix_memalign(void **ptr, size_t alignment, size_t size
#endif /* if defined(HAVE_POSIX_MEMALIGN) */
#if defined(HAVE_MEMALIGN)
#if defined(HAVE_MEMALIGN) || defined(HAVE_JEMALLOC_MEMALIGN)
MOZALLOC_EXPORT void* moz_xmemalign(size_t boundary, size_t size)
NS_ATTR_MALLOC NS_WARN_UNUSED_RESULT;

View File

@ -63,11 +63,11 @@
#define strndup(_, __) moz_strndup(_, __)
#endif
#if defined(HAVE_POSIX_MEMALIGN)
#if defined(HAVE_POSIX_MEMALIGN) || defined(HAVE_JEMALLOC_POSIX_MEMALIGN)
#define posix_memalign(_, __, ___) moz_posix_memalign(_, __, ___)
#endif
#if defined(HAVE_MEMALIGN)
#if defined(HAVE_MEMALIGN) || defined(HAVE_JEMALLOC_MEMALIGN)
#define memalign(_, __) moz_memalign(_, __)
#endif