mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-07-22 00:27:33 +03:00
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:
parent
80737c3323
commit
3597e91482
2 changed files with 14 additions and 19 deletions
11
src/util.c
11
src/util.c
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue