[master] b3484a4 Catch redefinition of non-method sub's early.

Poul-Henning Kamp phk at varnish-cache.org
Mon May 23 09:58:07 CEST 2011


commit b3484a49f736c8457756a6d24d553d27cae60113
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon May 23 07:57:46 2011 +0000

    Catch redefinition of non-method sub's early.

diff --git a/bin/varnishtest/tests/v00034.vtc b/bin/varnishtest/tests/v00034.vtc
new file mode 100644
index 0000000..c73994b
--- /dev/null
+++ b/bin/varnishtest/tests/v00034.vtc
@@ -0,0 +1,15 @@
+varnishtest "Test sub redefinition"
+
+server s1 {
+	rxreq
+	txresp
+} -start
+
+varnish v1 -vcl+backend { } -start
+
+varnish v1 -badvcl {
+	backend foo { .host = "127.0.0.1"; }
+	sub c1 { }
+	sub c1 { }
+	sub vcl_recv { call c1; }
+}
diff --git a/lib/libvcl/vcc_compile.h b/lib/libvcl/vcc_compile.h
index df2c01f..09138b9 100644
--- a/lib/libvcl/vcc_compile.h
+++ b/lib/libvcl/vcc_compile.h
@@ -310,7 +310,7 @@ void vcc_VarVal(struct vcc *tl, const struct var *vp,
 void vcc_ParseImport(struct vcc *tl);
 
 /* vcc_xref.c */
-void vcc_AddDef(struct vcc *tl, const struct token *t, enum symkind type);
+int vcc_AddDef(struct vcc *tl, const struct token *t, enum symkind type);
 void vcc_AddRef(struct vcc *tl, const struct token *t, enum symkind type);
 int vcc_CheckReferences(struct vcc *tl);
 
diff --git a/lib/libvcl/vcc_parse.c b/lib/libvcl/vcc_parse.c
index 8f694d3..5636b71 100644
--- a/lib/libvcl/vcc_parse.c
+++ b/lib/libvcl/vcc_parse.c
@@ -194,7 +194,7 @@ vcc_Compound(struct vcc *tl)
 static void
 vcc_Function(struct vcc *tl)
 {
-	int m;
+	int m, i;
 
 	vcc_NextToken(tl);
 	ExpectErr(tl, ID);
@@ -214,7 +214,13 @@ vcc_Function(struct vcc *tl)
 		Fb(tl, 0, " */\n");
 	} else {
 		tl->fb = tl->fc;
-		vcc_AddDef(tl, tl->t, SYM_SUB);
+		i = vcc_AddDef(tl, tl->t, SYM_SUB);
+		if (i > 1) {
+			vsb_printf(tl->sb,
+			    "Function %.*s redefined\n", PF(tl->t));
+			vcc_ErrWhere(tl, tl->t);
+			return;
+		}
 		tl->curproc = vcc_AddProc(tl, tl->t);
 		Fh(tl, 0, "static int VGC_function_%.*s (struct sess *sp);\n",
 		    PF(tl->t));
diff --git a/lib/libvcl/vcc_xref.c b/lib/libvcl/vcc_xref.c
index 17b3a8a..3cd2627 100644
--- a/lib/libvcl/vcc_xref.c
+++ b/lib/libvcl/vcc_xref.c
@@ -87,7 +87,7 @@ vcc_AddRef(struct vcc *tl, const struct token *t, enum symkind kind)
 	sym->nref++;
 }
 
-void
+int
 vcc_AddDef(struct vcc *tl, const struct token *t, enum symkind kind)
 {
 	struct symbol *sym;
@@ -95,6 +95,7 @@ vcc_AddDef(struct vcc *tl, const struct token *t, enum symkind kind)
 	sym = VCC_GetSymbolTok(tl, t, kind);
 	AN(sym);
 	sym->ndef++;
+	return (sym->ndef);
 }
 
 /*--------------------------------------------------------------------*/



More information about the varnish-commit mailing list