]> mj.ucw.cz Git - libucw.git/commitdiff
JSON: Checks for INF/NAN moved to json_new_number()
authorMartin Mares <mj@ucw.cz>
Fri, 17 Jul 2015 13:33:37 +0000 (15:33 +0200)
committerMartin Mares <mj@ucw.cz>
Fri, 17 Jul 2015 13:33:37 +0000 (15:33 +0200)
ucw-json/format.c
ucw-json/json.c
ucw-json/json.h

index 30f8757fd799199ad0c47ffd6c99c0de1018768d..8549f2ba114136b8803014c8bb9c82126681d378 100644 (file)
@@ -15,7 +15,6 @@
 #include <ucw-json/json.h>
 
 #include <float.h>
-#include <math.h>
 #include <stdio.h>
 
 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);
 }
 
index fbcd5278c389056c0a8ab09a06c84b5df95f84db..28aad1b68d20a3940887abb6deedc38de24038a7 100644 (file)
@@ -12,6 +12,8 @@
 #include <ucw/mempool.h>
 #include <ucw-json/json.h>
 
+#include <math.h>
+
 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);
index 06be568a4003da65366d5dd9d8460888e2d7b4e8..95bf50e048512c1a28ce14122e421e3ad0237b48 100644 (file)
@@ -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)