Commit c50ff59c authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Switch std_conversion onto SF_number functions

parent c4257032
...@@ -98,7 +98,7 @@ client c1 { ...@@ -98,7 +98,7 @@ client c1 {
txreq -hdr "foo: 999999999999.999" \ txreq -hdr "foo: 999999999999.999" \
-hdr "bytes: 999999999999b" \ -hdr "bytes: 999999999999b" \
-hdr "duration: 999999999999.999s" \ -hdr "duration: 999999999999.999s" \
-hdr "integer: 999999999999.999" \ -hdr "integer: 999999999999.000" \
-hdr "time: 999999999999.999" -hdr "time: 999999999999.999"
rxresp rxresp
expect resp.http.converted == 999999999999.999 expect resp.http.converted == 999999999999.999
......
...@@ -147,8 +147,8 @@ vmod_bytes(VRT_CTX, struct VARGS(bytes) *a) ...@@ -147,8 +147,8 @@ vmod_bytes(VRT_CTX, struct VARGS(bytes) *a)
VCL_INT v_matchproto_(td_std_integer) VCL_INT v_matchproto_(td_std_integer)
vmod_integer(VRT_CTX, struct VARGS(integer) *a) vmod_integer(VRT_CTX, struct VARGS(integer) *a)
{ {
const char *e; const char *p, *errtxt = NULL;
double r; double r, tmp;
int nargs; int nargs;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
...@@ -167,9 +167,11 @@ vmod_integer(VRT_CTX, struct VARGS(integer) *a) ...@@ -167,9 +167,11 @@ vmod_integer(VRT_CTX, struct VARGS(integer) *a)
return (a->bytes); return (a->bytes);
if (a->valid_s && a->s != NULL) { if (a->valid_s && a->s != NULL) {
r = VNUMpfx(a->s, &e); p = a->s;
if (e != NULL) r = SF_Parse_Number(&p, &errtxt);
r = NAN; if (!errno && *p == '\0' && modf(r, &tmp) == 0.0)
return (r);
r = NAN;
} }
if (a->valid_duration) if (a->valid_duration)
...@@ -190,7 +192,10 @@ vmod_integer(VRT_CTX, struct VARGS(integer) *a) ...@@ -190,7 +192,10 @@ vmod_integer(VRT_CTX, struct VARGS(integer) *a)
if (a->valid_fallback) if (a->valid_fallback)
return (a->fallback); return (a->fallback);
VRT_fail(ctx, "std.integer: conversion failed"); if (errtxt != NULL)
VRT_fail(ctx, "std.integer: conversion failed: %s", errtxt);
else
VRT_fail(ctx, "std.integer: conversion failed");
return (0); return (0);
} }
...@@ -234,6 +239,7 @@ VCL_REAL v_matchproto_(td_std_real) ...@@ -234,6 +239,7 @@ VCL_REAL v_matchproto_(td_std_real)
vmod_real(VRT_CTX, struct VARGS(real) *a) vmod_real(VRT_CTX, struct VARGS(real) *a)
{ {
VCL_REAL r; VCL_REAL r;
const char *p, *errtxt = NULL;
int nargs; int nargs;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
...@@ -260,15 +266,19 @@ vmod_real(VRT_CTX, struct VARGS(real) *a) ...@@ -260,15 +266,19 @@ vmod_real(VRT_CTX, struct VARGS(real) *a)
return ((VCL_REAL)a->time); return ((VCL_REAL)a->time);
if (a->valid_s && a->s != NULL) { if (a->valid_s && a->s != NULL) {
r = VNUM(a->s); p = a->s;
if (!isnan(r)) r = SF_Parse_Decimal(&p, &errtxt);
if (!errno && *p == '\0')
return (r); return (r);
} }
if (a->valid_fallback) if (a->valid_fallback)
return (a->fallback); return (a->fallback);
VRT_fail(ctx, "std.real: conversion failed"); if (errtxt != NULL)
VRT_fail(ctx, "std.real: conversion failed: %s", errtxt);
else
VRT_fail(ctx, "std.real: conversion failed");
return (0); return (0);
} }
......
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