diff options
| author | ruki <[email protected]> | 2024-05-07 22:45:17 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2024-05-07 22:45:17 +0800 |
| commit | 9cfed981e14f97344e4c24e6a213a6d67a247d8c (patch) | |
| tree | 2b65c3823bdcfe84e09b5b6f1a98e9447a69edd7 | |
| parent | 1d2fd828a4a7af1f8196f333f6bb79e5161107dc (diff) | |
use integer instead of number #5029
| -rw-r--r-- | core/src/xmake/base64/encode.c | 5 | ||||
| -rw-r--r-- | core/src/xmake/bloom_filter/bloom_filter_data_set.c | 5 | ||||
| -rw-r--r-- | core/src/xmake/hash/md5.c | 7 | ||||
| -rw-r--r-- | core/src/xmake/hash/sha.c | 9 | ||||
| -rw-r--r-- | core/src/xmake/hash/xxhash.c | 9 | ||||
| -rw-r--r-- | core/src/xmake/io/file_write.c | 9 | ||||
| -rw-r--r-- | core/src/xmake/io/pipe_read.c | 7 | ||||
| -rw-r--r-- | core/src/xmake/io/pipe_write.c | 5 | ||||
| -rw-r--r-- | core/src/xmake/io/socket_recv.c | 7 | ||||
| -rw-r--r-- | core/src/xmake/io/socket_recvfrom.c | 7 | ||||
| -rw-r--r-- | core/src/xmake/io/socket_send.c | 5 | ||||
| -rw-r--r-- | core/src/xmake/io/socket_sendto.c | 5 | ||||
| -rw-r--r-- | core/src/xmake/lz4/block_compress.c | 5 | ||||
| -rw-r--r-- | core/src/xmake/lz4/block_decompress.c | 5 | ||||
| -rw-r--r-- | core/src/xmake/lz4/compress.c | 5 | ||||
| -rw-r--r-- | core/src/xmake/lz4/compress_stream_read.c | 7 | ||||
| -rw-r--r-- | core/src/xmake/lz4/compress_stream_write.c | 5 | ||||
| -rw-r--r-- | core/src/xmake/lz4/decompress.c | 5 | ||||
| -rw-r--r-- | core/src/xmake/lz4/decompress_stream_read.c | 7 | ||||
| -rw-r--r-- | core/src/xmake/lz4/decompress_stream_write.c | 5 |
20 files changed, 72 insertions, 52 deletions
diff --git a/core/src/xmake/base64/encode.c b/core/src/xmake/base64/encode.c index ce9fc8a2a..0bb3ec339 100644 --- a/core/src/xmake/base64/encode.c +++ b/core/src/xmake/base64/encode.c @@ -41,14 +41,15 @@ tb_int_t xm_base64_encode(lua_State* lua) // get data and size tb_size_t size = 0; tb_byte_t const* data = tb_null; - if (lua_isnumber(lua, 1)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tonumber(lua, 1); - if (lua_isnumber(lua, 2)) size = (tb_size_t)lua_tonumber(lua, 2); + if (lua_isinteger(lua, 1)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 1); + if (lua_isinteger(lua, 2)) size = (tb_size_t)lua_tointeger(lua, 2); if (!data || !size) { lua_pushnil(lua); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); return 2; } + tb_assert_static(sizeof(lua_Integer) == sizeof(tb_pointer_t)); // encode it tb_char_t buff[8192]; diff --git a/core/src/xmake/bloom_filter/bloom_filter_data_set.c b/core/src/xmake/bloom_filter/bloom_filter_data_set.c index 330ba393e..116d1900c 100644 --- a/core/src/xmake/bloom_filter/bloom_filter_data_set.c +++ b/core/src/xmake/bloom_filter/bloom_filter_data_set.c @@ -49,14 +49,15 @@ tb_int_t xm_bloom_filter_data_set(lua_State* lua) // get data and size tb_size_t size = 0; tb_byte_t const* data = tb_null; - if (lua_isnumber(lua, 2)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tonumber(lua, 2); - if (lua_isnumber(lua, 3)) size = (tb_size_t)lua_tonumber(lua, 3); + if (lua_isinteger(lua, 2)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); + if (lua_isinteger(lua, 3)) size = (tb_size_t)lua_tointeger(lua, 3); if (!data || !size) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); return 2; } + tb_assert_static(sizeof(lua_Integer) == sizeof(tb_pointer_t)); // set data tb_bool_t ok = tb_bloom_filter_data_set(filter, data, size); diff --git a/core/src/xmake/hash/md5.c b/core/src/xmake/hash/md5.c index d392ae670..5d388306c 100644 --- a/core/src/xmake/hash/md5.c +++ b/core/src/xmake/hash/md5.c @@ -39,16 +39,17 @@ tb_int_t xm_hash_md5(lua_State* lua) tb_assert_and_check_return_val(lua, 0); // is bytes? get data and size - if (lua_isnumber(lua, 1) && lua_isnumber(lua, 2)) + if (lua_isinteger(lua, 1) && lua_isinteger(lua, 2)) { - tb_byte_t const* data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tonumber(lua, 1); - tb_size_t size = (tb_size_t)lua_tonumber(lua, 2); + tb_byte_t const* data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 1); + tb_size_t size = (tb_size_t)lua_tointeger(lua, 2); if (!data || !size) { lua_pushnil(lua); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); return 2; } + tb_assert_static(sizeof(lua_Integer) == sizeof(tb_pointer_t)); // compute md5 tb_byte_t buffer[16]; diff --git a/core/src/xmake/hash/sha.c b/core/src/xmake/hash/sha.c index a89ee5df7..00de5d078 100644 --- a/core/src/xmake/hash/sha.c +++ b/core/src/xmake/hash/sha.c @@ -39,19 +39,20 @@ tb_int_t xm_hash_sha(lua_State* lua) tb_assert_and_check_return_val(lua, 0); // get mode - tb_size_t mode = (tb_size_t)lua_tonumber(lua, 1); + tb_size_t mode = (tb_size_t)lua_tointeger(lua, 1); // is bytes? get data and size - if (lua_isnumber(lua, 2) && lua_isnumber(lua, 3)) + if (lua_isinteger(lua, 2) && lua_isinteger(lua, 3)) { - tb_byte_t const* data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tonumber(lua, 2); - tb_size_t size = (tb_size_t)lua_tonumber(lua, 3); + tb_byte_t const* data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); + tb_size_t size = (tb_size_t)lua_tointeger(lua, 3); if (!data || !size) { lua_pushnil(lua); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); return 2; } + tb_assert_static(sizeof(lua_Integer) == sizeof(tb_pointer_t)); // compute sha tb_sha_t sha; diff --git a/core/src/xmake/hash/xxhash.c b/core/src/xmake/hash/xxhash.c index 9901f58f6..f2b73a695 100644 --- a/core/src/xmake/hash/xxhash.c +++ b/core/src/xmake/hash/xxhash.c @@ -43,7 +43,7 @@ tb_int_t xm_hash_xxhash(lua_State* lua) tb_assert_and_check_return_val(lua, 0); // get mode - tb_size_t mode = (tb_size_t)lua_tonumber(lua, 1); + tb_size_t mode = (tb_size_t)lua_tointeger(lua, 1); if (mode != 64 && mode != 128) { lua_pushnil(lua); @@ -52,10 +52,11 @@ tb_int_t xm_hash_xxhash(lua_State* lua) } // is bytes? get data and size - if (lua_isnumber(lua, 2) && lua_isnumber(lua, 3)) + if (lua_isinteger(lua, 2) && lua_isinteger(lua, 3)) { - tb_byte_t const* data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tonumber(lua, 2); - tb_size_t size = (tb_size_t)lua_tonumber(lua, 3); + tb_assert_static(sizeof(lua_Integer) == sizeof(tb_pointer_t)); + tb_byte_t const* data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); + tb_size_t size = (tb_size_t)lua_tointeger(lua, 3); if (!data || !size) { lua_pushnil(lua); diff --git a/core/src/xmake/io/file_write.c b/core/src/xmake/io/file_write.c index 97285dca7..9504e188b 100644 --- a/core/src/xmake/io/file_write.c +++ b/core/src/xmake/io/file_write.c @@ -166,14 +166,15 @@ tb_int_t xm_io_file_write(lua_State* lua) // get bytes data lua_pushstring(lua, "data"); lua_gettable(lua, i); - if (lua_isnumber(lua, -1)) - data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tonumber(lua, -1); + if (lua_isinteger(lua, -1)) + data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, -1); lua_pop(lua, 1); + tb_assert_static(sizeof(lua_Integer) == sizeof(tb_pointer_t)); lua_pushstring(lua, "size"); lua_gettable(lua, i); - if (lua_isnumber(lua, -1)) - datasize = (tb_size_t)lua_tonumber(lua, -1); + if (lua_isinteger(lua, -1)) + datasize = (tb_size_t)lua_tointeger(lua, -1); lua_pop(lua, 1); // mark as binary data diff --git a/core/src/xmake/io/pipe_read.c b/core/src/xmake/io/pipe_read.c index 72a931f5c..7553f89dd 100644 --- a/core/src/xmake/io/pipe_read.c +++ b/core/src/xmake/io/pipe_read.c @@ -54,18 +54,19 @@ tb_int_t xm_io_pipe_read(lua_State* lua) // get data tb_byte_t* data = tb_null; - if (lua_isnumber(lua, 2)) - data = (tb_byte_t*)(tb_size_t)(tb_long_t)lua_tonumber(lua, 2); + if (lua_isinteger(lua, 2)) + data = (tb_byte_t*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); if (!data) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid data(%p)!", data); return 2; } + tb_assert_static(sizeof(lua_Integer) == sizeof(tb_pointer_t)); // get size tb_long_t size = 0; - if (lua_isnumber(lua, 3)) size = (tb_long_t)lua_tonumber(lua, 3); + if (lua_isinteger(lua, 3)) size = (tb_long_t)lua_tointeger(lua, 3); if (size <= 0) { lua_pushinteger(lua, -1); diff --git a/core/src/xmake/io/pipe_write.c b/core/src/xmake/io/pipe_write.c index 0c8c2bd12..54b82339b 100644 --- a/core/src/xmake/io/pipe_write.c +++ b/core/src/xmake/io/pipe_write.c @@ -55,14 +55,15 @@ tb_int_t xm_io_pipe_write(lua_State* lua) // get data and size tb_size_t size = 0; tb_byte_t const* data = tb_null; - if (lua_isnumber(lua, 2)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tonumber(lua, 2); - if (lua_isnumber(lua, 3)) size = (tb_size_t)lua_tonumber(lua, 3); + if (lua_isinteger(lua, 2)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); + if (lua_isinteger(lua, 3)) size = (tb_size_t)lua_tointeger(lua, 3); if (!data || !size) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); return 2; } + tb_assert_static(sizeof(lua_Integer) == sizeof(tb_pointer_t)); // write data tb_long_t real = tb_pipe_file_write(pipefile, data, size); diff --git a/core/src/xmake/io/socket_recv.c b/core/src/xmake/io/socket_recv.c index e3bd2dfed..8b5bfdf0e 100644 --- a/core/src/xmake/io/socket_recv.c +++ b/core/src/xmake/io/socket_recv.c @@ -54,18 +54,19 @@ tb_int_t xm_io_socket_recv(lua_State* lua) // get data tb_byte_t* data = tb_null; - if (lua_isnumber(lua, 2)) - data = (tb_byte_t*)(tb_size_t)(tb_long_t)lua_tonumber(lua, 2); + if (lua_isinteger(lua, 2)) + data = (tb_byte_t*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); if (!data) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid data(%p)!", data); return 2; } + tb_assert_static(sizeof(lua_Integer) == sizeof(tb_pointer_t)); // get size tb_long_t size = 0; - if (lua_isnumber(lua, 3)) size = (tb_long_t)lua_tonumber(lua, 3); + if (lua_isinteger(lua, 3)) size = (tb_long_t)lua_tointeger(lua, 3); if (size <= 0) { lua_pushinteger(lua, -1); diff --git a/core/src/xmake/io/socket_recvfrom.c b/core/src/xmake/io/socket_recvfrom.c index 2a6ed7a16..2558ebaf4 100644 --- a/core/src/xmake/io/socket_recvfrom.c +++ b/core/src/xmake/io/socket_recvfrom.c @@ -54,18 +54,19 @@ tb_int_t xm_io_socket_recvfrom(lua_State* lua) // get data tb_byte_t* data = tb_null; - if (lua_isnumber(lua, 2)) - data = (tb_byte_t*)(tb_size_t)(tb_long_t)lua_tonumber(lua, 2); + if (lua_isinteger(lua, 2)) + data = (tb_byte_t*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); if (!data) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid data(%p)!", data); return 2; } + tb_assert_static(sizeof(lua_Integer) == sizeof(tb_pointer_t)); // get size tb_long_t size = 0; - if (lua_isnumber(lua, 3)) size = (tb_long_t)lua_tonumber(lua, 3); + if (lua_isinteger(lua, 3)) size = (tb_long_t)lua_tointeger(lua, 3); if (size <= 0) { lua_pushinteger(lua, -1); diff --git a/core/src/xmake/io/socket_send.c b/core/src/xmake/io/socket_send.c index ecf3421ff..3cf69f298 100644 --- a/core/src/xmake/io/socket_send.c +++ b/core/src/xmake/io/socket_send.c @@ -55,14 +55,15 @@ tb_int_t xm_io_socket_send(lua_State* lua) // get data and size tb_size_t size = 0; tb_byte_t const* data = tb_null; - if (lua_isnumber(lua, 2)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tonumber(lua, 2); - if (lua_isnumber(lua, 3)) size = (tb_size_t)lua_tonumber(lua, 3); + if (lua_isinteger(lua, 2)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); + if (lua_isinteger(lua, 3)) size = (tb_size_t)lua_tointeger(lua, 3); if (!data || !size) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); return 2; } + tb_assert_static(sizeof(lua_Integer) == sizeof(tb_pointer_t)); // send data tb_long_t real = tb_socket_send(sock, data, size); diff --git a/core/src/xmake/io/socket_sendto.c b/core/src/xmake/io/socket_sendto.c index de3b39b75..c8e315b48 100644 --- a/core/src/xmake/io/socket_sendto.c +++ b/core/src/xmake/io/socket_sendto.c @@ -55,14 +55,15 @@ tb_int_t xm_io_socket_sendto(lua_State* lua) // get data and size tb_size_t size = 0; tb_byte_t const* data = tb_null; - if (lua_isnumber(lua, 2)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tonumber(lua, 2); - if (lua_isnumber(lua, 3)) size = (tb_size_t)lua_tonumber(lua, 3); + if (lua_isinteger(lua, 2)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); + if (lua_isinteger(lua, 3)) size = (tb_size_t)lua_tointeger(lua, 3); if (!data || !size) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); return 2; } + tb_assert_static(sizeof(lua_Integer) == sizeof(tb_pointer_t)); // get address tb_char_t const* addr = lua_tostring(lua, 4); diff --git a/core/src/xmake/lz4/block_compress.c b/core/src/xmake/lz4/block_compress.c index 206f22c17..46201ef22 100644 --- a/core/src/xmake/lz4/block_compress.c +++ b/core/src/xmake/lz4/block_compress.c @@ -41,14 +41,15 @@ tb_int_t xm_lz4_block_compress(lua_State* lua) // get data and size tb_int_t size = 0; tb_byte_t const* data = tb_null; - if (lua_isnumber(lua, 1)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tonumber(lua, 1); - if (lua_isnumber(lua, 2)) size = (tb_int_t)lua_tointeger(lua, 2); + if (lua_isinteger(lua, 1)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 1); + if (lua_isinteger(lua, 2)) size = (tb_int_t)lua_tointeger(lua, 2); if (!data || !size || size > LZ4_MAX_INPUT_SIZE) { lua_pushnil(lua); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); return 2; } + tb_assert_static(sizeof(lua_Integer) == sizeof(tb_pointer_t)); // do compress tb_bool_t ok = tb_false; diff --git a/core/src/xmake/lz4/block_decompress.c b/core/src/xmake/lz4/block_decompress.c index d9972f595..5df99eba6 100644 --- a/core/src/xmake/lz4/block_decompress.c +++ b/core/src/xmake/lz4/block_decompress.c @@ -41,14 +41,15 @@ tb_int_t xm_lz4_block_decompress(lua_State* lua) // get data and size tb_size_t size = 0; tb_byte_t const* data = tb_null; - if (lua_isnumber(lua, 1)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tonumber(lua, 1); - if (lua_isnumber(lua, 2)) size = (tb_size_t)lua_tonumber(lua, 2); + if (lua_isinteger(lua, 1)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 1); + if (lua_isinteger(lua, 2)) size = (tb_size_t)lua_tointeger(lua, 2); if (!data || !size) { lua_pushnil(lua); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); return 2; } + tb_assert_static(sizeof(lua_Integer) == sizeof(tb_pointer_t)); // get real size tb_int_t real = (tb_int_t)lua_tointeger(lua, 3); diff --git a/core/src/xmake/lz4/compress.c b/core/src/xmake/lz4/compress.c index 298023b0b..5e77191b1 100644 --- a/core/src/xmake/lz4/compress.c +++ b/core/src/xmake/lz4/compress.c @@ -41,14 +41,15 @@ tb_int_t xm_lz4_compress(lua_State* lua) // get data and size tb_size_t size = 0; tb_byte_t const* data = tb_null; - if (lua_isnumber(lua, 1)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tonumber(lua, 1); - if (lua_isnumber(lua, 2)) size = (tb_size_t)lua_tonumber(lua, 2); + if (lua_isinteger(lua, 1)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 1); + if (lua_isinteger(lua, 2)) size = (tb_size_t)lua_tointeger(lua, 2); if (!data || !size) { lua_pushnil(lua); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); return 2; } + tb_assert_static(sizeof(lua_Integer) == sizeof(tb_pointer_t)); // do compress tb_bool_t ok = tb_false; diff --git a/core/src/xmake/lz4/compress_stream_read.c b/core/src/xmake/lz4/compress_stream_read.c index cf5e6b8e3..06dadef3c 100644 --- a/core/src/xmake/lz4/compress_stream_read.c +++ b/core/src/xmake/lz4/compress_stream_read.c @@ -53,18 +53,19 @@ tb_int_t xm_lz4_compress_stream_read(lua_State* lua) // get data tb_byte_t* data = tb_null; - if (lua_isnumber(lua, 2)) - data = (tb_byte_t*)(tb_size_t)(tb_long_t)lua_tonumber(lua, 2); + if (lua_isinteger(lua, 2)) + data = (tb_byte_t*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); if (!data) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid data(%p)!", data); return 2; } + tb_assert_static(sizeof(lua_Integer) == sizeof(tb_pointer_t)); // get size tb_long_t size = 0; - if (lua_isnumber(lua, 3)) size = (tb_long_t)lua_tonumber(lua, 3); + if (lua_isinteger(lua, 3)) size = (tb_long_t)lua_tointeger(lua, 3); if (size <= 0) { lua_pushinteger(lua, -1); diff --git a/core/src/xmake/lz4/compress_stream_write.c b/core/src/xmake/lz4/compress_stream_write.c index 066839bab..3f584d0a8 100644 --- a/core/src/xmake/lz4/compress_stream_write.c +++ b/core/src/xmake/lz4/compress_stream_write.c @@ -54,14 +54,15 @@ tb_int_t xm_lz4_compress_stream_write(lua_State* lua) // get data and size tb_size_t size = 0; tb_byte_t const* data = tb_null; - if (lua_isnumber(lua, 2)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tonumber(lua, 2); - if (lua_isnumber(lua, 3)) size = (tb_size_t)lua_tonumber(lua, 3); + if (lua_isinteger(lua, 2)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); + if (lua_isinteger(lua, 3)) size = (tb_size_t)lua_tointeger(lua, 3); if (!data || !size) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); return 2; } + tb_assert_static(sizeof(lua_Integer) == sizeof(tb_pointer_t)); // is end? tb_bool_t end = tb_false; diff --git a/core/src/xmake/lz4/decompress.c b/core/src/xmake/lz4/decompress.c index 44cdf79d4..8e08e8f2a 100644 --- a/core/src/xmake/lz4/decompress.c +++ b/core/src/xmake/lz4/decompress.c @@ -41,14 +41,15 @@ tb_int_t xm_lz4_decompress(lua_State* lua) // get data and size tb_size_t size = 0; tb_byte_t const* data = tb_null; - if (lua_isnumber(lua, 1)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tonumber(lua, 1); - if (lua_isnumber(lua, 2)) size = (tb_size_t)lua_tonumber(lua, 2); + if (lua_isinteger(lua, 1)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 1); + if (lua_isinteger(lua, 2)) size = (tb_size_t)lua_tointeger(lua, 2); if (!data || !size) { lua_pushnil(lua); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); return 2; } + tb_assert_static(sizeof(lua_Integer) == sizeof(tb_pointer_t)); // do decompress tb_bool_t ok = tb_false; diff --git a/core/src/xmake/lz4/decompress_stream_read.c b/core/src/xmake/lz4/decompress_stream_read.c index 61f920354..6b54336ca 100644 --- a/core/src/xmake/lz4/decompress_stream_read.c +++ b/core/src/xmake/lz4/decompress_stream_read.c @@ -53,18 +53,19 @@ tb_int_t xm_lz4_decompress_stream_read(lua_State* lua) // get data tb_byte_t* data = tb_null; - if (lua_isnumber(lua, 2)) - data = (tb_byte_t*)(tb_size_t)(tb_long_t)lua_tonumber(lua, 2); + if (lua_isinteger(lua, 2)) + data = (tb_byte_t*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); if (!data) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid data(%p)!", data); return 2; } + tb_assert_static(sizeof(lua_Integer) == sizeof(tb_pointer_t)); // get size tb_long_t size = 0; - if (lua_isnumber(lua, 3)) size = (tb_long_t)lua_tonumber(lua, 3); + if (lua_isinteger(lua, 3)) size = (tb_long_t)lua_tointeger(lua, 3); if (size <= 0) { lua_pushinteger(lua, -1); diff --git a/core/src/xmake/lz4/decompress_stream_write.c b/core/src/xmake/lz4/decompress_stream_write.c index 00a652349..60fbb4f58 100644 --- a/core/src/xmake/lz4/decompress_stream_write.c +++ b/core/src/xmake/lz4/decompress_stream_write.c @@ -54,14 +54,15 @@ tb_int_t xm_lz4_decompress_stream_write(lua_State* lua) // get data and size tb_size_t size = 0; tb_byte_t const* data = tb_null; - if (lua_isnumber(lua, 2)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tonumber(lua, 2); - if (lua_isnumber(lua, 3)) size = (tb_size_t)lua_tonumber(lua, 3); + if (lua_isinteger(lua, 2)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); + if (lua_isinteger(lua, 3)) size = (tb_size_t)lua_tointeger(lua, 3); if (!data || !size) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); return 2; } + tb_assert_static(sizeof(lua_Integer) == sizeof(tb_pointer_t)); // write data tb_long_t real = xm_lz4_dstream_write(stream, data, size, tb_false); |
