Add --with-mangling.
Add the --with-mangling configure option, which can be used to specify name mangling on a per public symbol basis that takes precedence over --with-jemalloc-prefix. Expose the memalign() and valloc() overrides even if --with-jemalloc-prefix is specified. This change does no real harm, and simplifies the code.
This commit is contained in:
@@ -74,7 +74,7 @@ int ctl_bymib(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp,
|
||||
bool ctl_boot(void);
|
||||
|
||||
#define xmallctl(name, oldp, oldlenp, newp, newlen) do { \
|
||||
if (JEMALLOC_P(mallctl)(name, oldp, oldlenp, newp, newlen) \
|
||||
if (je_mallctl(name, oldp, oldlenp, newp, newlen) \
|
||||
!= 0) { \
|
||||
malloc_write("<jemalloc>: Failure in xmallctl(\""); \
|
||||
malloc_write(name); \
|
||||
@@ -84,7 +84,7 @@ bool ctl_boot(void);
|
||||
} while (0)
|
||||
|
||||
#define xmallctlnametomib(name, mibp, miblenp) do { \
|
||||
if (JEMALLOC_P(mallctlnametomib)(name, mibp, miblenp) != 0) { \
|
||||
if (je_mallctlnametomib(name, mibp, miblenp) != 0) { \
|
||||
malloc_write( \
|
||||
"<jemalloc>: Failure in xmallctlnametomib(\""); \
|
||||
malloc_write(name); \
|
||||
@@ -94,7 +94,7 @@ bool ctl_boot(void);
|
||||
} while (0)
|
||||
|
||||
#define xmallctlbymib(mib, miblen, oldp, oldlenp, newp, newlen) do { \
|
||||
if (JEMALLOC_P(mallctlbymib)(mib, miblen, oldp, oldlenp, newp, \
|
||||
if (je_mallctlbymib(mib, miblen, oldp, oldlenp, newp, \
|
||||
newlen) != 0) { \
|
||||
malloc_write( \
|
||||
"<jemalloc>: Failure in xmallctlbymib()\n"); \
|
||||
|
@@ -30,7 +30,7 @@
|
||||
#include <pthread.h>
|
||||
#include <math.h>
|
||||
|
||||
#define JEMALLOC_MANGLE
|
||||
#define JEMALLOC_NO_DEMANGLE
|
||||
#include "../jemalloc@install_suffix@.h"
|
||||
|
||||
#include "jemalloc/internal/private_namespace.h"
|
||||
@@ -149,7 +149,7 @@ static const bool config_ivsalloc =
|
||||
#include "jemalloc/internal/qr.h"
|
||||
#include "jemalloc/internal/ql.h"
|
||||
|
||||
extern void (*JEMALLOC_P(malloc_message))(void *wcbopaque, const char *s);
|
||||
extern void (*je_malloc_message)(void *wcbopaque, const char *s);
|
||||
|
||||
/*
|
||||
* Define a custom assert() in order to reduce the chances of deadlock during
|
||||
@@ -618,13 +618,13 @@ sa2u(size_t size, size_t alignment, size_t *run_size_p)
|
||||
|
||||
/*
|
||||
* Wrapper around malloc_message() that avoids the need for
|
||||
* JEMALLOC_P(malloc_message)(...) throughout the code.
|
||||
* je_malloc_message(...) throughout the code.
|
||||
*/
|
||||
JEMALLOC_INLINE void
|
||||
malloc_write(const char *s)
|
||||
{
|
||||
|
||||
JEMALLOC_P(malloc_message)(NULL, s);
|
||||
je_malloc_message(NULL, s);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@@ -15,9 +15,6 @@ extern "C" {
|
||||
#define JEMALLOC_VERSION_GID "@jemalloc_version_gid@"
|
||||
|
||||
#include "jemalloc_defs@install_suffix@.h"
|
||||
#ifndef JEMALLOC_P
|
||||
# define JEMALLOC_P(s) s
|
||||
#endif
|
||||
|
||||
#define ALLOCM_LG_ALIGN(la) (la)
|
||||
#if LG_SIZEOF_PTR == 2
|
||||
@@ -32,34 +29,99 @@ extern "C" {
|
||||
#define ALLOCM_ERR_OOM 1
|
||||
#define ALLOCM_ERR_NOT_MOVED 2
|
||||
|
||||
extern const char *JEMALLOC_P(malloc_conf);
|
||||
extern void (*JEMALLOC_P(malloc_message))(void *, const char *);
|
||||
/*
|
||||
* The je_ prefix on the following public symbol declarations is an artifact of
|
||||
* namespace management, and should be omitted in application code unless
|
||||
* JEMALLOC_NO_DEMANGLE is defined (see below).
|
||||
*/
|
||||
extern const char *je_malloc_conf;
|
||||
extern void (*je_malloc_message)(void *, const char *);
|
||||
|
||||
void *JEMALLOC_P(malloc)(size_t size) JEMALLOC_ATTR(malloc);
|
||||
void *JEMALLOC_P(calloc)(size_t num, size_t size) JEMALLOC_ATTR(malloc);
|
||||
int JEMALLOC_P(posix_memalign)(void **memptr, size_t alignment, size_t size)
|
||||
void *je_malloc(size_t size) JEMALLOC_ATTR(malloc);
|
||||
void *je_calloc(size_t num, size_t size) JEMALLOC_ATTR(malloc);
|
||||
int je_posix_memalign(void **memptr, size_t alignment, size_t size)
|
||||
JEMALLOC_ATTR(nonnull(1));
|
||||
void *JEMALLOC_P(realloc)(void *ptr, size_t size);
|
||||
void JEMALLOC_P(free)(void *ptr);
|
||||
void *je_realloc(void *ptr, size_t size);
|
||||
void je_free(void *ptr);
|
||||
|
||||
size_t JEMALLOC_P(malloc_usable_size)(const void *ptr);
|
||||
void JEMALLOC_P(malloc_stats_print)(void (*write_cb)(void *, const char *),
|
||||
void *cbopaque, const char *opts);
|
||||
int JEMALLOC_P(mallctl)(const char *name, void *oldp, size_t *oldlenp,
|
||||
void *newp, size_t newlen);
|
||||
int JEMALLOC_P(mallctlnametomib)(const char *name, size_t *mibp,
|
||||
size_t *miblenp);
|
||||
int JEMALLOC_P(mallctlbymib)(const size_t *mib, size_t miblen, void *oldp,
|
||||
size_t je_malloc_usable_size(const void *ptr);
|
||||
void je_malloc_stats_print(void (*write_cb)(void *, const char *),
|
||||
void *je_cbopaque, const char *opts);
|
||||
int je_mallctl(const char *name, void *oldp, size_t *oldlenp, void *newp,
|
||||
size_t newlen);
|
||||
int je_mallctlnametomib(const char *name, size_t *mibp, size_t *miblenp);
|
||||
int je_mallctlbymib(const size_t *mib, size_t miblen, void *oldp,
|
||||
size_t *oldlenp, void *newp, size_t newlen);
|
||||
|
||||
int JEMALLOC_P(allocm)(void **ptr, size_t *rsize, size_t size, int flags)
|
||||
int je_allocm(void **ptr, size_t *rsize, size_t size, int flags)
|
||||
JEMALLOC_ATTR(nonnull(1));
|
||||
int JEMALLOC_P(rallocm)(void **ptr, size_t *rsize, size_t size,
|
||||
size_t extra, int flags) JEMALLOC_ATTR(nonnull(1));
|
||||
int JEMALLOC_P(sallocm)(const void *ptr, size_t *rsize, int flags)
|
||||
int je_rallocm(void **ptr, size_t *rsize, size_t size, size_t extra,
|
||||
int flags) JEMALLOC_ATTR(nonnull(1));
|
||||
int je_sallocm(const void *ptr, size_t *rsize, int flags)
|
||||
JEMALLOC_ATTR(nonnull(1));
|
||||
int JEMALLOC_P(dallocm)(void *ptr, int flags) JEMALLOC_ATTR(nonnull(1));
|
||||
int JEMALLOC_P(nallocm)(size_t *rsize, size_t size, int flags);
|
||||
int je_dallocm(void *ptr, int flags) JEMALLOC_ATTR(nonnull(1));
|
||||
int je_nallocm(size_t *rsize, size_t size, int flags);
|
||||
|
||||
/*
|
||||
* By default application code must explicitly refer to mangled symbol names,
|
||||
* so that it is possible to use jemalloc in conjunction with another allocator
|
||||
* in the same application. Define JEMALLOC_MANGLE in order to cause automatic
|
||||
* name mangling that matches the API prefixing that happened as a result of
|
||||
* --with-mangling and/or --with-jemalloc-prefix configuration settings.
|
||||
*/
|
||||
#ifdef JEMALLOC_MANGLE
|
||||
#ifndef JEMALLOC_NO_DEMANGLE
|
||||
#define JEMALLOC_NO_DEMANGLE
|
||||
#endif
|
||||
#define malloc_conf je_malloc_conf
|
||||
#define malloc_message je_malloc_message
|
||||
#define malloc je_malloc
|
||||
#define calloc je_calloc
|
||||
#define posix_memalign je_posix_memalign
|
||||
#define realloc je_realloc
|
||||
#define free je_free
|
||||
#define malloc_usable_size je_malloc_usable_size
|
||||
#define malloc_stats_print je_malloc_stats_print
|
||||
#define mallctl je_mallctl
|
||||
#define mallctlnametomib je_mallctlnametomib
|
||||
#define mallctlbymib je_mallctlbymib
|
||||
#define memalign je_memalign
|
||||
#define valloc je_valloc
|
||||
#define allocm je_allocm
|
||||
#define dallocm je_dallocm
|
||||
#define nallocm je_nallocm
|
||||
#define rallocm je_rallocm
|
||||
#define sallocm je_sallocm
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The je_* macros can be used as stable alternative names for the public
|
||||
* jemalloc API if JEMALLOC_NO_DEMANGLE is defined. This is primarily meant
|
||||
* for use in jemalloc itself, but it can be used by application code to
|
||||
* provide isolation from the name mangling specified via --with-mangling
|
||||
* and/or --with-jemalloc-prefix.
|
||||
*/
|
||||
#ifndef JEMALLOC_NO_DEMANGLE
|
||||
#undef je_malloc_conf
|
||||
#undef je_malloc_message
|
||||
#undef je_malloc
|
||||
#undef je_calloc
|
||||
#undef je_posix_memalign
|
||||
#undef je_realloc
|
||||
#undef je_free
|
||||
#undef je_malloc_usable_size
|
||||
#undef je_malloc_stats_print
|
||||
#undef je_mallctl
|
||||
#undef je_mallctlnametomib
|
||||
#undef je_mallctlbymib
|
||||
#undef je_memalign
|
||||
#undef je_valloc
|
||||
#undef je_allocm
|
||||
#undef je_dallocm
|
||||
#undef je_nallocm
|
||||
#undef je_rallocm
|
||||
#undef je_sallocm
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
|
@@ -1,22 +1,35 @@
|
||||
#ifndef JEMALLOC_DEFS_H_
|
||||
#define JEMALLOC_DEFS_H_
|
||||
|
||||
/*
|
||||
* If JEMALLOC_PREFIX is defined, it will cause all public APIs to be prefixed.
|
||||
* This makes it possible, with some care, to use multiple allocators
|
||||
* simultaneously.
|
||||
*
|
||||
* In many cases it is more convenient to manually prefix allocator function
|
||||
* calls than to let macros do it automatically, particularly when using
|
||||
* multiple allocators simultaneously. Define JEMALLOC_MANGLE before
|
||||
* #include'ing jemalloc.h in order to cause name mangling that corresponds to
|
||||
* the API prefixing.
|
||||
* If JEMALLOC_PREFIX is defined via --with-jemalloc-prefix, it will cause all
|
||||
* public APIs to be prefixed. This makes it possible, with some care, to use
|
||||
* multiple allocators simultaneously.
|
||||
*/
|
||||
#undef JEMALLOC_PREFIX
|
||||
#undef JEMALLOC_CPREFIX
|
||||
#if (defined(JEMALLOC_PREFIX) && defined(JEMALLOC_MANGLE))
|
||||
#undef JEMALLOC_P
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Name mangling for public symbols is controlled by --with-mangling and
|
||||
* --with-jemalloc-prefix. With default settings the je_ prefix is stripped by
|
||||
* these macro definitions.
|
||||
*/
|
||||
#undef je_malloc_conf
|
||||
#undef je_malloc_message
|
||||
#undef je_malloc
|
||||
#undef je_calloc
|
||||
#undef je_posix_memalign
|
||||
#undef je_realloc
|
||||
#undef je_free
|
||||
#undef je_malloc_usable_size
|
||||
#undef je_malloc_stats_print
|
||||
#undef je_mallctl
|
||||
#undef je_mallctlnametomib
|
||||
#undef je_mallctlbymib
|
||||
#undef je_memalign
|
||||
#undef je_valloc
|
||||
#undef je_allocm
|
||||
#undef je_dallocm
|
||||
#undef je_nallocm
|
||||
#undef je_rallocm
|
||||
#undef je_sallocm
|
||||
|
||||
/*
|
||||
* JEMALLOC_PRIVATE_NAMESPACE is used as a prefix for all library-private APIs.
|
||||
@@ -150,5 +163,3 @@
|
||||
|
||||
/* sizeof(long) == 2^LG_SIZEOF_LONG. */
|
||||
#undef LG_SIZEOF_LONG
|
||||
|
||||
#endif /* JEMALLOC_DEFS_H_ */
|
||||
|
Reference in New Issue
Block a user