summaryrefslogtreecommitdiff
path: root/src/_safety.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/_safety.h')
-rw-r--r--src/_safety.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/_safety.h b/src/_safety.h
index 8f157b7b..5f8dadc4 100644
--- a/src/_safety.h
+++ b/src/_safety.h
@@ -53,6 +53,18 @@ extern struct __dangerous {
(__count)++; \
} while (0)
+#define ADD_PREV_STRING(__val, __arr, __count) do { \
+ void *tmp = realloc((__arr), ((__count) + 1) * sizeof((__arr)[0])); \
+ if (tmp == NULL) { \
+ fprintf(stderr, "Out of memory tracking values\n"); \
+ abort(); \
+ } \
+ (__arr) = tmp; \
+ printf("Adding %s\n", (__val)); \
+ (__arr)[__count] = strdup(__val); \
+ (__count)++; \
+} while (0)
+
#define ASSERT_PREV(__val, __arr, __count, __prev) do { \
int __found = 0; \
for (size_t __i = 0; __i < (__count); __i++) { \
@@ -66,6 +78,20 @@ extern struct __dangerous {
} \
} while (0)
+#define ASSERT_PREV_STRING(__val, __arr, __count, __prev) do { \
+ int __found = 0; \
+ for (size_t __i = 0; __i < (__count); __i++) { \
+ printf("checking '%s' vs [%zu] '%s'\n", (__val), __i, (__arr)[__i]); \
+ if (strcmp((__arr)[__i], (__val)) == 0) { \
+ __found = 1; \
+ break; \
+ } \
+ } \
+ if (!__found) { \
+ UNDEFINED("In call to %s(): %s was not returned by a previous call to %s", __func__, __val, __prev); \
+ } \
+} while (0)
+
#define ASSERT_NONNULL(__ptr) do { \
if (!__ptr) { \
UNDEFINED("In call to %s(), parameter %s cannot be NULL", __func__, #__ptr); \