summaryrefslogtreecommitdiff
path: root/include/libwapcaplet/libwapcaplet.h
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2015-07-18 10:22:44 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2015-07-18 10:22:44 +0100
commitb20c9fb6a6a20059786fc52acd60cda9c6833291 (patch)
tree6ee530388010c81fb6ef0c8342d920699f2be02c /include/libwapcaplet/libwapcaplet.h
parent2c99255d4e567c5acefdf4f1c06d9f1a6378b680 (diff)
downloadlibwapcaplet-b20c9fb6a6a20059786fc52acd60cda9c6833291.tar.gz
libwapcaplet-b20c9fb6a6a20059786fc52acd60cda9c6833291.tar.bz2
Update to include asserts in interface macros, and test successfully
Diffstat (limited to 'include/libwapcaplet/libwapcaplet.h')
-rw-r--r--include/libwapcaplet/libwapcaplet.h12
1 files changed, 7 insertions, 5 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.