[master] cb3cc7b Allow multiple imports of the same VMOD, if the file_id is identical.
Poul-Henning Kamp
phk at FreeBSD.org
Wed May 30 07:06:23 UTC 2018
commit cb3cc7b39a45119d62cebc0d9bcc41c32582737b
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed May 30 07:05:24 2018 +0000
Allow multiple imports of the same VMOD, if the file_id is identical.
diff --git a/bin/varnishtest/tests/m00001.vtc b/bin/varnishtest/tests/m00001.vtc
index 7c79f89..6e07812 100644
--- a/bin/varnishtest/tests/m00001.vtc
+++ b/bin/varnishtest/tests/m00001.vtc
@@ -66,11 +66,6 @@ varnish v1 -cliok "vcl.discard vcl2"
varnish v1 -cliok "vcl.list"
varnish v1 -cliok "debug.vmod"
-varnish v1 -errvcl {Module std already imported.} {
- import std;
- import std;
-}
-
varnish v1 -errvcl {Symbol type (vmod) can not be used in expression.} {
import std;
diff --git a/lib/libvcc/vcc_vmod.c b/lib/libvcc/vcc_vmod.c
index 1699ff7..f34b0f3 100644
--- a/lib/libvcc/vcc_vmod.c
+++ b/lib/libvcc/vcc_vmod.c
@@ -163,6 +163,7 @@ vcc_ParseImport(struct vcc *tl)
struct symbol *msym;
const struct vmod_data *vmd;
struct vjsn *vj;
+ int again = 0;
t1 = tl->t;
SkipToken(tl, ID); /* "import" */
@@ -182,19 +183,15 @@ vcc_ParseImport(struct vcc *tl)
return;
}
if (msym != 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, msym->def_b, msym->def_e);
- return;
- }
+ again = 1;
+ } else {
- msym = VCC_SymbolGet(tl, SYM_VMOD, SYMTAB_CREATE, XREF_NONE);
- ERRCHK(tl);
- AN(msym);
- msym->def_b = t1;
- msym->def_e = tl->t;
+ msym = VCC_SymbolGet(tl, SYM_VMOD, SYMTAB_CREATE, XREF_NONE);
+ ERRCHK(tl);
+ AN(msym);
+ msym->def_b = t1;
+ msym->def_e = tl->t;
+ }
if (tl->t->tok == ID) {
if (!vcc_IdIs(tl->t, "from")) {
@@ -223,6 +220,10 @@ vcc_ParseImport(struct vcc *tl)
SkipToken(tl, ';');
+ if (!again)
+ msym->def_e = tl->t;
+
+
if (VFIL_searchpath(tl->vmod_path,
vcc_path_dlopen, &hdl, fn, &fnpx)) {
VSB_printf(tl->sb, "Could not load VMOD %.*s\n", PF(mod));
@@ -287,6 +288,19 @@ vcc_ParseImport(struct vcc *tl)
return;
}
+ if (again && strcmp(vmd->file_id, msym->extra)) {
+ VSB_printf(tl->sb,
+ "Different version of 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, msym->def_b, msym->def_e);
+ }
+ if (again) {
+ AZ(dlclose(hdl));
+ return;
+ }
+
ifp = New_IniFin(tl);
VSB_printf(ifp->ini, "\tif (VRT_Vmod_Init(ctx,\n");
@@ -317,6 +331,7 @@ vcc_ParseImport(struct vcc *tl)
AN(vj);
msym->eval_priv = vj;
msym->wildcard = vcc_json_wildcard;
+ msym->extra = TlDup(tl, vmd->file_id);
vcc_json_always(tl, msym);
More information about the varnish-commit
mailing list