aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorspacewander <spacewanderlzx@gmail.com>2018-07-17 11:47:44 +0800
committerYichun Zhang (agentzh) <yichun@openresty.com>2018-10-17 14:17:54 -0700
commitf88d2b47027508bcf6f2d45bd0d07f79cd29c651 (patch)
tree58d36a29f0f8b240fc06936d0c832c8c7379505a
parentdca43df18558c87f74249a39aaacbde044d115c1 (diff)
downloadlua-cjson-f88d2b47027508bcf6f2d45bd0d07f79cd29c651.tar.gz
lua-cjson-f88d2b47027508bcf6f2d45bd0d07f79cd29c651.tar.bz2
lua-cjson-f88d2b47027508bcf6f2d45bd0d07f79cd29c651.zip
feature: ported to the ARM64 platform by masking off the bits higher than 47-bit in the lightud.2.1.0.7rc1
Signed-off-by: Yichun Zhang (agentzh) <agentzh@gmail.com>
-rw-r--r--lua_cjson.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/lua_cjson.c b/lua_cjson.c
index 505e900..9de3f5a 100644
--- a/lua_cjson.c
+++ b/lua_cjson.c
@@ -37,6 +37,7 @@
37 */ 37 */
38 38
39#include <assert.h> 39#include <assert.h>
40#include <stdint.h>
40#include <string.h> 41#include <string.h>
41#include <math.h> 42#include <math.h>
42#include <limits.h> 43#include <limits.h>
@@ -92,6 +93,9 @@
92#define strcasecmp _stricmp 93#define strcasecmp _stricmp
93#endif 94#endif
94 95
96#define json_lightudata_mask(ludata) \
97 ((void *) ((uintptr_t) (ludata) & ((1UL << 47) - 1)))
98
95static const char * const *json_empty_array; 99static const char * const *json_empty_array;
96static const char * const *json_array; 100static const char * const *json_array;
97 101
@@ -733,7 +737,7 @@ static void json_append_data(lua_State *l, json_config_t *cfg,
733 has_metatable = lua_getmetatable(l, -1); 737 has_metatable = lua_getmetatable(l, -1);
734 738
735 if (has_metatable) { 739 if (has_metatable) {
736 lua_pushlightuserdata(l, &json_array); 740 lua_pushlightuserdata(l, json_lightudata_mask(&json_array));
737 lua_rawget(l, LUA_REGISTRYINDEX); 741 lua_rawget(l, LUA_REGISTRYINDEX);
738 as_array = lua_rawequal(l, -1, -2); 742 as_array = lua_rawequal(l, -1, -2);
739 lua_pop(l, 2); 743 lua_pop(l, 2);
@@ -750,7 +754,8 @@ static void json_append_data(lua_State *l, json_config_t *cfg,
750 } else { 754 } else {
751 if (has_metatable) { 755 if (has_metatable) {
752 lua_getmetatable(l, -1); 756 lua_getmetatable(l, -1);
753 lua_pushlightuserdata(l, &json_empty_array); 757 lua_pushlightuserdata(l, json_lightudata_mask(
758 &json_empty_array));
754 lua_rawget(l, LUA_REGISTRYINDEX); 759 lua_rawget(l, LUA_REGISTRYINDEX);
755 as_array = lua_rawequal(l, -1, -2); 760 as_array = lua_rawequal(l, -1, -2);
756 lua_pop(l, 2); /* pop pointer + metatable */ 761 lua_pop(l, 2); /* pop pointer + metatable */
@@ -1277,7 +1282,7 @@ static void json_parse_array_context(lua_State *l, json_parse_t *json)
1277 1282
1278 /* set array_mt on the table at the top of the stack */ 1283 /* set array_mt on the table at the top of the stack */
1279 if (json->cfg->decode_array_with_array_mt) { 1284 if (json->cfg->decode_array_with_array_mt) {
1280 lua_pushlightuserdata(l, &json_array); 1285 lua_pushlightuserdata(l, json_lightudata_mask(&json_array));
1281 lua_rawget(l, LUA_REGISTRYINDEX); 1286 lua_rawget(l, LUA_REGISTRYINDEX);
1282 lua_setmetatable(l, -2); 1287 lua_setmetatable(l, -2);
1283 } 1288 }
@@ -1455,7 +1460,7 @@ static int lua_cjson_new(lua_State *l)
1455 fpconv_init(); 1460 fpconv_init();
1456 1461
1457 /* Test if array metatables are in registry */ 1462 /* Test if array metatables are in registry */
1458 lua_pushlightuserdata(l, &json_empty_array); 1463 lua_pushlightuserdata(l, json_lightudata_mask(&json_empty_array));
1459 lua_rawget(l, LUA_REGISTRYINDEX); 1464 lua_rawget(l, LUA_REGISTRYINDEX);
1460 if (lua_isnil(l, -1)) { 1465 if (lua_isnil(l, -1)) {
1461 /* Create array metatables. 1466 /* Create array metatables.
@@ -1467,12 +1472,12 @@ static int lua_cjson_new(lua_State *l)
1467 lua_pop(l, 1); 1472 lua_pop(l, 1);
1468 1473
1469 /* empty_array_mt */ 1474 /* empty_array_mt */
1470 lua_pushlightuserdata(l, &json_empty_array); 1475 lua_pushlightuserdata(l, json_lightudata_mask(&json_empty_array));
1471 lua_newtable(l); 1476 lua_newtable(l);
1472 lua_rawset(l, LUA_REGISTRYINDEX); 1477 lua_rawset(l, LUA_REGISTRYINDEX);
1473 1478
1474 /* array_mt */ 1479 /* array_mt */
1475 lua_pushlightuserdata(l, &json_array); 1480 lua_pushlightuserdata(l, json_lightudata_mask(&json_array));
1476 lua_newtable(l); 1481 lua_newtable(l);
1477 lua_rawset(l, LUA_REGISTRYINDEX); 1482 lua_rawset(l, LUA_REGISTRYINDEX);
1478 } 1483 }
@@ -1489,17 +1494,17 @@ static int lua_cjson_new(lua_State *l)
1489 lua_setfield(l, -2, "null"); 1494 lua_setfield(l, -2, "null");
1490 1495
1491 /* Set cjson.empty_array_mt */ 1496 /* Set cjson.empty_array_mt */
1492 lua_pushlightuserdata(l, &json_empty_array); 1497 lua_pushlightuserdata(l, json_lightudata_mask(&json_empty_array));
1493 lua_rawget(l, LUA_REGISTRYINDEX); 1498 lua_rawget(l, LUA_REGISTRYINDEX);
1494 lua_setfield(l, -2, "empty_array_mt"); 1499 lua_setfield(l, -2, "empty_array_mt");
1495 1500
1496 /* Set cjson.array_mt */ 1501 /* Set cjson.array_mt */
1497 lua_pushlightuserdata(l, &json_array); 1502 lua_pushlightuserdata(l, json_lightudata_mask(&json_array));
1498 lua_rawget(l, LUA_REGISTRYINDEX); 1503 lua_rawget(l, LUA_REGISTRYINDEX);
1499 lua_setfield(l, -2, "array_mt"); 1504 lua_setfield(l, -2, "array_mt");
1500 1505
1501 /* Set cjson.empty_array */ 1506 /* Set cjson.empty_array */
1502 lua_pushlightuserdata(l, &json_array); 1507 lua_pushlightuserdata(l, json_lightudata_mask(&json_array));
1503 lua_setfield(l, -2, "empty_array"); 1508 lua_setfield(l, -2, "empty_array");
1504 1509
1505 /* Set module name / version fields */ 1510 /* Set module name / version fields */