summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2015-07-18 09:22:44 (GMT)
committer Daniel Silverstone <dsilvers@digital-scurf.org>2015-07-18 09:22:44 (GMT)
commitb20c9fb6a6a20059786fc52acd60cda9c6833291 (patch)
tree6ee530388010c81fb6ef0c8342d920699f2be02c
parent2c99255d4e567c5acefdf4f1c06d9f1a6378b680 (diff)
downloadlibwapcaplet-b20c9fb6a6a20059786fc52acd60cda9c6833291.tar.gz
libwapcaplet-b20c9fb6a6a20059786fc52acd60cda9c6833291.tar.bz2
Update to include asserts in interface macros, and test successfully
-rw-r--r--include/libwapcaplet/libwapcaplet.h12
-rw-r--r--test/testmain.c12
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 <sys/types.h>
#include <stdbool.h>
#include <stdint.h>
+#include <assert.h>
/**
* 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)