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 {
set resp.http.x-qux = std.real2integer(
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
# 128bit integers on $exotic_platform.
set resp.http.x-int-fallback = std.real2integer(9000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000, 2);
......@@ -31,6 +34,7 @@ client c1 {
expect resp.http.x-foo == resp.http.x-bar
expect resp.http.x-baz == 1140618699.000
expect resp.http.x-qux == 1140618699
expect resp.http.x-xyzzy == resp.http.x-qux
expect resp.http.x-int-fallback == 2
} -run
......
......@@ -102,28 +102,23 @@ vmod_duration(VRT_CTX, VCL_STRING p, VCL_DURATION d)
VCL_INT __match_proto__(td_std_integer)
vmod_integer(VRT_CTX, VCL_STRING p, VCL_INT i)
{
char *e;
long r;
const char *e;
double r;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
if (p == NULL)
return (i);
while(isspace(*p))
p++;
if (*p != '+' && *p != '-' && !isdigit(*p))
r = VNUMpfx(p, &e);
if (isnan(r) || e != NULL)
return (i);
e = NULL;
r = strtol(p, &e, 0);
if (e == NULL || *e != '\0')
r = trunc(r);
if (r > LONG_MAX || r < LONG_MIN)
return (i);
return (r);
return ((long)r);
}
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