From ac426323570113bb13605b20d47273c8c23e3fe3 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 13 Aug 2020 17:25:43 +0200 Subject: Add format attributes --- test/ampatree_test.c | 2 ++ test/bitset_test.c | 2 ++ test/btree_test.c | 1 + test/dict_bench.c | 2 ++ test/hash_test.c | 1 + test/patree_test.c | 2 ++ test/ring_test.c | 2 ++ test/strindex_test.c | 2 ++ test/tree_bench.c | 1 + test/trie_test.c | 2 ++ wscript | 3 +-- zix/common.h | 6 ++++++ 12 files changed, 24 insertions(+), 2 deletions(-) diff --git a/test/ampatree_test.c b/test/ampatree_test.c index e14e85f..bc7d161 100644 --- a/test/ampatree_test.c +++ b/test/ampatree_test.c @@ -15,6 +15,7 @@ */ #include "zix/ampatree.h" +#include "zix/common.h" #include #include @@ -43,6 +44,7 @@ static const char* strings[] = { "http://echo.jpl.nasa.gov/publications/review_abs.html", }; +ZIX_LOG_FUNC(1, 2) static int test_fail(const char* fmt, ...) { diff --git a/test/bitset_test.c b/test/bitset_test.c index 62c574c..3ac1bb7 100644 --- a/test/bitset_test.c +++ b/test/bitset_test.c @@ -15,6 +15,7 @@ */ #include "zix/bitset.h" +#include "zix/common.h" #include #include @@ -24,6 +25,7 @@ #define MIN(a, b) (((a) < (b)) ? (a) : (b)) +ZIX_LOG_FUNC(1, 2) static int test_fail(const char* fmt, ...) { diff --git a/test/btree_test.c b/test/btree_test.c index f9d45a0..974a987 100644 --- a/test/btree_test.c +++ b/test/btree_test.c @@ -117,6 +117,7 @@ wildcard_cmp(const void* a, const void* b, const void* user_data) } } +ZIX_LOG_FUNC(2, 3) static int test_fail(ZixBTree* t, const char* fmt, ...) { diff --git a/test/dict_bench.c b/test/dict_bench.c index 742388a..21d9cfb 100644 --- a/test/dict_bench.c +++ b/test/dict_bench.c @@ -18,6 +18,7 @@ #include "zix/ampatree.h" #include "zix/chunk.h" +#include "zix/common.h" #include "zix/hash.h" #include "zix/patree.h" #include "zix/trie.h" @@ -32,6 +33,7 @@ static const unsigned seed = 1; +ZIX_LOG_FUNC(1, 2) static int test_fail(const char* fmt, ...) { diff --git a/test/hash_test.c b/test/hash_test.c index b2143eb..eeb371d 100644 --- a/test/hash_test.c +++ b/test/hash_test.c @@ -44,6 +44,7 @@ static const char* strings[] = { "Done", "Dtwo", "Dthree", "Dfour", "Dfive", "Dsix", "Dseven", "Deight", }; +ZIX_LOG_FUNC(1, 2) static int test_fail(const char* fmt, ...) { diff --git a/test/patree_test.c b/test/patree_test.c index efd8999..d7def0c 100644 --- a/test/patree_test.c +++ b/test/patree_test.c @@ -14,6 +14,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include "zix/common.h" #include "zix/patree.h" #include @@ -43,6 +44,7 @@ static const char* strings[] = { "http://echo.jpl.nasa.gov/publications/review_abs.html", }; +ZIX_LOG_FUNC(1, 2) static int test_fail(const char* fmt, ...) { diff --git a/test/ring_test.c b/test/ring_test.c index 6fa9589..5345754 100644 --- a/test/ring_test.c +++ b/test/ring_test.c @@ -14,6 +14,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include "zix/common.h" #include "zix/ring.h" #include "zix/thread.h" @@ -29,6 +30,7 @@ static ZixRing* ring = 0; static unsigned n_writes = 0; static bool read_error = false; +ZIX_LOG_FUNC(1, 2) static int failure(const char* fmt, ...) { diff --git a/test/strindex_test.c b/test/strindex_test.c index 0ad3be5..1dcd062 100644 --- a/test/strindex_test.c +++ b/test/strindex_test.c @@ -14,12 +14,14 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include "zix/common.h" #include "zix/strindex.h" #include #include #include +ZIX_LOG_FUNC(1, 2) static int test_fail(const char* fmt, ...) { diff --git a/test/tree_bench.c b/test/tree_bench.c index b966252..766402f 100644 --- a/test/tree_bench.c +++ b/test/tree_bench.c @@ -66,6 +66,7 @@ g_int_cmp(const void* a, const void* b, void* user_data) return int_cmp(a, b, user_data); } +ZIX_LOG_FUNC(1, 2) static int test_fail(const char* fmt, ...) { diff --git a/test/trie_test.c b/test/trie_test.c index 2ddc019..f4b3eb2 100644 --- a/test/trie_test.c +++ b/test/trie_test.c @@ -14,6 +14,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include "zix/common.h" #include "zix/trie.h" #include @@ -43,6 +44,7 @@ static const char* strings[] = { "http://echo.jpl.nasa.gov/publications/review_abs.html", }; +ZIX_LOG_FUNC(1, 2) static int test_fail(const char* fmt, ...) { diff --git a/wscript b/wscript index e127519..d1b78ef 100644 --- a/wscript +++ b/wscript @@ -43,7 +43,7 @@ def configure(conf): '-Wno-atomic-implicit-seq-cst', '-Wno-bad-function-cast', '-Wno-cast-align', - '-Wno-format-nonliteral', + '-Wno-format', '-Wno-implicit-int-conversion', '-Wno-padded', '-Wno-reserved-id-macro', @@ -59,7 +59,6 @@ def configure(conf): '-Wno-null-dereference', '-Wno-padded', '-Wno-suggest-attribute=const', - '-Wno-suggest-attribute=format', '-Wno-suggest-attribute=pure', ], 'msvc': [ diff --git a/zix/common.h b/zix/common.h index f0737eb..e427885 100644 --- a/zix/common.h +++ b/zix/common.h @@ -52,6 +52,12 @@ extern "C" { # include #endif +#ifdef __GNUC__ +#define ZIX_LOG_FUNC(fmt, arg1) __attribute__((format(printf, fmt, arg1))) +#else +#define ZIX_LOG_FUNC(fmt, arg1) +#endif + // Unused parameter macro to suppresses warnings and make it impossible to use #if defined(__cplusplus) # define ZIX_UNUSED(name) -- cgit v1.2.1