From 99e50e90bd2a03638f9bef11dae12d9951b0c793 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 4 May 2010 12:57:40 -0400 Subject: [PATCH] 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 --- event.c | 10 +++++----- mm-internal.h | 19 +++++++++++++------ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/event.c b/event.c index cfa0cbfe..6336e4e6 100644 --- a/event.c +++ b/event.c @@ -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); diff --git a/mm-internal.h b/mm-internal.h index 0d01a139..79855d6a 100644 --- a/mm-internal.h +++ b/mm-internal.h @@ -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))