]> granicus.if.org Git - libevent/commitdiff
Fix symbol conflict between mm_*() macros and libmm
authorNick Mathewson <nickm@torproject.org>
Tue, 4 May 2010 16:57:40 +0000 (12:57 -0400)
committerNick Mathewson <nickm@torproject.org>
Tue, 4 May 2010 16:57:40 +0000 (12:57 -0400)
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
mm-internal.h

diff --git a/event.c b/event.c
index cfa0cbfe7721236c044cdf60665479d2c36db971..6336e4e691196aa29bf34a69bac0b1a1aa40ba90 100644 (file)
--- 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);
index 0d01a1399e289fa4d69f6e5bb62918c1f157ea2d..79855d6a0538e93fb701c8f4a8cbcfb2aafed34a 100644 (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))