From e9211114fc0ca4a5d29ed20f9f6090f95fab5e9b Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Thu, 30 Apr 2015 12:59:56 +0200 Subject: [PATCH] Don't fail to compile when aligned alloc is not available. --- heaptrack_preload.cpp | 8 ++++++++ tests/test.cpp | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/heaptrack_preload.cpp b/heaptrack_preload.cpp index 9ec8a65..6c877b5 100644 --- a/heaptrack_preload.cpp +++ b/heaptrack_preload.cpp @@ -29,6 +29,8 @@ using namespace std; +#define HAVE_ALIGNED_ALLOC defined(_ISOC11_SOURCE) + namespace { namespace hooks { @@ -71,7 +73,9 @@ HOOK(cfree); HOOK(realloc); HOOK(posix_memalign); HOOK(valloc); +#if HAVE_ALIGNED_ALLOC HOOK(aligned_alloc); +#endif HOOK(dlopen); HOOK(dlclose); @@ -111,7 +115,9 @@ void init() hooks::realloc.init(); hooks::posix_memalign.init(); hooks::valloc.init(); +#if HAVE_ALIGNED_ALLOC hooks::aligned_alloc.init(); +#endif // cleanup environment to prevent tracing of child apps unsetenv("LD_PRELOAD"); @@ -213,6 +219,7 @@ int posix_memalign(void **memptr, size_t alignment, size_t size) noexcept return ret; } +#if HAVE_ALIGNED_ALLOC void* aligned_alloc(size_t alignment, size_t size) noexcept { if (!hooks::aligned_alloc) { @@ -227,6 +234,7 @@ void* aligned_alloc(size_t alignment, size_t size) noexcept return ret; } +#endif void* valloc(size_t size) noexcept { diff --git a/tests/test.cpp b/tests/test.cpp index b01f14c..59b6031 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -1,6 +1,8 @@ #include #include +#define HAVE_ALIGNED_ALLOC defined(_ISOC11_SOURCE) + struct Foo { Foo() : i(new int) @@ -51,9 +53,11 @@ int main() printf("calloc: %p\n", buf); cfree(buf); +#if HAVE_ALIGNED_ALLOC buf = aligned_alloc(16, 160); printf("aligned_alloc: %p\n", buf); free(buf); +#endif buf = valloc(32); printf("valloc: %p\n", buf); -- 2.7.4