From: Brian Demsky Date: Fri, 18 May 2012 23:44:26 +0000 (-0700) Subject: At least everything compiles now... Subramanian's changes pushed into main fork... X-Git-Tag: pldi2013~434 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=model-checker.git;a=commitdiff_plain;h=018d30be3784726642f6fbff03c669b59798eea7 At least everything compiles now... Subramanian's changes pushed into main fork... unclear whether it works... --- diff --git a/___malloc.c b/___malloc.c deleted file mode 100644 index 3ec0d3f..0000000 --- a/___malloc.c +++ /dev/null @@ -1,49 +0,0 @@ -#include "common.h" - -/* for RTLD_NEXT */ -#ifndef __USE_GNU -#define __USE_GNU -#endif - -#include -#include - -static void * (*real_malloc)(size_t) = NULL; -static void (*real_free)(void *ptr) = NULL; - -static void __my_alloc_init(void) -{ - - real_malloc = (void *(*)(size_t))dlsym(RTLD_NEXT, "malloc"); - real_free = (void (*)(void *))dlsym(RTLD_NEXT, "free"); - if (real_malloc == NULL || real_free == NULL) { - fprintf(stderr, "Error in `dlsym`: %s\n", dlerror()); - return; - } -} - -void * myMalloc(size_t size) -{ - if (real_malloc == NULL) - __my_alloc_init(); - - return real_malloc(size); -} - -void myFree(void *ptr) -{ - if (real_free == NULL) - __my_alloc_init(); - - real_free(ptr); -} - -void * operator new(size_t size) throw(std::bad_alloc) -{ - return myMalloc(size); -} - -void operator delete(void *p) throw() -{ - myFree(p); -} diff --git a/mallocwrap.cc b/mallocwrap.cc new file mode 100644 index 0000000..3ec0d3f --- /dev/null +++ b/mallocwrap.cc @@ -0,0 +1,49 @@ +#include "common.h" + +/* for RTLD_NEXT */ +#ifndef __USE_GNU +#define __USE_GNU +#endif + +#include +#include + +static void * (*real_malloc)(size_t) = NULL; +static void (*real_free)(void *ptr) = NULL; + +static void __my_alloc_init(void) +{ + + real_malloc = (void *(*)(size_t))dlsym(RTLD_NEXT, "malloc"); + real_free = (void (*)(void *))dlsym(RTLD_NEXT, "free"); + if (real_malloc == NULL || real_free == NULL) { + fprintf(stderr, "Error in `dlsym`: %s\n", dlerror()); + return; + } +} + +void * myMalloc(size_t size) +{ + if (real_malloc == NULL) + __my_alloc_init(); + + return real_malloc(size); +} + +void myFree(void *ptr) +{ + if (real_free == NULL) + __my_alloc_init(); + + real_free(ptr); +} + +void * operator new(size_t size) throw(std::bad_alloc) +{ + return myMalloc(size); +} + +void operator delete(void *p) throw() +{ + myFree(p); +}