r5201 - in trunk/varnish-cache: bin/varnishtest/tests lib/libvcl

phk at varnish-cache.org phk at varnish-cache.org
Tue Sep 14 09:31:05 CEST 2010


Author: phk
Date: 2010-09-14 09:31:05 +0200 (Tue, 14 Sep 2010)
New Revision: 5201

Modified:
   trunk/varnish-cache/bin/varnishtest/tests/m00001.vtc
   trunk/varnish-cache/lib/libvcl/vcc_compile.h
   trunk/varnish-cache/lib/libvcl/vcc_vmod.c
Log:
Give VCC symbols a kind, and use SYM_VMOD to complain if a VMOD is
attempted imported more than once.



Modified: trunk/varnish-cache/bin/varnishtest/tests/m00001.vtc
===================================================================
--- trunk/varnish-cache/bin/varnishtest/tests/m00001.vtc	2010-09-13 19:52:12 UTC (rev 5200)
+++ trunk/varnish-cache/bin/varnishtest/tests/m00001.vtc	2010-09-14 07:31:05 UTC (rev 5201)
@@ -48,3 +48,9 @@
 varnish v1 -cliok "debug.vmod"
 
 varnish v1 -expect vmods == 0
+
+varnish v1 -badvcl {
+	import std from "${topbuild}/lib/libvmod_std/.libs/libvmod_std.so.1" ;
+	import std from "${topbuild}/lib/libvmod_std/.libs/libvmod_std.so.1" ;
+}
+

Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_compile.h	2010-09-13 19:52:12 UTC (rev 5200)
+++ trunk/varnish-cache/lib/libvcl/vcc_compile.h	2010-09-14 07:31:05 UTC (rev 5201)
@@ -68,17 +68,31 @@
 	char			*dec;
 };
 
+enum symkind {
+	SYM_NONE,
+	SYM_VAR,
+	SYM_FUNC,
+	SYM_PROC,
+	SYM_VMOD
+};
+
 struct symbol {
 	unsigned			magic;
 #define SYMBOL_MAGIC			0x3368c9fb
 	VTAILQ_ENTRY(symbol)		list;
+
 	char				*name;
 	unsigned			nlen;
 	unsigned			wildcard;
+
+	enum symkind			kind;
+	enum var_type			fmt;
+
+	struct token			*def_b, *def_e;
+
 	const char			*cfunc;
 	const char			*args;
 	const struct var		*var;
-	enum var_type			fmt;
 	unsigned			r_methods;
 };
 

Modified: trunk/varnish-cache/lib/libvcl/vcc_vmod.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_vmod.c	2010-09-13 19:52:12 UTC (rev 5200)
+++ trunk/varnish-cache/lib/libvcl/vcc_vmod.c	2010-09-14 07:31:05 UTC (rev 5201)
@@ -46,20 +46,45 @@
 {
 	void *hdl;
 	char fn[1024];
-	struct token *mod;
+	struct token *mod, *t1;
 	const char *modname;
 	const char *proto;
 	const char **spec;
 	struct symbol *sym;
+	const struct symbol *osym;
 	const char *p;
 	// int *modlen;
 
-	SkipToken(tl, ID);
+	t1 = tl->t;
+	SkipToken(tl, ID);		/* "import" */
 
 	ExpectErr(tl, ID);
 	mod = tl->t;
+
 	vcc_NextToken(tl);
 
+	osym = VCC_FindSymbol(tl, mod);
+	if (osym != NULL && osym->kind != SYM_VMOD) {
+		vsb_printf(tl->sb, "Module %.*s conflics with other symbol.\n",
+		    PF(mod));
+		vcc_ErrWhere2(tl, t1, tl->t);
+		return;
+	}
+	if (osym != NULL) {
+		vsb_printf(tl->sb, "Module %.*s already imported.\n", 
+		    PF(mod));
+		vcc_ErrWhere2(tl, t1, tl->t);
+		vsb_printf(tl->sb, "Previous import was here:\n");
+		vcc_ErrWhere2(tl, osym->def_b, osym->def_e);
+		return;
+	}
+
+	bprintf(fn, "%.*s", PF(mod));
+	sym = VCC_AddSymbol(tl, fn);
+	sym->kind = SYM_VMOD;
+	sym->def_b = t1;
+	sym->def_e = tl->t;
+
 	if (tl->t->tok == ID) {
 		vcc_NextToken(tl);
 		ExpectErr(tl, CSTR);




More information about the varnish-commit mailing list