[master] 90d21bcfe param: Turn vcc_* booleans into vcc_feature aliases

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Mon Jun 27 13:38:07 UTC 2022


commit 90d21bcfe53854f3ff364b17975c5db6025cf4dc
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Tue May 31 08:23:02 2022 +0200

    param: Turn vcc_* booleans into vcc_feature aliases
    
    The vcc_feature parameter is in charge of translating param.set calls
    from the alias name to the bit flag. On the other hand param.show will
    defer to the generic alias display.
    
    With this change we lose the "camel case" functions used to set those
    bits through functions between mgt and libvcc. The functions were
    renamed VCC_Opt_<lowercase> to look more appropriate than "all_lower"
    or "ALL_UPPER".

diff --git a/bin/varnishd/mgt/mgt.h b/bin/varnishd/mgt/mgt.h
index d067aff42..4ae97b6d9 100644
--- a/bin/varnishd/mgt/mgt.h
+++ b/bin/varnishd/mgt/mgt.h
@@ -237,8 +237,6 @@ extern char *mgt_cc_cmd_def;
 extern char *mgt_cc_warn;
 extern const char *mgt_vcl_path;
 extern const char *mgt_vmod_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_param_tweak.c b/bin/varnishd/mgt/mgt_param_tweak.c
index 42fb802b4..6990f1b79 100644
--- a/bin/varnishd/mgt/mgt_param_tweak.c
+++ b/bin/varnishd/mgt/mgt_param_tweak.c
@@ -36,6 +36,7 @@
 
 #include <limits.h>
 #include <math.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -776,7 +777,20 @@ static const char * const vcc_feature_tags[] = {
 int v_matchproto_(tweak_t)
 tweak_vcc_feature(struct vsb *vsb, const struct parspec *par, const char *arg)
 {
+	const struct parspec *orig;
+	char buf[32];
+	int val;
 
+	if (arg != NULL && arg != JSON_FMT &&
+	    strcmp(par->name, "vcc_feature")) {
+		orig = TRUST_ME(par->priv);
+		val = parse_boolean(vsb, arg);
+		if (val < 0)
+			return (-1);
+		bprintf(buf, "%c%s", val ? '+' : '-',
+		    par->name + strlen("vcc_"));
+		return (tweak_vcc_feature(vsb, orig, buf));
+	}
 	return (tweak_generic_bits(vsb, par, arg, mgt_param.vcc_feature_bits,
 	    VCC_FEATURE_Reserved, vcc_feature_tags, "vcc_feature bit", '+'));
 }
diff --git a/bin/varnishd/mgt/mgt_vcc.c b/bin/varnishd/mgt/mgt_vcc.c
index 9716df6b7..f55031a1c 100644
--- a/bin/varnishd/mgt/mgt_vcc.c
+++ b/bin/varnishd/mgt/mgt_vcc.c
@@ -68,8 +68,6 @@ char *mgt_cc_cmd_def;
 char *mgt_cc_warn;
 const char *mgt_vcl_path;
 const char *mgt_vmod_path;
-#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"
@@ -108,9 +106,9 @@ run_vcc(void *priv)
 	VCC_VCL_path(vcc, mgt_vcl_path);
 	VCC_VMOD_path(vcc, mgt_vmod_path);
 
-#define MGT_VCC(type, name, camelcase)			\
-	VCC_ ## camelcase (vcc, mgt_vcc_ ## name);
-#include "tbl/mgt_vcc.h"
+#define VCC_FEATURE_BIT(U, l, d)			\
+	VCC_Opt_ ## l(vcc, MGT_VCC_FEATURE(VCC_FEATURE_ ## U));
+#include "tbl/vcc_feature_bits.h"
 
 	STV_Foreach(stv)
 		VCC_Predef(vcc, "VCL_STEVEDORE", stv->ident);
