From c305d55c7f321c01b4d135ef6d41879fd5f8e9f5 Mon Sep 17 00:00:00 2001 From: lijunlong Date: Tue, 10 Feb 2026 09:08:50 +0800 Subject: optimize: rename cjson.decoce_allow_comments to cjson.decocde_allow_comment. reslove two warnings and update the doc. --- README.md | 5 +++-- lua_cjson.c | 12 ++++++------ strbuf.c | 4 ++-- tests/test.lua | 8 ++++---- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 233a094..08398cb 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ Table of Contents * [encode_skip_unsupported_value_types](#encode_skip_unsupported_value_types) * [encode_indent](#encode_indent) * [decode_array_with_array_mt](#decode_array_with_array_mt) + * [decode_allow_comment](#decode_allow_comment) Description =========== @@ -263,9 +264,9 @@ cjson.encode(t) -- {"my_array":[]} properly re-encoded as an array [Back to TOC](#table-of-contents) -decode_allow_comments +decode_allow_comment -------------------------- -**syntax:** `cjson.decode_allow_comments(enabled)` +**syntax:** `cjson.decode_allow_comment(enabled)` **default:** false diff --git a/lua_cjson.c b/lua_cjson.c index de77f26..0ee9f7d 100644 --- a/lua_cjson.c +++ b/lua_cjson.c @@ -179,7 +179,7 @@ typedef struct { int decode_invalid_numbers; int decode_max_depth; int decode_array_with_array_mt; - int decode_allow_comments; + int decode_allow_comment; int encode_skip_unsupported_value_types; } json_config_t; @@ -386,11 +386,11 @@ static int json_cfg_decode_array_with_array_mt(lua_State *l) } /* Configures whether decoder allows comments */ -static int json_cfg_decode_allow_comments(lua_State *l) +static int json_cfg_decode_allow_comment(lua_State *l) { json_config_t *cfg = json_arg_init(l, 1); - json_enum_option(l, 1, &cfg->decode_allow_comments, NULL, 1); + json_enum_option(l, 1, &cfg->decode_allow_comment, NULL, 1); return 1; } @@ -527,7 +527,7 @@ static void json_create_config(lua_State *l) cfg->encode_number_precision = DEFAULT_ENCODE_NUMBER_PRECISION; cfg->encode_empty_table_as_object = DEFAULT_ENCODE_EMPTY_TABLE_AS_OBJECT; cfg->decode_array_with_array_mt = DEFAULT_DECODE_ARRAY_WITH_ARRAY_MT; - cfg->decode_allow_comments = DEFAULT_DECODE_ALLOW_COMMENTS; + cfg->decode_allow_comment = DEFAULT_DECODE_ALLOW_COMMENTS; cfg->encode_escape_forward_slash = DEFAULT_ENCODE_ESCAPE_FORWARD_SLASH; cfg->encode_skip_unsupported_value_types = DEFAULT_ENCODE_SKIP_UNSUPPORTED_VALUE_TYPES; cfg->encode_indent = DEFAULT_ENCODE_INDENT; @@ -1302,7 +1302,7 @@ static void json_next_token(json_parse_t *json, json_token_t *token) json->ptr++; } - if (!json->cfg->decode_allow_comments) + if (!json->cfg->decode_allow_comment) break; /* Eat comments. */ @@ -1671,7 +1671,7 @@ static int lua_cjson_new(lua_State *l) { "decode", json_decode }, { "encode_empty_table_as_object", json_cfg_encode_empty_table_as_object }, { "decode_array_with_array_mt", json_cfg_decode_array_with_array_mt }, - { "decode_allow_comments", json_cfg_decode_allow_comments }, + { "decode_allow_comment", json_cfg_decode_allow_comment }, { "encode_sparse_array", json_cfg_encode_sparse_array }, { "encode_max_depth", json_cfg_encode_max_depth }, { "decode_max_depth", json_cfg_decode_max_depth }, diff --git a/strbuf.c b/strbuf.c index 704f702..8aa0747 100644 --- a/strbuf.c +++ b/strbuf.c @@ -86,7 +86,7 @@ static inline void debug_stats(strbuf_t *s) { if (s->debug) { fprintf(stderr, "strbuf(%p) reallocs: %d, length: %zd, size: %zd\n", - s, s->reallocs, s->length, s->size); + (void *) s, s->reallocs, s->length, s->size); } } @@ -165,7 +165,7 @@ void strbuf_resize(strbuf_t *s, size_t len) if (s->debug > 1) { fprintf(stderr, "strbuf(%p) resize: %zd => %zd\n", - s, s->size, newsize); + (void *) s, s->size, newsize); } s->size = newsize; diff --git a/tests/test.lua b/tests/test.lua index 068a9f0..270f63a 100755 --- a/tests/test.lua +++ b/tests/test.lua @@ -334,8 +334,8 @@ local cjson_tests = { false, { "Expected value but found invalid unicode escape code at character 2" } }, -- Test comments - { 'Set decode_allow_comments(true)', - json.decode_allow_comments, { true }, true, { true } }, + { 'Set decode_allow_comment(true)', + json.decode_allow_comment, { true }, true, { true } }, { "Decode single-line comment", json.decode, { '{//comment\n}' }, true, { {} } }, { "Decode single-line comment with windows newline", @@ -356,8 +356,8 @@ local cjson_tests = { { "Decode comment inside number [throw error]", json.decode, { '{"a":1/*x*/0}' }, false, { "Expected comma or object end but found T_INTEGER at character 12" } }, - { 'Set decode_allow_comments(false)', - json.decode_allow_comments, { false }, true, { false } }, + { 'Set decode_allow_comment(false)', + json.decode_allow_comment, { false }, true, { false } }, -- Test indenting { 'Set encode_indent(" ")', -- cgit v1.2.3-55-g6feb