summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--configure.ac8
-rw-r--r--src/jv.c4
-rw-r--r--src/jv_parse.c9
-rw-r--r--src/jv_print.c4
4 files changed, 25 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac
index 2d6bf1cb..7d2355b2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -110,6 +110,14 @@ EOF
fi
])
+dnl Disable decNumber support
+AC_ARG_ENABLE([decnum],
+ AC_HELP_STRING([--disable-decnum], [disable decnum support]))
+
+AS_IF([test "x$enable_decnum" != "xno"],[
+ AC_DEFINE([USE_DECNUM],1)
+])
+
AM_CONDITIONAL([ENABLE_VALGRIND], [test "x$enable_valgrind" != xno])
AM_CONDITIONAL([ENABLE_ASAN], [test "x$enable_asan" = xyes])
AM_CONDITIONAL([ENABLE_UBSAN], [test "x$enable_ubsan" = xyes])
diff --git a/src/jv.c b/src/jv.c
index b2bb495a..866dd43e 100644
--- a/src/jv.c
+++ b/src/jv.c
@@ -411,6 +411,7 @@ jv jv_number(double x) {
double jv_number_value(jv j) {
assert(JVP_HAS_KIND(j, JV_KIND_NUMBER));
+#ifdef USE_DECNUM
if (JVP_HAS_FLAGS(j, JVP_FLAGS_NUMBER_LITERAL)) {
jvp_literal_number* n = jvp_literal_number_ptr(j);
@@ -421,8 +422,11 @@ double jv_number_value(jv j) {
return n->num_double;
} else {
+#endif
return j.u.number;
+#ifdef USE_DECNUM
}
+#endif
}
int jv_is_integer(jv j){
diff --git a/src/jv_parse.c b/src/jv_parse.c
index d709e416..9ced9f6d 100644
--- a/src/jv_parse.c
+++ b/src/jv_parse.c
@@ -501,11 +501,20 @@ static pfunc check_literal(struct jv_parser* p) {
} else {
// FIXME: better parser
p->tokenbuf[p->tokenpos] = 0;
+#ifdef USE_DECNUM
jv number = jv_number_with_literal(p->tokenbuf);
if (jv_get_kind(number) == JV_KIND_INVALID) {
return "Invalid numeric literal";
}
TRY(value(p, number));
+#else
+ char *end = 0;
+ double d = jvp_strtod(&p->dtoa, p->tokenbuf, &end);
+ if (end == 0 || *end != 0) {
+ return "Invalid numeric literal";
+ }
+ TRY(value(p, jv_number(d)));
+#endif
}
p->tokenpos = 0;
return 0;
diff --git a/src/jv_print.c b/src/jv_print.c
index 6c848035..15532c69 100644
--- a/src/jv_print.c
+++ b/src/jv_print.c
@@ -234,10 +234,12 @@ static void jv_dump_term(struct dtoa_context* C, jv x, int flags, int indent, FI
if (jvp_number_is_nan(x)) {
jv_dump_term(C, jv_null(), flags, indent, F, S);
} else {
+#ifdef USE_DECNUM
const char * literal_data = jv_number_get_literal(x);
if (literal_data) {
put_str(literal_data, F, S, flags & JV_PRINT_ISATTY);
} else {
+#endif
double d = jv_number_value(x);
if (d != d) {
// JSON doesn't have NaN, so we'll render it as "null"
@@ -249,7 +251,9 @@ static void jv_dump_term(struct dtoa_context* C, jv x, int flags, int indent, FI
put_str(jvp_dtoa_fmt(C, buf, d), F, S, flags & JV_PRINT_ISATTY);
}
}
+#ifdef USE_DECNUM
}
+#endif
break;
}
case JV_KIND_STRING: