Commit cb3cc7b3 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Allow multiple imports of the same VMOD, if the file_id is identical.

parent f70e31f5
...@@ -66,11 +66,6 @@ varnish v1 -cliok "vcl.discard vcl2" ...@@ -66,11 +66,6 @@ varnish v1 -cliok "vcl.discard vcl2"
varnish v1 -cliok "vcl.list" varnish v1 -cliok "vcl.list"
varnish v1 -cliok "debug.vmod" 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.} { varnish v1 -errvcl {Symbol type (vmod) can not be used in expression.} {
import std; import std;
......
...@@ -163,6 +163,7 @@ vcc_ParseImport(struct vcc *tl) ...@@ -163,6 +163,7 @@ vcc_ParseImport(struct vcc *tl)
struct symbol *msym; struct symbol *msym;
const struct vmod_data *vmd; const struct vmod_data *vmd;
struct vjsn *vj; struct vjsn *vj;
int again = 0;
t1 = tl->t; t1 = tl->t;
SkipToken(tl, ID); /* "import" */ SkipToken(tl, ID); /* "import" */
...@@ -182,19 +183,15 @@ vcc_ParseImport(struct vcc *tl) ...@@ -182,19 +183,15 @@ vcc_ParseImport(struct vcc *tl)
return; return;
} }
if (msym != NULL) { if (msym != NULL) {
VSB_printf(tl->sb, "Module %.*s already imported.\n", again = 1;
PF(mod)); } else {
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;
}
msym = VCC_SymbolGet(tl, SYM_VMOD, SYMTAB_CREATE, XREF_NONE); msym = VCC_SymbolGet(tl, SYM_VMOD, SYMTAB_CREATE, XREF_NONE);
ERRCHK(tl); ERRCHK(tl);
AN(msym); AN(msym);
msym->def_b = t1; msym->def_b = t1;
msym->def_e = tl->t; msym->def_e = tl->t;
}
if (tl->t->tok == ID) { if (tl->t->tok == ID) {
if (!vcc_IdIs(tl->t, "from")) { if (!vcc_IdIs(tl->t, "from")) {
...@@ -223,6 +220,10 @@ vcc_ParseImport(struct vcc *tl) ...@@ -223,6 +220,10 @@ vcc_ParseImport(struct vcc *tl)
SkipToken(tl, ';'); SkipToken(tl, ';');
if (!again)
msym->def_e = tl->t;
if (VFIL_searchpath(tl->vmod_path, if (VFIL_searchpath(tl->vmod_path,
vcc_path_dlopen, &hdl, fn, &fnpx)) { vcc_path_dlopen, &hdl, fn, &fnpx)) {
VSB_printf(tl->sb, "Could not load VMOD %.*s\n", PF(mod)); VSB_printf(tl->sb, "Could not load VMOD %.*s\n", PF(mod));
...@@ -287,6 +288,19 @@ vcc_ParseImport(struct vcc *tl) ...@@ -287,6 +288,19 @@ vcc_ParseImport(struct vcc *tl)
return; 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); ifp = New_IniFin(tl);
VSB_printf(ifp->ini, "\tif (VRT_Vmod_Init(ctx,\n"); VSB_printf(ifp->ini, "\tif (VRT_Vmod_Init(ctx,\n");
...@@ -317,6 +331,7 @@ vcc_ParseImport(struct vcc *tl) ...@@ -317,6 +331,7 @@ vcc_ParseImport(struct vcc *tl)
AN(vj); AN(vj);
msym->eval_priv = vj; msym->eval_priv = vj;
msym->wildcard = vcc_json_wildcard; msym->wildcard = vcc_json_wildcard;
msym->extra = TlDup(tl, vmd->file_id);
vcc_json_always(tl, msym); vcc_json_always(tl, msym);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment