summaryrefslogtreecommitdiffstats
path: root/qemu/qobject/qjson.c
diff options
context:
space:
mode:
Diffstat (limited to 'qemu/qobject/qjson.c')
-rw-r--r--qemu/qobject/qjson.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/qemu/qobject/qjson.c b/qemu/qobject/qjson.c
index 33f8ef530..ef160d211 100644
--- a/qemu/qobject/qjson.c
+++ b/qemu/qobject/qjson.c
@@ -11,6 +11,7 @@
*
*/
+#include "qemu/osdep.h"
#include "qapi/qmp/json-lexer.h"
#include "qapi/qmp/json-parser.h"
#include "qapi/qmp/json-streamer.h"
@@ -20,6 +21,7 @@
#include "qapi/qmp/qbool.h"
#include "qapi/qmp/qfloat.h"
#include "qapi/qmp/qdict.h"
+#include "qemu/unicode.h"
typedef struct JSONParsingState
{
@@ -28,7 +30,7 @@ typedef struct JSONParsingState
QObject *result;
} JSONParsingState;
-static void parse_json(JSONMessageParser *parser, QList *tokens)
+static void parse_json(JSONMessageParser *parser, GQueue *tokens)
{
JSONParsingState *s = container_of(parser, JSONParsingState, parser);
s->result = json_parser_parse(tokens, s->ap);
@@ -237,6 +239,15 @@ static void to_json(const QObject *obj, QString *str, int pretty, int indent)
char buffer[1024];
int len;
+ /* FIXME: snprintf() is locale dependent; but JSON requires
+ * numbers to be formatted as if in the C locale. Dependence
+ * on C locale is a pervasive issue in QEMU. */
+ /* FIXME: This risks printing Inf or NaN, which are not valid
+ * JSON values. */
+ /* FIXME: the default precision of 6 for %f often causes
+ * rounding errors; we should be using DBL_DECIMAL_DIG (17),
+ * and only rounding to a shorter number if the result would
+ * still produce the same floating point value. */
len = snprintf(buffer, sizeof(buffer), "%f", qfloat_get_double(val));
while (len > 0 && buffer[len - 1] == '0') {
len--;
@@ -247,7 +258,7 @@ static void to_json(const QObject *obj, QString *str, int pretty, int indent)
} else {
buffer[len] = 0;
}
-
+
qstring_append(str, buffer);
break;
}