From ca42b9a996f9046ba3876ad8a81cda1d935b39cf Mon Sep 17 00:00:00 2001 From: Mark Pulford Date: Thu, 29 Dec 2011 23:03:58 +1030 Subject: Use internal dtoa/strtod for double conversion The internal Lua CJSON dtoa/strtod routines have locale support disabled. This avoids problems under locales with comma decimal separators. Build changes: - CMake: Check for big endian architectures - Makefile: Provide option to build with dtoa.c Modifications to dtoa.c: - Include locale dtoa_config.h configuration - Rename Infinity/NaN to inf/nan to match common C libraries - Rename strtod() -> internal_strtod() to prevent conflict with libc function Modifications to g_fmt.c: - Return output string length (instead of original buffer pointer) - Provide precision as an argument to g_fmt() - Silence compilations warnings from vendor source - while(a = b) - Unused label "done:" - Only swap to scientific notation when once the number of decimal digits required exceeds the precision available. This matches standard printf format %g. - Display a "0" in front of numbers < 1. --- Makefile | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 57f2e1b..b283634 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,10 @@ ## DISABLE_CJSON_GLOBAL: Do not store module is "cjson" global. ## DISABLE_INVALID_NUMBERS: Permanently disable invalid JSON numbers: ## NaN, Infinity, hex. +## +## Optional built-in number conversion uses the following defines: +## USE_INTERNAL_DTOA: Use builtin strtod/dtoa for numeric conversions. +## IEEE_BIG_ENDIAN: Required on big endian architectures. ##### Build defaults ##### LUA_VERSION = 5.1 @@ -42,10 +46,25 @@ INSTALL_CMD = install #CJSON_CFLAGS = -DDISABLE_INVALID_NUMBERS #CJSON_LDFLAGS = -shared -L$(PREFIX)/lib -llua51 +##### Use built in number conversion (optional) ##### + +## Enable built in number conversion +#FPCONV_OBJS = g_fmt.o dtoa.o +#CJSON_CFLAGS += -DUSE_INTERNAL_DTOA + +## Compile built in number conversion for big endian architectures +#CJSON_CFLAGS += -DIEEE_BIG_ENDIAN + +## Compile built in number conversion to support multi-threaded +## applications (recommended) +#CJSON_CFLAGS += -pthread -DMULTIPLE_THREADS +#CJSON_LDFLAGS += -pthread + ##### End customisable sections ##### BUILD_CFLAGS = -I$(LUA_INCLUDE_DIR) $(CJSON_CFLAGS) -OBJS := lua_cjson.o strbuf.o fpconv.o +FPCONV_OBJS ?= fpconv.o +OBJS := lua_cjson.o strbuf.o $(FPCONV_OBJS) .PHONY: all clean install package doc -- cgit v1.2.3-55-g6feb