From: Nick Mathewson Date: Fri, 17 Apr 2009 06:56:57 +0000 (+0000) Subject: Add a configure flag to hardcode all of our mm functions. X-Git-Tag: release-2.0.1-alpha~6 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7fa8451d7e9310d0aac2f619ffecb3bd93dca267;p=libevent Add a configure flag to hardcode all of our mm functions. svn:r1186 --- diff --git a/configure.in b/configure.in index c5b7c671..f8c6c74c 100644 --- a/configure.in +++ b/configure.in @@ -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 89e3b8b0..d9dc1b2e 100644 --- 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; diff --git a/include/event2/event.h b/include/event2/event.h index 9065f6be..7f9d8094 100644 --- a/include/event2/event.h +++ b/include/event2/event.h @@ -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 *); diff --git a/mm-internal.h b/mm-internal.h index 6900e8f9..da6003dc 100644 --- a/mm-internal.h +++ b/mm-internal.h @@ -32,12 +32,20 @@ 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 }