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"
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;
......
......@@ -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);
......
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