diff options
author | Daniel Elstner <daniel.kitta@gmail.com> | 2015-09-13 21:32:27 +0200 |
---|---|---|
committer | Daniel Elstner <daniel.kitta@gmail.com> | 2015-09-13 21:32:27 +0200 |
commit | fd4918101e0878be9d399a344511253f5867a646 (patch) | |
tree | 4979db79a74b07692cedd34589ba01771958b6fb | |
parent | 9fb7e7fe2c7edafdeedf1976d1723ffe557c8a7c (diff) | |
download | libsigrokdecode-fd4918101e0878be9d399a344511253f5867a646.tar.gz libsigrokdecode-fd4918101e0878be9d399a344511253f5867a646.zip |
log: Enable varargs format warnings
Decorate srd_log() with the GCC format printf attribute so that the
compiler can check the format string and arguments for consistency.
Also remove the srd_err(), sr_warn(), etc. functions and replace
them with macro wrappers around srd_log().
-rw-r--r-- | libsigrokdecode-internal.h | 22 | ||||
-rw-r--r-- | log.c | 65 |
2 files changed, 16 insertions, 71 deletions
diff --git a/libsigrokdecode-internal.h b/libsigrokdecode-internal.h index 9260363..bcf6bb7 100644 --- a/libsigrokdecode-internal.h +++ b/libsigrokdecode-internal.h @@ -66,12 +66,22 @@ SRD_PRIV void srd_inst_free(struct srd_decoder_inst *di); SRD_PRIV void srd_inst_free_all(struct srd_session *sess, GSList *stack); /* log.c */ -SRD_PRIV int srd_log(int loglevel, const char *format, ...); -SRD_PRIV int srd_spew(const char *format, ...); -SRD_PRIV int srd_dbg(const char *format, ...); -SRD_PRIV int srd_info(const char *format, ...); -SRD_PRIV int srd_warn(const char *format, ...); -SRD_PRIV int srd_err(const char *format, ...); +#if defined(G_OS_WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) +/* + * On MinGW, we need to specify the gnu_printf format flavor or GCC + * will assume non-standard Microsoft printf syntax. + */ +SRD_PRIV int srd_log(int loglevel, const char *format, ...) + __attribute__((__format__ (__gnu_printf__, 2, 3))); +#else +SRD_PRIV int srd_log(int loglevel, const char *format, ...) G_GNUC_PRINTF(2, 3); +#endif + +#define srd_spew(...) srd_log(SRD_LOG_SPEW, __VA_ARGS__) +#define srd_dbg(...) srd_log(SRD_LOG_DBG, __VA_ARGS__) +#define srd_info(...) srd_log(SRD_LOG_INFO, __VA_ARGS__) +#define srd_warn(...) srd_log(SRD_LOG_WARN, __VA_ARGS__) +#define srd_err(...) srd_log(SRD_LOG_ERR, __VA_ARGS__) /* module_sigrokdecode.c */ PyMODINIT_FUNC PyInit_sigrokdecode(void); @@ -181,69 +181,4 @@ SRD_PRIV int srd_log(int loglevel, const char *format, ...) return ret; } -/** @private */ -SRD_PRIV int srd_spew(const char *format, ...) -{ - int ret; - va_list args; - - va_start(args, format); - ret = srd_log_cb(srd_log_cb_data, SRD_LOG_SPEW, format, args); - va_end(args); - - return ret; -} - -/** @private */ -SRD_PRIV int srd_dbg(const char *format, ...) -{ - int ret; - va_list args; - - va_start(args, format); - ret = srd_log_cb(srd_log_cb_data, SRD_LOG_DBG, format, args); - va_end(args); - - return ret; -} - -/** @private */ -SRD_PRIV int srd_info(const char *format, ...) -{ - int ret; - va_list args; - - va_start(args, format); - ret = srd_log_cb(srd_log_cb_data, SRD_LOG_INFO, format, args); - va_end(args); - - return ret; -} - -/** @private */ -SRD_PRIV int srd_warn(const char *format, ...) -{ - int ret; - va_list args; - - va_start(args, format); - ret = srd_log_cb(srd_log_cb_data, SRD_LOG_WARN, format, args); - va_end(args); - - return ret; -} - -/** @private */ -SRD_PRIV int srd_err(const char *format, ...) -{ - int ret; - va_list args; - - va_start(args, format); - ret = srd_log_cb(srd_log_cb_data, SRD_LOG_ERR, format, args); - va_end(args); - - return ret; -} - /** @} */ |