From e8fc2545df63f79a43d7e639f310ccfd29b9ef10 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 6 Jan 2022 15:37:25 +0300 Subject: [PATCH] Allow access attribute from gcc 10 only --- src/common/cbasetypes.h | 11 ++++++++-- src/common/strlib.h | 48 ++++++++++++++++++++--------------------- 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/src/common/cbasetypes.h b/src/common/cbasetypes.h index caf4175107a..ef3043c32ce 100644 --- a/src/common/cbasetypes.h +++ b/src/common/cbasetypes.h @@ -339,14 +339,21 @@ typedef uintptr_t uintptr; #if defined(__GNUC__) && !defined(__clang__) #define GCCATTR(str) __attribute__ (str) #else // defined(__GNUC__) && !defined(__clang__) -#define GCCATTR(str) +#define GCCATTR(str) +#endif // defined(__GNUC__) && !defined(__clang__) + +// attribute for gcc only +#if defined(__GNUC__) && !defined(__clang__) && (GCC_VERSION >= 100000) +#define GCC10ATTR(str) __attribute__ (str) +#else // defined(__GNUC__) && !defined(__clang__) +#define GCC10ATTR(str) #endif // defined(__GNUC__) && !defined(__clang__) // attribute for gcc only #if defined(__GNUC__) && !defined(__clang__) && (GCC_VERSION >= 110000) #define GCC11ATTR(str) __attribute__ (str) #else // defined(__GNUC__) && !defined(__clang__) -#define GCC11ATTR(str) +#define GCC11ATTR(str) #endif // defined(__GNUC__) && !defined(__clang__) // fallthrough attribute only enabled on gcc >= 7.0 diff --git a/src/common/strlib.h b/src/common/strlib.h index 6385ddb7c8f..a6ecbc1a628 100644 --- a/src/common/strlib.h +++ b/src/common/strlib.h @@ -111,28 +111,28 @@ struct StringBuf { typedef struct StringBuf StringBuf; struct strlib_interface { - char *(*jstrescape) (char* pt) GCCATTR ((access (read_only, 1))); - char *(*jstrescapecpy) (char* pt, const char* spt) GCCATTR ((access (write_only, 1), access (read_only, 2))); - int (*jmemescapecpy) (char* pt, const char* spt, int size) GCCATTR ((access (write_only, 1), access (read_only, 2, 3))); - int (*remove_control_chars_) (char* str) GCCATTR ((access (read_write, 1))); - char *(*trim_) (char* str) GCCATTR ((access (read_write, 1))); - char *(*normalize_name_) (char* str, const char* delims) GCCATTR ((access (read_write, 1), access (read_only, 2))); - const char *(*stristr_) (const char *haystack, const char *needle) GCCATTR ((access (read_only, 1), access (read_only, 2))); + char *(*jstrescape) (char* pt) GCC10ATTR ((access (read_only, 1))); + char *(*jstrescapecpy) (char* pt, const char* spt) GCC10ATTR ((access (write_only, 1), access (read_only, 2))); + int (*jmemescapecpy) (char* pt, const char* spt, int size) GCC10ATTR ((access (write_only, 1), access (read_only, 2, 3))); + int (*remove_control_chars_) (char* str) GCC10ATTR ((access (read_write, 1))); + char *(*trim_) (char* str) GCC10ATTR ((access (read_write, 1))); + char *(*normalize_name_) (char* str, const char* delims) GCC10ATTR ((access (read_write, 1), access (read_only, 2))); + const char *(*stristr_) (const char *haystack, const char *needle) GCC10ATTR ((access (read_only, 1), access (read_only, 2))); /* only used when '!(defined(WIN32) && defined(_MSC_VER)) && !defined(HAVE_STRNLEN)', needs to be defined at all times however */ - size_t (*strnlen_) (const char* string, size_t maxlen) GCCATTR ((access (read_only, 1, 2))); + size_t (*strnlen_) (const char* string, size_t maxlen) GCC10ATTR ((access (read_only, 1, 2))); /* only used when 'WIN32' */ - char * (*strtok_r_) (char *s1, const char *s2, char **lasts) GCCATTR ((access (read_write, 1), access (read_only, 2), access (read_write, 3))); + char * (*strtok_r_) (char *s1, const char *s2, char **lasts) GCC10ATTR ((access (read_write, 1), access (read_only, 2), access (read_write, 3))); - int (*e_mail_check_) (char* email) GCCATTR ((access (read_write, 1))); - int (*config_switch_) (const char* str) GCCATTR ((access (read_only, 1))); + int (*e_mail_check_) (char* email) GCC10ATTR ((access (read_write, 1))); + int (*config_switch_) (const char* str) GCC10ATTR ((access (read_only, 1))); /// strncpy that always null-terminates the string - char *(*safestrncpy_) (char* dst, const char* src, size_t n) GCCATTR ((access (write_only, 1, 3), access (read_only, 2))); + char *(*safestrncpy_) (char* dst, const char* src, size_t n) GCC10ATTR ((access (write_only, 1, 3), access (read_only, 2))); /// doesn't crash on null pointer - size_t (*safestrnlen_) (const char* string, size_t maxlen) GCCATTR ((access (read_only, 1, 2))); + size_t (*safestrnlen_) (const char* string, size_t maxlen) GCC10ATTR ((access (read_only, 1, 2))); /// Works like snprintf, but always null-terminates the buffer. /// Returns the size of the string (without null-terminator) @@ -141,26 +141,26 @@ struct strlib_interface { /// Returns the line of the target position in the string. /// Lines start at 1. - int (*strline_) (const char* str, size_t pos) GCCATTR ((access (read_only, 1))); + int (*strline_) (const char* str, size_t pos) GCC10ATTR ((access (read_only, 1))); /// Produces the hexadecimal representation of the given input. /// The output buffer must be at least count*2+1 in size. /// Returns true on success, false on failure. - bool (*bin2hex_) (char *output, const unsigned char *input, size_t count) GCCATTR ((access (write_only, 1), access (read_only, 2, 3))); + bool (*bin2hex_) (char *output, const unsigned char *input, size_t count) GCC10ATTR ((access (write_only, 1), access (read_only, 2, 3))); }; struct stringbuf_interface { StringBuf* (*Malloc) (void); - void (*Init) (StringBuf* self) GCCATTR ((access (write_only, 1))); - int (*Printf) (StringBuf *self, const char *fmt, ...) __attribute__((format(printf, 2, 3))) GCCATTR ((access(read_write, 1))); + void (*Init) (StringBuf* self) GCC10ATTR ((access (write_only, 1))); + int (*Printf) (StringBuf *self, const char *fmt, ...) __attribute__((format(printf, 2, 3))) GCC10ATTR ((access(read_write, 1))); int (*Vprintf) (StringBuf* self, const char* fmt, va_list args) __attribute__((format(printf, 2, 0))); - int (*Append) (StringBuf* self, const StringBuf *sbuf) GCCATTR ((access (read_write, 1), access (read_only, 2))); - int (*AppendStr) (StringBuf* self, const char* str) GCCATTR ((access (read_write, 1), access (read_only, 2))); - int (*Length) (StringBuf* self) GCCATTR ((access (read_only, 1))); - char* (*Value) (StringBuf* self) GCCATTR ((access (read_write, 1))); - void (*Clear) (StringBuf* self) GCCATTR ((access (read_write, 1))); - void (*Destroy) (StringBuf* self) GCCATTR ((access (read_write, 1))); - void (*Free) (StringBuf* self) GCCATTR ((access (read_write, 1))); + int (*Append) (StringBuf* self, const StringBuf *sbuf) GCC10ATTR ((access (read_write, 1), access (read_only, 2))); + int (*AppendStr) (StringBuf* self, const char* str) GCC10ATTR ((access (read_write, 1), access (read_only, 2))); + int (*Length) (StringBuf* self) GCC10ATTR ((access (read_only, 1))); + char* (*Value) (StringBuf* self) GCC10ATTR ((access (read_write, 1))); + void (*Clear) (StringBuf* self) GCC10ATTR ((access (read_write, 1))); + void (*Destroy) (StringBuf* self) GCC10ATTR ((access (read_write, 1))); + void (*Free) (StringBuf* self) GCC10ATTR ((access (read_write, 1))); }; struct sv_interface {