[master] e212c5c Get rid of the interstitial "var" structure.

Poul-Henning Kamp phk at FreeBSD.org
Wed Jan 24 11:39:07 UTC 2018


commit e212c5c009666a2033525ddae24622aa61427fa3
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Jan 24 11:37:24 2018 +0000

    Get rid of the interstitial "var" structure.

diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py
index dfa71b9..5e5c04f 100755
--- a/lib/libvcc/generate.py
+++ b/lib/libvcc/generate.py
@@ -1229,7 +1229,6 @@ def restrict(fo, spec):
 		p = " | "
 	if len(d) == 0:
 		fo.write("0")
-	fo.write(",\n")
 
 #######################################################################
 
@@ -1244,46 +1243,68 @@ fo.write("""
 
 #include "vcc_compile.h"
 
-const struct var vcc_vars[] = {
+void
+vcc_Var_Init(struct vcc *tl)
+{
+	struct symbol *sym;
 """)
 
 
 def one_var(nm, spec):
 	fh.write("\n")
+	fo.write("\n")
 	cnam = spec.nam.replace(".", "_")
 	ctyp = vcltypes[spec.typ]
 
-	fo.write("\t{ \"%s\", %s,\n" % (nm, spec.typ))
+	# fo.write("\t{ \"%s\", %s,\n" % (nm, spec.typ))
+	fo.write("\tsym = VCC_Symbol(tl, NULL, \"%s\", NULL," % nm)
+	if (spec.typ == "HEADER"):
+		fo.write(" SYM_NONE, 1);\n")
+		fo.write("\tAN(sym);\n");
+		fo.write("\tsym->wildcard = vcc_Var_Wildcard;\n")
+	else:
+		fo.write(" SYM_VAR, 1);\n")
+	fo.write("\tAN(sym);\n")
+	fo.write("\tsym->fmt = %s;\n" % spec.typ)
+	fo.write("\tsym->eval = vcc_Eval_Var;\n")
 
 	if len(spec.rd) == 0:
-		fo.write('\t    NULL,\t/* No reads allowed */\n')
+		fo.write('\t/* No reads allowed */\n')
 	elif spec.typ == "HEADER":
-		fo.write('\t    "HDR_')
+		fo.write('\tsym->rname = "HDR_')
 		fo.write(nm.split(".")[0].upper())
-		fo.write('",\n')
+		fo.write('";\n')
+		fo.write("\tsym->r_methods =\n")
+		restrict(fo, spec.rd)
+		fo.write(";\n")
 	else:
-		fo.write('\t    "VRT_r_%s(ctx)",\n' % cnam)
+		fo.write('\tsym->rname = "VRT_r_%s(ctx)";\n' % cnam)
 		if nm == spec.nam:
 			fh.write("VCL_" + spec.typ + " VRT_r_%s(VRT_CTX);\n" % cnam)
-	restrict(fo, spec.rd)
+		fo.write("\tsym->r_methods =\n")
+		restrict(fo, spec.rd)
+		fo.write(";\n")
 
 	if len(spec.wr) == 0:
-		fo.write('\t    NULL,\t/* No writes allowed */\n')
+		fo.write('\t/* No writes allowed */\n')
 	elif spec.typ == "HEADER":
-		fo.write('\t    "HDR_')
+		fo.write('\tsym->lname = "HDR_')
 		fo.write(nm.split(".")[0].upper())
-		fo.write('",\n')
+		fo.write('";\n')
+		fo.write("\tsym->w_methods =\n")
+		restrict(fo, spec.wr)
+		fo.write(";\n")
 	else:
-		fo.write('\t    "VRT_l_%s(ctx, ",\n' % cnam)
+		fo.write('\tsym->lname = "VRT_l_%s(ctx, ";\n' % cnam)
 		if nm == spec.nam:
 			fh.write("void VRT_l_%s(VRT_CTX, " % cnam)
 			if spec.typ != "STRING" and spec.typ != "BODY":
 				fh.write("VCL_" + spec.typ + ");\n")
 			else:
 				fh.write(ctyp + ", ...);\n")
