From b20c9fb6a6a20059786fc52acd60cda9c6833291 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sat, 18 Jul 2015 10:22:44 +0100 Subject: Update to include asserts in interface macros, and test successfully --- include/libwapcaplet/libwapcaplet.h | 12 +++++++----- test/testmain.c | 12 ++++++++++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/include/libwapcaplet/libwapcaplet.h b/include/libwapcaplet/libwapcaplet.h index 47d93a6..e46ffa8 100644 --- a/include/libwapcaplet/libwapcaplet.h +++ b/include/libwapcaplet/libwapcaplet.h @@ -17,6 +17,7 @@ extern "C" #include #include #include +#include /** * The type of a reference counter used in libwapcaplet. @@ -121,7 +122,7 @@ extern lwc_error lwc_intern_substring(lwc_string *str, * @note Use this if copying the string and intending both sides to retain * ownership. */ -#define lwc_string_ref(str) ({lwc_string *__lwc_s = (str); __lwc_s->refcnt++; __lwc_s;}) +#define lwc_string_ref(str) ({lwc_string *__lwc_s = (str); assert(__lwc_s != NULL); __lwc_s->refcnt++; __lwc_s;}) /** * Release a reference on an lwc_string. @@ -135,7 +136,8 @@ extern lwc_error lwc_intern_substring(lwc_string *str, * will also result in the string being freed.) */ #define lwc_string_unref(str) { \ - lwc_string *__lwc_s = (str); \ + lwc_string *__lwc_s = (str); \ + assert(__lwc_s != NULL); \ __lwc_s->refcnt--; \ if ((__lwc_s->refcnt == 0) || \ ((__lwc_s->refcnt == 1) && (__lwc_s->insensitive == __lwc_s))) \ @@ -215,7 +217,7 @@ lwc__intern_caseless_string(lwc_string *str); * in future. Any code relying on it currently should be * modified to use ::lwc_string_length if possible. */ -#define lwc_string_data(str) ((const char *)((str)+1)) +#define lwc_string_data(str) ({assert(str != NULL); (const char *)((str)+1);}) /** * Retrieve the data length for an interned string. @@ -223,7 +225,7 @@ lwc__intern_caseless_string(lwc_string *str); * @param str The string to retrieve the length of. * @return The length of \a str. */ -#define lwc_string_length(str) ((str)->len) +#define lwc_string_length(str) ({assert(str != NULL); (str)->len;}) /** * Retrieve (or compute if unavailable) a hash value for the content of the string. @@ -237,7 +239,7 @@ lwc__intern_caseless_string(lwc_string *str); * to be stable between invocations of the program. Never use the hash * value as a way to directly identify the value of the string. */ -#define lwc_string_hash_value(str) ((str)->hash) +#define lwc_string_hash_value(str) ({assert(str != NULL); (str)->hash;}) /** * Iterate the context and return every string in it. diff --git a/test/testmain.c b/test/testmain.c index 95fd6d2..421d06f 100644 --- a/test/testmain.c +++ b/test/testmain.c @@ -16,8 +16,16 @@ #endif /* This means that assertion failures are silent in tests */ -extern void __assert_fail(void); -void __assert_fail(void) { abort(); } +#ifndef NDEBUG +void __assert_fail(const char *__assertion, const char *__file, + unsigned int __line, const char *__function) { + (void)__assertion; + (void)__file; + (void)__line; + (void)__function; + abort(); +} +#endif int main(int argc, char **argv) -- cgit v1.2.3