From 38facd4a1d5add23d6860aa728b1489a8384a985 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Fri, 20 Oct 2017 21:54:06 +0300 Subject: [PATCH] Add two-argument alloc_size attribute to calloc_explicitly_typed (GCC) * include/gc_config_macros.h [!GC_ATTR_CALLOC_SIZE] (GC_ATTR_CALLOC_SIZE): New macro (which uses alloc_size attribute if GCC or Clang). * include/gc_typed.h (GC_calloc_explicitly_typed): Add GC_ATTR_CALLOC_SIZE(1,2) attribute. --- include/gc_config_macros.h | 8 +++++++- include/gc_typed.h | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/gc_config_macros.h b/include/gc_config_macros.h index 38752d6..f99a11f 100644 --- a/include/gc_config_macros.h +++ b/include/gc_config_macros.h @@ -244,20 +244,26 @@ #ifndef GC_ATTR_ALLOC_SIZE /* 'alloc_size' attribute improves __builtin_object_size correctness. */ - /* Only single-argument form of 'alloc_size' attribute is used. */ +# undef GC_ATTR_CALLOC_SIZE # ifdef __clang__ # if __has_attribute(__alloc_size__) # define GC_ATTR_ALLOC_SIZE(argnum) __attribute__((__alloc_size__(argnum))) +# define GC_ATTR_CALLOC_SIZE(n, s) __attribute__((__alloc_size__(n, s))) # else # define GC_ATTR_ALLOC_SIZE(argnum) /* empty */ # endif # elif GC_GNUC_PREREQ(4, 3) && !defined(__ICC) # define GC_ATTR_ALLOC_SIZE(argnum) __attribute__((__alloc_size__(argnum))) +# define GC_ATTR_CALLOC_SIZE(n, s) __attribute__((__alloc_size__(n, s))) # else # define GC_ATTR_ALLOC_SIZE(argnum) /* empty */ # endif #endif +#ifndef GC_ATTR_CALLOC_SIZE +# define GC_ATTR_CALLOC_SIZE(n, s) /* empty */ +#endif + #ifndef GC_ATTR_NONNULL # if GC_GNUC_PREREQ(4, 0) # define GC_ATTR_NONNULL(argnum) __attribute__((__nonnull__(argnum))) diff --git a/include/gc_typed.h b/include/gc_typed.h index 06e8261..8b1e92f 100644 --- a/include/gc_typed.h +++ b/include/gc_typed.h @@ -90,7 +90,7 @@ GC_API GC_ATTR_MALLOC GC_ATTR_ALLOC_SIZE(1) void * GC_CALL GC_malloc_explicitly_typed_ignore_off_page(size_t /* size_in_bytes */, GC_descr /* d */); -GC_API GC_ATTR_MALLOC void * GC_CALL +GC_API GC_ATTR_MALLOC GC_ATTR_CALLOC_SIZE(1, 2) void * GC_CALL GC_calloc_explicitly_typed(size_t /* nelements */, size_t /* element_size_in_bytes */, GC_descr /* d */); -- 2.7.4