-	restrict(fo, spec.wr)
-
-	fo.write("\t},\n")
+		fo.write("\tsym->w_methods =\n")
+		restrict(fo, spec.wr)
+		fo.write(";\n")
 
 aliases.sort()
 for i in sp_variables:
@@ -1292,7 +1313,8 @@ for i in sp_variables:
 		if j[1] == i[0]:
 			one_var(j[0], sp_variables[i])
 
-fo.write("\t{ NULL }\n};\n\n")
+# fo.write("\t{ NULL }\n};\n\n")
+fo.write("}\n")
 
 for i in stv_variables:
 	fh.write(vcltypes[i[1]] + " VRT_Stv_" + i[0] + "(const char *);\n")
diff --git a/lib/libvcc/vcc_compile.c b/lib/libvcc/vcc_compile.c
index 298b7a8..95e5b76 100644
--- a/lib/libvcc/vcc_compile.c
+++ b/lib/libvcc/vcc_compile.c
@@ -556,9 +556,7 @@ vcc_resolve_includes(struct vcc *tl)
 static struct vsb *
 vcc_CompileSource(struct vcc *tl, struct source *sp)
 {
-	struct symbol *sym;
 	struct proc *p;
-	const struct var *v;
 	struct vsb *vsb;
 	struct inifin *ifp;
 
@@ -569,22 +567,7 @@ vcc_CompileSource(struct vcc *tl, struct source *sp)
 
 	vcc_Backend_Init(tl);
 
-	for (v = vcc_vars; v->name != NULL; v++) {
-		if (v->fmt == HEADER) {
-			sym = VCC_Symbol(tl, NULL, v->name, NULL,
-			    SYM_NONE, 1);
-			sym->wildcard = vcc_Var_Wildcard;
-			sym->wildcard_priv = v;
-		} else {
-			sym = VCC_Symbol(tl, NULL, v->name, NULL, SYM_VAR, 1);
-		}
-		sym->fmt = v->fmt;
-		sym->eval = vcc_Eval_Var;
-		sym->r_methods = v->r_methods;
-		sym->w_methods = v->w_methods;
-		sym->lname = v->lname;
-		REPLACE(sym->rname, v->rname);
-	}
+	vcc_Var_Init(tl);
 
 	Fh(tl, 0, "\nextern const struct VCL_conf VCL_conf;\n");
 
diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h
index 00b55dd..e0b0da9 100644
--- a/lib/libvcc/vcc_compile.h
+++ b/lib/libvcc/vcc_compile.h
@@ -121,7 +121,6 @@ struct symbol {
 	char				*name;
 	unsigned			nlen;
 	sym_wildcard_t			*wildcard;
-	const void			*wildcard_priv;
 	enum symkind			kind;
 
 	const struct token		*def_b, *def_e, *ref_b;
@@ -138,7 +137,7 @@ struct symbol {
 	const char			*extra;
 
 	/* SYM_VAR */
-	char				*rname;
+	const char			*rname;
 	unsigned			r_methods;
 	const char			*lname;
 	unsigned			w_methods;
@@ -225,15 +224,6 @@ struct vcc {
 
 };
 
-struct var {
-	const char		*name;
-	vcc_type_t		fmt;
-	const char		*rname;
-	unsigned		r_methods;
-	const char		*lname;
-	unsigned		w_methods;
-};
-
 struct method {
 	const char		*name;
 	unsigned		ret_bitmap;
@@ -294,7 +284,7 @@ void VCC_GlobalSymbol(struct symbol *, vcc_type_t fmt, const char *pfx);
 struct symbol *VCC_HandleSymbol(struct vcc *, vcc_type_t , const char *);
 
 /* vcc_obj.c */
-extern const struct var vcc_vars[];
+void vcc_Var_Init(struct vcc *);
 
 /* vcc_parse.c */
 void vcc_Parse(struct vcc *tl);
diff --git a/lib/libvcc/vcc_symb.c b/lib/libvcc/vcc_symb.c
index c743767..cb94ffb 100644
--- a/lib/libvcc/vcc_symb.c
+++ b/lib/libvcc/vcc_symb.c
@@ -220,7 +220,7 @@ VCC_GlobalSymbol(struct symbol *sym, vcc_type_t fmt, const char *pfx)
 	VSB_printf(vsb, "%s_", pfx);
 	VCC_PrintCName(vsb, sym->name, NULL);
 	AZ(VSB_finish(vsb));
-	REPLACE(sym->rname, VSB_data(vsb));
+	sym->rname = strdup(VSB_data(vsb));
 	AN(sym->rname);
 	VSB_destroy(&vsb);
 
diff --git a/lib/libvcc/vcc_var.c b/lib/libvcc/vcc_var.c
index 706c5d0..133455f 100644
--- a/lib/libvcc/vcc_var.c
+++ b/lib/libvcc/vcc_var.c
@@ -41,13 +41,10 @@ vcc_Var_Wildcard(struct vcc *tl, struct symbol *parent,
     const char *b, const char *e)
 {
 	struct symbol *sym;
-	struct var *v;
-	const struct var *vh;
 	struct vsb *vsb;
 	unsigned len;
 
-	vh = parent->wildcard_priv;
-	assert(vh->fmt == HEADER);
+	assert(parent->fmt == HEADER);
 
 	if (b + 127 <= e) {
 		VSB_printf(tl->sb, "HTTP header (%.20s..) is too long.\n", b);
@@ -56,16 +53,17 @@ vcc_Var_Wildcard(struct vcc *tl, struct symbol *parent,
 		return;
 	}
 
-	v = TlAlloc(tl, sizeof *v);
-	AN(v);
-	v->r_methods = vh->r_methods;
-	v->w_methods = vh->w_methods;
-	v->fmt = vh->fmt;
+	sym = VCC_Symbol(tl, parent, b, e, SYM_VAR, 1);
+	AN(sym);
+	sym->fmt = parent->fmt;
+	sym->eval = vcc_Eval_Var;
+	sym->r_methods = parent->r_methods;
+	sym->w_methods = parent->w_methods;
 
 	/* Create a C-name version of the header name */
 	vsb = VSB_new_auto();
 	AN(vsb);
-	VSB_printf(vsb, "&VGC_%s_", vh->rname);
+	VSB_printf(vsb, "&VGC_%s_", parent->rname);
 	VCC_PrintCName(vsb, b, e);
 	AZ(VSB_finish(vsb));
 
@@ -73,24 +71,15 @@ vcc_Var_Wildcard(struct vcc *tl, struct symbol *parent,
 	len = (unsigned)(e - b);
 	Fh(tl, 0, "static const struct gethdr_s %s =\n", VSB_data(vsb) + 1);
 	Fh(tl, 0, "    { %s, \"\\%03o%.*s:\"};\n",
-	    vh->rname, len + 1, len, b);
+	    parent->rname, len + 1, len, b);
 
 	/* Create the symbol r/l values */
-	v->rname = TlDup(tl, VSB_data(vsb));
+	sym->rname = TlDup(tl, VSB_data(vsb));
 	VSB_clear(vsb);
-	VSB_printf(vsb, "VRT_SetHdr(ctx, %s,", v->rname);
+	VSB_printf(vsb, "VRT_SetHdr(ctx, %s,", sym->rname);
 	AZ(VSB_finish(vsb));
-	v->lname = TlDup(tl, VSB_data(vsb));
+	sym->lname = TlDup(tl, VSB_data(vsb));
 	VSB_destroy(&vsb);
-
-	sym = VCC_Symbol(tl, parent, b, e, SYM_VAR, 1);
-	AN(sym);
-	sym->fmt = v->fmt;
-	sym->eval = vcc_Eval_Var;
-	sym->r_methods = v->r_methods;
-	sym->w_methods = v->w_methods;
-	sym->lname = v->lname;
-	REPLACE(sym->rname, v->rname);
 }
 
 /*--------------------------------------------------------------------*/


More information about the varnish-commit mailing list