Skip to content

Commit

Permalink
Allow access attribute from gcc 10 only
Browse files Browse the repository at this point in the history
  • Loading branch information
4144 committed Jan 6, 2022
1 parent 5b17217 commit e8fc254
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 26 deletions.
11 changes: 9 additions & 2 deletions src/common/cbasetypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 24 additions & 24 deletions src/common/strlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down

0 comments on commit e8fc254

Please sign in to comment.