[master] 430bbce96 tabularize parameters to be passed to vcc

Nils Goroll nils.goroll at uplex.de
Thu Apr 9 12:41:07 UTC 2020


commit 430bbce965d170f1afaf6ea3f6fa339743621fa0
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Thu Apr 9 14:32:30 2020 +0200

    tabularize parameters to be passed to vcc
    
    Parameters are passed to vcc via specific setter functions, presumably
    to avoid binary compability issues between the main program (here:
    vanishd) and a library (here: libvcc).
    
    This commit does not change that interface in any way, but generates
    both sides from a common table include to avoid having to edit five
    spots in four different source files and write trivial setter functions
    for a simple mgt_vcc parameter change.

diff --git a/bin/varnishd/mgt/mgt.h b/bin/varnishd/mgt/mgt.h
index 43987de1c..54b42ad80 100644
--- a/bin/varnishd/mgt/mgt.h
+++ b/bin/varnishd/mgt/mgt.h
@@ -221,10 +221,8 @@ int mgt_has_vcl(void);
 extern char *mgt_cc_cmd;
 extern const char *mgt_vcl_path;
 extern const char *mgt_vmod_path;
-extern unsigned mgt_vcc_err_unref;
-extern unsigned mgt_vcc_acl_pedantic;
-extern unsigned mgt_vcc_allow_inline_c;
-extern unsigned mgt_vcc_unsafe_path;
+#define MGT_VCC(t, n, cc) extern t mgt_vcc_ ## n;
+#include <tbl/mgt_vcc.h>
 
 #if defined(PTHREAD_CANCELED) || defined(PTHREAD_MUTEX_DEFAULT)
 #error "Keep pthreads out of in manager process"
diff --git a/bin/varnishd/mgt/mgt_vcc.c b/bin/varnishd/mgt/mgt_vcc.c
index 39e9ddcd3..e82fa81c5 100644
--- a/bin/varnishd/mgt/mgt_vcc.c
+++ b/bin/varnishd/mgt/mgt_vcc.c
@@ -65,11 +65,8 @@ struct vcc_priv {
 char *mgt_cc_cmd;
 const char *mgt_vcl_path;
 const char *mgt_vmod_path;
-unsigned mgt_vcc_err_unref;
-unsigned mgt_vcc_allow_inline_c;
-unsigned mgt_vcc_unsafe_path;
-unsigned mgt_vcc_acl_pedantic;
-
+#define MGT_VCC(t, n, cc) t mgt_vcc_ ## n;
+#include <tbl/mgt_vcc.h>
 
 #define VGC_SRC		"vgc.c"
 #define VGC_LIB		"vgc.so"
@@ -107,10 +104,11 @@ run_vcc(void *priv)
 	VCC_Builtin_VCL(vcc, builtin_vcl);
 	VCC_VCL_path(vcc, mgt_vcl_path);
 	VCC_VMOD_path(vcc, mgt_vmod_path);
-	VCC_Err_Unref(vcc, mgt_vcc_err_unref);
-	VCC_Allow_InlineC(vcc, mgt_vcc_allow_inline_c);
-	VCC_Unsafe_Path(vcc, mgt_vcc_unsafe_path);
-	VCC_Acl_Pedantic(vcc, mgt_vcc_acl_pedantic);
+
+#define MGT_VCC(type, name, camelcase)			\
+	VCC_ ## camelcase (vcc, mgt_vcc_ ## name);
+#include "tbl/mgt_vcc.h"
+
 	STV_Foreach(stv)
 		VCC_Predef(vcc, "VCL_STEVEDORE", stv->ident);
 	VTAILQ_FOREACH(vpg, &vclhead, list)
diff --git a/include/Makefile.am b/include/Makefile.am
index 9186df797..23e355c86 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -22,6 +22,7 @@ nobase_pkginclude_HEADERS = \
 	tbl/http_headers.h \
 	tbl/http_response.h \
 	tbl/locks.h \
+	tbl/mgt_vcc.h \
 	tbl/obj_attr.h \
 	tbl/oc_exp_flags.h \
 	tbl/oc_flags.h \
diff --git a/include/libvcc.h b/include/libvcc.h
index 63cd136a0..aa5f17288 100644
--- a/include/libvcc.h
+++ b/include/libvcc.h
@@ -33,15 +33,15 @@
 struct vcc;
 
 struct vcc *VCC_New(void);
-void VCC_Allow_InlineC(struct vcc *, unsigned);
 void VCC_Builtin_VCL(struct vcc *, const char *);
-void VCC_Err_Unref(struct vcc *, unsigned);
-void VCC_Unsafe_Path(struct vcc *, unsigned);
-void VCC_Acl_Pedantic(struct vcc *, unsigned);
 void VCC_VCL_path(struct vcc *, const char *);
 void VCC_VMOD_path(struct vcc *, const char *);
 void VCC_Predef(struct vcc *, const char *type, const char *name);
 void VCC_VCL_Range(unsigned *, unsigned *);
 
+#define MGT_VCC(t, n, cc)					\
+	void VCC_ ## cc (struct vcc *, t);
+#include "tbl/mgt_vcc.h"
+
 int VCC_Compile(struct vcc *, struct vsb **,
     const char *, const char *, const char *, const char *);
diff --git a/include/tbl/mgt_vcc.h b/include/tbl/mgt_vcc.h
new file mode 100644
index 000000000..efff37265
--- /dev/null
+++ b/include/tbl/mgt_vcc.h
@@ -0,0 +1,5 @@
+MGT_VCC(unsigned, acl_pedantic,   Acl_Pedantic)
+MGT_VCC(unsigned, allow_inline_c, Allow_InlineC)
+MGT_VCC(unsigned, err_unref,      Err_Unref)
+MGT_VCC(unsigned, unsafe_path,    Unsafe_Path)
+#undef MGT_VCC
diff --git a/lib/libvcc/vcc_compile.c b/lib/libvcc/vcc_compile.c
index 94fabd984..78b08d04d 100644
--- a/lib/libvcc/vcc_compile.c
+++ b/lib/libvcc/vcc_compile.c
@@ -889,37 +889,13 @@ VCC_VMOD_path(struct vcc *vcc, const char *str)
  * Configure settings
  */
 
-void
-VCC_Err_Unref(struct vcc *vcc, unsigned u)
-{
-
-	CHECK_OBJ_NOTNULL(vcc, VCC_MAGIC);
-	vcc->err_unref = u;
-}
-
-void
-VCC_Allow_InlineC(struct vcc *vcc, unsigned u)
-{
-
-	CHECK_OBJ_NOTNULL(vcc, VCC_MAGIC);
-	vcc->allow_inline_c = u;
-}
-
-void
-VCC_Unsafe_Path(struct vcc *vcc, unsigned u)
-{
-
-	CHECK_OBJ_NOTNULL(vcc, VCC_MAGIC);
-	vcc->unsafe_path = u;
-}
-
-void
-VCC_Acl_Pedantic(struct vcc *vcc, unsigned u)
-{
-
-	CHECK_OBJ_NOTNULL(vcc, VCC_MAGIC);
-	vcc->acl_pedantic = u;
-}
+#define MGT_VCC(type, name, camelcase)				\
+	void VCC_ ## camelcase (struct vcc *vcc, type val)	\
+	{							\
+		CHECK_OBJ_NOTNULL(vcc, VCC_MAGIC);		\
+		vcc->name = val;				\
+	}
+#include "tbl/mgt_vcc.h"
 
 /*--------------------------------------------------------------------
  * Configure settings


More information about the varnish-commit mailing list