[master] d25ce0b Rather than add to a never ending list of things we cannot add/subtract, examine the list of things we can handle, and if not, and we are looking for strings anyway, convert to string right away.

Poul-Henning Kamp phk at FreeBSD.org
Wed Feb 8 10:02:05 CET 2017


commit d25ce0b57ae73e8163e8c3376e91996242a135dd
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Feb 8 09:00:15 2017 +0000

    Rather than add to a never ending list of things we cannot add/subtract,
    examine the list of things we can handle, and if not, and we are
    looking for strings anyway, convert to string right away.
    
    Really fixes #2205

diff --git a/bin/varnishtest/tests/v00020.vtc b/bin/varnishtest/tests/v00020.vtc
index 7100e11..5f734fc 100644
--- a/bin/varnishtest/tests/v00020.vtc
+++ b/bin/varnishtest/tests/v00020.vtc
@@ -77,6 +77,7 @@ varnish v1 -vcl {
 		set req.http.foo = now - 1s;
 
 		set req.http.foo = now - now;
+		set req.http.foo = 1 + 1s;
 
 		set req.http.foo = 1 + 1;
 		set req.http.foo = 1 - 1;
@@ -169,13 +170,6 @@ varnish v1 -errvcl {TIME + TIME not possible.} {
 	}
 }
 
-varnish v1 -errvcl {TIME + INT not possible.} {
-	backend b { .host = "127.0.0.1"; }
-	sub vcl_recv {
-		set req.http.foo = now + 1;
-	}
-}
-
 varnish v1 -errvcl {INT + STRING not possible.} {
 	backend b { .host = "127.0.0.1"; }
 	sub vcl_backend_response {
@@ -190,34 +184,6 @@ varnish v1 -errvcl {INT + TIME not possible.} {
 	}
 }
 
-varnish v1 -errvcl {INT + DURATION not possible.} {
-	backend b { .host = "127.0.0.1"; }
-	sub vcl_recv {
-		set req.http.foo = 1 + 1s;
-	}
-}
-
-varnish v1 -errvcl {DURATION + INT not possible.} {
-	backend b { .host = "127.0.0.1"; }
-	sub vcl_recv {
-		set req.http.foo = 1s + 1;
-	}
-}
-
-varnish v1 -errvcl {DURATION + TIME not possible.} {
-	backend b { .host = "127.0.0.1"; }
-	sub vcl_recv {
-		set req.http.foo = 1s + now;
-	}
-}
-
-varnish v1 -errvcl {DURATION + STRING not possible.} {
-	backend b { .host = "127.0.0.1"; }
-	sub vcl_recv {
-		set req.http.foo = 1s + "foo";
-	}
-}
-
 varnish v1 -errvcl {DURATION + INT not possible.} {
 	backend b { .host = "127.0.0.1"; }
 	sub vcl_recv {
diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index 729873b..ce6395d 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -376,10 +376,11 @@ vcc_expr_tostring(struct vcc *tl, struct expr **e, vcc_type_t fmt)
 	uint8_t	constant = EXPR_VAR;
 
 	CHECK_OBJ_NOTNULL(*e, EXPR_MAGIC);
-	AN(fmt == STRING || fmt == STRING_LIST);
-	AZ(fmt == (*e)->fmt);
+	assert(fmt == STRING || fmt == STRING_LIST);
+	assert(fmt != (*e)->fmt);
 
-	if ((*e)->fmt == STRING || ((*e)->fmt == STRING_LIST && vcc_isconst(*e))) {
+	if ((*e)->fmt == STRING ||
+	    ((*e)->fmt == STRING_LIST && vcc_isconst(*e))) {
 		(*e)->fmt = fmt;
 		return;
 	}
@@ -1018,17 +1019,6 @@ static const struct adds {
 	{ '+', INT,		REAL,		REAL },
 	{ '-', INT,		REAL,		REAL },
 
-	/* Error */
-	{ '+', DURATION,	INT,		VOID },
-	{ '+', DURATION,	REAL,		VOID },
-	{ '+', DURATION,	TIME,		VOID },
-	{ '+', DURATION,	STRING,		VOID },
-	{ '+', INT,		DURATION,	VOID },
-	{ '+', IP,		IP,		VOID },
-	{ '+', REAL,		DURATION,	VOID },
-	{ '+', TIME,		INT,		VOID },
-	{ '+', TIME,		REAL,		VOID },
-
 	{ EOI, VOID, VOID, VOID }
 };
 
@@ -1044,15 +1034,27 @@ vcc_expr_add(struct vcc *tl, struct expr **e, vcc_type_t fmt)
 	*e = NULL;
 	vcc_expr_mul(tl, e, fmt);
 	ERRCHK(tl);
+
+	if (tl->t->tok != '+' && tl->t->tok != '-')
+		return;
+
 	f2 = (*e)->fmt;
+	for (ap = vcc_adds; ap->op != EOI; ap++)
+		if (ap->a == f2 && ap->op == tl->t->tok)
+			break;
+
+	if (ap->op == EOI &&
+	    (fmt == STRING || fmt == STRING_LIST) &&
+	    f2 != STRING && f2 != STRING_LIST) {
+		vcc_expr_tostring(tl, e, fmt);
+		f2 = (*e)->fmt;
+	}
 
 	while (tl->t->tok == '+' || tl->t->tok == '-') {
 		tk = tl->t;
 		vcc_NextToken(tl);
 		if (f2 == TIME)
 			vcc_expr_mul(tl, &e2, DURATION);
-		else if (f2 == IP)
-			vcc_expr_mul(tl, &e2, STRING);
 		else
 			vcc_expr_mul(tl, &e2, f2);
 		ERRCHK(tl);



More information about the varnish-commit mailing list