diff options
author | Mark Pulford <mark@kyne.com.au> | 2012-01-01 23:30:34 +1030 |
---|---|---|
committer | Mark Pulford <mark@kyne.com.au> | 2012-01-01 23:30:34 +1030 |
commit | 77408a81a696472338c2f90147e41fff3e81005d (patch) | |
tree | a4972c000f94d416df20f8786f4e75e3ded5d263 | |
parent | 929c814b12e3575859fa0d5a8ea9950ae2187c56 (diff) | |
download | lua-cjson-77408a81a696472338c2f90147e41fff3e81005d.tar.gz lua-cjson-77408a81a696472338c2f90147e41fff3e81005d.tar.bz2 lua-cjson-77408a81a696472338c2f90147e41fff3e81005d.zip |
Add build option to disable invalid numbers
Windows MinGW doesn't convert Infinity/NaN/hexadecimal numbers. Add
DISABLE_INVALID_NUMBERS build option option to disable invalid numbers.
-rw-r--r-- | Makefile | 8 | ||||
-rw-r--r-- | lua-cjson-1.0devel-1.rockspec | 11 | ||||
-rw-r--r-- | lua_cjson.c | 15 | ||||
-rw-r--r-- | manual.txt | 21 |
4 files changed, 39 insertions, 16 deletions
@@ -2,8 +2,10 @@ LUA_VERSION = 5.1 | |||
2 | 2 | ||
3 | ## Available defines for CJSON_CFLAGS | 3 | ## Available defines for CJSON_CFLAGS |
4 | # | 4 | # |
5 | # USE_INTERNAL_ISINF: Workaround for Solaris platforms missing isinf(). | 5 | # USE_INTERNAL_ISINF: Workaround for Solaris platforms missing isinf(). |
6 | # DISABLE_CJSON_GLOBAL: Do not store module is "cjson" global | 6 | # DISABLE_CJSON_GLOBAL: Do not store module is "cjson" global. |
7 | # DISABLE_INVALID_NUMBERS: Permanently disable invalid JSON numbers: | ||
8 | # - NaN, Infinity, hex. | ||
7 | 9 | ||
8 | ## Build defaults | 10 | ## Build defaults |
9 | TARGET = cjson.so | 11 | TARGET = cjson.so |
@@ -38,7 +40,7 @@ INSTALL_CMD = install | |||
38 | ## Windows (MinGW) | 40 | ## Windows (MinGW) |
39 | #TARGET = cjson.dll | 41 | #TARGET = cjson.dll |
40 | #PREFIX = /home/user/opt | 42 | #PREFIX = /home/user/opt |
41 | #CJSON_CFLAGS = | 43 | #CJSON_CFLAGS = -DDISABLE_INVALID_NUMBERS |
42 | #CJSON_LDFLAGS = -shared -L$(PREFIX)/lib -llua51 | 44 | #CJSON_LDFLAGS = -shared -L$(PREFIX)/lib -llua51 |
43 | 45 | ||
44 | ## End platform specific section | 46 | ## End platform specific section |
diff --git a/lua-cjson-1.0devel-1.rockspec b/lua-cjson-1.0devel-1.rockspec index fa20c53..9ef9f2c 100644 --- a/lua-cjson-1.0devel-1.rockspec +++ b/lua-cjson-1.0devel-1.rockspec | |||
@@ -25,15 +25,18 @@ build = { | |||
25 | cjson = { | 25 | cjson = { |
26 | sources = { "lua_cjson.c", "strbuf.c", "fpconv.c" }, | 26 | sources = { "lua_cjson.c", "strbuf.c", "fpconv.c" }, |
27 | defines = { | 27 | defines = { |
28 | -- Optional workaround: | ||
29 | -- USE_INTERNAL_ISINF: Provide internal isinf() implementation. Required | ||
30 | -- on some Solaris platforms. | ||
31 | -- LuaRocks does not support platform specific configuration for Solaris. | 28 | -- LuaRocks does not support platform specific configuration for Solaris. |
32 | -- Uncomment the line below on Solaris platforms. | 29 | -- Uncomment the line below on Solaris platforms if required. |
33 | -- "USE_INTERNAL_ISINF" | 30 | -- "USE_INTERNAL_ISINF" |
34 | } | 31 | } |
35 | } | 32 | } |
36 | }, | 33 | }, |
34 | -- Override default build options (per platform) | ||
35 | platforms = { | ||
36 | win32 = { modules = { cjson = { defines = { | ||
37 | "DISABLE_INVALID_NUMBERS" | ||
38 | } } } } | ||
39 | }, | ||
37 | copy_directories = { "tests" } | 40 | copy_directories = { "tests" } |
38 | } | 41 | } |
39 | 42 | ||
diff --git a/lua_cjson.c b/lua_cjson.c index 175433a..ca85156 100644 --- a/lua_cjson.c +++ b/lua_cjson.c | |||
@@ -67,6 +67,11 @@ | |||
67 | #define DEFAULT_ENCODE_KEEP_BUFFER 1 | 67 | #define DEFAULT_ENCODE_KEEP_BUFFER 1 |
68 | #define DEFAULT_ENCODE_NUMBER_PRECISION 14 | 68 | #define DEFAULT_ENCODE_NUMBER_PRECISION 14 |
69 | 69 | ||
70 | #ifdef DISABLE_INVALID_NUMBERS | ||
71 | #undef DEFAULT_DECODE_REFUSE_BADNUM | ||
72 | #define DEFAULT_DECODE_REFUSE_BADNUM 1 | ||
73 | #endif | ||
74 | |||
70 | typedef enum { | 75 | typedef enum { |
71 | T_OBJ_BEGIN, | 76 | T_OBJ_BEGIN, |
72 | T_OBJ_END, | 77 | T_OBJ_END, |
@@ -341,6 +346,16 @@ static int json_cfg_refuse_invalid_numbers(lua_State *l) | |||
341 | &cfg->encode_refuse_badnum, | 346 | &cfg->encode_refuse_badnum, |
342 | &cfg->decode_refuse_badnum); | 347 | &cfg->decode_refuse_badnum); |
343 | 348 | ||
349 | #if DISABLE_INVALID_NUMBERS | ||
350 | /* Some non-POSIX platforms don't handle double <-> string translations | ||
351 | * for Infinity/NaN/hexadecimal properly. Throw an error if the | ||
352 | * user attempts to enable them. */ | ||
353 | if (!cfg->encode_refuse_badnum || !cfg->decode_refuse_badnum) { | ||
354 | cfg->encode_refuse_badnum = cfg->decode_refuse_badnum = 1; | ||
355 | luaL_error(l, "Infinity, NaN, and/or hexadecimal numbers are not supported."); | ||
356 | } | ||
357 | #endif | ||
358 | |||
344 | return 1; | 359 | return 1; |
345 | } | 360 | } |
346 | 361 | ||
@@ -42,15 +42,6 @@ RPM:: Linux | |||
42 | LuaRocks:: Unix, Windows | 42 | LuaRocks:: Unix, Windows |
43 | 43 | ||
44 | 44 | ||
45 | Build Options (#define) | ||
46 | ~~~~~~~~~~~~~~~~~~~~~~~ | ||
47 | |||
48 | [horizontal] | ||
49 | USE_INTERNAL_ISINF:: Workaround for Solaris platforms missing isinf(). | ||
50 | DISABLE_CJSON_GLOBAL:: Do not store module table in global "cjson" | ||
51 | variable. Redundant from Lua 5.2 onwards. | ||
52 | |||
53 | |||
54 | Make | 45 | Make |
55 | ~~~~ | 46 | ~~~~ |
56 | 47 | ||
@@ -117,6 +108,18 @@ Review the http://luarocks.org/en/Documentation[LuaRocks documentation] | |||
117 | for further details. | 108 | for further details. |
118 | 109 | ||
119 | 110 | ||
111 | Build Options (#define) | ||
112 | ~~~~~~~~~~~~~~~~~~~~~~~ | ||
113 | |||
114 | [horizontal] | ||
115 | USE_INTERNAL_ISINF:: Workaround for Solaris platforms missing ++isinf++(3). | ||
116 | DISABLE_CJSON_GLOBAL:: Do not store module table in global "cjson" | ||
117 | variable. Redundant from Lua 5.2 onwards. | ||
118 | DISABLE_INVALID_NUMBERS:: Recommended on platforms where ++strtod++(3) / | ||
119 | ++sprintf++(3) are not POSIX compliant (Eg, Windows MinGW). Restricts | ||
120 | the +cjson.refuse_invalid_numbers+ runtime configuration to +true+. | ||
121 | |||
122 | |||
120 | API (Functions) | 123 | API (Functions) |
121 | --------------- | 124 | --------------- |
122 | 125 | ||