From 2353d034b20558ed8cd1ce81786faa31c0ed33d1 Mon Sep 17 00:00:00 2001 From: William Langford Date: Wed, 3 Apr 2019 21:55:39 -0400 Subject: Add configure guards around literal jv_numbers Allow building jq in a mode that doesn't use decnumber for benchmarking purposes. decnumber support is enabled by default, and this option is meant to be removed once we're happy with the performance. --- configure.ac | 8 ++++++++ src/jv.c | 4 ++++ src/jv_parse.c | 9 +++++++++ src/jv_print.c | 4 ++++ 4 files changed, 25 insertions(+) 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: -- cgit v1.2.3