aboutsummaryrefslogtreecommitdiffstats
path: root/main/lua-cjson
diff options
context:
space:
mode:
authorKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2017-05-25 13:03:08 +0300
committerKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2017-05-25 13:03:08 +0300
commit1b818894b380a14c33fe2eb880d3393a3f9db354 (patch)
tree69ea35ab2b571b8b640d691419b6899e76b90441 /main/lua-cjson
parent3db1fe39c495486ce8c4e6f93bce8da75d9e0a10 (diff)
downloadaports-1b818894b380a14c33fe2eb880d3393a3f9db354.tar.bz2
aports-1b818894b380a14c33fe2eb880d3393a3f9db354.tar.xz
main/lua-cjson: sort object keys
Diffstat (limited to 'main/lua-cjson')
-rw-r--r--main/lua-cjson/0004-Option-for-sorting-object-keys.patch156
-rw-r--r--main/lua-cjson/APKBUILD14
2 files changed, 160 insertions, 10 deletions
diff --git a/main/lua-cjson/0004-Option-for-sorting-object-keys.patch b/main/lua-cjson/0004-Option-for-sorting-object-keys.patch
new file mode 100644
index 0000000000..21c6aae17f
--- /dev/null
+++ b/main/lua-cjson/0004-Option-for-sorting-object-keys.patch
@@ -0,0 +1,156 @@
+From 58da501ed46ee364b10bf079df78e63c195ecd0f Mon Sep 17 00:00:00 2001
+From: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
+Date: Mon, 22 May 2017 19:10:58 +0300
+Subject: [PATCH] Option for sorting object keys
+
+---
+ lua_cjson.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++------
+ 1 file changed, 62 insertions(+), 6 deletions(-)
+
+diff --git a/lua_cjson.c b/lua_cjson.c
+index 22f33f1..ac9fa42 100644
+--- a/lua_cjson.c
++++ b/lua_cjson.c
+@@ -65,6 +65,10 @@
+ #define isinf(x) (!isnan(x) && isnan((x) - (x)))
+ #endif
+
++#if LUA_VERSION_NUM > 501
++#define lua_lessthan(l, a, b) (lua_compare((l), (a), (b), LUA_OPLT))
++#endif
++
+ #define DEFAULT_SPARSE_CONVERT 0
+ #define DEFAULT_SPARSE_RATIO 2
+ #define DEFAULT_SPARSE_SAFE 10
+@@ -74,6 +78,7 @@
+ #define DEFAULT_DECODE_INVALID_NUMBERS 1
+ #define DEFAULT_ENCODE_KEEP_BUFFER 1
+ #define DEFAULT_ENCODE_NUMBER_PRECISION 14
++#define DEFAULT_ENCODE_SORT_KEYS 0
+
+ #ifdef DISABLE_INVALID_NUMBERS
+ #undef DEFAULT_DECODE_INVALID_NUMBERS
+@@ -130,6 +135,7 @@ typedef struct {
+ int encode_invalid_numbers; /* 2 => Encode as "null" */
+ int encode_number_precision;
+ int encode_keep_buffer;
++ int encode_sort_keys;
+
+ int decode_invalid_numbers;
+ int decode_max_depth;
+@@ -327,6 +333,14 @@ static int json_cfg_encode_keep_buffer(lua_State *l)
+ return 1;
+ }
+
++/* Configures whether object keys are sorted when encoding */
++static int json_cfg_encode_sort_keys(lua_State *l)
++{
++ json_config_t *cfg = json_arg_init(l, 1);
++
++ return json_enum_option(l, 1, &cfg->encode_sort_keys, NULL, 1);
++}
++
+ #if defined(DISABLE_INVALID_NUMBERS) && !defined(USE_INTERNAL_FPCONV)
+ void json_verify_invalid_number_setting(lua_State *l, int *setting)
+ {
+@@ -396,6 +410,7 @@ static void json_create_config(lua_State *l)
+ cfg->decode_invalid_numbers = DEFAULT_DECODE_INVALID_NUMBERS;
+ cfg->encode_keep_buffer = DEFAULT_ENCODE_KEEP_BUFFER;
+ cfg->encode_number_precision = DEFAULT_ENCODE_NUMBER_PRECISION;
++ cfg->encode_sort_keys = DEFAULT_ENCODE_SORT_KEYS;
+
+ #if DEFAULT_ENCODE_KEEP_BUFFER > 0
+ strbuf_init(&cfg->encode_buf, 0);
+@@ -627,24 +642,66 @@ static void json_append_number(lua_State *l, json_config_t *cfg,
+ strbuf_extend_length(json, len);
+ }
+
++static void sort_lua_stack(lua_State *l, int lo, int hi)
++{
++ if (lo >= hi)
++ return;
++
++ int i = lo - 1;
++ int j = hi + 1;
++
++ lua_pushvalue(l, lo);
++
++ while (1) {
++ while (lua_lessthan(l, -1, ++i));
++ while (lua_lessthan(l, --j, -1));
++ if (i >= j)
++ break;
++
++ lua_pushvalue(l, i);
++ lua_pushvalue(l, j);
++ lua_replace(l, i);
++ lua_replace(l, j);
++ }
++
++ lua_pop(l, 1);
++
++ sort_lua_stack(l, lo, j);
++ sort_lua_stack(l, j + 1, hi);
++}
++
+ static void json_append_object(lua_State *l, json_config_t *cfg,
+ int current_depth, strbuf_t *json)
+ {
+ int comma, keytype;
++ int sort = cfg->encode_sort_keys;
++ int tbl_index = lua_gettop(l);
+
+ /* Object */
+ strbuf_append_char(json, '{');
+
+ lua_pushnil(l);
+- /* table, startkey */
++
++ if (sort) {
++ while (lua_next(l, tbl_index)) {
++ lua_pop(l, 1);
++ lua_pushvalue(l, -1);
++ }
++ sort_lua_stack(l, tbl_index + 1, lua_gettop(l));
++ }
++
+ comma = 0;
+- while (lua_next(l, -2) != 0) {
++ while (sort ? lua_gettop(l) > tbl_index : lua_next(l, tbl_index)) {
+ if (comma)
+ strbuf_append_char(json, ',');
+ else
+ comma = 1;
+
+- /* table, key, value */
++ if (sort) {
++ lua_pushvalue(l, -1);
++ lua_gettable(l, tbl_index);
++ }
++
+ keytype = lua_type(l, -2);
+ if (keytype == LUA_TNUMBER) {
+ strbuf_append_char(json, '"');
+@@ -659,10 +716,8 @@ static void json_append_object(lua_State *l, json_config_t *cfg,
+ /* never returns */
+ }
+
+- /* table, key, value */
+ json_append_data(l, cfg, current_depth, json);
+- lua_pop(l, 1);
+- /* table, key */
++ lua_pop(l, sort ? 2 : 1);
+ }
+
+ strbuf_append_char(json, '}');
+@@ -1365,6 +1420,7 @@ static int lua_cjson_new(lua_State *l)
+ { "encode_keep_buffer", json_cfg_encode_keep_buffer },
+ { "encode_invalid_numbers", json_cfg_encode_invalid_numbers },
+ { "decode_invalid_numbers", json_cfg_decode_invalid_numbers },
++ { "encode_sort_keys", json_cfg_encode_sort_keys },
+ { "new", lua_cjson_new },
+ { NULL, NULL }
+ };
+--
+2.13.0
+
diff --git a/main/lua-cjson/APKBUILD b/main/lua-cjson/APKBUILD
index 8f9dbd6e6e..d9111feee1 100644
--- a/main/lua-cjson/APKBUILD
+++ b/main/lua-cjson/APKBUILD
@@ -3,7 +3,7 @@
_luaversions="5.1 5.2 5.3"
pkgname=lua-cjson
pkgver=2.1.0
-pkgrel=6
+pkgrel=7
pkgdesc="fast JSON parsing and encoding support for Lua"
url="http://www.kyne.com.au/~mark/software/lua-cjson.php"
arch="all"
@@ -20,6 +20,7 @@ source="http://www.kyne.com.au/~mark/software/download/lua-cjson-$pkgver.tar.gz
0001-Use-pkg-config-to-detect-cflags-or-fallback-to-LUA_I.patch
0002-lua53-integers.patch
0003-empty-array-metadata.patch
+ 0004-Option-for-sorting-object-keys.patch
"
@@ -72,15 +73,8 @@ for _i in $_luaversions; do
eval "split_${_i/./_}() { _split $_i; }"
done
-md5sums="24f270663e9f6ca8ba2a02cef19f7963 lua-cjson-2.1.0.tar.gz
-84a94739f4ead0b4b2e80376dbed7b08 0001-Use-pkg-config-to-detect-cflags-or-fallback-to-LUA_I.patch
-1b37edbe331691d96d9a506ed6fbe1db 0002-lua53-integers.patch
-18d361083d5b5aab987d897629a38982 0003-empty-array-metadata.patch"
-sha256sums="51bc69cd55931e0cba2ceae39e9efa2483f4292da3a88a1ed470eda829f6c778 lua-cjson-2.1.0.tar.gz
-cef22bd926c88053b1be147c6420e9b9918b09a32cb3cad9e81524619048020a 0001-Use-pkg-config-to-detect-cflags-or-fallback-to-LUA_I.patch
-76bcddec37e70538831d366998e7b1ccf9609bd7f07fe181b3475667be7dcfd9 0002-lua53-integers.patch
-a28eb784e0d33d149f69f1011a8f65549c38cbe5d9a2e823ce40c3cd9c7c6cde 0003-empty-array-metadata.patch"
sha512sums="4343513b942f2ed98dc1ea6d7e852303bc1263f8acc5c70c8d674aec7adfc8279c5af7d5173a417b6f9a74543b8f6c8f98742d002f4f75832bbf23bb5a30ad2f lua-cjson-2.1.0.tar.gz
5137cf25ca125b03ff2e95cedd8396d63b9a4919b1aba4ef333fd8945a4fd20f423c1e8d36b954a15969bd344cd43bb6c50df8b878cd74a706d6065455fbb003 0001-Use-pkg-config-to-detect-cflags-or-fallback-to-LUA_I.patch
2cf4d4fa116850a6a8fb74f27779383a339ca08ed81cdcb03be985c731b91234e7552a26913b609f2c9b02516fc74171d4e5fbb446bcdaf0eddddac3af08865a 0002-lua53-integers.patch
-77a05166a88b7ec7d1c7fa2cd7e22fdf75dd2882d67529f8c924e8408c8bf3d210b8e2cd803cffc6d6460a63e079e331237811f1dbfeb03051090f4d6278a350 0003-empty-array-metadata.patch"
+77a05166a88b7ec7d1c7fa2cd7e22fdf75dd2882d67529f8c924e8408c8bf3d210b8e2cd803cffc6d6460a63e079e331237811f1dbfeb03051090f4d6278a350 0003-empty-array-metadata.patch
+d76c5ad8edd9f7ad017254ad1d1e9a822a42a12b9783a8217ab74e8afcc0aa58967dce52405e081ebd3ea63a63e8b0d0383c19112bfa579e10b47cd58debb7ee 0004-Option-for-sorting-object-keys.patch"