summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFedja Beader <fedja@protonmail.ch>2025-04-06 20:37:54 +0200
committerFedja Beader <fedja@protonmail.ch>2025-04-06 20:39:29 +0200
commit0e72a0586ff855a178fa6188cdbac8dd768fc263 (patch)
tree91b459abe6378ad5644c64082b255d42fbb415cd
parent0bcc88159aee0e680d4cdc2949b24b10b571135f (diff)
downloadmanaplus-logger.h_attribute_format.tar.gz
manaplus-logger.h_attribute_format.tar.bz2
manaplus-logger.h_attribute_format.tar.xz
manaplus-logger.h_attribute_format.zip
logger.h: de-duplicate __attribute__(__format__(..))logger.h_attribute_format
-rw-r--r--src/localconsts.h26
-rw-r--r--src/logger.h59
2 files changed, 35 insertions, 50 deletions
diff --git a/src/localconsts.h b/src/localconsts.h
index a120ed9d7..6d922ab09 100644
--- a/src/localconsts.h
+++ b/src/localconsts.h
@@ -171,6 +171,32 @@
#define gnu_printf printf
#endif // __clang__
+
+#ifdef __GNUC__
+ #ifdef __OpenBSD__
+ #define A_FORMAT_PRINTF(fmtIndex, firstArgIndex) \
+ __attribute__((__format__(printf, (fmtIndex), (firstArgIndex))))
+ #else // __OpenBSD__
+
+ #ifdef BAD_CILKPLUS
+ // This one is 0-indexed?
+ #define A_FORMAT_PRINTF(fmtIndex, firstArgIndex) \
+ __attribute__((__format__(gnu_printf, \
+ ((fmtIndex) - 1), \
+ ((firstArgIndex)-1) \
+ )))
+ #else // BAD_CILKPLUS
+ #define A_FORMAT_PRINTF(fmtIndex, firstArgIndex) \
+ __attribute__((__format__(gnu_printf, \
+ (fmtIndex), \
+ (firstArgIndex) \
+ )))
+ #endif // BAD_CILKPLUS
+
+ #endif // __OpenBSD__
+#endif // __GNUC__
+
+
#ifdef ADVGCC
#define const2 const
diff --git a/src/logger.h b/src/logger.h
index b8c48e429..89f4c5286 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(2, 3);
/**
* 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(2, 3);
/**
* 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(2, 3);
/**
* Enters a message in the log. The message will be timestamped.