1
0
mirror of https://github.com/stedolan/jq.git synced 2024-05-11 05:55:39 +00:00

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.
This commit is contained in:
William Langford
2019-04-03 21:55:39 -04:00
parent ccc3e1f401
commit 2353d034b2
4 changed files with 25 additions and 0 deletions

View File

@ -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])

View File

@ -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){

View File

@ -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;

View File

@ -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: