Mailing List Archive

[master] c1ad57b12 Change the VJSN API to work on OSX
commit c1ad57b12f6e1c585af4560eec3a6d1ba0de1cc2
Author: Poul-Henning Kamp <phk@FreeBSD.org>
Date: Tue Oct 26 17:58:41 2021 +0000

Change the VJSN API to work on OSX

When VJSN is both in libvarnish and libvarnishapi, as in varnishtest,
you would think one of them took precedence, but not so on OSX.

In the shlib (libvarnishapi) text (code) symbols come from the version
in the main binary (varnishtest) which got it from libvarnish, whereas
the data symbols come from the version in libvarnishapi, so we now
hide the data symbols behind code.

diff --git a/bin/varnishadm/varnishadm.c b/bin/varnishadm/varnishadm.c
index 1a7f7c00c..306564416 100644
--- a/bin/varnishadm/varnishadm.c
+++ b/bin/varnishadm/varnishadm.c
@@ -258,21 +258,21 @@ command_generator (const char *text, int state)
free(answer);
AN(jsn_cmds);
AN(jsn_cmds->value);
- assert (jsn_cmds->value->type == VJSN_ARRAY);
+ assert (vjsn_is_array(jsn_cmds->value));
jv = VTAILQ_FIRST(&jsn_cmds->value->children);
- assert (jv->type == VJSN_NUMBER);
+ assert (vjsn_is_number(jv));
jv = VTAILQ_NEXT(jv, list);
- assert (jv->type == VJSN_ARRAY);
+ assert (vjsn_is_array(jv));
jv = VTAILQ_NEXT(jv, list);
- assert (jv->type == VJSN_NUMBER);
+ assert (vjsn_is_number(jv));
jv = VTAILQ_NEXT(jv, list);
}
while (jv != NULL) {
- assert (jv->type == VJSN_OBJECT);
+ assert (vjsn_is_object(jv));
jv2 = VTAILQ_FIRST(&jv->children);
AN(jv2);
jv = VTAILQ_NEXT(jv, list);
- assert (jv2->type == VJSN_STRING);
+ assert (vjsn_is_string(jv2));
assert (!strcmp(jv2->name, "request"));
if (!strncmp(text, jv2->value, strlen(text)))
return (strdup(jv2->value));
diff --git a/bin/varnishd/mgt/mgt_symtab.c b/bin/varnishd/mgt/mgt_symtab.c
index 88b9aa844..754a6d528 100644
--- a/bin/varnishd/mgt/mgt_symtab.c
+++ b/bin/varnishd/mgt/mgt_symtab.c
@@ -54,7 +54,7 @@ mgt_vcl_symtab_val(const struct vjsn_val *vv, const char *val)

jv = vjsn_child(vv, val);
AN(jv);
- assert(jv->type == VJSN_STRING);
+ assert(vjsn_is_string(jv));
AN(jv->value);
return (jv->value);
}
@@ -165,13 +165,13 @@ mgt_vcl_symtab(struct vclprog *vp, const char *input)
AZ(err);
AN(vj);
vp->symtab = vj;
- assert(vj->value->type == VJSN_ARRAY);
+ assert(vjsn_is_array(vj->value));
VTAILQ_FOREACH(v1, &vj->value->children, list) {
- assert(v1->type == VJSN_OBJECT);
+ assert(vjsn_is_object(v1));
v2 = vjsn_child(v1, "dir");
if (v2 == NULL)
continue;
- assert(v2->type == VJSN_STRING);
+ assert(vjsn_is_string(v2));
if (strcmp(v2->value, "import"))
continue;
typ = mgt_vcl_symtab_val(v1, "type");
diff --git a/include/vjsn.h b/include/vjsn.h
index 15a9eaa46..e4b8eb827 100644
--- a/include/vjsn.h
+++ b/include/vjsn.h
@@ -28,13 +28,14 @@
* SUCH DAMAGE.
*/

-extern const char VJSN_OBJECT[];
-extern const char VJSN_ARRAY[];
-extern const char VJSN_NUMBER[];
-extern const char VJSN_STRING[];
-extern const char VJSN_TRUE[];
-extern const char VJSN_FALSE[];
-extern const char VJSN_NULL[];
+#define VJSN_TYPES \
+ VJSN_TYPE_MACRO(OBJECT, object) \
+ VJSN_TYPE_MACRO(ARRAY, array) \
+ VJSN_TYPE_MACRO(NUMBER, number) \
+ VJSN_TYPE_MACRO(STRING, string) \
+ VJSN_TYPE_MACRO(TRUE, true) \
+ VJSN_TYPE_MACRO(FALSE, false) \
+ VJSN_TYPE_MACRO(NULL, null)

struct vjsn_val {
unsigned magic;
@@ -64,3 +65,8 @@ void vjsn_delete(struct vjsn **);
void vjsn_dump(const struct vjsn *js, FILE *fo);
void vjsn_dump_val(const struct vjsn_val *jsv, FILE *fo);
struct vjsn_val *vjsn_child(const struct vjsn_val *, const char *);
+
+#define VJSN_TYPE_MACRO(UPPER, lower) \
+ int vjsn_is_##lower(const struct vjsn_val *jsv);
+VJSN_TYPES
+#undef VJSN_TYPE_MACRO
diff --git a/lib/libvarnish/vjsn.c b/lib/libvarnish/vjsn.c
index 8b5444703..62163415a 100644
--- a/lib/libvarnish/vjsn.c
+++ b/lib/libvarnish/vjsn.c
@@ -43,13 +43,10 @@
#include "vqueue.h"
#include "vjsn.h"

-const char VJSN_OBJECT[] = "object";
-const char VJSN_ARRAY[] = "array";
-const char VJSN_NUMBER[] = "number";
-const char VJSN_STRING[] = "string";
-const char VJSN_TRUE[] = "true";
-const char VJSN_FALSE[] = "false";
-const char VJSN_NULL[] = "null";
+#define VJSN_TYPE_MACRO(UPPER, lower) \
+ static const char VJSN_##UPPER[] = #lower;
+VJSN_TYPES
+#undef VJSN_TYPE_MACRO

#define VJSN_EXPECT(js, xxx, ret) \
do { \
@@ -504,6 +501,17 @@ vjsn_dump(const struct vjsn *js, FILE *fo)
vjsn_dump_i(js->value, fo, 0);
}

+#define VJSN_TYPE_MACRO(UPPER, lower) \
+ int \
+ vjsn_is_##lower(const struct vjsn_val *jsv) \
+ { \
+ CHECK_OBJ_NOTNULL(jsv, VJSN_VAL_MAGIC); \
+ return (jsv->type == VJSN_##UPPER); \
+ }
+VJSN_TYPES
+#undef VJSN_TYPE_MACRO
+
+
#ifdef VJSN_TEST

/*
diff --git a/lib/libvarnishapi/vsc.c b/lib/libvarnishapi/vsc.c
index 2fdcfe740..4d2f65c03 100644
--- a/lib/libvarnishapi/vsc.c
+++ b/lib/libvarnishapi/vsc.c
@@ -237,7 +237,7 @@ vsc_fill_point(const struct vsc *vsc, const struct vsc_seg *seg,

vt = vjsn_child(vv, "name");
AN(vt);
- assert(vt->type == VJSN_STRING);
+ assert(vjsn_is_string(vt));

VSB_clear(vsb);
VSB_printf(vsb, "%s.%s", seg->fantom->ident, vt->value);
@@ -253,7 +253,7 @@ vsc_fill_point(const struct vsc *vsc, const struct vsc_seg *seg,
#define DOF(n, k) \
vt = vjsn_child(vv, k); \
AN(vt); \
- assert(vt->type == VJSN_STRING); \
+ assert(vjsn_is_string(vt)); \
point->point.n = vt->value;

DOF(ctype, "ctype");
@@ -262,7 +262,7 @@ vsc_fill_point(const struct vsc *vsc, const struct vsc_seg *seg,
#undef DOF
vt = vjsn_child(vv, "type");
AN(vt);
- assert(vt->type == VJSN_STRING);
+ assert(vjsn_is_string(vt));

if (!strcmp(vt->value, "counter")) {
point->point.semantics = 'c';
@@ -276,7 +276,7 @@ vsc_fill_point(const struct vsc *vsc, const struct vsc_seg *seg,

vt = vjsn_child(vv, "format");
AN(vt);
- assert(vt->type == VJSN_STRING);
+ assert(vjsn_is_string(vt));

if (!strcmp(vt->value, "integer")) {
point->point.format = 'i';
@@ -292,7 +292,7 @@ vsc_fill_point(const struct vsc *vsc, const struct vsc_seg *seg,

vt = vjsn_child(vv, "level");
AN(vt);
- assert(vt->type == VJSN_STRING);
+ assert(vjsn_is_string(vt));

if (!strcmp(vt->value, "info")) {
point->point.level = &levels[info];
diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index 598a283b4..1c601931c 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -496,7 +496,7 @@ vcc_func(struct vcc *tl, struct expr **e, const void *priv,
int n;

CAST_OBJ_NOTNULL(vv, priv, VJSN_VAL_MAGIC);
- assert(vv->type == VJSN_ARRAY);
+ assert(vjsn_is_array(vv));
vv = VTAILQ_FIRST(&vv->children);
rfmt = VCC_Type(VTAILQ_FIRST(&vv->children)->value);
AN(rfmt);
@@ -530,7 +530,7 @@ vcc_func(struct vcc *tl, struct expr **e, const void *priv,
}
VTAILQ_INIT(&head);
for (;vv != NULL; vv = VTAILQ_NEXT(vv, list)) {
- assert(vv->type == VJSN_ARRAY);
+ assert(vjsn_is_array(vv));
fa = calloc(1, sizeof *fa);
AN(fa);
fa->cname = cfunc;
@@ -559,7 +559,7 @@ vcc_func(struct vcc *tl, struct expr **e, const void *priv,
}
}
}
- if (sa != NULL && vvp != NULL && vvp->type == VJSN_TRUE) {
+ if (sa != NULL && vvp != NULL && vjsn_is_true(vvp)) {
fa->optional = 1;
vvp = VTAILQ_NEXT(vvp, list);
}
diff --git a/lib/libvcc/vcc_vmod.c b/lib/libvcc/vcc_vmod.c
index 496164f23..2b5ec5959 100644
--- a/lib/libvcc/vcc_vmod.c
+++ b/lib/libvcc/vcc_vmod.c
@@ -108,15 +108,15 @@ func_sym(struct vcc *tl, vcc_kind_t kind, const struct symbol *psym,

v = VTAILQ_NEXT(v, list);

- assert(v->type == VJSN_ARRAY);
+ assert(vjsn_is_array(v));
sym->action = vcc_Act_Call;
sym->vmod_name = psym->vmod_name;
sym->eval = vcc_Eval_SymFunc;
sym->eval_priv = v;
v = VTAILQ_FIRST(&v->children);
- assert(v->type == VJSN_ARRAY);
+ assert(vjsn_is_array(v));
v = VTAILQ_FIRST(&v->children);
- assert(v->type == VJSN_STRING);
+ assert(vjsn_is_string(v));
sym->type = VCC_Type(v->value);
AN(sym->type);
sym->r_methods = VCL_MET_TASK_ALL;
@@ -134,9 +134,9 @@ vcc_json_always(struct vcc *tl, const struct vjsn *vj, const char *vmod_name)
ifp = NULL;

VTAILQ_FOREACH(vv, &vj->value->children, list) {
- assert(vv->type == VJSN_ARRAY);
+ assert(vjsn_is_array(vv));
vv2 = VTAILQ_FIRST(&vv->children);
- assert(vv2->type == VJSN_STRING);
+ assert(vjsn_is_string(vv2));
if (!strcmp(vv2->value, "$VMOD")) {
vmod_syntax =
strtod(VTAILQ_NEXT(vv2, list)->value, NULL);
@@ -281,12 +281,12 @@ vcc_VmodSymbols(struct vcc *tl, const struct symbol *sym)
}

for (; vv != NULL; vv = VTAILQ_NEXT(vv, list)) {
- if (vv->type != VJSN_ARRAY)
+ if (!vjsn_is_array(vv))
continue;
vv1 = VTAILQ_FIRST(&vv->children);
- assert(vv1->type == VJSN_STRING);
+ assert(vjsn_is_string(vv1));
vv2 = VTAILQ_NEXT(vv1, list);
- if (vv2->type != VJSN_STRING)
+ if (!vjsn_is_string(vv2))
continue;

kind = vcc_vmod_kind(vv1->value);
@@ -499,9 +499,9 @@ vcc_Act_New(struct vcc *tl, struct token *t, struct symbol *sym)

vv = VTAILQ_NEXT(vv, list);
// vv = flags
- assert(vv->type == VJSN_OBJECT);
+ assert(vjsn_is_object(vv));
VTAILQ_FOREACH(vf, &vv->children, list)
- if (!strcmp(vf->name, "NULL_OK") && vf->type == VJSN_TRUE)
+ if (!strcmp(vf->name, "NULL_OK") && vjsn_is_true(vf))
null_ok = 1;
if (!null_ok)
VTAILQ_INSERT_TAIL(&tl->sym_objects, isym, sideways);
@@ -514,7 +514,7 @@ vcc_Act_New(struct vcc *tl, struct token *t, struct symbol *sym)

vf = VTAILQ_FIRST(&vv->children);
vv = VTAILQ_NEXT(vv, list);
- assert(vf->type == VJSN_STRING);
+ assert(vjsn_is_string(vf));
assert(!strcmp(vf->value, "$INIT"));

vf = VTAILQ_NEXT(vf, list);
@@ -530,7 +530,7 @@ vcc_Act_New(struct vcc *tl, struct token *t, struct symbol *sym)
isym->def_e = tl->t;

vf = VTAILQ_FIRST(&vv->children);
- assert(vf->type == VJSN_STRING);
+ assert(vjsn_is_string(vf));
assert(!strcmp(vf->value, "$FINI"));

vf = VTAILQ_NEXT(vf, list);
_______________________________________________
varnish-commit mailing list
varnish-commit@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-commit