diff options
-rw-r--r-- | src/localconsts.h | 34 | ||||
-rw-r--r-- | src/logger.h | 59 | ||||
-rw-r--r-- | src/utils/stringutils.h | 13 | ||||
-rw-r--r-- | src/utils/xml/libxml.cpp | 9 |
4 files changed, 48 insertions, 67 deletions
diff --git a/src/localconsts.h b/src/localconsts.h index a120ed9d7..6e2122bcf 100644 --- a/src/localconsts.h +++ b/src/localconsts.h @@ -171,6 +171,40 @@ #define gnu_printf printf #endif // __clang__ +/* + * A_FORMAT_PRINTF: Proxy for printf-like attribute tagging, + * All argument positions start indexed by 1 + * + * isMember true if member function. The below will shift by one + * if required by toolchain. + * fmtIndex: position of format string in argument list + * firstArgIndex: position of first optional argument to format. + */ +#ifdef BAD_CILKPLUS +#define A_FORMAT_MEMBER_SHIFT 0 +#else +#define A_FORMAT_MEMBER_SHIFT 1 +#endif + +// idk how to clean this up +#ifdef __GNUC__ + #ifdef __OpenBSD__ + #define A_FORMAT_PRINTF_FUNC printf + #else + #define A_FORMAT_PRINTF_FUNC gnu_printf + #endif +#else + #define A_FORMAT_PRINTF_FUNC gnu_printf +#endif + +#define A_FORMAT_PRINTF(isMember, fmtIndex, firstArgIndex) \ + __attribute__((__format__( \ + A_FORMAT_PRINTF_FUNC, \ + ((fmtIndex) + ((isMember) ? A_FORMAT_MEMBER_SHIFT : 0)), \ + ((firstArgIndex) + ((isMember) ? A_FORMAT_MEMBER_SHIFT : 0)) \ + ))) + + #ifdef ADVGCC #define const2 const diff --git a/src/logger.h b/src/logger.h index b8c48e429..da165189d 100644 --- a/src/logger.h +++ b/src/logger.h @@ -91,64 +91,23 @@ class Logger final /** * Enters a message in the log. The message will be timestamped. */ - void log(const char *const log_text, ...) A_NONNULL(2) -#ifdef __GNUC__ -#ifdef __OpenBSD__ - - __attribute__((__format__(printf, 2, 3))) -#else // __OpenBSD__ - -#ifdef BAD_CILKPLUS - __attribute__((__format__(gnu_printf, 1, 2))) -#else // BAD_CILKPLUS - - __attribute__((__format__(gnu_printf, 2, 3))) -#endif // BAD_CILKPLUS - -#endif // __OpenBSD__ -#endif // __GNUC__ - ; + void log(const char *const log_text, ...) + A_NONNULL(2) + A_FORMAT_PRINTF(true, 1, 2); /** * Enters a message in the log. The message will be timestamped. */ - void assertLog(const char *const log_text, ...) A_NONNULL(2) -#ifdef __GNUC__ -#ifdef __OpenBSD__ - - __attribute__((__format__(printf, 2, 3))) -#else // __OpenBSD__ - -#ifdef BAD_CILKPLUS - __attribute__((__format__(gnu_printf, 1, 2))) -#else // BAD_CILKPLUS - - __attribute__((__format__(gnu_printf, 2, 3))) -#endif // BAD_CILKPLUS - -#endif // __OpenBSD__ -#endif // __GNUC__ - ; + void assertLog(const char *const log_text, ...) + A_NONNULL(2) + A_FORMAT_PRINTF(true, 1, 2); /** * Enters a message in the log (thread safe). */ - void log_r(const char *const log_text, ...) A_NONNULL(2) -#ifdef __GNUC__ -#ifdef __OpenBSD__ - __attribute__((__format__(printf, 2, 3))) -#else // __OpenBSD__ - -#ifdef BAD_CILKPLUS - __attribute__((__format__(gnu_printf, 1, 2))) -#else // BAD_CILKPLUS - - __attribute__((__format__(gnu_printf, 2, 3))) -#endif // BAD_CILKPLUS - -#endif // __OpenBSD__ -#endif // __GNUC__ - ; + void log_r(const char *const log_text, ...) + A_NONNULL(2) + A_FORMAT_PRINTF(true, 1, 2); /** * Enters a message in the log. The message will be timestamped. diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h index b5eca16ab..6d33c3830 100644 --- a/src/utils/stringutils.h +++ b/src/utils/stringutils.h @@ -100,15 +100,10 @@ const char *ipToString(const uint32_t address) A_WARN_UNUSED; /** * A safe version of sprintf that returns a std::string of the result. */ -std::string strprintf(const char *const format, ...) A_NONNULL(1) A_WARN_UNUSED -#ifdef __GNUC__ -#ifdef __OpenBSD__ - __attribute__((__format__(printf, 1, 2))) -#else // __OpenBSD__ - __attribute__((__format__(gnu_printf, 1, 2))) -#endif // __OpenBSD__ -#endif // __GNUC__ -; +std::string strprintf(const char *const format, ...) + A_NONNULL(1) + A_WARN_UNUSED + A_FORMAT_PRINTF(false, 1, 2); /** * Removes colors from a string diff --git a/src/utils/xml/libxml.cpp b/src/utils/xml/libxml.cpp index cc49a6012..97d2db58c 100644 --- a/src/utils/xml/libxml.cpp +++ b/src/utils/xml/libxml.cpp @@ -44,14 +44,7 @@ namespace } // namespace static void xmlErrorLogger(void *ctx A_UNUSED, const char *msg A_UNUSED, ...) -#ifdef __GNUC__ -#ifdef __OpenBSD__ - __attribute__((__format__(printf, 2, 3))) -#else // __OpenBSD__ - __attribute__((__format__(gnu_printf, 2, 3))) -#endif // __OpenBSD__ -#endif // __GNUC__ -; + A_FORMAT_PRINTF(false, 2, 3); static void xmlErrorLogger(void *ctx A_UNUSED, const char *msg, ...) { |