Commit 4a655c0a authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

Add a miniobj macro for taking over pointer

There's a recurring pattern throughout the code base of taking over
a reference (by nulling the original) essentially when resources are
freed. Instead of repeating this anti dangling pointers measure, it
can be wrapped in a documenting utility macro.
parent b47aa71d
......@@ -59,6 +59,14 @@
CHECK_OBJ((to), (type_magic)); \
} while (0)
#define TAKE_OBJ_NOTNULL(to, pfrom, type_magic) \
do { \
assert((pfrom) != NULL); \
(to) = *(pfrom); \
*(pfrom) = NULL; \
CHECK_OBJ_NOTNULL((to), (type_magic)); \
} while (0)
#define REPLACE(ptr, val) \
do { \
free(ptr); \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment