Commit 2feafdcf authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Move the VMOD C-prototypes into the JSON data.

parent 2a7ea235
......@@ -132,7 +132,7 @@ VPI_Vmod_Init(VRT_CTX, struct vmod **hdl, unsigned nbr, void *ptr, int len,
strcmp(d->name, nm) ||
d->func == NULL ||
d->func_len <= 0 ||
d->proto == NULL ||
d->proto != NULL ||
d->json == NULL) {
VSB_printf(ctx->msg, "Loading vmod %s from %s (%s):\n",
nm, backup, path);
......
......@@ -58,6 +58,7 @@
* binary/load-time compatible, increment MAJOR version
*
* NEXT (2022-09-15)
* C-prototypes moved into JSON
* VRT_AddVDP() deprecated
* VRT_AddVFP() deprecated
* VRT_RemoveVDP() deprecated
......
......@@ -164,6 +164,7 @@ vcc_json_always(struct vcc *tl, const struct vjsn *vj, const char *vmod_name)
struct inifin *ifp;
const struct vjsn_val *vv, *vv2;
double vmod_syntax = 0.0;
int cproto_seen = 0;
AN(vj);
AN(vmod_name);
......@@ -197,6 +198,8 @@ vcc_json_always(struct vcc *tl, const struct vjsn *vj, const char *vmod_name)
} else if (!strcmp(vv2->value, "$ALIAS")) {
} else if (!strcmp(vv2->value, "$FUNC")) {
} else if (!strcmp(vv2->value, "$OBJ")) {
} else if (!strcmp(vv2->value, "$CPROTO")) {
cproto_seen = 1;
} else {
VTAILQ_FOREACH(vv2, &vv->children, list)
fprintf(stderr, "\tt %s n %s v %s\n",
......@@ -204,6 +207,8 @@ vcc_json_always(struct vcc *tl, const struct vjsn *vj, const char *vmod_name)
WRONG("Vmod JSON syntax error");
}
}
if (!cproto_seen)
WRONG("Vmod JSON has no CPROTO");
}
static const struct vmod_data *
......@@ -244,7 +249,8 @@ vcc_VmodSanity(struct vcc *tl, void *hdl, const struct token *mod, char *fnp)
if (vmd->name == NULL ||
vmd->func == NULL ||
vmd->func_len <= 0 ||
vmd->proto == NULL ||
vmd->json == NULL ||
vmd->proto != NULL ||
vmd->abi == NULL) {
VSB_printf(tl->sb, "Mangled VMOD %.*s\n", PF(mod));
VSB_printf(tl->sb, "\tFile name: %s\n", fnp);
......@@ -335,6 +341,32 @@ vcc_VmodSymbols(struct vcc *tl, const struct symbol *sym)
}
}
static void
vcc_emit_c_prototypes(const struct vcc *tl, const struct vjsn *vj)
{
const struct vjsn_val *vv, *vv2, *vv3;
Fh(tl, 0, "\n");
vv = vj->value;
assert (vjsn_is_array(vv));
vv3 = NULL;
VTAILQ_FOREACH(vv2, &vv->children, list) {
assert (vjsn_is_array(vv2));
vv3 = VTAILQ_FIRST(&vv2->children);
assert (vjsn_is_string(vv3));
if (!strcmp(vv3->value, "$CPROTO"))
break;
}
assert(vv3 != NULL);
while (1) {
vv3 = VTAILQ_NEXT(vv3, list);
if (vv3 == NULL)
break;
assert (vjsn_is_string(vv3));
Fh(tl, 0, "%s\n", vv3->value);
}
}
void
vcc_ParseImport(struct vcc *tl)
{
......@@ -493,7 +525,7 @@ vcc_ParseImport(struct vcc *tl)
Fh(tl, 0, "\n/* --- BEGIN VMOD %.*s --- */\n\n", PF(mod));
Fh(tl, 0, "static struct vmod *VGC_vmod_%.*s;\n", PF(mod));
Fh(tl, 0, "static struct vmod_priv vmod_priv_%.*s;\n", PF(mod));
Fh(tl, 0, "\n%s\n", vmd->proto);
vcc_emit_c_prototypes(tl, vj);
Fh(tl, 0, "\n/* --- END VMOD %.*s --- */\n\n", PF(mod));
free(fnpx);
}
......
......@@ -1084,24 +1084,22 @@ class vcc(object):
fmt_cstruct(fo, '.enum_%s =' % j, '&VENUM(%s),' % j)
fo.write("};\n")
def vmod_proto(self, fo, fnx):
fo.write("\nstatic const char Vmod_Proto[] =\n")
for i in open(fnx):
fo.write('\t"%s\\n"\n' % i.rstrip())
fo.write('\t"static struct %s %s;";\n' % (self.csn, self.csn))
def iter_json(self):
def iter_json(self, fnx):
jl = [["$VMOD", "1.0"]]
jl.append(["$CPROTO"])
for i in open(fnx):
jl[-1].append(i.rstrip())
jl[-1].append("static struct %s %s;" % (self.csn, self.csn))
for j in self.contents:
j.json(jl)
for i in json.dumps(jl, indent=2, separators=(",", ": ")).splitlines():
yield i + " "
def json(self, fo):
def json(self, fo, fnx):
fo.write("\nstatic const char Vmod_Json[] = {\n")
for i in self.iter_json():
for i in self.iter_json(fnx):
fo.write('\t"')
for j in i:
if j in '"\\':
......@@ -1127,7 +1125,6 @@ class vcc(object):
fo.write('\t.func =\t\t&%s,\n' % self.csn)
fo.write('\t.func_len =\tsizeof(%s),\n' % self.csn)
fo.write('\t.func_name =\t"%s",\n' % self.csn)
fo.write('\t.proto =\tVmod_Proto,\n')
fo.write('\t.json =\t\tVmod_Json,\n')
fo.write('\t.abi =\t\tVMOD_ABI_Version,\n')
fo.write("\t.file_id =\t\"%s\",\n" % self.file_id)
......@@ -1176,9 +1173,7 @@ class vcc(object):
fx.close()
self.vmod_proto(fo, fnx)
self.json(fo)
self.json(fo, fnx)
self.vmod_data(fo)
......
......@@ -1087,7 +1087,7 @@ const struct vmod_data Vmod_wrong2_Data = {
.func = foo_struct,
.func_len = sizeof foo_struct,
.func_name = "foo_struct",
.proto = "blablabla",
.json = "blablabla",
};
extern const struct vmod_data Vmod_wrong3_Data;
......@@ -1098,7 +1098,7 @@ const struct vmod_data Vmod_wrong3_Data = {
.func = foo_struct,
.func_len = sizeof foo_struct,
.func_name = "foo_struct",
.proto = "blablabla",
.json = "blablabla",
.abi = "abiblabla",
};
......
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