[4.0] c58e98d Add a miniobj macro for taking over pointer

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Fri Mar 18 13:48:03 CET 2016


commit c58e98d67e517801980904f119074584d2c9c247
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 e1db10d..fc9b0b5 100644
--- a/include/miniobj.h
+++ b/include/miniobj.h
@@ -52,6 +52,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 {								\
 		if ((ptr) != NULL)					\



More information about the varnish-commit mailing list