Commit 2761c436 authored by Federico G. Schwindt's avatar Federico G. Schwindt

Let std.integer also do real to integer conversion

With input from nigoroll.
parent c61d207a
...@@ -19,6 +19,9 @@ varnish v1 -vcl+backend { ...@@ -19,6 +19,9 @@ varnish v1 -vcl+backend {
set resp.http.x-qux = std.real2integer( set resp.http.x-qux = std.real2integer(
std.real(req.http.foo, 2.0), 2); std.real(req.http.foo, 2.0), 2);
set resp.http.x-xyzzy = std.integer(
std.real(req.http.foo, 2.0), 2);
# Representation of 9e99, which is larger than what fits in the # Representation of 9e99, which is larger than what fits in the
# 128bit integers on $exotic_platform. # 128bit integers on $exotic_platform.
set resp.http.x-int-fallback = std.real2integer(9000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000, 2); set resp.http.x-int-fallback = std.real2integer(9000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000, 2);
...@@ -31,6 +34,7 @@ client c1 { ...@@ -31,6 +34,7 @@ client c1 {
expect resp.http.x-foo == resp.http.x-bar expect resp.http.x-foo == resp.http.x-bar
expect resp.http.x-baz == 1140618699.000 expect resp.http.x-baz == 1140618699.000
expect resp.http.x-qux == 1140618699 expect resp.http.x-qux == 1140618699
expect resp.http.x-xyzzy == resp.http.x-qux
expect resp.http.x-int-fallback == 2 expect resp.http.x-int-fallback == 2
} -run } -run
......
...@@ -102,28 +102,23 @@ vmod_duration(VRT_CTX, VCL_STRING p, VCL_DURATION d) ...@@ -102,28 +102,23 @@ vmod_duration(VRT_CTX, VCL_STRING p, VCL_DURATION d)
VCL_INT __match_proto__(td_std_integer) VCL_INT __match_proto__(td_std_integer)
vmod_integer(VRT_CTX, VCL_STRING p, VCL_INT i) vmod_integer(VRT_CTX, VCL_STRING p, VCL_INT i)
{ {
char *e; const char *e;
long r; double r;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
if (p == NULL) if (p == NULL)
return (i); return (i);
while(isspace(*p)) r = VNUMpfx(p, &e);
p++; if (isnan(r) || e != NULL)
if (*p != '+' && *p != '-' && !isdigit(*p))
return (i); return (i);
e = NULL; r = trunc(r);
if (r > LONG_MAX || r < LONG_MIN)
r = strtol(p, &e, 0);
if (e == NULL || *e != '\0')
return (i); return (i);
return (r); return ((long)r);
} }
VCL_IP VCL_IP
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment