[master] f176f05 Allow automatic promotion from INT to REAL.
Poul-Henning Kamp
phk at FreeBSD.org
Fri Sep 9 10:59:12 CEST 2016
commit f176f05c13abfb87a91ea938c2bcc09a7f74220a
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Fri Sep 9 08:50:47 2016 +0000
Allow automatic promotion from INT to REAL.
Fixes #2084
diff --git a/bin/varnishtest/tests/r02084.vtc b/bin/varnishtest/tests/r02084.vtc
new file mode 100644
index 0000000..aa3bafb
--- /dev/null
+++ b/bin/varnishtest/tests/r02084.vtc
@@ -0,0 +1,27 @@
+varnishtest "REAL - INT types"
+
+server s1 {
+ rxreq
+ txresp
+} -start
+
+varnish v1 -vcl+backend {
+ import std;
+
+ sub vcl_deliver {
+ set resp.http.add = 10.0 + std.integer(req.http.foo, 0);
+ set resp.http.sub = 10.0 - std.integer(req.http.foo, 0);
+ set resp.http.mul = 10.0 * std.integer(req.http.foo, 0);
+ set resp.http.div = 10.0 / std.integer(req.http.foo, 0);
+ }
+
+} -start
+
+client c1 {
+ txreq -hdr "foo: 3"
+ rxresp
+ expect resp.http.add == 13.000
+ expect resp.http.sub == 7.000
+ expect resp.http.mul == 30.000
+ expect resp.http.div == 3.333
+} -run
diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index ad944b6..9624af2 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -910,14 +910,13 @@ vcc_expr_mul(struct vcc *tl, struct expr **e, vcc_type_t fmt)
vcc_NextToken(tl);
vcc_expr4(tl, &e2, f2);
ERRCHK(tl);
- if (e2->fmt->multype == NULL) {
+ if (e2->fmt != REAL && e2->fmt != INT) {
VSB_printf(tl->sb,
"%s %.*s %s not possible.\n",
f2->name, PF(tk), e2->fmt->name);
vcc_ErrWhere(tl, tk);
return;
}
- assert(e2->fmt == f2);
if (tk->tok == '*')
*e = vcc_expr_edit(f3, "(\v1*\v2)", *e, e2);
else
@@ -1017,6 +1016,10 @@ vcc_expr_add(struct vcc *tl, struct expr **e, vcc_type_t fmt)
ADD_OK("-", INT, INT, INT);
ADD_OK("+", REAL, REAL, REAL);
ADD_OK("-", REAL, REAL, REAL);
+ ADD_OK("+", REAL, INT, REAL);
+ ADD_OK("-", REAL, INT, REAL);
+ ADD_OK("+", INT, REAL, REAL);
+ ADD_OK("-", INT, REAL, REAL);
#undef ADD_OK
More information about the varnish-commit
mailing list