Skip to content

Commit

Permalink
Merge pull request #5068 from xmake-io/termux
Browse files Browse the repository at this point in the history
use integer instead of number
  • Loading branch information
waruqi authored May 7, 2024
2 parents 1d2fd82 + 243b757 commit d9c1e1f
Show file tree
Hide file tree
Showing 22 changed files with 82 additions and 53 deletions.
5 changes: 3 additions & 2 deletions core/src/xmake/base64/encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
5 changes: 3 additions & 2 deletions core/src/xmake/bloom_filter/bloom_filter_data_set.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions core/src/xmake/hash/md5.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
9 changes: 5 additions & 4 deletions core/src/xmake/hash/sha.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions core/src/xmake/hash/xxhash.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions core/src/xmake/io/file_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions core/src/xmake/io/pipe_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions core/src/xmake/io/pipe_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions core/src/xmake/io/socket_recv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions core/src/xmake/io/socket_recvfrom.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions core/src/xmake/io/socket_send.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions core/src/xmake/io/socket_sendto.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions core/src/xmake/lz4/block_compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions core/src/xmake/lz4/block_decompress.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions core/src/xmake/lz4/compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions core/src/xmake/lz4/compress_stream_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions core/src/xmake/lz4/compress_stream_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions core/src/xmake/lz4/decompress.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions core/src/xmake/lz4/decompress_stream_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit d9c1e1f

Please sign in to comment.