[master] 3bd4f51 Now that we fall out of VCL the moment ctx->handling gets set, we can ditch the bogus return values and some decorations.

Poul-Henning Kamp phk at FreeBSD.org
Fri Feb 3 11:20:06 CET 2017


commit 3bd4f5165f4a6d97a76c17392254be59abfa098b
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Fri Feb 3 10:18:39 2017 +0000

    Now that we fall out of VCL the moment ctx->handling gets set,
    we can ditch the bogus return values and some decorations.

diff --git a/bin/varnishd/builtin.vcl b/bin/varnishd/builtin.vcl
index 2ccbf4c..a01094d 100644
--- a/bin/varnishd/builtin.vcl
+++ b/bin/varnishd/builtin.vcl
@@ -186,6 +186,7 @@ sub vcl_backend_error {
 # Housekeeping
 
 sub vcl_init {
+    return (ok);
 }
 
 sub vcl_fini {
diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c
index a380256..967c563 100644
--- a/bin/varnishd/cache/cache_vcl.c
+++ b/bin/varnishd/cache/cache_vcl.c
@@ -755,7 +755,7 @@ vcl_load(struct cli *cli, struct vrt_ctx *ctx,
 
 	VSB_clear(ctx->msg);
 	i = vcl_send_event(ctx, VCL_EVENT_LOAD);
-	if (i) {
+	if (i || *ctx->handling != VCL_RET_OK) {
 		vcl_cancel_load(ctx, cli, name, "initialization");
 		return;
 	}
@@ -1054,7 +1054,7 @@ vcl_call_method(struct worker *wrk, struct req *req, struct busyobj *bo,
 	wrk->seen_methods |= method;
 	AN(vsl);
 	VSLb(vsl, SLT_VCL_call, "%s", VCL_Method_Name(method));
-	(void)func(&ctx);
+	func(&ctx);
 	VSLb(vsl, SLT_VCL_return, "%s", VCL_Return_Name(wrk->handling));
 	wrk->cur_method |= 1;		// Magic marker
 
diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py
index d4bd61c..c71fc1b 100755
--- a/lib/libvcc/generate.py
+++ b/lib/libvcc/generate.py
@@ -1102,7 +1102,7 @@ enum vcl_event_e {
 typedef int vcl_event_f(VRT_CTX, enum vcl_event_e);
 typedef int vcl_init_f(VRT_CTX);
 typedef void vcl_fini_f(VRT_CTX);
-typedef int vcl_func_f(VRT_CTX);
+typedef void vcl_func_f(VRT_CTX);
 """)
 
 
diff --git a/lib/libvcc/vcc_action.c b/lib/libvcc/vcc_action.c
index 9e45f58..fb8d97b 100644
--- a/lib/libvcc/vcc_action.c
+++ b/lib/libvcc/vcc_action.c
@@ -47,8 +47,7 @@ parse_call(struct vcc *tl)
 	ExpectErr(tl, ID);
 	vcc_AddCall(tl, tl->t);
 	vcc_AddRef(tl, tl->t, SYM_SUB);
-	Fb(tl, 1, "if (VGC_function_%.*s(ctx))\n", PF(tl->t));
-	Fb(tl, 1, "\treturn (1);\n");
+	Fb(tl, 1, "VGC_function_%.*s(ctx);\n", PF(tl->t));
 	vcc_NextToken(tl);
 }
 
@@ -325,7 +324,6 @@ parse_return(struct vcc *tl)
 	}
 	ERRCHK(tl);
 	Fb(tl, 1, "VRT_handling(ctx, VCL_RET_%s);\n", h);
-	Fb(tl, 1, "return (1);\n");
 	ExpectErr(tl, ')');
 	vcc_NextToken(tl);
 }
diff --git a/lib/libvcc/vcc_compile.c b/lib/libvcc/vcc_compile.c
index 9de5eac..16a29d1 100644
--- a/lib/libvcc/vcc_compile.c
+++ b/lib/libvcc/vcc_compile.c
@@ -310,10 +310,7 @@ EmitInitFini(const struct vcc *tl)
 			has_event = 1;
 	}
 
-	Fc(tl, 0, "\t(void)VGC_function_vcl_init(ctx);\n");
-	Fc(tl, 0, "\tif (*ctx->handling == 0)\n");
-	Fc(tl, 0, "\t\tVRT_handling(ctx, VCL_RET_OK);\n");
-	Fc(tl, 0, "\treturn (*ctx->handling == VCL_RET_OK ? 0: -1);\n");
+	Fc(tl, 0, "\treturn(0);\n");
 	Fc(tl, 0, "}\n");
 
 	/*
@@ -321,8 +318,6 @@ EmitInitFini(const struct vcc *tl)
 	 */
 	Fc(tl, 0, "\nstatic int\nVGC_Discard(VRT_CTX)\n{\n\n");
 
-	Fc(tl, 0, "\t(void)VGC_function_vcl_fini(ctx);\n\n");
-
 	Fc(tl, 0, "\tswitch (vgc_inistep) {\n\n");
 	VTAILQ_FOREACH_REVERSE(p, &tl->inifin, inifinhead, list) {
 		AZ(VSB_finish(p->fin));
@@ -336,7 +331,7 @@ EmitInitFini(const struct vcc *tl)
 		}
 		VSB_destroy(&p->fin);
 	}
-	Fc(tl, 0, "\t}\n\n");
+	Fc(tl, 0, "\t}\n");
 
 	Fc(tl, 0, "\treturn (0);\n");
 	Fc(tl, 0, "}\n");
@@ -558,6 +553,7 @@ vcc_CompileSource(struct vcc *tl, struct source *sp)
 	struct symbol *sym;
 	const struct var *v;
 	struct vsb *vsb;
+	struct inifin *ifp;
 	int i;
 
 	vcc_Expr_Init(tl);
@@ -639,14 +635,19 @@ vcc_CompileSource(struct vcc *tl, struct source *sp)
 	if (vcc_CheckUses(tl) || tl->err)
 		return (NULL);
 
+	/* Tie vcl_init/fini in */
+	ifp = New_IniFin(tl);
+	VSB_printf(ifp->ini, "\tVGC_function_vcl_init(ctx);");
+	VSB_printf(ifp->fin, "\t\tVGC_function_vcl_fini(ctx);");
+
 	/* Emit method functions */
 	Fh(tl, 1, "\n");
 	for (i = 1; i < VCL_MET_MAX; i++) {
 		Fh(tl, 1,
-		    "int __match_proto__(vcl_func_f) "
+		    "void __match_proto__(vcl_func_f) "
 		    "VGC_function_%s(VRT_CTX);\n",
 		    method_tab[i].name);
-		Fc(tl, 1, "\nint __match_proto__(vcl_func_f)\n");
+		Fc(tl, 1, "\nvoid __match_proto__(vcl_func_f)\n");
 		Fc(tl, 1,
 		    "VGC_function_%s(VRT_CTX)\n",
 		    method_tab[i].name);
@@ -659,7 +660,7 @@ vcc_CompileSource(struct vcc *tl, struct source *sp)
 		 */
 		Fc(tl, 1, "%s", VSB_data(tl->fm[i]));
 		if (method_tab[i].bitval == VCL_MET_INIT)
-			Fc(tl, 1, "  return (1);\n");
+			Fc(tl, 1, "  return;\n");
 		Fc(tl, 1, "}\n");
 	}
 
diff --git a/lib/libvcc/vcc_parse.c b/lib/libvcc/vcc_parse.c
index ff7334c..6e28970 100644
--- a/lib/libvcc/vcc_parse.c
+++ b/lib/libvcc/vcc_parse.c
@@ -196,7 +196,7 @@ vcc_Compound(struct vcc *tl)
 			vcc_ErrWhere(tl, tl->t);
 			return;
 		}
-		Fb(tl, 1, "if (*ctx->handling) return(1);\n");
+		Fb(tl, 1, "if (*ctx->handling) return;\n");
 	}
 }
 
@@ -246,9 +246,8 @@ vcc_ParseFunction(struct vcc *tl)
 			return;
 		}
 		tl->curproc = vcc_AddProc(tl, tl->t);
-		Fh(tl, 0, "int VGC_function_%.*s "
-		    "(VRT_CTX);\n", PF(tl->t));
-		Fc(tl, 1, "\nint __match_proto__(vcl_func_t)\n");
+		Fh(tl, 0, "void VGC_function_%.*s(VRT_CTX);\n", PF(tl->t));
+		Fc(tl, 1, "\nvoid __match_proto__(vcl_func_t)\n");
 		Fc(tl, 1, "VGC_function_%.*s(VRT_CTX)\n",
 		    PF(tl->t));
 	}
@@ -256,13 +255,6 @@ vcc_ParseFunction(struct vcc *tl)
 	tl->indent += INDENT;
 	Fb(tl, 1, "{\n");
 	L(tl, vcc_Compound(tl));
-	if (m == -1) {
-		/*
-		 * non-method subroutines must have an explicit non-action
-		 * return in case they just fall through the bottom.
-		 */
-		Fb(tl, 1, "  return(0);\n");
-	}
 	Fb(tl, 1, "}\n");
 	tl->indent -= INDENT;
 	tl->fb = NULL;
diff --git a/lib/libvcc/vcc_vmod.c b/lib/libvcc/vcc_vmod.c
index c2c4742..c6e08c1 100644
--- a/lib/libvcc/vcc_vmod.c
+++ b/lib/libvcc/vcc_vmod.c
@@ -237,7 +237,7 @@ vcc_ParseImport(struct vcc *tl)
 			    p, PF(mod));
 			VSB_printf(ifp->fin,
 			    "\t\t(void)%s(ctx, &vmod_priv_%.*s,\n"
-			    "\t\t    VCL_EVENT_DISCARD);\n", p, PF(mod));
+			    "\t\t\t    VCL_EVENT_DISCARD);\n", p, PF(mod));
 			VSB_printf(ifp->event, "\t%s(ctx, &vmod_priv_%.*s, ev)",
 			    p, PF(mod));
 		} else if (!strcmp(p, "$FUNC")) {



More information about the varnish-commit mailing list