Allow je_malloc_message to be overridden when linking statically

If an application wants to override je_malloc_message, it is better to define
the symbol locally than to change its value in main(), which might be too late
for various reasons.

Due to je_malloc_message being initialized in util.c, statically linking
jemalloc with an application defining je_malloc_message fails due to
"multiple definition of" the symbol.

Defining it without a value (like je_malloc_conf) makes it more easily
overridable.
This commit is contained in:
Mike Hommey 2012-05-02 13:15:00 +02:00 committed by Jason Evans
parent 80737c3323
commit 3597e91482
2 changed files with 14 additions and 19 deletions

View file

@ -56,8 +56,7 @@ wrtmessage(void *cbopaque, const char *s)
#endif
}
JEMALLOC_EXPORT void (*je_malloc_message)(void *, const char *s) =
wrtmessage;
JEMALLOC_EXPORT void (*je_malloc_message)(void *, const char *s);
/*
* Wrapper around malloc_message() that avoids the need for
@ -67,7 +66,10 @@ void
malloc_write(const char *s)
{
je_malloc_message(NULL, s);
if (je_malloc_message != NULL)
je_malloc_message(NULL, s);
else
wrtmessage(NULL, s);
}
/*
@ -606,7 +608,8 @@ malloc_vcprintf(void (*write_cb)(void *, const char *), void *cbopaque,
* function, so use the default one. malloc_write() is an
* inline function, so use malloc_message() directly here.
*/
write_cb = je_malloc_message;
write_cb = (je_malloc_message != NULL) ? je_malloc_message :
wrtmessage;
cbopaque = NULL;
}