[master] d466f8e vcc: support negative DURATION constants

Nils Goroll nils.goroll at uplex.de
Fri Mar 3 14:00:07 CET 2017


commit d466f8ebb3bf7303cba60831caa29db289388e00
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Fri Mar 3 13:57:53 2017 +0100

    vcc: support negative DURATION constants
    
    we should probably unify the '-' and CNUM case in vcc_expr4() some time

diff --git a/bin/varnishtest/tests/v00020.vtc b/bin/varnishtest/tests/v00020.vtc
index 5f734fc..ba76e2d 100644
--- a/bin/varnishtest/tests/v00020.vtc
+++ b/bin/varnishtest/tests/v00020.vtc
@@ -37,15 +37,6 @@ varnish v1 -errvcl {Symbol not found: 'vcl_recv' (expected type STRING_LIST)} {
 	}
 }
 
-# XXX: not obvious if this actually fails for the desired reason ?
-varnish v1 -errvcl {Unknown token '-' when looking for DURATION} {
-	sub vcl_recv {
-		if (req.ttl < -3s || req.ttl) {
-			set req.http.foo = vcl_recv;
-		}
-	}
-}
-
 varnish v1 -errvcl {Operator * not possible on type STRING.} {
 	sub vcl_recv {
 		set req.http.foo = "bla" * "foo";
@@ -113,6 +104,7 @@ varnish v1 -vcl {
 
 		set req.http.foo = client.ip + ", " + server.ip;
 
+		set req.ttl = -1s;
 		set req.ttl = 1s;
 		set req.ttl *= 1.5;
 		set req.ttl = 1.5 s * 2.5;
diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index 5ec79cc..d116b9c 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -869,15 +869,21 @@ vcc_expr4(struct vcc *tl, struct expr **e, vcc_type_t fmt)
 		*e = e1;
 		return;
 	case '-':
-		if (fmt == INT || fmt == REAL) {
+		if (fmt == INT || fmt == REAL || fmt == DURATION) {
 			vcc_NextToken(tl);
 			ExpectErr(tl, CNUM);
 			if (fmt == INT) {
-				e1 = vcc_mk_expr(INT, "-%.*s", PF(tl->t));
+				e1 = vcc_mk_expr(fmt, "-%.*s", PF(tl->t));
 				vcc_NextToken(tl);
+			} else if (fmt == REAL) {
+				e1 = vcc_mk_expr(fmt, "-%f", vcc_DoubleVal(tl));
+			} else if (fmt == DURATION) {
+				vcc_NumVal(tl, &d, &i);
+				ERRCHK(tl);
+				e1 = vcc_mk_expr(fmt, "-%g",
+				    d * vcc_TimeUnit(tl));
 			} else {
-				e1 = vcc_mk_expr(REAL, "-%f",
-				    vcc_DoubleVal(tl));
+				INCOMPL();
 			}
 			ERRCHK(tl);
 			e1->constant = EXPR_CONST;



More information about the varnish-commit mailing list