From b1078c3d88a32c92517bc9379750c31f68228c9d Mon Sep 17 00:00:00 2001 From: Steven Dee <steve@smartercode.net> Date: Sun, 7 Dec 2014 02:23:01 -0500 Subject: [PATCH] llvm doesn't care about your size They apparently removed alloc_size at some point (it was a no-op beforehand), causing the attribute to throw an error when clang compiles anything including allocator.h. --- src/allocator.h | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/allocator.h b/src/allocator.h index 803d89fe..4a486936 100644 --- a/src/allocator.h +++ b/src/allocator.h @@ -33,11 +33,22 @@ typedef struct HAllocator_ { typedef struct HArena_ HArena ; // hidden implementation HArena *h_new_arena(HAllocator* allocator, size_t block_size); // pass 0 for default... -#ifndef SWIG -void* h_arena_malloc(HArena *arena, size_t count) __attribute__(( malloc, alloc_size(2) )); + +#if defined __llvm__ +# if __has_attribute(malloc) +# define ATTR_MALLOC(n) __attribute__((malloc)) +# else +# define ATTR_MALLOC(n) +# endif +#elif defined SWIG +# define ATTR_MALLOC(n) +#elif defined __GNUC__ +# define ATTR_MALLOC(n) __attribute__((malloc, alloc_size(2))) #else -void* h_arena_malloc(HArena *arena, size_t count); +# define ATTR_MALLOC(n) #endif + +void* h_arena_malloc(HArena *arena, size_t count) ATTR_MALLOC(2); void h_arena_free(HArena *arena, void* ptr); // For future expansion, with alternate memory managers. void h_delete_arena(HArena *arena); -- GitLab