[master] 9ea6149 Add a tiny bit of compile time type-safety, just because we can.

Poul-Henning Kamp phk at FreeBSD.org
Mon May 4 11:05:09 CEST 2015


commit 9ea6149ae1d37aa4053449a490c9b4938e38aba3
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon May 4 09:04:50 2015 +0000

    Add a tiny bit of compile time type-safety, just because we can.

diff --git a/bin/varnishd/cache/cache_vrt_vmod.c b/bin/varnishd/cache/cache_vrt_vmod.c
index f3e2519..5245708 100644
--- a/bin/varnishd/cache/cache_vrt_vmod.c
+++ b/bin/varnishd/cache/cache_vrt_vmod.c
@@ -62,7 +62,7 @@ struct vmod {
 static VTAILQ_HEAD(,vmod)	vmods = VTAILQ_HEAD_INITIALIZER(vmods);
 
 int
-VRT_Vmod_Init(void **hdl, void *ptr, int len, const char *nm,
+VRT_Vmod_Init(struct vmod **hdl, void *ptr, int len, const char *nm,
     const char *path, const char *file_id, VRT_CTX)
 {
 	struct vmod *v;
@@ -73,6 +73,8 @@ VRT_Vmod_Init(void **hdl, void *ptr, int len, const char *nm,
 	ASSERT_CLI();
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
 	AN(ctx->cli);
+	AN(hdl);
+	AZ(*hdl);
 
 	dlhdl = dlopen(path, RTLD_NOW | RTLD_LOCAL);
 	if (dlhdl == NULL) {
@@ -141,15 +143,16 @@ VRT_Vmod_Init(void **hdl, void *ptr, int len, const char *nm,
 }
 
 void
-VRT_Vmod_Fini(void **hdl)
+VRT_Vmod_Fini(struct vmod **hdl)
 {
 	struct vmod *v;
 
 	ASSERT_CLI();
 
-	AN(*hdl);
-	CAST_OBJ_NOTNULL(v, *hdl, VMOD_MAGIC);
+	AN(hdl);
+	v = *hdl;
 	*hdl = NULL;
+	CHECK_OBJ_NOTNULL(v, VMOD_MAGIC);
 
 #ifndef DONT_DLCLOSE_VMODS
 	/*
diff --git a/include/vrt.h b/include/vrt.h
index e034f91..5e4882e 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -58,6 +58,7 @@ struct cli;
 struct director;
 struct VCL_conf;
 struct suckaddr;
+struct vmod;
 
 /***********************************************************************
  * This is the central definition of the mapping from VCL types to
@@ -243,9 +244,9 @@ void VRT_fini_vbe(VRT_CTX, struct director **, const struct vrt_backend *);
 int VRT_VSA_GetPtr(const struct suckaddr *sua, const unsigned char ** dst);
 
 /* VMOD/Modules related */
-int VRT_Vmod_Init(void **hdl, void *ptr, int len, const char *nm,
+int VRT_Vmod_Init(struct vmod **hdl, void *ptr, int len, const char *nm,
     const char *path, const char *file_id, VRT_CTX);
-void VRT_Vmod_Fini(void **hdl);
+void VRT_Vmod_Fini(struct vmod **hdl);
 
 struct vmod_priv;
 typedef void vmod_priv_free_f(void *);
diff --git a/lib/libvcc/vcc_vmod.c b/lib/libvcc/vcc_vmod.c
index 9564ca9..8391c98 100644
--- a/lib/libvcc/vcc_vmod.c
+++ b/lib/libvcc/vcc_vmod.c
@@ -218,7 +218,7 @@ vcc_ParseImport(struct vcc *tl)
 	}
 
 	Fh(tl, 0, "\n/* --- BEGIN VMOD %.*s --- */\n\n", PF(mod));
-	Fh(tl, 0, "static void *VGC_vmod_%.*s;\n", PF(mod));
+	Fh(tl, 0, "static struct vmod *VGC_vmod_%.*s;\n", PF(mod));
 	Fh(tl, 0, "static struct vmod_priv vmod_priv_%.*s;\n", PF(mod));
 	Fh(tl, 0, "\n%s\n", vmd->proto);
 	Fh(tl, 0, "\n/* --- END VMOD %.*s --- */\n\n", PF(mod));



More information about the varnish-commit mailing list