diff options
Diffstat (limited to 'src/core/support/alloc.c')
-rw-r--r-- | src/core/support/alloc.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/core/support/alloc.c b/src/core/support/alloc.c index bfcb77956b..ca72379b1d 100644 --- a/src/core/support/alloc.c +++ b/src/core/support/alloc.c @@ -34,13 +34,27 @@ #include <grpc/support/alloc.h> #include <stdlib.h> +#include <grpc/support/log.h> #include <grpc/support/port_platform.h> #include "src/core/profiling/timers.h" +static gpr_allocation_functions g_alloc_functions = {malloc, realloc, free}; + +gpr_allocation_functions gpr_get_allocation_functions() { + return g_alloc_functions; +} + +void gpr_set_allocation_functions(gpr_allocation_functions functions) { + GPR_ASSERT(functions.malloc_fn != NULL); + GPR_ASSERT(functions.realloc_fn != NULL); + GPR_ASSERT(functions.free_fn != NULL); + g_alloc_functions = functions; +} + void *gpr_malloc(size_t size) { void *p; GPR_TIMER_BEGIN("gpr_malloc", 0); - p = malloc(size); + p = g_alloc_functions.malloc_fn(size); if (!p) { abort(); } @@ -50,13 +64,13 @@ void *gpr_malloc(size_t size) { void gpr_free(void *p) { GPR_TIMER_BEGIN("gpr_free", 0); - free(p); + g_alloc_functions.free_fn(p); GPR_TIMER_END("gpr_free", 0); } void *gpr_realloc(void *p, size_t size) { GPR_TIMER_BEGIN("gpr_realloc", 0); - p = realloc(p, size); + p = g_alloc_functions.realloc_fn(p, size); if (!p) { abort(); } |