From ba4f9938561e98eefcf1ab7fc2a6bbf5043407e7 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 17 Jul 2015 15:33:37 +0200 Subject: [PATCH] JSON: Checks for INF/NAN moved to json_new_number() --- ucw-json/format.c | 2 -- ucw-json/json.c | 10 ++++++++++ ucw-json/json.h | 9 ++------- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/ucw-json/format.c b/ucw-json/format.c index 30f8757f..8549f2ba 100644 --- a/ucw-json/format.c +++ b/ucw-json/format.c @@ -15,7 +15,6 @@ #include #include -#include #include void json_set_output(struct json_context *js, struct fastbuf *fb) @@ -68,7 +67,6 @@ static void write_string(struct json_context *js, const char *p) static void write_number(struct fastbuf *fb, double val) { - ASSERT(isfinite(val)); bprintf(fb, "%.*g", DBL_DIG+1, val); } diff --git a/ucw-json/json.c b/ucw-json/json.c index fbcd5278..28aad1b6 100644 --- a/ucw-json/json.c +++ b/ucw-json/json.c @@ -12,6 +12,8 @@ #include #include +#include + static void json_init(struct json_context *js) { mp_save(js->pool, &js->init_state); @@ -60,6 +62,14 @@ struct json_node *json_new_node(struct json_context *js, enum json_node_type typ return n; } +struct json_node *json_new_number(struct json_context *js, double value) +{ + ASSERT(isfinite(value)); + struct json_node *n = json_new_node(js, JSON_NUMBER); + n->number = value; + return n; +} + struct json_node *json_new_array(struct json_context *js) { struct json_node *n = json_new_node(js, JSON_ARRAY); diff --git a/ucw-json/json.h b/ucw-json/json.h index 06be568a..95bf50e0 100644 --- a/ucw-json/json.h +++ b/ucw-json/json.h @@ -192,13 +192,8 @@ static inline struct json_node *json_new_bool(struct json_context *js UNUSED, bo return (struct json_node *) &static_bool[value]; } -/** Creates a new numeric value. **/ -static inline struct json_node *json_new_number(struct json_context *js, double value) -{ - struct json_node *n = json_new_node(js, JSON_NUMBER); - n->number = value; - return n; -} +/** Creates a new numeric value. The @value must be a finite number. **/ +struct json_node *json_new_number(struct json_context *js, double value); /** Creates a new string value. The @value is kept only as a reference. **/ static inline struct json_node *json_new_string_ref(struct json_context *js, const char *value) -- 2.39.2