]> granicus.if.org Git - libevent/commitdiff
Add a configure flag to hardcode all of our mm functions.
authorNick Mathewson <nickm@torproject.org>
Fri, 17 Apr 2009 06:56:57 +0000 (06:56 +0000)
committerNick Mathewson <nickm@torproject.org>
Fri, 17 Apr 2009 06:56:57 +0000 (06:56 +0000)
svn:r1186

configure.in
event.c
include/event2/event.h
mm-internal.h

index c5b7c67126b28ddd2ea38e2da5ddf7912be924b5..f8c6c74c27949abdac912e5c5c82be92c5c0a4c8 100644 (file)
@@ -31,6 +31,9 @@ AC_ARG_ENABLE(gcc-warnings,
 AC_ARG_ENABLE(thread-support,
      AS_HELP_STRING(--enable-thread-support, enable support for threading),
        [], [enable_thread_support=yes])
+AC_ARG_ENABLE(malloc-replacement,
+     AS_HELP_STRING(--disable-malloc-replacement, disable support for replacing the memory mgt functions),
+        [], [enable_malloc_replacement=yes])
 AC_PROG_LIBTOOL
 
 dnl   Uncomment "AC_DISABLE_SHARED" to make shared librraries not get
@@ -420,6 +423,12 @@ if test x$enable_thread_support = xno; then
        [Define if libevent should not be compiled with thread support])
 fi
 
+# check if we should hard-code the mm functions.
+if test x$enable_malloc_replacement = xno; then
+  AC_DEFINE(DISABLE_MM_REPLACEMENT, 1,
+        [Define if libevent should not allow replacing the mm functions])
+fi
+
 # Add some more warnings which we use in development but not in the
 # released versions.  (Some relevant gcc versions can't handle these.)
 if test x$enable_gcc_warnings = xyes; then
diff --git a/event.c b/event.c
index 89e3b8b049ac0514abcef74bc57e78625d50cf2c..d9dc1b2e4514b80d302aedce33e237af2ea18f43 100644 (file)
--- a/event.c
+++ b/event.c
@@ -1562,6 +1562,7 @@ event_get_method(void)
        return (current_base->evsel->name);
 }
 
+#ifndef _EVENT_DISABLE_MM_REPLACEMENT
 static void *(*_mm_malloc_fn)(size_t sz) = NULL;
 static void *(*_mm_realloc_fn)(void *p, size_t sz) = NULL;
 static void (*_mm_free_fn)(void *p) = NULL;
@@ -1632,7 +1633,7 @@ event_set_mem_functions(void *(*malloc_fn)(size_t sz),
        _mm_realloc_fn = realloc_fn;
        _mm_free_fn = free_fn;
 }
-
+#endif
 
 /* support for threading */
 void (*_evthread_locking_fn)(int mode, void *lock) = NULL;
index 9065f6bed94009e12f8edb28ca3ca01aa4d28135..7f9d80940c6af604a419020494a002249e764818 100644 (file)
@@ -573,6 +573,7 @@ int event_base_priority_init(struct event_base *, int);
   */
 int    event_priority_set(struct event *, int);
 
+#ifndef _EVENT_DISABLE_MM_REPLACEMENT
 /**
  Override the functions that libevent uses for memory management.
 
@@ -593,6 +594,7 @@ int event_priority_set(struct event *, int);
 void event_set_mem_functions(void *(*malloc_fn)(size_t sz),
                              void *(*realloc_fn)(void *ptr, size_t sz),
                              void (*free_fn)(void *ptr));
+#endif
 
 void event_base_dump_events(struct event_base *, FILE *);
 
index 6900e8f991aa1b7d8e898c93172306827d4f7cf1..da6003dc1272af4bdf0cc2080809369d2c8e5d09 100644 (file)
 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);
+#else
+#define mm_malloc(sz) malloc(sz)
+#define mm_calloc(n, sz) calloc((n), (sz))
+#define mm_strdup(s) strdup(s)
+#define mm_realloc(p, sz) realloc((p), (sz))
+#define mm_free(p) free(p)
+#endif
 
 #ifdef __cplusplus
 }