From 6264bb40e0e9d87f24bc38ad1496b153262b5331 Mon Sep 17 00:00:00 2001 From: Mark Pulford Date: Sat, 21 Jan 2012 12:44:41 +1030 Subject: Ignore DISABLE_INVALID_NUMBERS with builtin fpconv --- lua_cjson.c | 26 ++++++++++++++------------ manual.txt | 3 ++- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/lua_cjson.c b/lua_cjson.c index b14c242..498c686 100644 --- a/lua_cjson.c +++ b/lua_cjson.c @@ -321,6 +321,18 @@ static int json_cfg_encode_keep_buffer(lua_State *l) return 1; } +#if defined(DISABLE_INVALID_NUMBERS) && !defined(USE_INTERNAL_FPCONV) +void json_verify_invalid_number_setting(lua_State *l, int *setting) +{ + if (*setting == 1) { + *setting = 0; + luaL_error(l, "Infinity, NaN, and/or hexadecimal numbers are not supported."); + } +} +#else +#define json_verify_invalid_number_setting(l, s) do { } while(0) +#endif + static int json_cfg_encode_invalid_numbers(lua_State *l) { static const char *options[] = { "off", "on", "null", NULL }; @@ -328,12 +340,7 @@ static int json_cfg_encode_invalid_numbers(lua_State *l) json_enum_option(l, 1, &cfg->encode_invalid_numbers, options, 1); -#if DISABLE_INVALID_NUMBERS - if (cfg->encode_invalid_numbers == 1) { - cfg->encode_invalid_numbers = 0; - luaL_error(l, "Infinity, NaN, and/or hexadecimal numbers are not supported."); - } -#endif + json_verify_invalid_number_setting(l, &cfg->encode_invalid_numbers); return 1; } @@ -344,12 +351,7 @@ static int json_cfg_decode_invalid_numbers(lua_State *l) json_enum_option(l, 1, &cfg->decode_invalid_numbers, NULL, 1); -#if DISABLE_INVALID_NUMBERS - if (cfg->decode_invalid_numbers) { - cfg->decode_invalid_numbers = 0; - luaL_error(l, "Infinity, NaN, and/or hexadecimal numbers are not supported."); - } -#endif + json_verify_invalid_number_setting(l, &cfg->encode_invalid_numbers); return 1; } diff --git a/manual.txt b/manual.txt index eacd2c7..d7c916a 100644 --- a/manual.txt +++ b/manual.txt @@ -120,7 +120,8 @@ DISABLE_INVALID_NUMBERS:: Recommended on platforms where ++strtod++(3) / ++sprintf++(3) are not POSIX compliant (Eg, Windows MinGW). Prevents +cjson.encode_invalid_numbers+ and +cjson.decode_invalid_numbers+ from being enabled. However, +cjson.encode_invalid_numbers+ may be - set to +"null"+. + set to +"null"+. This option is unnecessary and is ignored when + using built-in floating point conversion. Built-in dtoa() support -- cgit v1.2.3