From 3aead6d2301d4f1d78f1fa9eff9553544b49f63c Mon Sep 17 00:00:00 2001 From: funshine Date: Wed, 18 Mar 2015 17:01:01 +0800 Subject: [PATCH 1/2] try to fix cjson.encode in integer only version --- app/modules/cjson.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/app/modules/cjson.c b/app/modules/cjson.c index 8dc6bbaf..47e4ab9a 100644 --- a/app/modules/cjson.c +++ b/app/modules/cjson.c @@ -45,13 +45,10 @@ #include "flash_api.h" #include "strbuf.h" -#ifdef LUA_NUMBER_INTEGRAL -#include "fpconv.h" -#else + #define FPCONV_G_FMT_BUFSIZE 32 #define fpconv_strtod c_strtod #define fpconv_init() ((void)0) -#endif #ifndef CJSON_MODNAME #define CJSON_MODNAME "cjson" @@ -774,12 +771,10 @@ static void json_append_number(lua_State *l, json_config_t *cfg, } strbuf_ensure_empty_length(json, FPCONV_G_FMT_BUFSIZE); -#ifdef LUA_NUMBER_INTEGRAL - len = fpconv_g_fmt(strbuf_empty_ptr(json), num, cfg->encode_number_precision); -#else - c_sprintf(strbuf_empty_ptr(json), "%.14g", num); + // len = fpconv_g_fmt(strbuf_empty_ptr(json), num, cfg->encode_number_precision); + c_sprintf(strbuf_empty_ptr(json), LUA_NUMBER_FMT, num); len = c_strlen(strbuf_empty_ptr(json)); -#endif + strbuf_extend_length(json, len); } From 3d14530b8057e6eb9b2076b5bca02c56505c8a56 Mon Sep 17 00:00:00 2001 From: funshine Date: Wed, 18 Mar 2015 19:37:47 +0800 Subject: [PATCH 2/2] fix cjson.encode() when in integer version --- app/cjson/fpconv.c | 3 ++- app/modules/cjson.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/cjson/fpconv.c b/app/cjson/fpconv.c index a5ce8125..f199b459 100644 --- a/app/cjson/fpconv.c +++ b/app/cjson/fpconv.c @@ -35,6 +35,7 @@ #include "fpconv.h" +#if 0 /* Lua CJSON assumes the locale is the same for all threads within a * process and doesn't change after initialisation. * @@ -203,6 +204,6 @@ void fpconv_init() { fpconv_update_locale(); } - +#endif /* vi:ai et sw=4 ts=4: */ diff --git a/app/modules/cjson.c b/app/modules/cjson.c index 47e4ab9a..22afdf70 100644 --- a/app/modules/cjson.c +++ b/app/modules/cjson.c @@ -772,7 +772,7 @@ static void json_append_number(lua_State *l, json_config_t *cfg, strbuf_ensure_empty_length(json, FPCONV_G_FMT_BUFSIZE); // len = fpconv_g_fmt(strbuf_empty_ptr(json), num, cfg->encode_number_precision); - c_sprintf(strbuf_empty_ptr(json), LUA_NUMBER_FMT, num); + c_sprintf(strbuf_empty_ptr(json), LUA_NUMBER_FMT, (LUA_NUMBER)num); len = c_strlen(strbuf_empty_ptr(json)); strbuf_extend_length(json, len);