r1957 - trunk/varnish-cache/include
phk at projects.linpro.no
phk at projects.linpro.no
Thu Sep 20 09:02:35 CEST 2007
Author: phk
Date: 2007-09-20 09:02:35 +0200 (Thu, 20 Sep 2007)
New Revision: 1957
Modified:
trunk/varnish-cache/include/miniobj.h
Log:
Add a REPLACE() macro, for manipulating malloced string variables.
Modified: trunk/varnish-cache/include/miniobj.h
===================================================================
--- trunk/varnish-cache/include/miniobj.h 2007-09-20 06:26:17 UTC (rev 1956)
+++ trunk/varnish-cache/include/miniobj.h 2007-09-20 07:02:35 UTC (rev 1957)
@@ -30,10 +30,21 @@
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);
+#define REPLACE(ptr, val) \
+ do { \
+ if ((ptr) != NULL) \
+ free(ptr); \
+ if ((val) != NULL) { \
+ ptr = strdup(val); \
+ AN((ptr)); \
+ } else { \
+ ptr = NULL; \
+ } \
+ } while (0);
More information about the varnish-commit
mailing list