[master] 12a16117d Omit the separator in VCC functions extra arguments

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Wed Dec 11 15:28:06 UTC 2019


commit 12a16117da90cf08bbf9d6dd05512477f0b81a7c
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Wed Dec 11 16:15:45 2019 +0100

    Omit the separator in VCC functions extra arguments
    
    Instead, the comma is emitted when there is indeed an extra argument.
    
    This change was initially submitted in #3147 and is needed when the
    extra argument may vary for a given symbol. More specifically, when
    a method symbol may be shared by several instance symbols, it becomes
    really difficult to find a spot where that extra comma might be added.
    
    Removing it from the extra argument itself makes this easier once we
    reach the point where method symbols are unique (per object) instead
    of repeated (per instance).

diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index bab9251b5..cacbbdfac 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -465,7 +465,7 @@ vcc_func(struct vcc *tl, struct expr **e, const void *priv,
 	VTAILQ_HEAD(,func_arg) head;
 	struct token *t1;
 	const struct vjsn_val *vv, *vvp;
-	const char *sa;
+	const char *sa, *extra_sep;
 	char ssa[64];
 	int n;
 
@@ -483,8 +483,13 @@ vcc_func(struct vcc *tl, struct expr **e, const void *priv,
 	}
 	vv = VTAILQ_NEXT(vv, list);
 	SkipToken(tl, '(');
-	if (extra == NULL)
+	if (extra == NULL) {
 		extra = "";
+		extra_sep = "";
+	} else {
+		AN(*extra);
+		extra_sep = ", ";
+	}
 	VTAILQ_INIT(&head);
 	for (;vv != NULL; vv = VTAILQ_NEXT(vv, list)) {
 		assert(vv->type == VJSN_ARRAY);
@@ -570,10 +575,11 @@ vcc_func(struct vcc *tl, struct expr **e, const void *priv,
 	}
 
 	if (sa != NULL)
-		e1 = vcc_mk_expr(rfmt, "%s(ctx%s,\v+\n&(%s)\v+ {\n",
-		    cfunc, extra, sa);
+		e1 = vcc_mk_expr(rfmt, "%s(ctx%s%s,\v+\n&(%s)\v+ {\n",
+		    cfunc, extra_sep, extra, sa);
 	else
-		e1 = vcc_mk_expr(rfmt, "%s(ctx%s\v+", cfunc, extra);
+		e1 = vcc_mk_expr(rfmt, "%s(ctx%s%s\v+",
+		    cfunc, extra_sep, extra);
 	n = 0;
 	VTAILQ_FOREACH_SAFE(fa, &head, list, fa2) {
 		n++;
diff --git a/lib/libvcc/vcc_vmod.c b/lib/libvcc/vcc_vmod.c
index a4d229a05..610547b4a 100644
--- a/lib/libvcc/vcc_vmod.c
+++ b/lib/libvcc/vcc_vmod.c
@@ -385,7 +385,6 @@ vcc_Act_New(struct vcc *tl, struct token *t, struct symbol *sym)
 	struct inifin *ifp;
 	struct vsb *buf;
 	const struct vjsn_val *vv, *vf;
-	const char *p;
 	int null_ok = 0;
 
 	(void)sym;
@@ -433,7 +432,7 @@ vcc_Act_New(struct vcc *tl, struct token *t, struct symbol *sym)
 
 	buf = VSB_new_auto();
 	AN(buf);
-	VSB_printf(buf, ", &%s, \"%s\"", sy1->rname, sy1->name);
+	VSB_printf(buf, "&%s, \"%s\"", sy1->rname, sy1->name);
 	AZ(VSB_finish(buf));
 	vcc_Eval_Func(tl, vf, VSB_data(buf), sy2);
 	VSB_destroy(&buf);
@@ -456,9 +455,7 @@ vcc_Act_New(struct vcc *tl, struct token *t, struct symbol *sym)
 	/* Instantiate symbols for the methods */
 	buf = VSB_new_auto();
 	AN(buf);
-	VSB_printf(buf, ", %s", sy1->rname);
-	AZ(VSB_finish(buf));
-	p = TlDup(tl, VSB_data(buf));
+
 	while (vv != NULL) {
 		vf = VTAILQ_FIRST(&vv->children);
 		assert(vf->type == VJSN_STRING);
@@ -472,7 +469,7 @@ vcc_Act_New(struct vcc *tl, struct token *t, struct symbol *sym)
 		sy3 = VCC_MkSym(tl, VSB_data(buf), SYM_FUNC, VCL_LOW, VCL_HIGH);
 		AN(sy3);
 		func_sym(sy3, sy2->vmod_name, VTAILQ_NEXT(vf, list));
-		sy3->extra = p;
+		sy3->extra = sy1->rname;
 		vv = VTAILQ_NEXT(vv, list);
 	}
 	VSB_destroy(&buf);


More information about the varnish-commit mailing list