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.
diff --git a/src/jemalloc.c b/src/jemalloc.c
index 34fd1aa..6e34706 100644
--- a/src/jemalloc.c
+++ b/src/jemalloc.c
@@ -36,7 +36,7 @@
unsigned ncpus;
/* Runtime configuration options. */
-const char *JEMALLOC_P(malloc_conf) JEMALLOC_ATTR(visibility("default"));
+const char *je_malloc_conf JEMALLOC_ATTR(visibility("default"));
#ifdef JEMALLOC_DEBUG
bool opt_abort = true;
# ifdef JEMALLOC_FILL
@@ -81,7 +81,7 @@
UNUSED int result = write(STDERR_FILENO, s, strlen(s));
}
-void (*JEMALLOC_P(malloc_message))(void *, const char *s)
+void (*je_malloc_message)(void *, const char *s)
JEMALLOC_ATTR(visibility("default")) = wrtmessage;
/******************************************************************************/
@@ -230,7 +230,7 @@
}
}
}
- JEMALLOC_P(malloc_stats_print)(NULL, NULL, NULL);
+ je_malloc_stats_print(NULL, NULL, NULL);
}
thread_allocated_t *
@@ -422,12 +422,12 @@
/* Get runtime configuration. */
switch (i) {
case 0:
- if (JEMALLOC_P(malloc_conf) != NULL) {
+ if (je_malloc_conf != NULL) {
/*
* Use options that were compiled into the
* program.
*/
- opts = JEMALLOC_P(malloc_conf);
+ opts = je_malloc_conf;
} else {
/* No configuration specified. */
buf[0] = '\0';
@@ -836,7 +836,7 @@
JEMALLOC_ATTR(malloc)
JEMALLOC_ATTR(visibility("default"))
void *
-JEMALLOC_P(malloc)(size_t size)
+je_malloc(size_t size)
{
void *ret;
size_t usize;
@@ -990,7 +990,7 @@
JEMALLOC_ATTR(nonnull(1))
JEMALLOC_ATTR(visibility("default"))
int
-JEMALLOC_P(posix_memalign)(void **memptr, size_t alignment, size_t size)
+je_posix_memalign(void **memptr, size_t alignment, size_t size)
{
return imemalign(memptr, alignment, size, true);
@@ -999,7 +999,7 @@
JEMALLOC_ATTR(malloc)
JEMALLOC_ATTR(visibility("default"))
void *
-JEMALLOC_P(calloc)(size_t num, size_t size)
+je_calloc(size_t num, size_t size)
{
void *ret;
size_t num_size;
@@ -1077,7 +1077,7 @@
JEMALLOC_ATTR(visibility("default"))
void *
-JEMALLOC_P(realloc)(void *ptr, size_t size)
+je_realloc(void *ptr, size_t size)
{
void *ret;
size_t usize;
@@ -1207,7 +1207,7 @@
JEMALLOC_ATTR(visibility("default"))
void
-JEMALLOC_P(free)(void *ptr)
+je_free(void *ptr)
{
if (ptr != NULL) {
@@ -1234,17 +1234,13 @@
/******************************************************************************/
/*
* Begin non-standard override functions.
- *
- * These overrides are omitted if the JEMALLOC_PREFIX is defined, since the
- * entire point is to avoid accidental mixed allocator usage.
*/
-#ifndef JEMALLOC_PREFIX
#ifdef JEMALLOC_OVERRIDE_MEMALIGN
JEMALLOC_ATTR(malloc)
JEMALLOC_ATTR(visibility("default"))
void *
-JEMALLOC_P(memalign)(size_t alignment, size_t size)
+je_memalign(size_t alignment, size_t size)
{
void *ret
#ifdef JEMALLOC_CC_SILENCE
@@ -1260,7 +1256,7 @@
JEMALLOC_ATTR(malloc)
JEMALLOC_ATTR(visibility("default"))
void *
-JEMALLOC_P(valloc)(size_t size)
+je_valloc(size_t size)
{
void *ret
#ifdef JEMALLOC_CC_SILENCE
@@ -1272,7 +1268,7 @@
}
#endif
-#if defined(__GLIBC__) && !defined(__UCLIBC__)
+#if (!defined(JEMALLOC_PREFIX) && defined(__GLIBC__) && !defined(__UCLIBC__))
/*
* glibc provides the RTLD_DEEPBIND flag for dlopen which can make it possible
* to inconsistently reference libc's malloc(3)-compatible functions
@@ -1283,20 +1279,18 @@
* ignored.
*/
JEMALLOC_ATTR(visibility("default"))
-void (* const __free_hook)(void *ptr) = JEMALLOC_P(free);
+void (* const __free_hook)(void *ptr) = je_free;
JEMALLOC_ATTR(visibility("default"))
-void *(* const __malloc_hook)(size_t size) = JEMALLOC_P(malloc);
+void *(* const __malloc_hook)(size_t size) = je_malloc;
JEMALLOC_ATTR(visibility("default"))
-void *(* const __realloc_hook)(void *ptr, size_t size) = JEMALLOC_P(realloc);
+void *(* const __realloc_hook)(void *ptr, size_t size) = je_realloc;
JEMALLOC_ATTR(visibility("default"))
-void *(* const __memalign_hook)(size_t alignment, size_t size) =
- JEMALLOC_P(memalign);
+void *(* const __memalign_hook)(size_t alignment, size_t size) = je_memalign;
#endif
-#endif /* JEMALLOC_PREFIX */
/*
* End non-standard override functions.
*/
@@ -1307,7 +1301,7 @@
JEMALLOC_ATTR(visibility("default"))
size_t
-JEMALLOC_P(malloc_usable_size)(const void *ptr)
+je_malloc_usable_size(const void *ptr)
{
size_t ret;
@@ -1325,8 +1319,8 @@
JEMALLOC_ATTR(visibility("default"))
void
-JEMALLOC_P(malloc_stats_print)(void (*write_cb)(void *, const char *),
- void *cbopaque, const char *opts)
+je_malloc_stats_print(void (*write_cb)(void *, const char *), void *cbopaque,
+ const char *opts)
{
stats_print(write_cb, cbopaque, opts);
@@ -1334,7 +1328,7 @@
JEMALLOC_ATTR(visibility("default"))
int
-JEMALLOC_P(mallctl)(const char *name, void *oldp, size_t *oldlenp, void *newp,
+je_mallctl(const char *name, void *oldp, size_t *oldlenp, void *newp,
size_t newlen)
{
@@ -1346,7 +1340,7 @@
JEMALLOC_ATTR(visibility("default"))
int
-JEMALLOC_P(mallctlnametomib)(const char *name, size_t *mibp, size_t *miblenp)
+je_mallctlnametomib(const char *name, size_t *mibp, size_t *miblenp)
{
if (malloc_init())
@@ -1357,8 +1351,8 @@
JEMALLOC_ATTR(visibility("default"))
int
-JEMALLOC_P(mallctlbymib)(const size_t *mib, size_t miblen, void *oldp,
- size_t *oldlenp, void *newp, size_t newlen)
+je_mallctlbymib(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp,
+ void *newp, size_t newlen)
{
if (malloc_init())
@@ -1385,7 +1379,7 @@
JEMALLOC_ATTR(nonnull(1))
JEMALLOC_ATTR(visibility("default"))
int
-JEMALLOC_P(allocm)(void **ptr, size_t *rsize, size_t size, int flags)
+je_allocm(void **ptr, size_t *rsize, size_t size, int flags)
{
void *p;
size_t usize;
@@ -1451,8 +1445,7 @@
JEMALLOC_ATTR(nonnull(1))
JEMALLOC_ATTR(visibility("default"))
int
-JEMALLOC_P(rallocm)(void **ptr, size_t *rsize, size_t size, size_t extra,
- int flags)
+je_rallocm(void **ptr, size_t *rsize, size_t size, size_t extra, int flags)
{
void *p, *q;
size_t usize;
@@ -1544,7 +1537,7 @@
JEMALLOC_ATTR(nonnull(1))
JEMALLOC_ATTR(visibility("default"))
int
-JEMALLOC_P(sallocm)(const void *ptr, size_t *rsize, int flags)
+je_sallocm(const void *ptr, size_t *rsize, int flags)
{
size_t sz;
@@ -1565,7 +1558,7 @@
JEMALLOC_ATTR(nonnull(1))
JEMALLOC_ATTR(visibility("default"))
int
-JEMALLOC_P(dallocm)(void *ptr, int flags)
+je_dallocm(void *ptr, int flags)
{
size_t usize;
@@ -1588,7 +1581,7 @@
JEMALLOC_ATTR(visibility("default"))
int
-JEMALLOC_P(nallocm)(size_t *rsize, size_t size, int flags)
+je_nallocm(size_t *rsize, size_t size, int flags)
{
size_t usize;
size_t alignment = (ZU(1) << (flags & ALLOCM_LG_ALIGN_MASK)
diff --git a/src/stats.c b/src/stats.c
index 2f61e7b..f905d04 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -108,7 +108,7 @@
* function, so use the default one. malloc_write() is an
* inline function, so use malloc_message() directly here.
*/
- write_cb = JEMALLOC_P(malloc_message);
+ write_cb = je_malloc_message;
cbopaque = NULL;
}
@@ -376,8 +376,7 @@
* */
epoch = 1;
u64sz = sizeof(uint64_t);
- err = JEMALLOC_P(mallctl)("epoch", &epoch, &u64sz, &epoch,
- sizeof(uint64_t));
+ err = je_mallctl("epoch", &epoch, &u64sz, &epoch, sizeof(uint64_t));
if (err != 0) {
if (err == EAGAIN) {
malloc_write("<jemalloc>: Memory allocation failure in "
@@ -395,7 +394,7 @@
* function, so use the default one. malloc_write() is an
* inline function, so use malloc_message() directly here.
*/
- write_cb = JEMALLOC_P(malloc_message);
+ write_cb = je_malloc_message;
cbopaque = NULL;
}
@@ -448,22 +447,22 @@
write_cb(cbopaque, "\n");
#define OPT_WRITE_BOOL(n) \
- if ((err = JEMALLOC_P(mallctl)("opt."#n, &bv, &bsz, \
- NULL, 0)) == 0) { \
+ if ((err = je_mallctl("opt."#n, &bv, &bsz, NULL, 0)) \
+ == 0) { \
write_cb(cbopaque, " opt."#n": "); \
write_cb(cbopaque, bv ? "true" : "false"); \
write_cb(cbopaque, "\n"); \
}
#define OPT_WRITE_SIZE_T(n) \
- if ((err = JEMALLOC_P(mallctl)("opt."#n, &sv, &ssz, \
- NULL, 0)) == 0) { \
+ if ((err = je_mallctl("opt."#n, &sv, &ssz, NULL, 0)) \
+ == 0) { \
write_cb(cbopaque, " opt."#n": "); \
write_cb(cbopaque, u2s(sv, 10, s)); \
write_cb(cbopaque, "\n"); \
}
#define OPT_WRITE_SSIZE_T(n) \
- if ((err = JEMALLOC_P(mallctl)("opt."#n, &ssv, &sssz, \
- NULL, 0)) == 0) { \
+ if ((err = je_mallctl("opt."#n, &ssv, &sssz, NULL, 0)) \
+ == 0) { \
if (ssv >= 0) { \
write_cb(cbopaque, " opt."#n": "); \
write_cb(cbopaque, u2s(ssv, 10, s)); \
@@ -474,8 +473,8 @@
write_cb(cbopaque, "\n"); \
}
#define OPT_WRITE_CHAR_P(n) \
- if ((err = JEMALLOC_P(mallctl)("opt."#n, &cpv, &cpsz, \
- NULL, 0)) == 0) { \
+ if ((err = je_mallctl("opt."#n, &cpv, &cpsz, NULL, 0)) \
+ == 0) { \
write_cb(cbopaque, " opt."#n": \""); \
write_cb(cbopaque, cpv); \
write_cb(cbopaque, "\"\n"); \
@@ -535,15 +534,15 @@
write_cb(cbopaque,
"Min active:dirty page ratio per arena: N/A\n");
}
- if ((err = JEMALLOC_P(mallctl)("arenas.tcache_max", &sv,
- &ssz, NULL, 0)) == 0) {
+ if ((err = je_mallctl("arenas.tcache_max", &sv, &ssz, NULL, 0))
+ == 0) {
write_cb(cbopaque,
"Maximum thread-cached size class: ");
write_cb(cbopaque, u2s(sv, 10, s));
write_cb(cbopaque, "\n");
}
- if ((err = JEMALLOC_P(mallctl)("opt.lg_tcache_gc_sweep", &ssv,
- &ssz, NULL, 0)) == 0) {
+ if ((err = je_mallctl("opt.lg_tcache_gc_sweep", &ssv, &ssz,
+ NULL, 0)) == 0) {
size_t tcache_gc_sweep = (1U << ssv);
bool tcache_enabled;
CTL_GET("opt.tcache", &tcache_enabled, bool);
@@ -552,8 +551,8 @@
u2s(tcache_gc_sweep, 10, s) : "N/A");
write_cb(cbopaque, "\n");
}
- if ((err = JEMALLOC_P(mallctl)("opt.prof", &bv, &bsz, NULL, 0))
- == 0 && bv) {
+ if ((err = je_mallctl("opt.prof", &bv, &bsz, NULL, 0)) == 0 &&
+ bv) {
CTL_GET("opt.lg_prof_sample", &sv, size_t);
write_cb(cbopaque, "Average profile sample interval: ");
write_cb(cbopaque, u2s((((uint64_t)1U) << sv), 10, s));
diff --git a/src/zone.c b/src/zone.c
index 07f8861..5beed5f 100644
--- a/src/zone.c
+++ b/src/zone.c
@@ -67,14 +67,14 @@
zone_malloc(malloc_zone_t *zone, size_t size)
{
- return (JEMALLOC_P(malloc)(size));
+ return (je_malloc(size));
}
static void *
zone_calloc(malloc_zone_t *zone, size_t num, size_t size)
{
- return (JEMALLOC_P(calloc)(num, size));
+ return (je_calloc(num, size));
}
static void *
@@ -82,7 +82,7 @@
{
void *ret = NULL; /* Assignment avoids useless compiler warning. */
- JEMALLOC_P(posix_memalign)(&ret, PAGE_SIZE, size);
+ je_posix_memalign(&ret, PAGE_SIZE, size);
return (ret);
}
@@ -91,14 +91,14 @@
zone_free(malloc_zone_t *zone, void *ptr)
{
- JEMALLOC_P(free)(ptr);
+ je_free(ptr);
}
static void *
zone_realloc(malloc_zone_t *zone, void *ptr, size_t size)
{
- return (JEMALLOC_P(realloc)(ptr, size));
+ return (je_realloc(ptr, size));
}
#if (JEMALLOC_ZONE_VERSION >= 6)
@@ -107,7 +107,7 @@
{
void *ret = NULL; /* Assignment avoids useless compiler warning. */
- JEMALLOC_P(posix_memalign)(&ret, alignment, size);
+ je_posix_memalign(&ret, alignment, size);
return (ret);
}
@@ -117,7 +117,7 @@
{
assert(ivsalloc(ptr) == size);
- JEMALLOC_P(free)(ptr);
+ je_free(ptr);
}
#endif
@@ -208,7 +208,7 @@
{
if (ivsalloc(ptr) != 0)
- JEMALLOC_P(free)(ptr);
+ je_free(ptr);
else {
size_t size = szone.size(zone, ptr);
if (size != 0)
@@ -222,17 +222,17 @@
size_t oldsize;
if (ptr == NULL)
- return (JEMALLOC_P(malloc)(size));
+ return (je_malloc(size));
oldsize = ivsalloc(ptr);
if (oldsize != 0)
- return (JEMALLOC_P(realloc)(ptr, size));
+ return (je_realloc(ptr, size));
else {
oldsize = szone.size(zone, ptr);
if (oldsize == 0)
- return (JEMALLOC_P(malloc)(size));
+ return (je_malloc(size));
else {
- void *ret = JEMALLOC_P(malloc)(size);
+ void *ret = je_malloc(size);
if (ret != NULL) {
memcpy(ret, ptr, (oldsize < size) ? oldsize :
size);
@@ -268,7 +268,7 @@
if (ivsalloc(ptr) != 0) {
assert(ivsalloc(ptr) == size);
- JEMALLOC_P(free)(ptr);
+ je_free(ptr);
} else {
assert(size == szone.size(zone, ptr));
szone.free_definite_size(zone, ptr, size);