diff --git a/include/Makefile.am b/include/Makefile.am
index 7b7b6b116..2fdb7a580 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -23,7 +23,6 @@ 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 aa5f17288..3bf4e15c8 100644
--- a/include/libvcc.h
+++ b/include/libvcc.h
@@ -39,9 +39,9 @@ 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"
+#define VCC_FEATURE_BIT(U, l, d)				\
+	void VCC_Opt_ ## l(struct vcc *, unsigned);
+#include "tbl/vcc_feature_bits.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
deleted file mode 100644
index 908938367..000000000
--- a/include/tbl/mgt_vcc.h
+++ /dev/null
@@ -1,9 +0,0 @@
-/*
- * This file is in the public domain
- *
- */
-
-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/include/tbl/params.h b/include/tbl/params.h
index 1cccb1df1..9cf5de581 100644
--- a/include/tbl/params.h
+++ b/include/tbl/params.h
@@ -1634,38 +1634,6 @@ PARAM_STRING(
 	/* dyn_def_reason */	"${libdir}/varnish/vmods"
 )
 
-/*--------------------------------------------------------------------
- * VCC parameters
- */
-
-#  define PARAM_VCC(nm, def, descr)					\
-	PARAM_PRE							\
-	PARAM(, , nm, tweak_boolean, &mgt_ ## nm, NULL, NULL, def,	\
-	    "bool", descr)						\
-	PARAM_POST
-
-PARAM_VCC(
-	/* name */	vcc_err_unref,
-	/* def */	"on",
-	/* descr */
-	"Unreferenced VCL objects result in error."
-)
-
-PARAM_VCC(
-	/* name */	vcc_allow_inline_c,
-	/* def */	"off",
-	/* descr */
-	"Allow inline C code in VCL."
-)
-
-PARAM_VCC(
-	/* name */	vcc_unsafe_path,
-	/* def */	"on",
-	/* descr */
-	"Allow '/' in vmod & include paths.\n"
-	"Allow 'import ... from ...'."
-)
-
 /*--------------------------------------------------------------------
  * PCRE2 parameters
  */
@@ -1723,12 +1691,14 @@ PARAM_PCRE2(
 	    "Deprecated alias for the " #nm " parameter.")	\
 	PARAM_POST
 
-PARAM_ALIAS(deprecated_dummy, debug)
+PARAM_ALIAS(deprecated_dummy,	debug)
+PARAM_ALIAS(vcc_err_unref,	vcc_feature)
+PARAM_ALIAS(vcc_allow_inline_c,	vcc_feature)
+PARAM_ALIAS(vcc_unsafe_path,	vcc_feature)
 
 #  undef PARAM_ALIAS
 #  undef PARAM_PCRE2
 #  undef PARAM_STRING
-#  undef PARAM_VCC
 #endif /* defined(PARAM_ALL) */
 
 /*--------------------------------------------------------------------
diff --git a/lib/libvcc/vcc_compile.c b/lib/libvcc/vcc_compile.c
index d3acb0383..4d04328bf 100644
--- a/lib/libvcc/vcc_compile.c
+++ b/lib/libvcc/vcc_compile.c
@@ -921,13 +921,13 @@ VCC_VMOD_path(struct vcc *vcc, const char *str)
  * Configure settings
  */
 
-#define MGT_VCC(type, name, camelcase)				\
-	void VCC_ ## camelcase (struct vcc *vcc, type val)	\
+#define VCC_FEATURE_BIT(U, l, d)				\
+	void VCC_Opt_ ## l(struct vcc *vcc, unsigned val)	\
 	{							\
 		CHECK_OBJ_NOTNULL(vcc, VCC_MAGIC);		\
-		vcc->name = val;				\
+		vcc->l = val;					\
 	}
-#include "tbl/mgt_vcc.h"
+#include "tbl/vcc_feature_bits.h"
 
 /*--------------------------------------------------------------------
  * Configure settings
diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h
index d697d3381..6f8b71f3b 100644
--- a/lib/libvcc/vcc_compile.h
+++ b/lib/libvcc/vcc_compile.h
@@ -253,8 +253,8 @@ struct vcc {
 	char			*builtin_vcl;
 	struct vfil_path	*vcl_path;
 	struct vfil_path	*vmod_path;
-#define MGT_VCC(t, n, cc) t n;
-#include <tbl/mgt_vcc.h>
+#define VCC_FEATURE_BIT(U, l, d) unsigned l;
+#include <tbl/vcc_feature_bits.h>
 
 	struct symtab		*syms[VCC_NAMESPACE__MAX];
 


More information about the varnish-commit mailing list