Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mpx/lua-cjson.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Pulford <mark@kyne.com.au>2011-12-29 17:23:11 +0400
committerMark Pulford <mark@kyne.com.au>2011-12-29 17:23:11 +0400
commit6cc88e3ac5275868e168acaf60203563f131355b (patch)
treec574da2dff2c4e95cc6d39d6de2393b64eedf4fc /lua_cjson.c
parent155393d5bd801ce5dbd76020facecd9270679e94 (diff)
Remove POSIX locale workaround
Diffstat (limited to 'lua_cjson.c')
-rw-r--r--lua_cjson.c72
1 files changed, 0 insertions, 72 deletions
diff --git a/lua_cjson.c b/lua_cjson.c
index 0f6d675..f5ea0dd 100644
--- a/lua_cjson.c
+++ b/lua_cjson.c
@@ -48,48 +48,6 @@
#define CJSON_VERSION "1.0devel"
#endif
-/* Support to reset locale to POSIX for strtod() / sprintf().
- * Some locales use comma as a decimal separator. This breaks JSON. */
-#ifdef USE_POSIX_USELOCALE
-
-#ifdef USE_POSIX_SETLOCALE
-#error Must not define USE_POSIX_USELOCALE and USE_POSIX_SETLOCALE simultaneously.
-#endif
-
-/* unistd.h defines _POSIX_VERSION */
-#include <unistd.h>
-
-#if _POSIX_VERSION >= 200809L
-/* POSIX.1-2008 adds threadsafe locale support */
-#include <locale.h>
-#elif defined(_POSIX_VERSION)
-/* Some pre-POSIX.1-2008 operating systems offer xlocale.h instead */
-#include <xlocale.h>
-#else
-#error Missing _POSIX_VERSION define
-#endif /* _POSIX_VERSION */
-
-#define LOCALE_SET_POSIX(x) (x)->saved_locale = uselocale((x)->posix_locale)
-#define LOCALE_RESTORE(x) uselocale((x)->saved_locale)
-
-#elif defined(USE_POSIX_SETLOCALE)
-/* ANSI C / ISO C90 implementation. Not thread-safe, affects entire process. */
-#include <locale.h>
-
-#define LOCALE_SET_POSIX(x) \
- do { \
- (x)->saved_locale = setlocale(LC_NUMERIC, NULL); \
- setlocale(LC_NUMERIC, "C"); \
- } while(0)
-#define LOCALE_RESTORE(x) setlocale(LC_NUMERIC, (x)->saved_locale)
-
-#else /* Do not work around locale support in strtod() / sprintf() */
-
-#define LOCALE_SET_POSIX(x) do { } while(0)
-#define LOCALE_RESTORE(x) do { } while(0)
-
-#endif
-
/* Workaround for Solaris platforms missing isinf() */
#if !defined(isinf) && (defined(USE_INTERNAL_ISINF) || defined(MISSING_ISINF))
#define isinf(x) (!isnan(x) && isnan((x) - (x)))
@@ -146,12 +104,6 @@ typedef struct {
char *char2escape[256]; /* Encoding */
#endif
strbuf_t encode_buf;
-#if defined(USE_POSIX_USELOCALE)
- locale_t saved_locale;
- locale_t posix_locale;
-#elif defined(USE_POSIX_SETLOCALE)
- const char *saved_locale;
-#endif
char number_fmt[8]; /* "%.XXg\0" */
int current_depth;
@@ -395,10 +347,6 @@ static int json_destroy_config(lua_State *l)
json_config_t *cfg;
cfg = lua_touserdata(l, 1);
-#ifdef USE_POSIX_USELOCALE
- if (cfg->posix_locale)
- freelocale(cfg->posix_locale);
-#endif
if (cfg)
strbuf_free(&cfg->encode_buf);
cfg = NULL;
@@ -420,13 +368,6 @@ static void json_create_config(lua_State *l)
lua_setmetatable(l, -2);
strbuf_init(&cfg->encode_buf, 0);
-#ifdef USE_POSIX_USELOCALE
- cfg->saved_locale = NULL;
- /* Must not lua_error() before cfg->posix_locale has been initialised */
- cfg->posix_locale = newlocale(LC_ALL_MASK, "C", NULL);
- if (!cfg->posix_locale)
- luaL_error(l, "Failed to create POSIX locale for JSON");
-#endif
cfg->encode_sparse_convert = DEFAULT_SPARSE_CONVERT;
cfg->encode_sparse_ratio = DEFAULT_SPARSE_RATIO;
@@ -490,7 +431,6 @@ static void json_encode_exception(lua_State *l, json_config_t *cfg, int lindex,
{
if (!cfg->encode_keep_buffer)
strbuf_free(&cfg->encode_buf);
- LOCALE_RESTORE(cfg);
luaL_error(l, "Cannot serialise %s: %s",
lua_typename(l, lua_type(l, lindex)), reason);
}
@@ -581,7 +521,6 @@ static void json_encode_descend(lua_State *l, json_config_t *cfg)
if (cfg->current_depth > cfg->encode_max_depth) {
if (!cfg->encode_keep_buffer)
strbuf_free(&cfg->encode_buf);
- LOCALE_RESTORE(cfg);
luaL_error(l, "Cannot serialise, excessive nesting (%d)",
cfg->current_depth);
}
@@ -746,13 +685,9 @@ static int json_encode(lua_State *l)
else
strbuf_init(&cfg->encode_buf, 0);
- LOCALE_SET_POSIX(cfg);
-
json_append_data(l, cfg, &cfg->encode_buf);
json = strbuf_string(&cfg->encode_buf, &len);
- LOCALE_RESTORE(cfg);
-
lua_pushlstring(l, json, len);
if (!cfg->encode_keep_buffer)
@@ -1133,8 +1068,6 @@ static void json_throw_parse_error(lua_State *l, json_parse_t *json,
else
found = json_token_type_name[token->type];
- LOCALE_RESTORE(json->cfg);
-
/* Note: token->index is 0 based, display starting from 1 */
luaL_error(l, "Expected %s but found %s at character %d",
exp, found, token->index + 1);
@@ -1146,7 +1079,6 @@ static void json_decode_checkstack(lua_State *l, json_parse_t *json, int n)
return;
strbuf_free(json->tmp);
- LOCALE_RESTORE(json->cfg);
luaL_error(l, "Too many nested data structures");
}
@@ -1276,8 +1208,6 @@ static void lua_json_decode(lua_State *l, const char *json_text, int json_len)
* string must be smaller than the entire json string */
json.tmp = strbuf_new(json_len);
- LOCALE_SET_POSIX(json.cfg);
-
json_next_token(&json, &token);
json_process_value(l, &json, &token);
@@ -1287,8 +1217,6 @@ static void lua_json_decode(lua_State *l, const char *json_text, int json_len)
if (token.type != T_END)
json_throw_parse_error(l, &json, "the end", &token);
- LOCALE_RESTORE(json.cfg);
-
strbuf_free(json.tmp);
}