diff options
| author | ruki <[email protected]> | 2024-05-07 14:57:51 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-05-07 14:57:51 +0800 |
| commit | d9c1e1f6c9e7f4dd3564d7c61e5e3a73b9168c0c (patch) | |
| tree | d4f5e292b1173c2f1933ad20bc180af4a6cf50e3 | |
| parent | 1d2fd828a4a7af1f8196f333f6bb79e5161107dc (diff) | |
| parent | 243b757b48eace689d0c1e63f8dd80f4f47471a2 (diff) | |
Merge pull request #5068 from xmake-io/termux
use integer instead of number
22 files changed, 82 insertions, 53 deletions
diff --git a/core/src/xmake/base64/encode.c b/core/src/xmake/base64/encode.c index ce9fc8a2a..acf0b7c25 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 (xm_lua_isinteger(lua, 1)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 1); + if (xm_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..6de4a5d4a 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 (xm_lua_isinteger(lua, 2)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); + if (xm_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..c9ec2fb36 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 (xm_lua_isinteger(lua, 1) && xm_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..720647cdf 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 (xm_lua_isinteger(lua, 2) && xm_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..12dd3ba10 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,16 +52,17 @@ 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 (xm_lua_isinteger(lua, 2) && xm_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)); // compuate hash tb_byte_t const* buffer; diff --git a/core/src/xmake/io/file_write.c b/core/src/xmake/io/file_write.c index 97285dca7..9411efc31 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 (xm_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 (xm_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..9644e9e14 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 (xm_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 (xm_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..847e57544 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 (xm_lua_isinteger(lua, 2)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); + if (xm_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..efe8f9612 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 (xm_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 (xm_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..cec34847e 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 (xm_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 (xm_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..0f8656c6c 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 (xm_lua_isinteger(lua, 2)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); + if (xm_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..cd236cdcf 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 (xm_lua_isinteger(lua, 2)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); + if (xm_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..36238ff8b 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 (xm_lua_isinteger(lua, 1)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 1); + if (xm_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..23795f003 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 (xm_lua_isinteger(lua, 1)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 1); + if (xm_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..770612831 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 (xm_lua_isinteger(lua, 1)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 1); + if (xm_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..9cf665921 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 (xm_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 (xm_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..2b467073d 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 (xm_lua_isinteger(lua, 2)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); + if (xm_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..1f979c16e 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 (xm_lua_isinteger(lua, 1)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 1); + if (xm_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..75eda17e9 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 (xm_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 (xm_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..2f5e491a1 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 (xm_lua_isinteger(lua, 2)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); + if (xm_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); diff --git a/core/src/xmake/prefix.h b/core/src/xmake/prefix.h index fabb775fb..5d6fba582 100644 --- a/core/src/xmake/prefix.h +++ b/core/src/xmake/prefix.h @@ -130,6 +130,15 @@ static __tb_inline__ tb_void_t xm_lua_register(lua_State *lua, tb_char_t const* #endif } +static __tb_inline__ tb_int_t xm_lua_isinteger(lua_State* lua, int idx) +{ +#ifdef USE_LUAJIT + return lua_isnumber(lua, idx); +#else + return lua_isinteger(lua, idx); +#endif +} + #endif diff --git a/xmake/modules/private/service/remote_build/action.lua b/xmake/modules/private/service/remote_build/action.lua index f3a919f14..fcf3fff89 100644 --- a/xmake/modules/private/service/remote_build/action.lua +++ b/xmake/modules/private/service/remote_build/action.lua @@ -29,5 +29,5 @@ end function main() config.load() - remote_build_client.singleton():runcmd(os.programfile(), xmake.argv()) + remote_build_client.singleton():runcmd("xmake", xmake.argv()) end |
