Fix symbol conflict between mm_*() macros and libmm

Our mm_malloc, mm_calloc, etc functions were all exported, since C
hasn't got a nice portable way to say "we want to use this function
inside our library but not export it to others".  But they apparently
conflict with anything else that calls its symbols mm_*, as libmm does.

This patch renames the mm_*() functions to event_mm_*_(, and defines
maros in mm_internal so that all the code we have that uses mm_*()
will still work.  New code should also prefer the mm_*() macro names.

Reported by Gernot Tenchio.  Fixes sf bug 2996541
This commit is contained in:
Nick Mathewson 2010-05-04 12:57:40 -04:00
parent 20fda296c5
commit 99e50e90bd
2 changed files with 18 additions and 11 deletions

10
event.c
View File

@ -2451,7 +2451,7 @@ static void *(*_mm_realloc_fn)(void *p, size_t sz) = NULL;
static void (*_mm_free_fn)(void *p) = NULL;
void *
mm_malloc(size_t sz)
event_mm_malloc_(size_t sz)
{
if (_mm_malloc_fn)
return _mm_malloc_fn(sz);
@ -2460,7 +2460,7 @@ mm_malloc(size_t sz)
}
void *
mm_calloc(size_t count, size_t size)
event_mm_calloc_(size_t count, size_t size)
{
if (_mm_malloc_fn) {
size_t sz = count * size;
@ -2473,7 +2473,7 @@ mm_calloc(size_t count, size_t size)
}
char *
mm_strdup(const char *str)
event_mm_strdup_(const char *str)
{
if (_mm_malloc_fn) {
size_t ln = strlen(str);
@ -2490,7 +2490,7 @@ mm_strdup(const char *str)
}
void *
mm_realloc(void *ptr, size_t sz)
event_mm_realloc_(void *ptr, size_t sz)
{
if (_mm_realloc_fn)
return _mm_realloc_fn(ptr, sz);
@ -2499,7 +2499,7 @@ mm_realloc(void *ptr, size_t sz)
}
void
mm_free(void *ptr)
event_mm_free_(void *ptr)
{
if (_mm_free_fn)
_mm_free_fn(ptr);

View File

@ -33,12 +33,19 @@ extern "C" {
#endif
#ifndef _EVENT_DISABLE_MM_REPLACEMENT
/* Internal use only: Memory allocation functions. */
void *mm_malloc(size_t sz);
void *mm_calloc(size_t count, size_t size);
char *mm_strdup(const char *s);
void *mm_realloc(void *p, size_t sz);
void mm_free(void *p);
/* Internal use only: Memory allocation functions. We give them nice short
* mm_names for our own use, but make sure that the symbols have longer names
* so they don't conflict with other libraries (like, say, libmm). */
void *event_mm_malloc_(size_t sz);
void *event_mm_calloc_(size_t count, size_t size);
char *event_mm_strdup_(const char *s);
void *event_mm_realloc_(void *p, size_t sz);
void event_mm_free_(void *p);
#define mm_malloc(sz) event_mm_malloc_(sz)
#define mm_calloc(count, size) event_mm_calloc_((count), (size))
#define mm_strdup(s) event_mm_strdup_(s)
#define mm_realloc(p, sz) event_mm_realloc_((p), (sz))
#define mm_free(p) event_mm_free_(p)
#else
#define mm_malloc(sz) malloc(sz)
#define mm_calloc(n, sz) calloc((n), (sz))