From: Ralph Corderoy Date: Sat, 26 Aug 2017 17:41:42 +0000 (+0100) Subject: Use C99's variable-argument preprocessor macros for ALLOC_SIZE. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/f47607299747d62dddeee9518c01325b610c2383 Use C99's variable-argument preprocessor macros for ALLOC_SIZE. ALLOC_SIZE2() can be deleted. --- diff --git a/h/mh.h b/h/mh.h index 3ee706b3..3093df10 100644 --- a/h/mh.h +++ b/h/mh.h @@ -35,16 +35,14 @@ typedef unsigned char boolean; /* not int so we can pack in a structure */ #if __GNUC__ > 2 #define NORETURN __attribute__((__noreturn__)) #define CHECK_PRINTF(fmt, arg) __attribute__((format(printf, fmt, arg))) -#define ALLOC_SIZE(n) __attribute__((alloc_size(n))) -#define ALLOC_SIZE2(m, n) __attribute__((alloc_size(m, n))) +#define ALLOC_SIZE(...) __attribute__((alloc_size(__VA_ARGS__))) #define CONST __attribute__((const)) #define MALLOC __attribute__((malloc)) #define NMH_UNUSED(i) (void) i #else #define NORETURN #define CHECK_PRINTF(fmt, arg) -#define ALLOC_SIZE(n) -#define ALLOC_SIZE2(m, n) +#define ALLOC_SIZE(...) #define CONST #define MALLOC #define NMH_UNUSED(i) i diff --git a/h/utils.h b/h/utils.h index f8b21985..597569b5 100644 --- a/h/utils.h +++ b/h/utils.h @@ -17,7 +17,7 @@ void *mh_xmalloc(size_t size) MALLOC ALLOC_SIZE(1); void *mh_xrealloc(void *ptr, size_t size) ALLOC_SIZE(2); /* Call calloc(3), exiting on NULL return. */ -void *mh_xcalloc(size_t nelem, size_t elsize) MALLOC ALLOC_SIZE2(1, 2); +void *mh_xcalloc(size_t nelem, size_t elsize) MALLOC ALLOC_SIZE(1, 2); /* Duplicate a NUL-terminated string, exit on failure. */ char *mh_xstrdup(const char *src) MALLOC;