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

Rename struct vmod_open to vmod_import and keep it around.

parent fbf2c986
...@@ -42,11 +42,12 @@ ...@@ -42,11 +42,12 @@
#include "vmod_abi.h" #include "vmod_abi.h"
#include "vsb.h" #include "vsb.h"
struct vmod_open { struct vmod_import {
unsigned magic; unsigned magic;
#define VMOD_OPEN_MAGIC 0x9995b1f3 #define VMOD_IMPORT_MAGIC 0x31803a5d
void *hdl; void *hdl;
const char *err; const char *err;
const struct vmod_data *vmd;
}; };
struct vmod_obj { struct vmod_obj {
...@@ -60,14 +61,14 @@ struct vmod_obj { ...@@ -60,14 +61,14 @@ struct vmod_obj {
static int static int
vcc_path_dlopen(void *priv, const char *fn) vcc_path_dlopen(void *priv, const char *fn)
{ {
struct vmod_open *vop; struct vmod_import *vim;
CAST_OBJ_NOTNULL(vop, priv, VMOD_OPEN_MAGIC); CAST_OBJ_NOTNULL(vim, priv, VMOD_IMPORT_MAGIC);
AN(fn); AN(fn);
vop->hdl = dlopen(fn, RTLD_NOW | RTLD_LOCAL); vim->hdl = dlopen(fn, RTLD_NOW | RTLD_LOCAL);
if (vop->hdl == NULL) { if (vim->hdl == NULL) {
vop->err = dlerror(); vim->err = dlerror();
return (-1); return (-1);
} }
return (0); return (0);
...@@ -377,9 +378,9 @@ vcc_ParseImport(struct vcc *tl) ...@@ -377,9 +378,9 @@ vcc_ParseImport(struct vcc *tl)
struct symbol *msym, *vsym; struct symbol *msym, *vsym;
const struct vmod_data *vmd; const struct vmod_data *vmd;
struct vjsn *vj; struct vjsn *vj;
struct vmod_open vop[1]; struct vmod_import *vim;
const struct vmod_import *vimold;
INIT_OBJ(vop, VMOD_OPEN_MAGIC);
t1 = tl->t; t1 = tl->t;
SkipToken(tl, ID); /* "import" */ SkipToken(tl, ID); /* "import" */
...@@ -425,8 +426,11 @@ vcc_ParseImport(struct vcc *tl) ...@@ -425,8 +426,11 @@ vcc_ParseImport(struct vcc *tl)
SkipToken(tl, ';'); SkipToken(tl, ';');
if (VFIL_searchpath(tl->vmod_path, vcc_path_dlopen, vop, fn, &fnpx)) { ALLOC_OBJ(vim, VMOD_IMPORT_MAGIC);
if (vop->err == NULL) { AN(vim);
if (VFIL_searchpath(tl->vmod_path, vcc_path_dlopen, vim, fn, &fnpx)) {
if (vim->err == NULL) {
VSB_printf(tl->sb, VSB_printf(tl->sb,
"Could not find VMOD %.*s\n", PF(mod)); "Could not find VMOD %.*s\n", PF(mod));
} else { } else {
...@@ -434,22 +438,25 @@ vcc_ParseImport(struct vcc *tl) ...@@ -434,22 +438,25 @@ vcc_ParseImport(struct vcc *tl)
"Could not open VMOD %.*s\n", PF(mod)); "Could not open VMOD %.*s\n", PF(mod));
VSB_printf(tl->sb, "\tFile name: %s\n", VSB_printf(tl->sb, "\tFile name: %s\n",
fnpx != NULL ? fnpx : fn); fnpx != NULL ? fnpx : fn);
VSB_printf(tl->sb, "\tdlerror: %s\n", vop->err); VSB_printf(tl->sb, "\tdlerror: %s\n", vim->err);
} }
vcc_ErrWhere(tl, mod); vcc_ErrWhere(tl, mod);
free(fnpx); free(fnpx);
FREE_OBJ(vim);
return; return;
} }
vmd = vcc_VmodSanity(tl, vop->hdl, mod, fnpx); vmd = vcc_VmodSanity(tl, vim->hdl, mod, fnpx);
if (vmd == NULL || tl->err) { if (vmd == NULL || tl->err) {
AZ(dlclose(vop->hdl)); AZ(dlclose(vim->hdl));
free(fnpx); free(fnpx);
FREE_OBJ(vim);
return; return;
} }
if (msym->extra != NULL) { CAST_OBJ(vimold, (const void*)(msym->extra), VMOD_IMPORT_MAGIC);
if (!strcmp(msym->extra, vmd->file_id)) { if (vimold != NULL) {
if (!strcmp(vimold->vmd->file_id, vmd->file_id)) {
/* Identical import is OK */ /* Identical import is OK */
} else { } else {
VSB_printf(tl->sb, VSB_printf(tl->sb,
...@@ -457,8 +464,9 @@ vcc_ParseImport(struct vcc *tl) ...@@ -457,8 +464,9 @@ vcc_ParseImport(struct vcc *tl)
PF(tmod)); PF(tmod));
vcc_ErrWhere2(tl, t1, tl->t); vcc_ErrWhere2(tl, t1, tl->t);
} }
AZ(dlclose(vop->hdl)); AZ(dlclose(vim->hdl));
free(fnpx); free(fnpx);
FREE_OBJ(vim);
return; return;
} }
msym->def_b = t1; msym->def_b = t1;
...@@ -466,14 +474,17 @@ vcc_ParseImport(struct vcc *tl) ...@@ -466,14 +474,17 @@ vcc_ParseImport(struct vcc *tl)
VTAILQ_FOREACH(vsym, &tl->sym_vmods, sideways) { VTAILQ_FOREACH(vsym, &tl->sym_vmods, sideways) {
assert(vsym->kind == SYM_VMOD); assert(vsym->kind == SYM_VMOD);
if (!strcmp(vsym->extra, vmd->file_id)) { CAST_OBJ_NOTNULL(vimold, (const void*)(vsym->extra),
VMOD_IMPORT_MAGIC);
if (!strcmp(vimold->vmd->file_id, vmd->file_id)) {
/* Already loaded under different name */ /* Already loaded under different name */
msym->eval_priv = vsym->eval_priv; msym->eval_priv = vsym->eval_priv;
msym->extra = vsym->extra; msym->extra = vsym->extra;
msym->vmod_name = vsym->vmod_name; msym->vmod_name = vsym->vmod_name;
vcc_VmodSymbols(tl, msym); vcc_VmodSymbols(tl, msym);
AZ(dlclose(vop->hdl)); AZ(dlclose(vim->hdl));
free(fnpx); free(fnpx);
FREE_OBJ(vim);
return; return;
} }
} }
...@@ -516,7 +527,8 @@ vcc_ParseImport(struct vcc *tl) ...@@ -516,7 +527,8 @@ vcc_ParseImport(struct vcc *tl)
XXXAZ(p); XXXAZ(p);
AN(vj); AN(vj);
msym->eval_priv = vj; msym->eval_priv = vj;
msym->extra = TlDup(tl, vmd->file_id); vim->vmd = vmd;
msym->extra = (const char *)vim;
msym->vmod_name = TlDup(tl, vmd->name); msym->vmod_name = TlDup(tl, vmd->name);
vcc_VmodSymbols(tl, msym); vcc_VmodSymbols(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