Mailing List Archive

[master] 787a505a5 Add VMOD object methods to the symbol table
commit 787a505a545b56538a54da4b30f74c7faaa34c40
Author: Dridi Boukelmoune <dridi.boukelmoune@gmail.com>
Date: Fri Nov 29 16:40:25 2019 +0100

Add VMOD object methods to the symbol table

Although at this point we are still using the per-instance symbols from
the table.

For example with the following:

new fb1 = directors.fallback();
new fb2 = directors.fallback();

We will get the following entries in the symbol table:

object directors.fallback 41 41 directors.fallback
method VOID 40 41 directors.fallback.add_backend
method BACKEND 40 41 directors.fallback.backend
method VOID 40 41 directors.fallback.remove_backend
instance INSTANCE 41 41 fb1
func VOID 40 41 fb1.add_backend
func BACKEND 40 41 fb1.backend
func VOID 40 41 fb1.remove_backend
instance INSTANCE 41 41 fb2
func VOID 40 41 fb2.add_backend
func BACKEND 40 41 fb2.backend
func VOID 40 41 fb2.remove_backend

As long as the func symbols exist, and the instance symbols have the
generic type INSTANCE, the expression parser will not try to evaluate
the method symbols.

But the type-based symbols aren't ready to be evaluated yet so we can
have peaceful cohabitation for now. This makes this part of the code
even more complicated but it will eventually straighten up once the
SYM_FUNC symbols are gone.

diff --git a/lib/libvcc/vcc_vmod.c b/lib/libvcc/vcc_vmod.c
index acef1511b..0fc43bab2 100644
--- a/lib/libvcc/vcc_vmod.c
+++ b/lib/libvcc/vcc_vmod.c
@@ -244,7 +244,7 @@ vcc_VmodSymbols(struct vcc *tl, struct symbol *msym)
if (msym->kind == SYM_VMOD) {
CAST_OBJ_NOTNULL(vj, msym->eval_priv, VJSN_MAGIC);
vv = VTAILQ_FIRST(&vj->value->children);
- } else if (msym->kind == SYM_INSTANCE) {
+ } else if (msym->kind == SYM_INSTANCE || msym->kind == SYM_OBJECT) {
CAST_OBJ_NOTNULL(vv, msym->eval_priv, VJSN_VAL_MAGIC);
} else {
WRONG("symbol kind");
@@ -281,7 +281,8 @@ vcc_VmodSymbols(struct vcc *tl, struct symbol *msym)
*/

VSB_clear(buf);
- VSB_printf(buf, "%s.%s", msym->name, vv2->value);
+ VCC_SymName(buf, msym);
+ VSB_printf(buf, ".%s", vv2->value);
AZ(VSB_finish(buf));
fsym = VCC_MkSym(tl, VSB_data(buf), SYM_MAIN, kind,
VCL_LOW, VCL_HIGH);
@@ -289,14 +290,19 @@ vcc_VmodSymbols(struct vcc *tl, struct symbol *msym)

if (kind == SYM_FUNC) {
func_sym(fsym, msym->vmod_name, VTAILQ_NEXT(vv2, list));
- /* XXX: until we use SYM_METHOD, string check. */
- if (!strcmp(vv1->value, "$METHOD"))
+ /* XXX: until we use SYM_METHOD only, string check. */
+ if (!strcmp(vv1->value, "$METHOD")) {
fsym->extra = msym->rname;
+ /* XXX: cohabitation temporary hack */
+ if (msym->kind == SYM_OBJECT)
+ fsym->kind = SYM_METHOD;
+ }
} else {
assert(kind == SYM_OBJECT);
fsym->eval_priv = vv2;
fsym->vmod_name = msym->vmod_name;
vcc_VmodObject(tl, fsym);
+ vcc_VmodSymbols(tl, fsym);
}
}

_______________________________________________
varnish-commit mailing list
varnish-commit@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-commit