[master] 2962375b4 Reimplement the storage.*.* properties as type driven properties

Poul-Henning Kamp phk at FreeBSD.org
Tue Jun 4 06:39:10 UTC 2019


commit 2962375b4ed80e2197a318f92f2fb9f6cfcd12f8
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Jun 4 06:37:28 2019 +0000

    Reimplement the storage.*.* properties as type driven properties

diff --git a/bin/varnishd/storage/stevedore.c b/bin/varnishd/storage/stevedore.c
index 49835eba4..0f33bd656 100644
--- a/bin/varnishd/storage/stevedore.c
+++ b/bin/varnishd/storage/stevedore.c
@@ -41,7 +41,6 @@
 #include "storage/storage.h"
 #include "vrt_obj.h"
 
-
 static pthread_mutex_t stv_mtx;
 
 /*--------------------------------------------------------------------
@@ -214,18 +213,13 @@ VRT_stevedore(const char *nm)
 	return (stv_find(nm));
 }
 
-#define VRTSTVVAR(nm, vtype, ctype, dval)	\
-ctype						\
-VRT_Stv_##nm(const char *nm)			\
-{						\
-	const struct stevedore *stv;		\
-						\
-	stv = stv_find(nm);			\
-	if (stv == NULL)			\
-		return (dval);			\
-	if (stv->var_##nm == NULL)		\
-		return (dval);			\
-	return (stv->var_##nm(stv));		\
+#define VRTSTVVAR(nm, vtype, ctype, dval)		\
+ctype							\
+VRT_stevedore_##nm(VCL_STEVEDORE stv)			\
+{							\
+	if (stv == NULL)				\
+		return (0);				\
+	CHECK_OBJ_NOTNULL(stv, STEVEDORE_MAGIC);	\
+	return (stv->var_##nm(stv));			\
 }
-
 #include "tbl/vrt_stv_var.h"
diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py
index 892dfff5b..fb464bc39 100755
--- a/lib/libvcc/generate.py
+++ b/lib/libvcc/generate.py
@@ -731,12 +731,11 @@ vcc_Var_Init(struct vcc *tl)
     struct symbol *sym;
 """)
 
-
 parse_var_doc(join(srcroot, "doc/sphinx/reference/vcl_var.rst"))
 fo.write("}\n")
 
 for i in stv_variables:
-    fh.write(vcltypes[i[1]].c + " VRT_Stv_" + i[0] + "(const char *);\n")
+    fh.write(vcltypes[i[1]].c + " VRT_stevedore_" + i[0] + "(VCL_STEVEDORE);\n")
 
 fo.write("\n/* VCL type identifiers */\n")
 
diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index 13931d13c..6301cb722 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -813,7 +813,11 @@ static const struct vcc_methods {
 	const char		*impl;
 } vcc_methods[] = {
 	//{ BACKEND, BOOL,	"healthy",	"VRT_Healthy(ctx, \v1, 0)" },
-	{ NULL, NULL,		NULL,		NULL},	// XXX: For Flexelint
+
+#define VRTSTVVAR(nm, vtype, ctype, dval) \
+	{ STEVEDORE, vtype, #nm, "VRT_stevedore_" #nm "(\v1)"},
+#include "tbl/vrt_stv_var.h"
+
 	{ NULL, NULL,		NULL,		NULL},
 };
 
diff --git a/lib/libvcc/vcc_storage.c b/lib/libvcc/vcc_storage.c
index aa83a32dc..ac4fbeb7d 100644
--- a/lib/libvcc/vcc_storage.c
+++ b/lib/libvcc/vcc_storage.c
@@ -59,27 +59,11 @@
 #include <string.h>
 
 #include "vcc_compile.h"
-#include "libvcc.h"		// VCC_Stevedore() proto
-
-/*--------------------------------------------------------------------
- *
- */
-
-static struct stvars {
-	const char	*name;
-	vcc_type_t	type;
-} stvars[] = {
-#define VRTSTVVAR(nm, vtype, ctype, dval)	{ #nm, vtype },
-#include "tbl/vrt_stv_var.h"
-#undef VRTSTVVAR
-	{ NULL,			BOOL }
-};
 
 void
 vcc_stevedore(struct vcc *vcc, const char *stv_name)
 {
 	struct symbol *sym;
-	struct stvars *sv;
 	char buf[1024];
 
 	CHECK_OBJ_NOTNULL(vcc, VCC_MAGIC);
@@ -91,15 +75,4 @@ vcc_stevedore(struct vcc *vcc, const char *stv_name)
 	bprintf(buf, "VRT_stevedore(\"%s\")", stv_name);
 	sym->rname = TlDup(vcc, buf);
 	sym->r_methods = ~0;
-
-	for (sv = stvars; sv->name != NULL; sv++) {
-		bprintf(buf, "storage.%s.%s", stv_name, sv->name);
-		sym = VCC_MkSym(vcc, buf, SYM_VAR, VCL_LOW, VCL_41);
-		AN(sym);
-		sym->type = sv->type;
-		sym->eval = vcc_Eval_Var;
-		bprintf(buf, "VRT_Stv_%s(\"%s\")", sv->name, stv_name);
-		sym->rname = TlDup(vcc, buf);
-		sym->r_methods = ~0;
-	}
 }


More information about the varnish-commit mailing list