[master] 4a655c0 Add a miniobj macro for taking over pointer

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Fri Mar 18 12:24:04 CET 2016


commit 4a655c0ad3e77c1e39b30dd0ed87365ae2eafbcc
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Fri Mar 18 11:57:58 2016 +0100

    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.

diff --git a/include/miniobj.h b/include/miniobj.h
index 8b4f043..95f3bef 100644
--- a/include/miniobj.h
+++ b/include/miniobj.h
@@ -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);						\



More information about the varnish-commit mailing list