summaryrefslogtreecommitdiffstats
path: root/usr.sbin/fifolog/lib/miniobj.h
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/fifolog/lib/miniobj.h')
-rw-r--r--usr.sbin/fifolog/lib/miniobj.h18
1 files changed, 13 insertions, 5 deletions
diff --git a/usr.sbin/fifolog/lib/miniobj.h b/usr.sbin/fifolog/lib/miniobj.h
index a805316..dd79be1 100644
--- a/usr.sbin/fifolog/lib/miniobj.h
+++ b/usr.sbin/fifolog/lib/miniobj.h
@@ -26,11 +26,11 @@
* $FreeBSD$
*/
-#define ALLOC_OBJ(to, type_magic) \
+#define ALLOC_OBJ(to, type_magic) \
do { \
(to) = calloc(sizeof *(to), 1); \
- assert((to) != NULL); \
- (to)->magic = (type_magic); \
+ if ((to) != NULL) \
+ (to)->magic = (type_magic); \
} while (0)
#define FREE_OBJ(to) \
@@ -39,6 +39,9 @@
free(to); \
} while (0)
+#define VALID_OBJ(ptr, type_magic) \
+ ((ptr) != NULL && (ptr)->magic == (type_magic))
+
#define CHECK_OBJ(ptr, type_magic) \
do { \
assert((ptr)->magic == type_magic); \
@@ -50,6 +53,12 @@
assert((ptr)->magic == type_magic); \
} while (0)
+#define CHECK_OBJ_ORNULL(ptr, type_magic) \
+ do { \
+ if ((ptr) != NULL) \
+ assert((ptr)->magic == type_magic); \
+ } while (0)
+
#define CAST_OBJ(to, from, type_magic) \
do { \
(to) = (from); \
@@ -57,10 +66,9 @@
CHECK_OBJ((to), (type_magic)); \
} while (0)
-#define CAST_OBJ_NOTNULL(to, from, type_magic) \
+#define CAST_OBJ_NOTNULL(to, from, type_magic) \
do { \
(to) = (from); \
assert((to) != NULL); \
CHECK_OBJ((to), (type_magic)); \
} while (0)
-
OpenPOWER on IntegriCloud