From c89c94bf89e98c8e42e786aacc0b334a57474179 Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 9 Nov 2025 19:11:32 +0800 Subject: format code --- core/src/xmake/engine.c | 1554 +++++++++++++++++++++++------------------------ 1 file changed, 751 insertions(+), 803 deletions(-) (limited to 'core/src/xmake/engine.c') diff --git a/core/src/xmake/engine.c b/core/src/xmake/engine.c index 61ba79af1..a65395423 100644 --- a/core/src/xmake/engine.c +++ b/core/src/xmake/engine.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "engine" -#define TB_TRACE_MODULE_DEBUG (1) +#define TB_TRACE_MODULE_NAME "engine" +#define TB_TRACE_MODULE_DEBUG (1) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -31,38 +31,39 @@ #include "xmake.h" #include "io/poller.h" #if defined(TB_CONFIG_OS_WINDOWS) -# include -# include -# include +#include +#include +#include #elif defined(TB_CONFIG_OS_MACOSX) || defined(TB_CONFIG_OS_IOS) -# include -# include -# include -#elif defined(TB_CONFIG_OS_LINUX) || defined(TB_CONFIG_OS_BSD) || defined(TB_CONFIG_OS_ANDROID) || defined(TB_CONFIG_OS_HAIKU) -# include -# include +#include +#include +#include +#elif defined(TB_CONFIG_OS_LINUX) || defined(TB_CONFIG_OS_BSD) || defined(TB_CONFIG_OS_ANDROID) || \ + defined(TB_CONFIG_OS_HAIKU) +#include +#include #endif #ifdef TB_CONFIG_OS_BSD -# include -# include -# include +#include +#include +#include #endif #ifdef TB_CONFIG_OS_HAIKU -# include +#include #endif #ifdef __COSMOPOLITAN__ -# include +#include #endif // for uid #ifndef TB_CONFIG_OS_WINDOWS -# include -# include +#include +#include #endif // for embed files #ifdef XM_EMBED_ENABLE -# include "lz4/prefix.h" +#include "lz4/prefix.h" #endif /* ////////////////////////////////////////////////////////////////////////////////////// @@ -71,321 +72,318 @@ // proc/self #if defined(TB_CONFIG_OS_LINUX) -# define XM_PROC_SELF_FILE "/proc/self/exe" +#define XM_PROC_SELF_FILE "/proc/self/exe" #elif defined(TB_CONFIG_OS_BSD) && !defined(__OpenBSD__) && !defined(__FreeBSD__) -# if defined(__NetBSD__) -# define XM_PROC_SELF_FILE "/proc/curproc/exe" -# else -# define XM_PROC_SELF_FILE "/proc/curproc/file" -# endif +#if defined(__NetBSD__) +#define XM_PROC_SELF_FILE "/proc/curproc/exe" +#else +#define XM_PROC_SELF_FILE "/proc/curproc/file" +#endif #endif // hook lua memory allocator -#define XM_HOOK_LUA_MEMALLOC (0) +#define XM_HOOK_LUA_MEMALLOC (0) /* ////////////////////////////////////////////////////////////////////////////////////// * types */ // the engine type -typedef struct __xm_engine_t -{ +typedef struct __xm_engine_t { // the lua - lua_State* lua; + lua_State *lua; // the engine name - tb_char_t name[64]; + tb_char_t name[64]; // the io poller - tb_poller_ref_t poller; - xm_poller_state_t poller_state; + tb_poller_ref_t poller; + xm_poller_state_t poller_state; #ifdef XM_EMBED_ENABLE // the temporary directory - tb_char_t tmpdir[TB_PATH_MAXN]; + tb_char_t tmpdir[TB_PATH_MAXN]; // the embed files - tb_byte_t const* embeddata[32]; - tb_size_t embedsize[32]; - tb_size_t embedcount; + tb_byte_t const *embeddata[32]; + tb_size_t embedsize[32]; + tb_size_t embedcount; #endif - -}xm_engine_t; +} xm_engine_t; /* ////////////////////////////////////////////////////////////////////////////////////// * declaration */ // the os functions -tb_int_t xm_os_argv(lua_State* lua); -tb_int_t xm_os_args(lua_State* lua); -tb_int_t xm_os_find(lua_State* lua); -tb_int_t xm_os_link(lua_State* lua); -tb_int_t xm_os_isdir(lua_State* lua); -tb_int_t xm_os_rmdir(lua_State* lua); -tb_int_t xm_os_mkdir(lua_State* lua); -tb_int_t xm_os_cpdir(lua_State* lua); -tb_int_t xm_os_chdir(lua_State* lua); -tb_int_t xm_os_mtime(lua_State* lua); -tb_int_t xm_os_sleep(lua_State* lua); -tb_int_t xm_os_mclock(lua_State* lua); -tb_int_t xm_os_curdir(lua_State* lua); -tb_int_t xm_os_tmpdir(lua_State* lua); -tb_int_t xm_os_islink(lua_State* lua); -tb_int_t xm_os_isfile(lua_State* lua); -tb_int_t xm_os_touch(lua_State* lua); -tb_int_t xm_os_rmfile(lua_State* lua); -tb_int_t xm_os_cpfile(lua_State* lua); -tb_int_t xm_os_fscase(lua_State* lua); -tb_int_t xm_os_rename(lua_State* lua); -tb_int_t xm_os_exists(lua_State* lua); -tb_int_t xm_os_setenv(lua_State* lua); -tb_int_t xm_os_getenv(lua_State* lua); -tb_int_t xm_os_getenvs(lua_State* lua); -tb_int_t xm_os_cpuinfo(lua_State* lua); -tb_int_t xm_os_meminfo(lua_State* lua); -tb_int_t xm_os_readlink(lua_State* lua); -tb_int_t xm_os_filesize(lua_State* lua); -tb_int_t xm_os_emptydir(lua_State* lua); -tb_int_t xm_os_syserror(lua_State* lua); -tb_int_t xm_os_strerror(lua_State* lua); -tb_int_t xm_os_getwinsize(lua_State* lua); -tb_int_t xm_os_getpid(lua_State* lua); -tb_int_t xm_os_signal(lua_State* lua); +tb_int_t xm_os_argv(lua_State *lua); +tb_int_t xm_os_args(lua_State *lua); +tb_int_t xm_os_find(lua_State *lua); +tb_int_t xm_os_link(lua_State *lua); +tb_int_t xm_os_isdir(lua_State *lua); +tb_int_t xm_os_rmdir(lua_State *lua); +tb_int_t xm_os_mkdir(lua_State *lua); +tb_int_t xm_os_cpdir(lua_State *lua); +tb_int_t xm_os_chdir(lua_State *lua); +tb_int_t xm_os_mtime(lua_State *lua); +tb_int_t xm_os_sleep(lua_State *lua); +tb_int_t xm_os_mclock(lua_State *lua); +tb_int_t xm_os_curdir(lua_State *lua); +tb_int_t xm_os_tmpdir(lua_State *lua); +tb_int_t xm_os_islink(lua_State *lua); +tb_int_t xm_os_isfile(lua_State *lua); +tb_int_t xm_os_touch(lua_State *lua); +tb_int_t xm_os_rmfile(lua_State *lua); +tb_int_t xm_os_cpfile(lua_State *lua); +tb_int_t xm_os_fscase(lua_State *lua); +tb_int_t xm_os_rename(lua_State *lua); +tb_int_t xm_os_exists(lua_State *lua); +tb_int_t xm_os_setenv(lua_State *lua); +tb_int_t xm_os_getenv(lua_State *lua); +tb_int_t xm_os_getenvs(lua_State *lua); +tb_int_t xm_os_cpuinfo(lua_State *lua); +tb_int_t xm_os_meminfo(lua_State *lua); +tb_int_t xm_os_readlink(lua_State *lua); +tb_int_t xm_os_filesize(lua_State *lua); +tb_int_t xm_os_emptydir(lua_State *lua); +tb_int_t xm_os_syserror(lua_State *lua); +tb_int_t xm_os_strerror(lua_State *lua); +tb_int_t xm_os_getwinsize(lua_State *lua); +tb_int_t xm_os_getpid(lua_State *lua); +tb_int_t xm_os_signal(lua_State *lua); #ifndef TB_CONFIG_OS_WINDOWS -tb_int_t xm_os_uid(lua_State* lua); -tb_int_t xm_os_gid(lua_State* lua); -tb_int_t xm_os_getown(lua_State* lua); +tb_int_t xm_os_uid(lua_State *lua); +tb_int_t xm_os_gid(lua_State *lua); +tb_int_t xm_os_getown(lua_State *lua); #endif // the io/file functions -tb_int_t xm_io_stdfile(lua_State* lua); -tb_int_t xm_io_file_open(lua_State* lua); -tb_int_t xm_io_file_read(lua_State* lua); -tb_int_t xm_io_file_readable(lua_State* lua); -tb_int_t xm_io_file_seek(lua_State* lua); -tb_int_t xm_io_file_size(lua_State* lua); -tb_int_t xm_io_file_rawfd(lua_State* lua); -tb_int_t xm_io_file_write(lua_State* lua); -tb_int_t xm_io_file_flush(lua_State* lua); -tb_int_t xm_io_file_close(lua_State* lua); -tb_int_t xm_io_file_isatty(lua_State* lua); +tb_int_t xm_io_stdfile(lua_State *lua); +tb_int_t xm_io_file_open(lua_State *lua); +tb_int_t xm_io_file_read(lua_State *lua); +tb_int_t xm_io_file_readable(lua_State *lua); +tb_int_t xm_io_file_seek(lua_State *lua); +tb_int_t xm_io_file_size(lua_State *lua); +tb_int_t xm_io_file_rawfd(lua_State *lua); +tb_int_t xm_io_file_write(lua_State *lua); +tb_int_t xm_io_file_flush(lua_State *lua); +tb_int_t xm_io_file_close(lua_State *lua); +tb_int_t xm_io_file_isatty(lua_State *lua); // the io/filelock functions -tb_int_t xm_io_filelock_open(lua_State* lua); -tb_int_t xm_io_filelock_lock(lua_State* lua); -tb_int_t xm_io_filelock_unlock(lua_State* lua); -tb_int_t xm_io_filelock_trylock(lua_State* lua); -tb_int_t xm_io_filelock_close(lua_State* lua); +tb_int_t xm_io_filelock_open(lua_State *lua); +tb_int_t xm_io_filelock_lock(lua_State *lua); +tb_int_t xm_io_filelock_unlock(lua_State *lua); +tb_int_t xm_io_filelock_trylock(lua_State *lua); +tb_int_t xm_io_filelock_close(lua_State *lua); // the io/socket functions -tb_int_t xm_io_socket_open(lua_State* lua); -tb_int_t xm_io_socket_rawfd(lua_State* lua); -tb_int_t xm_io_socket_peeraddr(lua_State* lua); -tb_int_t xm_io_socket_wait(lua_State* lua); -tb_int_t xm_io_socket_bind(lua_State* lua); -tb_int_t xm_io_socket_ctrl(lua_State* lua); -tb_int_t xm_io_socket_listen(lua_State* lua); -tb_int_t xm_io_socket_accept(lua_State* lua); -tb_int_t xm_io_socket_connect(lua_State* lua); -tb_int_t xm_io_socket_send(lua_State* lua); -tb_int_t xm_io_socket_sendto(lua_State* lua); -tb_int_t xm_io_socket_sendfile(lua_State* lua); -tb_int_t xm_io_socket_recv(lua_State* lua); -tb_int_t xm_io_socket_recvfrom(lua_State* lua); -tb_int_t xm_io_socket_kill(lua_State* lua); -tb_int_t xm_io_socket_close(lua_State* lua); +tb_int_t xm_io_socket_open(lua_State *lua); +tb_int_t xm_io_socket_rawfd(lua_State *lua); +tb_int_t xm_io_socket_peeraddr(lua_State *lua); +tb_int_t xm_io_socket_wait(lua_State *lua); +tb_int_t xm_io_socket_bind(lua_State *lua); +tb_int_t xm_io_socket_ctrl(lua_State *lua); +tb_int_t xm_io_socket_listen(lua_State *lua); +tb_int_t xm_io_socket_accept(lua_State *lua); +tb_int_t xm_io_socket_connect(lua_State *lua); +tb_int_t xm_io_socket_send(lua_State *lua); +tb_int_t xm_io_socket_sendto(lua_State *lua); +tb_int_t xm_io_socket_sendfile(lua_State *lua); +tb_int_t xm_io_socket_recv(lua_State *lua); +tb_int_t xm_io_socket_recvfrom(lua_State *lua); +tb_int_t xm_io_socket_kill(lua_State *lua); +tb_int_t xm_io_socket_close(lua_State *lua); // the io/pipe functions -tb_int_t xm_io_pipe_open(lua_State* lua); -tb_int_t xm_io_pipe_openpair(lua_State* lua); -tb_int_t xm_io_pipe_close(lua_State* lua); -tb_int_t xm_io_pipe_read(lua_State* lua); -tb_int_t xm_io_pipe_write(lua_State* lua); -tb_int_t xm_io_pipe_wait(lua_State* lua); -tb_int_t xm_io_pipe_connect(lua_State* lua); +tb_int_t xm_io_pipe_open(lua_State *lua); +tb_int_t xm_io_pipe_openpair(lua_State *lua); +tb_int_t xm_io_pipe_close(lua_State *lua); +tb_int_t xm_io_pipe_read(lua_State *lua); +tb_int_t xm_io_pipe_write(lua_State *lua); +tb_int_t xm_io_pipe_wait(lua_State *lua); +tb_int_t xm_io_pipe_connect(lua_State *lua); // the io/poller functions -tb_int_t xm_io_poller_insert(lua_State* lua); -tb_int_t xm_io_poller_modify(lua_State* lua); -tb_int_t xm_io_poller_remove(lua_State* lua); -tb_int_t xm_io_poller_spank(lua_State* lua); -tb_int_t xm_io_poller_support(lua_State* lua); -tb_int_t xm_io_poller_wait(lua_State* lua); +tb_int_t xm_io_poller_insert(lua_State *lua); +tb_int_t xm_io_poller_modify(lua_State *lua); +tb_int_t xm_io_poller_remove(lua_State *lua); +tb_int_t xm_io_poller_spank(lua_State *lua); +tb_int_t xm_io_poller_support(lua_State *lua); +tb_int_t xm_io_poller_wait(lua_State *lua); // the path functions -tb_int_t xm_path_relative(lua_State* lua); -tb_int_t xm_path_absolute(lua_State* lua); -tb_int_t xm_path_translate(lua_State* lua); -tb_int_t xm_path_directory(lua_State* lua); -tb_int_t xm_path_is_absolute(lua_State* lua); +tb_int_t xm_path_relative(lua_State *lua); +tb_int_t xm_path_absolute(lua_State *lua); +tb_int_t xm_path_translate(lua_State *lua); +tb_int_t xm_path_directory(lua_State *lua); +tb_int_t xm_path_is_absolute(lua_State *lua); // the hash functions -tb_int_t xm_hash_uuid4(lua_State* lua); -tb_int_t xm_hash_sha(lua_State* lua); -tb_int_t xm_hash_md5(lua_State* lua); -tb_int_t xm_hash_xxhash(lua_State* lua); -tb_int_t xm_hash_rand32(lua_State* lua); -tb_int_t xm_hash_rand64(lua_State* lua); -tb_int_t xm_hash_rand128(lua_State* lua); +tb_int_t xm_hash_uuid4(lua_State *lua); +tb_int_t xm_hash_sha(lua_State *lua); +tb_int_t xm_hash_md5(lua_State *lua); +tb_int_t xm_hash_xxhash(lua_State *lua); +tb_int_t xm_hash_rand32(lua_State *lua); +tb_int_t xm_hash_rand64(lua_State *lua); +tb_int_t xm_hash_rand128(lua_State *lua); // the base64 functions -tb_int_t xm_base64_encode(lua_State* lua); -tb_int_t xm_base64_decode(lua_State* lua); +tb_int_t xm_base64_encode(lua_State *lua); +tb_int_t xm_base64_decode(lua_State *lua); // the lz4 functions -tb_int_t xm_lz4_compress(lua_State* lua); -tb_int_t xm_lz4_decompress(lua_State* lua); -tb_int_t xm_lz4_block_compress(lua_State* lua); -tb_int_t xm_lz4_block_decompress(lua_State* lua); -tb_int_t xm_lz4_compress_file(lua_State* lua); -tb_int_t xm_lz4_decompress_file(lua_State* lua); -tb_int_t xm_lz4_compress_stream_open(lua_State* lua); -tb_int_t xm_lz4_compress_stream_read(lua_State* lua); -tb_int_t xm_lz4_compress_stream_write(lua_State* lua); -tb_int_t xm_lz4_compress_stream_close(lua_State* lua); -tb_int_t xm_lz4_decompress_stream_open(lua_State* lua); -tb_int_t xm_lz4_decompress_stream_read(lua_State* lua); -tb_int_t xm_lz4_decompress_stream_write(lua_State* lua); -tb_int_t xm_lz4_decompress_stream_close(lua_State* lua); +tb_int_t xm_lz4_compress(lua_State *lua); +tb_int_t xm_lz4_decompress(lua_State *lua); +tb_int_t xm_lz4_block_compress(lua_State *lua); +tb_int_t xm_lz4_block_decompress(lua_State *lua); +tb_int_t xm_lz4_compress_file(lua_State *lua); +tb_int_t xm_lz4_decompress_file(lua_State *lua); +tb_int_t xm_lz4_compress_stream_open(lua_State *lua); +tb_int_t xm_lz4_compress_stream_read(lua_State *lua); +tb_int_t xm_lz4_compress_stream_write(lua_State *lua); +tb_int_t xm_lz4_compress_stream_close(lua_State *lua); +tb_int_t xm_lz4_decompress_stream_open(lua_State *lua); +tb_int_t xm_lz4_decompress_stream_read(lua_State *lua); +tb_int_t xm_lz4_decompress_stream_write(lua_State *lua); +tb_int_t xm_lz4_decompress_stream_close(lua_State *lua); // the bloom filter functions -tb_int_t xm_bloom_filter_open(lua_State* lua); -tb_int_t xm_bloom_filter_close(lua_State* lua); -tb_int_t xm_bloom_filter_clear(lua_State* lua); -tb_int_t xm_bloom_filter_data(lua_State* lua); -tb_int_t xm_bloom_filter_size(lua_State* lua); -tb_int_t xm_bloom_filter_get(lua_State* lua); -tb_int_t xm_bloom_filter_set(lua_State* lua); -tb_int_t xm_bloom_filter_data_set(lua_State* lua); +tb_int_t xm_bloom_filter_open(lua_State *lua); +tb_int_t xm_bloom_filter_close(lua_State *lua); +tb_int_t xm_bloom_filter_clear(lua_State *lua); +tb_int_t xm_bloom_filter_data(lua_State *lua); +tb_int_t xm_bloom_filter_size(lua_State *lua); +tb_int_t xm_bloom_filter_get(lua_State *lua); +tb_int_t xm_bloom_filter_set(lua_State *lua); +tb_int_t xm_bloom_filter_data_set(lua_State *lua); // the windows functions #ifdef TB_CONFIG_OS_WINDOWS -tb_int_t xm_winos_cp_info(lua_State* lua); -tb_int_t xm_winos_console_cp(lua_State* lua); -tb_int_t xm_winos_console_output_cp(lua_State* lua); -tb_int_t xm_winos_ansi_cp(lua_State* lua); -tb_int_t xm_winos_oem_cp(lua_State* lua); -tb_int_t xm_winos_logical_drives(lua_State* lua); -tb_int_t xm_winos_registry_query(lua_State* lua); -tb_int_t xm_winos_registry_keys(lua_State* lua); -tb_int_t xm_winos_registry_values(lua_State* lua); -tb_int_t xm_winos_short_path(lua_State* lua); +tb_int_t xm_winos_cp_info(lua_State *lua); +tb_int_t xm_winos_console_cp(lua_State *lua); +tb_int_t xm_winos_console_output_cp(lua_State *lua); +tb_int_t xm_winos_ansi_cp(lua_State *lua); +tb_int_t xm_winos_oem_cp(lua_State *lua); +tb_int_t xm_winos_logical_drives(lua_State *lua); +tb_int_t xm_winos_registry_query(lua_State *lua); +tb_int_t xm_winos_registry_keys(lua_State *lua); +tb_int_t xm_winos_registry_values(lua_State *lua); +tb_int_t xm_winos_short_path(lua_State *lua); #endif // the string functions -tb_int_t xm_string_trim(lua_State* lua); -tb_int_t xm_string_split(lua_State* lua); -tb_int_t xm_string_lastof(lua_State* lua); -tb_int_t xm_string_convert(lua_State* lua); -tb_int_t xm_string_endswith(lua_State* lua); -tb_int_t xm_string_startswith(lua_State* lua); +tb_int_t xm_string_trim(lua_State *lua); +tb_int_t xm_string_split(lua_State *lua); +tb_int_t xm_string_lastof(lua_State *lua); +tb_int_t xm_string_convert(lua_State *lua); +tb_int_t xm_string_endswith(lua_State *lua); +tb_int_t xm_string_startswith(lua_State *lua); // the process functions -tb_int_t xm_process_open(lua_State* lua); -tb_int_t xm_process_openv(lua_State* lua); -tb_int_t xm_process_wait(lua_State* lua); -tb_int_t xm_process_kill(lua_State* lua); -tb_int_t xm_process_close(lua_State* lua); +tb_int_t xm_process_open(lua_State *lua); +tb_int_t xm_process_openv(lua_State *lua); +tb_int_t xm_process_wait(lua_State *lua); +tb_int_t xm_process_kill(lua_State *lua); +tb_int_t xm_process_close(lua_State *lua); // the fwatcher functions -tb_int_t xm_fwatcher_open(lua_State* lua); -tb_int_t xm_fwatcher_add(lua_State* lua); -tb_int_t xm_fwatcher_remove(lua_State* lua); -tb_int_t xm_fwatcher_wait(lua_State* lua); -tb_int_t xm_fwatcher_close(lua_State* lua); +tb_int_t xm_fwatcher_open(lua_State *lua); +tb_int_t xm_fwatcher_add(lua_State *lua); +tb_int_t xm_fwatcher_remove(lua_State *lua); +tb_int_t xm_fwatcher_wait(lua_State *lua); +tb_int_t xm_fwatcher_close(lua_State *lua); // the sandbox functions -tb_int_t xm_sandbox_interactive(lua_State* lua); +tb_int_t xm_sandbox_interactive(lua_State *lua); #ifdef XM_CONFIG_API_HAVE_READLINE // the readline functions -tb_int_t xm_readline_readline(lua_State* lua); -tb_int_t xm_readline_history_list(lua_State* lua); -tb_int_t xm_readline_add_history(lua_State* lua); -tb_int_t xm_readline_clear_history(lua_State* lua); +tb_int_t xm_readline_readline(lua_State *lua); +tb_int_t xm_readline_history_list(lua_State *lua); +tb_int_t xm_readline_add_history(lua_State *lua); +tb_int_t xm_readline_clear_history(lua_State *lua); #endif // the semver functions -tb_int_t xm_semver_parse(lua_State* lua); -tb_int_t xm_semver_compare(lua_State* lua); -tb_int_t xm_semver_satisfies(lua_State* lua); -tb_int_t xm_semver_select(lua_State* lua); +tb_int_t xm_semver_parse(lua_State *lua); +tb_int_t xm_semver_compare(lua_State *lua); +tb_int_t xm_semver_satisfies(lua_State *lua); +tb_int_t xm_semver_select(lua_State *lua); // the libc functions -tb_int_t xm_libc_malloc(lua_State* lua); -tb_int_t xm_libc_free(lua_State* lua); -tb_int_t xm_libc_memcpy(lua_State* lua); -tb_int_t xm_libc_memmov(lua_State* lua); -tb_int_t xm_libc_memset(lua_State* lua); -tb_int_t xm_libc_strndup(lua_State* lua); -tb_int_t xm_libc_dataptr(lua_State* lua); -tb_int_t xm_libc_byteof(lua_State* lua); -tb_int_t xm_libc_setbyte(lua_State* lua); +tb_int_t xm_libc_malloc(lua_State *lua); +tb_int_t xm_libc_free(lua_State *lua); +tb_int_t xm_libc_memcpy(lua_State *lua); +tb_int_t xm_libc_memmov(lua_State *lua); +tb_int_t xm_libc_memset(lua_State *lua); +tb_int_t xm_libc_strndup(lua_State *lua); +tb_int_t xm_libc_dataptr(lua_State *lua); +tb_int_t xm_libc_byteof(lua_State *lua); +tb_int_t xm_libc_setbyte(lua_State *lua); // the tty functions -tb_int_t xm_tty_term_mode(lua_State* lua); +tb_int_t xm_tty_term_mode(lua_State *lua); // the package functions -tb_int_t xm_package_loadxmi(lua_State* lua); +tb_int_t xm_package_loadxmi(lua_State *lua); // the utils functions -tb_int_t xm_utils_bin2c(lua_State* lua); +tb_int_t xm_utils_bin2c(lua_State *lua); #ifdef XM_CONFIG_API_HAVE_CURSES // register curses functions -tb_int_t xm_lua_curses_register(lua_State* lua, tb_char_t const* module); +tb_int_t xm_lua_curses_register(lua_State *lua, tb_char_t const *module); #endif // the thread functions -tb_int_t xm_thread_init(lua_State* lua); -tb_int_t xm_thread_exit(lua_State* lua); -tb_int_t xm_thread_wait(lua_State* lua); -tb_int_t xm_thread_suspend(lua_State* lua); -tb_int_t xm_thread_resume(lua_State* lua); +tb_int_t xm_thread_init(lua_State *lua); +tb_int_t xm_thread_exit(lua_State *lua); +tb_int_t xm_thread_wait(lua_State *lua); +tb_int_t xm_thread_suspend(lua_State *lua); +tb_int_t xm_thread_resume(lua_State *lua); // the thread/mutex functions -tb_int_t xm_thread_mutex_init(lua_State* lua); -tb_int_t xm_thread_mutex_exit(lua_State* lua); -tb_int_t xm_thread_mutex_lock(lua_State* lua); -tb_int_t xm_thread_mutex_trylock(lua_State* lua); -tb_int_t xm_thread_mutex_unlock(lua_State* lua); -tb_int_t xm_thread_mutex_incref(lua_State* lua); +tb_int_t xm_thread_mutex_init(lua_State *lua); +tb_int_t xm_thread_mutex_exit(lua_State *lua); +tb_int_t xm_thread_mutex_lock(lua_State *lua); +tb_int_t xm_thread_mutex_trylock(lua_State *lua); +tb_int_t xm_thread_mutex_unlock(lua_State *lua); +tb_int_t xm_thread_mutex_incref(lua_State *lua); // the thread/event functions -tb_int_t xm_thread_event_init(lua_State* lua); -tb_int_t xm_thread_event_exit(lua_State* lua); -tb_int_t xm_thread_event_post(lua_State* lua); -tb_int_t xm_thread_event_wait(lua_State* lua); -tb_int_t xm_thread_event_incref(lua_State* lua); +tb_int_t xm_thread_event_init(lua_State *lua); +tb_int_t xm_thread_event_exit(lua_State *lua); +tb_int_t xm_thread_event_post(lua_State *lua); +tb_int_t xm_thread_event_wait(lua_State *lua); +tb_int_t xm_thread_event_incref(lua_State *lua); // the thread/semaphore functions -tb_int_t xm_thread_semaphore_init(lua_State* lua); -tb_int_t xm_thread_semaphore_exit(lua_State* lua); -tb_int_t xm_thread_semaphore_post(lua_State* lua); -tb_int_t xm_thread_semaphore_wait(lua_State* lua); -tb_int_t xm_thread_semaphore_incref(lua_State* lua); +tb_int_t xm_thread_semaphore_init(lua_State *lua); +tb_int_t xm_thread_semaphore_exit(lua_State *lua); +tb_int_t xm_thread_semaphore_post(lua_State *lua); +tb_int_t xm_thread_semaphore_wait(lua_State *lua); +tb_int_t xm_thread_semaphore_incref(lua_State *lua); // the thread/queue functions -tb_int_t xm_thread_queue_init(lua_State* lua); -tb_int_t xm_thread_queue_exit(lua_State* lua); -tb_int_t xm_thread_queue_size(lua_State* lua); -tb_int_t xm_thread_queue_clear(lua_State* lua); -tb_int_t xm_thread_queue_incref(lua_State* lua); -tb_int_t xm_thread_queue_push(lua_State* lua); -tb_int_t xm_thread_queue_pop(lua_State* lua); +tb_int_t xm_thread_queue_init(lua_State *lua); +tb_int_t xm_thread_queue_exit(lua_State *lua); +tb_int_t xm_thread_queue_size(lua_State *lua); +tb_int_t xm_thread_queue_clear(lua_State *lua); +tb_int_t xm_thread_queue_incref(lua_State *lua); +tb_int_t xm_thread_queue_push(lua_State *lua); +tb_int_t xm_thread_queue_pop(lua_State *lua); // the thread/sharedata functions -tb_int_t xm_thread_sharedata_init(lua_State* lua); -tb_int_t xm_thread_sharedata_exit(lua_State* lua); -tb_int_t xm_thread_sharedata_clear(lua_State* lua); -tb_int_t xm_thread_sharedata_incref(lua_State* lua); -tb_int_t xm_thread_sharedata_set(lua_State* lua); -tb_int_t xm_thread_sharedata_get_(lua_State* lua); +tb_int_t xm_thread_sharedata_init(lua_State *lua); +tb_int_t xm_thread_sharedata_exit(lua_State *lua); +tb_int_t xm_thread_sharedata_clear(lua_State *lua); +tb_int_t xm_thread_sharedata_incref(lua_State *lua); +tb_int_t xm_thread_sharedata_set(lua_State *lua); +tb_int_t xm_thread_sharedata_get_(lua_State *lua); // open cjson -__tb_extern_c_enter__ -tb_int_t luaopen_cjson(lua_State *l); +__tb_extern_c_enter__ tb_int_t luaopen_cjson(lua_State *l); __tb_extern_c_leave__ /* ////////////////////////////////////////////////////////////////////////////////////// @@ -393,340 +391,320 @@ __tb_extern_c_leave__ */ // the os functions -static luaL_Reg const g_os_functions[] = -{ - { "argv", xm_os_argv } -, { "args", xm_os_args } -, { "find", xm_os_find } -, { "link", xm_os_link } -, { "isdir", xm_os_isdir } -, { "rmdir", xm_os_rmdir } -, { "mkdir", xm_os_mkdir } -, { "cpdir", xm_os_cpdir } -, { "chdir", xm_os_chdir } -, { "mtime", xm_os_mtime } -, { "sleep", xm_os_sleep } -, { "mclock", xm_os_mclock } -, { "curdir", xm_os_curdir } -, { "tmpdir", xm_os_tmpdir } -, { "islink", xm_os_islink } -, { "isfile", xm_os_isfile } -, { "touch", xm_os_touch } -, { "rmfile", xm_os_rmfile } -, { "cpfile", xm_os_cpfile } -, { "fscase", xm_os_fscase } -, { "rename", xm_os_rename } -, { "exists", xm_os_exists } -, { "setenv", xm_os_setenv } -, { "getenv", xm_os_getenv } -, { "getenvs", xm_os_getenvs } -, { "cpuinfo", xm_os_cpuinfo } -, { "meminfo", xm_os_meminfo } -, { "readlink", xm_os_readlink } -, { "emptydir", xm_os_emptydir } -, { "strerror", xm_os_strerror } -, { "syserror", xm_os_syserror } -, { "filesize", xm_os_filesize } -, { "getwinsize", xm_os_getwinsize} -, { "getpid", xm_os_getpid } -, { "signal", xm_os_signal } +static luaL_Reg const g_os_functions[] = { + { "argv", xm_os_argv }, + { "args", xm_os_args }, + { "find", xm_os_find }, + { "link", xm_os_link }, + { "isdir", xm_os_isdir }, + { "rmdir", xm_os_rmdir }, + { "mkdir", xm_os_mkdir }, + { "cpdir", xm_os_cpdir }, + { "chdir", xm_os_chdir }, + { "mtime", xm_os_mtime }, + { "sleep", xm_os_sleep }, + { "mclock", xm_os_mclock }, + { "curdir", xm_os_curdir }, + { "tmpdir", xm_os_tmpdir }, + { "islink", xm_os_islink }, + { "isfile", xm_os_isfile }, + { "touch", xm_os_touch }, + { "rmfile", xm_os_rmfile }, + { "cpfile", xm_os_cpfile }, + { "fscase", xm_os_fscase }, + { "rename", xm_os_rename }, + { "exists", xm_os_exists }, + { "setenv", xm_os_setenv }, + { "getenv", xm_os_getenv }, + { "getenvs", xm_os_getenvs }, + { "cpuinfo", xm_os_cpuinfo }, + { "meminfo", xm_os_meminfo }, + { "readlink", xm_os_readlink }, + { "emptydir", xm_os_emptydir }, + { "strerror", xm_os_strerror }, + { "syserror", xm_os_syserror }, + { "filesize", xm_os_filesize }, + { "getwinsize", xm_os_getwinsize }, + { "getpid", xm_os_getpid }, + { "signal", xm_os_signal }, #ifndef TB_CONFIG_OS_WINDOWS -, { "uid", xm_os_uid } -, { "gid", xm_os_gid } -, { "getown", xm_os_getown } + { "uid", xm_os_uid }, + { "gid", xm_os_gid }, + { "getown", xm_os_getown }, #endif -, { tb_null, tb_null } + { tb_null, tb_null }, }; // the windows functions #ifdef TB_CONFIG_OS_WINDOWS -static luaL_Reg const g_winos_functions[] = -{ - { "cp_info", xm_winos_cp_info } -, { "console_cp", xm_winos_console_cp } -, { "console_output_cp", xm_winos_console_output_cp } -, { "oem_cp", xm_winos_oem_cp } -, { "ansi_cp", xm_winos_ansi_cp } -, { "logical_drives", xm_winos_logical_drives } -, { "registry_query", xm_winos_registry_query } -, { "registry_keys", xm_winos_registry_keys } -, { "registry_values", xm_winos_registry_values } -, { "short_path", xm_winos_short_path } -, { tb_null, tb_null } +static luaL_Reg const g_winos_functions[] = { + { "cp_info", xm_winos_cp_info }, + { "console_cp", xm_winos_console_cp }, + { "console_output_cp", xm_winos_console_output_cp }, + { "oem_cp", xm_winos_oem_cp }, + { "ansi_cp", xm_winos_ansi_cp }, + { "logical_drives", xm_winos_logical_drives }, + { "registry_query", xm_winos_registry_query }, + { "registry_keys", xm_winos_registry_keys }, + { "registry_values", xm_winos_registry_values }, + { "short_path", xm_winos_short_path }, + { tb_null, tb_null }, }; #endif // the io functions -static luaL_Reg const g_io_functions[] = -{ - { "stdfile", xm_io_stdfile } -, { "file_open", xm_io_file_open } -, { "file_read", xm_io_file_read } -, { "file_readable", xm_io_file_readable } -, { "file_seek", xm_io_file_seek } -, { "file_size", xm_io_file_size } -, { "file_write", xm_io_file_write } -, { "file_flush", xm_io_file_flush } -, { "file_isatty", xm_io_file_isatty } -, { "file_close", xm_io_file_close } -, { "file_rawfd", xm_io_file_rawfd } -, { "filelock_open", xm_io_filelock_open } -, { "filelock_lock", xm_io_filelock_lock } -, { "filelock_trylock", xm_io_filelock_trylock } -, { "filelock_unlock", xm_io_filelock_unlock } -, { "filelock_close", xm_io_filelock_close } -, { "socket_open", xm_io_socket_open } -, { "socket_rawfd", xm_io_socket_rawfd } -, { "socket_peeraddr", xm_io_socket_peeraddr } -, { "socket_wait", xm_io_socket_wait } -, { "socket_bind", xm_io_socket_bind } -, { "socket_ctrl", xm_io_socket_ctrl } -, { "socket_listen", xm_io_socket_listen } -, { "socket_accept", xm_io_socket_accept } -, { "socket_connect", xm_io_socket_connect } -, { "socket_send", xm_io_socket_send } -, { "socket_sendto", xm_io_socket_sendto } -, { "socket_sendfile", xm_io_socket_sendfile } -, { "socket_recv", xm_io_socket_recv } -, { "socket_recvfrom", xm_io_socket_recvfrom } -, { "socket_kill" , xm_io_socket_kill } -, { "socket_close", xm_io_socket_close } -, { "pipe_open", xm_io_pipe_open } -, { "pipe_openpair", xm_io_pipe_openpair } -, { "pipe_close", xm_io_pipe_close } -, { "pipe_read", xm_io_pipe_read } -, { "pipe_write", xm_io_pipe_write } -, { "pipe_wait", xm_io_pipe_wait } -, { "pipe_connect", xm_io_pipe_connect } -, { "poller_insert", xm_io_poller_insert } -, { "poller_modify", xm_io_poller_modify } -, { "poller_remove", xm_io_poller_remove } -, { "poller_spank", xm_io_poller_spank } -, { "poller_support", xm_io_poller_support } -, { "poller_wait", xm_io_poller_wait } -, { tb_null, tb_null } +static luaL_Reg const g_io_functions[] = { + { "stdfile", xm_io_stdfile }, + { "file_open", xm_io_file_open }, + { "file_read", xm_io_file_read }, + { "file_readable", xm_io_file_readable }, + { "file_seek", xm_io_file_seek }, + { "file_size", xm_io_file_size }, + { "file_write", xm_io_file_write }, + { "file_flush", xm_io_file_flush }, + { "file_isatty", xm_io_file_isatty }, + { "file_close", xm_io_file_close }, + { "file_rawfd", xm_io_file_rawfd }, + { "filelock_open", xm_io_filelock_open }, + { "filelock_lock", xm_io_filelock_lock }, + { "filelock_trylock", xm_io_filelock_trylock }, + { "filelock_unlock", xm_io_filelock_unlock }, + { "filelock_close", xm_io_filelock_close }, + { "socket_open", xm_io_socket_open }, + { "socket_rawfd", xm_io_socket_rawfd }, + { "socket_peeraddr", xm_io_socket_peeraddr }, + { "socket_wait", xm_io_socket_wait }, + { "socket_bind", xm_io_socket_bind }, + { "socket_ctrl", xm_io_socket_ctrl }, + { "socket_listen", xm_io_socket_listen }, + { "socket_accept", xm_io_socket_accept }, + { "socket_connect", xm_io_socket_connect }, + { "socket_send", xm_io_socket_send }, + { "socket_sendto", xm_io_socket_sendto }, + { "socket_sendfile", xm_io_socket_sendfile }, + { "socket_recv", xm_io_socket_recv }, + { "socket_recvfrom", xm_io_socket_recvfrom }, + { "socket_kill", xm_io_socket_kill }, + { "socket_close", xm_io_socket_close }, + { "pipe_open", xm_io_pipe_open }, + { "pipe_openpair", xm_io_pipe_openpair }, + { "pipe_close", xm_io_pipe_close }, + { "pipe_read", xm_io_pipe_read }, + { "pipe_write", xm_io_pipe_write }, + { "pipe_wait", xm_io_pipe_wait }, + { "pipe_connect", xm_io_pipe_connect }, + { "poller_insert", xm_io_poller_insert }, + { "poller_modify", xm_io_poller_modify }, + { "poller_remove", xm_io_poller_remove }, + { "poller_spank", xm_io_poller_spank }, + { "poller_support", xm_io_poller_support }, + { "poller_wait", xm_io_poller_wait }, + { tb_null, tb_null }, }; // the path functions -static luaL_Reg const g_path_functions[] = -{ - { "relative", xm_path_relative } -, { "absolute", xm_path_absolute } -, { "translate", xm_path_translate } -, { "directory", xm_path_directory } -, { "is_absolute", xm_path_is_absolute } -, { tb_null, tb_null } +static luaL_Reg const g_path_functions[] = { + { "relative", xm_path_relative }, + { "absolute", xm_path_absolute }, + { "translate", xm_path_translate }, + { "directory", xm_path_directory }, + { "is_absolute", xm_path_is_absolute }, + { tb_null, tb_null }, }; // the hash functions -static luaL_Reg const g_hash_functions[] = -{ - { "uuid4", xm_hash_uuid4 } -, { "sha", xm_hash_sha } -, { "md5", xm_hash_md5 } -, { "xxhash", xm_hash_xxhash } -, { "rand32", xm_hash_rand32 } -, { "rand64", xm_hash_rand64 } -, { "rand128", xm_hash_rand128 } -, { tb_null, tb_null } +static luaL_Reg const g_hash_functions[] = { + { "uuid4", xm_hash_uuid4 }, + { "sha", xm_hash_sha }, + { "md5", xm_hash_md5 }, + { "xxhash", xm_hash_xxhash }, + { "rand32", xm_hash_rand32 }, + { "rand64", xm_hash_rand64 }, + { "rand128", xm_hash_rand128 }, + { tb_null, tb_null }, }; // the base64 functions -static luaL_Reg const g_base64_functions[] = -{ - { "encode", xm_base64_encode } -, { "decode", xm_base64_decode } -, { tb_null, tb_null } +static luaL_Reg const g_base64_functions[] = { + { "encode", xm_base64_encode }, + { "decode", xm_base64_decode }, + { tb_null, tb_null }, }; // the lz4 functions -static luaL_Reg const g_lz4_functions[] = -{ - { "compress", xm_lz4_compress } -, { "decompress", xm_lz4_decompress } -, { "block_compress", xm_lz4_block_compress } -, { "block_decompress", xm_lz4_block_decompress } -, { "compress_file", xm_lz4_compress_file } -, { "decompress_file", xm_lz4_decompress_file } -, { "compress_stream_open", xm_lz4_compress_stream_open } -, { "compress_stream_read", xm_lz4_compress_stream_read } -, { "compress_stream_write", xm_lz4_compress_stream_write } -, { "compress_stream_close", xm_lz4_compress_stream_close } -, { "decompress_stream_open", xm_lz4_decompress_stream_open } -, { "decompress_stream_read", xm_lz4_decompress_stream_read } -, { "decompress_stream_write",xm_lz4_decompress_stream_write } -, { "decompress_stream_close",xm_lz4_decompress_stream_close } -, { tb_null, tb_null } +static luaL_Reg const g_lz4_functions[] = { + { "compress", xm_lz4_compress }, + { "decompress", xm_lz4_decompress }, + { "block_compress", xm_lz4_block_compress }, + { "block_decompress", xm_lz4_block_decompress }, + { "compress_file", xm_lz4_compress_file }, + { "decompress_file", xm_lz4_decompress_file }, + { "compress_stream_open", xm_lz4_compress_stream_open }, + { "compress_stream_read", xm_lz4_compress_stream_read }, + { "compress_stream_write", xm_lz4_compress_stream_write }, + { "compress_stream_close", xm_lz4_compress_stream_close }, + { "decompress_stream_open", xm_lz4_decompress_stream_open }, + { "decompress_stream_read", xm_lz4_decompress_stream_read }, + { "decompress_stream_write", xm_lz4_decompress_stream_write }, + { "decompress_stream_close", xm_lz4_decompress_stream_close }, + { tb_null, tb_null }, }; // the bloom filter functions -static luaL_Reg const g_bloom_filter_functions[] = -{ - { "open", xm_bloom_filter_open } -, { "close", xm_bloom_filter_close } -, { "clear", xm_bloom_filter_clear } -, { "data", xm_bloom_filter_data } -, { "size", xm_bloom_filter_size } -, { "get", xm_bloom_filter_get } -, { "set", xm_bloom_filter_set } -, { "data_set", xm_bloom_filter_data_set } -, { tb_null, tb_null } +static luaL_Reg const g_bloom_filter_functions[] = { + { "open", xm_bloom_filter_open }, + { "close", xm_bloom_filter_close }, + { "clear", xm_bloom_filter_clear }, + { "data", xm_bloom_filter_data }, + { "size", xm_bloom_filter_size }, + { "get", xm_bloom_filter_get }, + { "set", xm_bloom_filter_set }, + { "data_set", xm_bloom_filter_data_set }, + { tb_null, tb_null }, }; // the string functions -static luaL_Reg const g_string_functions[] = -{ - { "trim", xm_string_trim } -, { "split", xm_string_split } -, { "lastof", xm_string_lastof } -, { "convert", xm_string_convert } -, { "endswith", xm_string_endswith } -, { "startswith", xm_string_startswith } -, { tb_null, tb_null } +static luaL_Reg const g_string_functions[] = { + { "trim", xm_string_trim }, + { "split", xm_string_split }, + { "lastof", xm_string_lastof }, + { "convert", xm_string_convert }, + { "endswith", xm_string_endswith }, + { "startswith", xm_string_startswith }, + { tb_null, tb_null }, }; // the process functions -static luaL_Reg const g_process_functions[] = -{ - { "open", xm_process_open } -, { "openv", xm_process_openv } -, { "wait", xm_process_wait } -, { "kill", xm_process_kill } -, { "close", xm_process_close } -, { tb_null, tb_null } +static luaL_Reg const g_process_functions[] = { + { "open", xm_process_open }, + { "openv", xm_process_openv }, + { "wait", xm_process_wait }, + { "kill", xm_process_kill }, + { "close", xm_process_close }, + { tb_null, tb_null }, }; // the fwatcher functions -static luaL_Reg const g_fwatcher_functions[] = -{ - { "open", xm_fwatcher_open } -, { "add", xm_fwatcher_add } -, { "remove", xm_fwatcher_remove } -, { "wait", xm_fwatcher_wait } -, { "close", xm_fwatcher_close } -, { tb_null, tb_null } +static luaL_Reg const g_fwatcher_functions[] = { + { "open", xm_fwatcher_open }, + { "add", xm_fwatcher_add }, + { "remove", xm_fwatcher_remove }, + { "wait", xm_fwatcher_wait }, + { "close", xm_fwatcher_close }, + { tb_null, tb_null }, }; // the sandbox functions -static luaL_Reg const g_sandbox_functions[] = -{ - { "interactive", xm_sandbox_interactive } -, { tb_null, tb_null } +static luaL_Reg const g_sandbox_functions[] = { + { "interactive", xm_sandbox_interactive }, + { tb_null, tb_null }, }; #ifdef XM_CONFIG_API_HAVE_READLINE // the readline functions -static luaL_Reg const g_readline_functions[] = -{ - { "readline", xm_readline_readline } -, { "history_list", xm_readline_history_list } -, { "add_history", xm_readline_add_history } -, { "clear_history", xm_readline_clear_history} -, { tb_null, tb_null } +static luaL_Reg const g_readline_functions[] = { + { "readline", xm_readline_readline }, + { "history_list", xm_readline_history_list }, + { "add_history", xm_readline_add_history }, + { "clear_history", xm_readline_clear_history }, + { tb_null, tb_null }, }; #endif // the semver functions -static luaL_Reg const g_semver_functions[] = -{ - { "parse", xm_semver_parse } -, { "compare", xm_semver_compare } -, { "satisfies", xm_semver_satisfies } -, { "select", xm_semver_select } -, { tb_null, tb_null } +static luaL_Reg const g_semver_functions[] = { + { "parse", xm_semver_parse }, + { "compare", xm_semver_compare }, + { "satisfies", xm_semver_satisfies }, + { "select", xm_semver_select }, + { tb_null, tb_null }, }; // the libc functions -static luaL_Reg const g_libc_functions[] = -{ - { "malloc", xm_libc_malloc } -, { "free", xm_libc_free } -, { "memcpy", xm_libc_memcpy } -, { "memset", xm_libc_memset } -, { "memmov", xm_libc_memmov } -, { "strndup", xm_libc_strndup } -, { "dataptr", xm_libc_dataptr } -, { "byteof", xm_libc_byteof } -, { "setbyte", xm_libc_setbyte } -, { tb_null, tb_null } +static luaL_Reg const g_libc_functions[] = { + { "malloc", xm_libc_malloc }, + { "free", xm_libc_free }, + { "memcpy", xm_libc_memcpy }, + { "memset", xm_libc_memset }, + { "memmov", xm_libc_memmov }, + { "strndup", xm_libc_strndup }, + { "dataptr", xm_libc_dataptr }, + { "byteof", xm_libc_byteof }, + { "setbyte", xm_libc_setbyte }, + { tb_null, tb_null }, }; // the tty functions -static luaL_Reg const g_tty_functions[] = -{ - { "term_mode", xm_tty_term_mode } -, { tb_null, tb_null } +static luaL_Reg const g_tty_functions[] = { + { "term_mode", xm_tty_term_mode }, + { tb_null, tb_null }, }; // the package functions -static luaL_Reg const g_package_functions[] = -{ - { "loadxmi", xm_package_loadxmi } -, { tb_null, tb_null } +static luaL_Reg const g_package_functions[] = { + { "loadxmi", xm_package_loadxmi }, + { tb_null, tb_null }, }; // the utils functions -static luaL_Reg const g_utils_functions[] = -{ - { "bin2c", xm_utils_bin2c } -, { tb_null, tb_null } +static luaL_Reg const g_utils_functions[] = { + { "bin2c", xm_utils_bin2c }, + { tb_null, tb_null }, }; // the thread functions -static luaL_Reg const g_thread_functions[] = -{ - { "thread_init", xm_thread_init } -, { "thread_exit", xm_thread_exit } -, { "thread_wait", xm_thread_wait } -, { "thread_resume", xm_thread_resume } -, { "thread_suspend", xm_thread_suspend } -, { "mutex_init", xm_thread_mutex_init } -, { "mutex_exit", xm_thread_mutex_exit } -, { "mutex_lock", xm_thread_mutex_lock } -, { "mutex_trylock", xm_thread_mutex_trylock } -, { "mutex_unlock", xm_thread_mutex_unlock } -, { "mutex_incref", xm_thread_mutex_incref } -, { "event_init", xm_thread_event_init } -, { "event_exit", xm_thread_event_exit } -, { "event_post", xm_thread_event_post } -, { "event_wait", xm_thread_event_wait } -, { "event_incref", xm_thread_event_incref } -, { "semaphore_init", xm_thread_semaphore_init } -, { "semaphore_exit", xm_thread_semaphore_exit } -, { "semaphore_post", xm_thread_semaphore_post } -, { "semaphore_wait", xm_thread_semaphore_wait } -, { "semaphore_incref", xm_thread_semaphore_incref } -, { "queue_init", xm_thread_queue_init } -, { "queue_exit", xm_thread_queue_exit } -, { "queue_size", xm_thread_queue_size } -, { "queue_clear", xm_thread_queue_clear } -, { "queue_incref", xm_thread_queue_incref } -, { "queue_push", xm_thread_queue_push } -, { "queue_pop", xm_thread_queue_pop } -, { "sharedata_init", xm_thread_sharedata_init } -, { "sharedata_exit", xm_thread_sharedata_exit } -, { "sharedata_clear", xm_thread_sharedata_clear } -, { "sharedata_incref", xm_thread_sharedata_incref } -, { "sharedata_set", xm_thread_sharedata_set } -, { "sharedata_get", xm_thread_sharedata_get_ } -, { tb_null, tb_null } +static luaL_Reg const g_thread_functions[] = { + { "thread_init", xm_thread_init }, + { "thread_exit", xm_thread_exit }, + { "thread_wait", xm_thread_wait }, + { "thread_resume", xm_thread_resume }, + { "thread_suspend", xm_thread_suspend }, + { "mutex_init", xm_thread_mutex_init }, + { "mutex_exit", xm_thread_mutex_exit }, + { "mutex_lock", xm_thread_mutex_lock }, + { "mutex_trylock", xm_thread_mutex_trylock }, + { "mutex_unlock", xm_thread_mutex_unlock }, + { "mutex_incref", xm_thread_mutex_incref }, + { "event_init", xm_thread_event_init }, + { "event_exit", xm_thread_event_exit }, + { "event_post", xm_thread_event_post }, + { "event_wait", xm_thread_event_wait }, + { "event_incref", xm_thread_event_incref }, + { "semaphore_init", xm_thread_semaphore_init }, + { "semaphore_exit", xm_thread_semaphore_exit }, + { "semaphore_post", xm_thread_semaphore_post }, + { "semaphore_wait", xm_thread_semaphore_wait }, + { "semaphore_incref", xm_thread_semaphore_incref }, + { "queue_init", xm_thread_queue_init }, + { "queue_exit", xm_thread_queue_exit }, + { "queue_size", xm_thread_queue_size }, + { "queue_clear", xm_thread_queue_clear }, + { "queue_incref", xm_thread_queue_incref }, + { "queue_push", xm_thread_queue_push }, + { "queue_pop", xm_thread_queue_pop }, + { "sharedata_init", xm_thread_sharedata_init }, + { "sharedata_exit", xm_thread_sharedata_exit }, + { "sharedata_clear", xm_thread_sharedata_clear }, + { "sharedata_incref", xm_thread_sharedata_incref }, + { "sharedata_set", xm_thread_sharedata_set }, + { "sharedata_get", xm_thread_sharedata_get_ }, + { tb_null, tb_null }, }; // the lua global instance for signal handler -static lua_State* g_lua = tb_null; +static lua_State *g_lua = tb_null; // the xmake script files data #ifdef XM_EMBED_ENABLE static tb_byte_t g_xmake_xmz_data[] = { - #include "xmake.xmz.h" +#include "xmake.xmz.h" }; #endif /* ////////////////////////////////////////////////////////////////////////////////////// * private implementation */ -static tb_bool_t xm_engine_save_arguments(xm_engine_t* engine, tb_int_t argc, tb_char_t** argv, tb_char_t** taskargv) -{ +static tb_bool_t xm_engine_save_arguments(xm_engine_t *engine, tb_int_t argc, tb_char_t **argv, tb_char_t **taskargv) { // check tb_assert_and_check_return_val(engine && engine->lua && argc >= 1 && argv, tb_false); @@ -738,11 +716,9 @@ static tb_bool_t xm_engine_save_arguments(xm_engine_t* engine, tb_int_t argc, tb lua_newtable(engine->lua); // patch the task arguments list - if (taskargv) - { - tb_char_t** taskarg = taskargv; - while (*taskarg) - { + if (taskargv) { + tb_char_t **taskarg = taskargv; + while (*taskarg) { lua_pushstring(engine->lua, *taskarg); lua_rawseti(engine->lua, -2, (int)lua_objlen(engine->lua, -2) + 1); taskarg++; @@ -751,10 +727,9 @@ static tb_bool_t xm_engine_save_arguments(xm_engine_t* engine, tb_int_t argc, tb // save all arguments to the new table tb_int_t i = 0; - for (i = 1; i < argc; i++) - { + for (i = 1; i < argc; i++) { #if defined(TB_CONFIG_OS_WINDOWS) && !defined(TB_COMPILER_LIKE_UNIX) - tb_char_t argvbuf[4096] = {0}; + tb_char_t argvbuf[4096] = { 0 }; tb_wcstombs(argvbuf, argvw[i], tb_arrayn(argvbuf)); // table_new[table.getn(table_new) + 1] = argv[i] lua_pushstring(engine->lua, argvbuf); @@ -769,8 +744,7 @@ static tb_bool_t xm_engine_save_arguments(xm_engine_t* engine, tb_int_t argc, tb return tb_true; } -static tb_bool_t xm_engine_get_program_file(xm_engine_t* engine, tb_char_t** argv, tb_char_t* path, tb_size_t maxn) -{ +static tb_bool_t xm_engine_get_program_file(xm_engine_t *engine, tb_char_t **argv, tb_char_t *path, tb_size_t maxn) { // check tb_assert_and_check_return_val(engine && path && maxn, tb_false); @@ -779,9 +753,8 @@ static tb_bool_t xm_engine_get_program_file(xm_engine_t* engine, tb_char_t** arg * The executable file compiled using cosmocc on macOS might retrieve a relative path to the programfile. * If the root directory has been changed, the retrieved programfile will be a non-existent path. */ - static tb_char_t s_program_filepath[TB_PATH_MAXN] = {0}; - if (s_program_filepath[0]) - { + static tb_char_t s_program_filepath[TB_PATH_MAXN] = { 0 }; + if (s_program_filepath[0]) { tb_strlcpy(path, s_program_filepath, maxn); lua_pushstring(engine->lua, s_program_filepath); lua_setglobal(engine->lua, "_PROGRAM_FILE"); @@ -789,23 +762,21 @@ static tb_bool_t xm_engine_get_program_file(xm_engine_t* engine, tb_char_t** arg } tb_bool_t ok = tb_false; - do - { + do { // get it from the environment variable first - if (tb_environment_first("XMAKE_PROGRAM_FILE", path, maxn) && tb_file_info(path, tb_null)) - { + if (tb_environment_first("XMAKE_PROGRAM_FILE", path, maxn) && tb_file_info(path, tb_null)) { ok = tb_true; break; } #if defined(TB_CONFIG_OS_WINDOWS) // get the executale file path as program directory - tb_wchar_t buf[TB_PATH_MAXN] = {0}; + tb_wchar_t buf[TB_PATH_MAXN] = { 0 }; tb_size_t size = (tb_size_t)GetModuleFileNameW(tb_null, buf, (DWORD)TB_PATH_MAXN); tb_assert_and_check_break(size < TB_PATH_MAXN); // end - buf[size] = L'\0'; - size = tb_wcstombs(path, buf, maxn); + buf[size] = L'\0'; + size = tb_wcstombs(path, buf, maxn); tb_assert_and_check_break(size < maxn); path[size] = '\0'; @@ -832,44 +803,41 @@ static tb_bool_t xm_engine_get_program_file(xm_engine_t* engine, tb_char_t** arg * @see it may be a relative path */ ssize_t size = readlink(XM_PROC_SELF_FILE, path, (size_t)maxn); - if (size > 0 && size < maxn) - { + if (size > 0 && size < maxn) { path[size] = '\0'; - ok = tb_true; + ok = tb_true; } #elif defined(TB_CONFIG_OS_BSD) && defined(KERN_PROC_PATHNAME) // only for FreeBSD and OpenBSD, https://github.com/xmake-io/xmake/issues/2948 - tb_int_t mib[4]; mib[0] = CTL_KERN; mib[1] = KERN_PROC; mib[2] = KERN_PROC_PATHNAME; mib[3] = -1; + tb_int_t mib[4]; + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = KERN_PROC_PATHNAME; + mib[3] = -1; size_t size = maxn; - if (sysctl(mib, 4, path, &size, tb_null, 0) == 0 && size < maxn) - { + if (sysctl(mib, 4, path, &size, tb_null, 0) == 0 && size < maxn) { path[size] = '\0'; - ok = tb_true; + ok = tb_true; } #elif defined(TB_CONFIG_OS_HAIKU) - int32 cookie = 0; + int32 cookie = 0; image_info info; - while (get_next_image_info(B_CURRENT_TEAM, &cookie, &info) == B_OK) - { - if (info.type == B_APP_IMAGE) - { + while (get_next_image_info(B_CURRENT_TEAM, &cookie, &info) == B_OK) { + if (info.type == B_APP_IMAGE) { tb_strlcpy(path, info.name, maxn); ok = tb_true; break; } } #else - static tb_char_t const* s_paths[] = - { + static tb_char_t const *s_paths[] = { "~/.local/bin/xmake", "/usr/local/bin/xmake", - "/usr/bin/xmake" + "/usr/bin/xmake", }; - for (tb_size_t i = 0; i < tb_arrayn(s_paths); i++) - { - tb_char_t const* p = s_paths[i]; - if (tb_file_info(p, tb_null)) - { + for (tb_size_t i = 0; i < tb_arrayn(s_paths); i++) { + tb_char_t const *p = s_paths[i]; + if (tb_file_info(p, tb_null)) { tb_strlcpy(path, p, maxn); ok = tb_true; break; @@ -877,11 +845,9 @@ static tb_bool_t xm_engine_get_program_file(xm_engine_t* engine, tb_char_t** arg } #endif - if (!ok && argv) - { - tb_char_t const* p = argv[0]; - if (p && tb_file_info(p, tb_null)) - { + if (!ok && argv) { + tb_char_t const *p = argv[0]; + if (p && tb_file_info(p, tb_null)) { tb_strlcpy(path, p, maxn); ok = tb_true; } @@ -890,8 +856,7 @@ static tb_bool_t xm_engine_get_program_file(xm_engine_t* engine, tb_char_t** arg } while (0); // ok? - if (ok) - { + if (ok) { // trace tb_trace_d("programfile: %s", path); @@ -906,11 +871,12 @@ static tb_bool_t xm_engine_get_program_file(xm_engine_t* engine, tb_char_t** arg } #ifdef XM_EMBED_ENABLE -static tb_bool_t xm_engine_get_temporary_directory(tb_char_t* path, tb_size_t maxn, tb_char_t const* name, tb_char_t const* version_cstr) -{ - tb_char_t data[TB_PATH_MAXN] = {0}; - if (tb_directory_temporary(data, sizeof(data))) - { +static tb_bool_t xm_engine_get_temporary_directory(tb_char_t *path, + tb_size_t maxn, + tb_char_t const *name, + tb_char_t const *version_cstr) { + tb_char_t data[TB_PATH_MAXN] = { 0 }; + if (tb_directory_temporary(data, sizeof(data))) { // get euid tb_int_t euid = 0; #ifndef TB_CONFIG_OS_WINDOWS @@ -924,73 +890,69 @@ static tb_bool_t xm_engine_get_temporary_directory(tb_char_t* path, tb_size_t ma } #endif -static tb_bool_t xm_engine_get_program_directory(xm_engine_t* engine, tb_char_t* path, tb_size_t maxn, tb_char_t const* programfile) -{ +static tb_bool_t xm_engine_get_program_directory(xm_engine_t *engine, + tb_char_t *path, + tb_size_t maxn, + tb_char_t const *programfile) { // check tb_assert_and_check_return_val(engine && path && maxn, tb_false); - static tb_char_t s_program_directory[TB_PATH_MAXN] = {0}; - if (s_program_directory[0]) - { + static tb_char_t s_program_directory[TB_PATH_MAXN] = { 0 }; + if (s_program_directory[0]) { tb_strlcpy(path, s_program_directory, maxn); lua_pushstring(engine->lua, s_program_directory); lua_setglobal(engine->lua, "_PROGRAM_DIR"); return tb_true; } - tb_bool_t ok = tb_false; - tb_char_t data[TB_PATH_MAXN] = {0}; - do - { + tb_bool_t ok = tb_false; + tb_char_t data[TB_PATH_MAXN] = { 0 }; + do { #ifdef XM_EMBED_ENABLE tb_size_t embedcount = engine->embedcount; - if (embedcount) - { + if (embedcount) { tb_uint32_t crc32 = 0; for (tb_size_t i = 0; i < embedcount; i++) crc32 += tb_crc32_make(engine->embeddata[i], engine->embedsize[i], 0); tb_snprintf(path, maxn, "%s/%x", engine->tmpdir, crc32); - } - else tb_strlcpy(path, engine->tmpdir, maxn); + } else + tb_strlcpy(path, engine->tmpdir, maxn); ok = tb_true; break; #endif // get it from the environment variable first - if (tb_environment_first("XMAKE_PROGRAM_DIR", data, sizeof(data)) && tb_path_absolute(data, path, maxn)) - { + if (tb_environment_first("XMAKE_PROGRAM_DIR", data, sizeof(data)) && tb_path_absolute(data, path, maxn)) { ok = tb_true; break; } // get it from program file path - if (programfile) - { + if (programfile) { // get real program file path from the symbol link #if !defined(TB_CONFIG_OS_WINDOWS) && !defined(TB_CONFIG_OS_IOS) tb_char_t programpath[TB_PATH_MAXN]; tb_long_t size = readlink(programfile, programpath, sizeof(programpath)); - if (size >= 0 && size < sizeof(programpath)) - { + if (size >= 0 && size < sizeof(programpath)) { programpath[size] = '\0'; // soft link to relative path? fix it - if (!tb_path_is_absolute(programpath)) - { - tb_char_t buff[TB_PATH_MAXN]; - tb_char_t const* rootdir = tb_path_directory(programfile, buff, sizeof(buff)); - if (rootdir && tb_path_absolute_to(rootdir, programpath, path, maxn)) // @note path and programfile are same buffer + if (!tb_path_is_absolute(programpath)) { + tb_char_t buff[TB_PATH_MAXN]; + tb_char_t const *rootdir = tb_path_directory(programfile, buff, sizeof(buff)); + if (rootdir && tb_path_absolute_to( + rootdir, programpath, path, maxn)) // @note path and programfile are same buffer tb_strlcpy(programpath, path, maxn); } - } - else tb_strlcpy(programpath, programfile, sizeof(programpath)); + } else + tb_strlcpy(programpath, programfile, sizeof(programpath)); #else - tb_char_t const* programpath = programfile; + tb_char_t const *programpath = programfile; #endif // get the root directory - tb_char_t data[TB_PATH_MAXN]; - tb_char_t const* rootdir = tb_path_directory(programpath, data, sizeof(data)); + tb_char_t data[TB_PATH_MAXN]; + tb_char_t const *rootdir = tb_path_directory(programpath, data, sizeof(data)); tb_assert_and_check_break(rootdir); // init share/name sub-directory @@ -998,17 +960,18 @@ static tb_bool_t xm_engine_get_program_directory(xm_engine_t* engine, tb_char_t* tb_snprintf(sharedir, sizeof(sharedir), "../share/%s", engine->name); // find the program (lua) directory - tb_size_t i; - tb_file_info_t info; - tb_char_t scriptpath[TB_PATH_MAXN]; - tb_char_t const* subdirs[] = {".", sharedir}; - for (i = 0; i < tb_arrayn(subdirs); i++) - { + tb_size_t i; + tb_file_info_t info; + tb_char_t scriptpath[TB_PATH_MAXN]; + tb_char_t const *subdirs[] = { + ".", + sharedir, + }; + for (i = 0; i < tb_arrayn(subdirs); i++) { // get program directory if (tb_path_absolute_to(rootdir, subdirs[i], path, maxn) && tb_path_absolute_to(path, "core/_xmake_main.lua", scriptpath, sizeof(scriptpath)) && - tb_file_info(scriptpath, &info) && info.type == TB_FILE_TYPE_FILE) - { + tb_file_info(scriptpath, &info) && info.type == TB_FILE_TYPE_FILE) { ok = tb_true; break; } @@ -1018,8 +981,7 @@ static tb_bool_t xm_engine_get_program_directory(xm_engine_t* engine, tb_char_t* } while (0); // ok? - if (ok) - { + if (ok) { // trace tb_trace_d("programdir: %s", path); @@ -1035,21 +997,18 @@ static tb_bool_t xm_engine_get_program_directory(xm_engine_t* engine, tb_char_t* return ok; } -static tb_bool_t xm_engine_get_project_directory(xm_engine_t* engine, tb_char_t* path, tb_size_t maxn) -{ +static tb_bool_t xm_engine_get_project_directory(xm_engine_t *engine, tb_char_t *path, tb_size_t maxn) { // check tb_assert_and_check_return_val(engine && path && maxn, tb_false); tb_bool_t ok = tb_false; - do - { + do { // attempt to get it from the environment variable first - tb_char_t data[TB_PATH_MAXN] = {0}; - if ( !tb_environment_first("XMAKE_PROJECT_DIR", data, sizeof(data)) - || !tb_path_absolute(data, path, maxn)) - { + tb_char_t data[TB_PATH_MAXN] = { 0 }; + if (!tb_environment_first("XMAKE_PROJECT_DIR", data, sizeof(data)) || !tb_path_absolute(data, path, maxn)) { // get it from the current directory - if (!tb_directory_current(path, maxn)) break; + if (!tb_directory_current(path, maxn)) + break; } // trace @@ -1065,15 +1024,15 @@ static tb_bool_t xm_engine_get_project_directory(xm_engine_t* engine, tb_char_t* } while (0); // failed? - if (!ok) tb_printf("error: not found the project directory!\n"); + if (!ok) + tb_printf("error: not found the project directory!\n"); // ok? return ok; } #if defined(TB_CONFIG_OS_WINDOWS) || defined(SIGINT) -static tb_void_t xm_engine_dump_traceback(lua_State* lua) -{ +static tb_void_t xm_engine_dump_traceback(lua_State *lua) { // @note it's not safe, but it doesn't matter, we're just trying to get the stack backtrace for debugging lua_getglobal(lua, "debug"); lua_getfield(lua, -1, "traceback"); @@ -1085,37 +1044,31 @@ static tb_void_t xm_engine_dump_traceback(lua_State* lua) #endif #if defined(TB_CONFIG_OS_WINDOWS) -static BOOL WINAPI xm_engine_signal_handler(DWORD signo) -{ - if (signo == CTRL_C_EVENT && g_lua) - { +static BOOL WINAPI xm_engine_signal_handler(DWORD signo) { + if (signo == CTRL_C_EVENT && g_lua) { xm_engine_dump_traceback(g_lua); tb_abort(); } return TRUE; } #elif defined(SIGINT) -static tb_void_t xm_engine_signal_handler(tb_int_t signo) -{ - if (signo == SIGINT && g_lua) - { +static tb_void_t xm_engine_signal_handler(tb_int_t signo) { + if (signo == SIGINT && g_lua) { xm_engine_dump_traceback(g_lua); tb_abort(); } } #endif -static tb_void_t xm_engine_init_host(xm_engine_t* engine) -{ +static tb_void_t xm_engine_init_host(xm_engine_t *engine) { // check tb_assert_and_check_return(engine && engine->lua); // init system host - tb_char_t const* syshost = tb_null; + tb_char_t const *syshost = tb_null; #if defined(__COSMOPOLITAN__) struct utsname buffer; - if (uname(&buffer) == 0) - { + if (uname(&buffer) == 0) { if (tb_strstr(buffer.sysname, "Darwin")) syshost = "macosx"; else if (tb_strstr(buffer.sysname, "Linux")) @@ -1138,48 +1091,48 @@ static tb_void_t xm_engine_init_host(xm_engine_t* engine) #elif defined(TB_CONFIG_OS_HAIKU) syshost = "haiku"; #endif - lua_pushstring(engine->lua, syshost? syshost : "unknown"); + lua_pushstring(engine->lua, syshost ? syshost : "unknown"); lua_setglobal(engine->lua, "_HOST"); // init subsystem host - tb_char_t const* subhost = syshost; + tb_char_t const *subhost = syshost; #if defined(TB_CONFIG_OS_WINDOWS) -# if defined(TB_COMPILER_ON_MSYS) +#if defined(TB_COMPILER_ON_MSYS) subhost = "msys"; -# elif defined(TB_COMPILER_ON_CYGWIN) +#elif defined(TB_COMPILER_ON_CYGWIN) subhost = "cygwin"; -# else +#else { - tb_char_t data[64] = {0}; - if (tb_environment_first("MSYSTEM", data, sizeof(data))) - { + tb_char_t data[64] = { 0 }; + if (tb_environment_first("MSYSTEM", data, sizeof(data))) { // on msys? if (!tb_strnicmp(data, "mingw", 5) // mingw32/64 on msys2 - || !tb_strnicmp(data, "clang", 5) // clang32/64 on msys2, @see https://github.com/xmake-io/xmake/issues/3060 - || !tb_stricmp(data, "ucrt64") // ucrt64 https://www.msys2.org/docs/environments/ + || !tb_strnicmp(data, + "clang", + 5) // clang32/64 on msys2, @see https://github.com/xmake-io/xmake/issues/3060 + || !tb_stricmp(data, "ucrt64") // ucrt64 https://www.msys2.org/docs/environments/ || !tb_stricmp(data, "msys")) // on msys2 subhost = "msys"; } } -# endif #endif - lua_pushstring(engine->lua, subhost? subhost : "unknown"); +#endif + lua_pushstring(engine->lua, subhost ? subhost : "unknown"); lua_setglobal(engine->lua, "_SUBHOST"); } -static __tb_inline__ tb_char_t const* xm_engine_xmake_arch() -{ - tb_char_t const* arch = tb_null; +static __tb_inline__ tb_char_t const *xm_engine_xmake_arch() { + tb_char_t const *arch = tb_null; #if defined(TB_CONFIG_OS_WINDOWS) && !defined(TB_COMPILER_LIKE_UNIX) -# if defined(TB_ARCH_x64) +#if defined(TB_ARCH_x64) arch = "x64"; -# elif defined(TB_ARCH_ARM64) +#elif defined(TB_ARCH_ARM64) arch = "arm64"; -# elif defined(TB_ARCH_ARM) +#elif defined(TB_ARCH_ARM) arch = "arm"; -# else +#else arch = "x86"; -# endif +#endif #elif defined(TB_ARCH_x64) arch = "x86_64"; #elif defined(TB_ARCH_x86) @@ -1192,48 +1145,46 @@ static __tb_inline__ tb_char_t const* xm_engine_xmake_arch() return arch; } -static tb_void_t xm_engine_init_arch(xm_engine_t* engine) -{ +static tb_void_t xm_engine_init_arch(xm_engine_t *engine) { // check tb_assert_and_check_return(engine && engine->lua); // init xmake arch - tb_char_t const* xmakearch = xm_engine_xmake_arch(); + tb_char_t const *xmakearch = xm_engine_xmake_arch(); lua_pushstring(engine->lua, xmakearch); lua_setglobal(engine->lua, "_XMAKE_ARCH"); // init system architecture - tb_char_t const* sysarch = tb_null; + tb_char_t const *sysarch = tb_null; #if defined(__COSMOPOLITAN__) struct utsname buffer; - if (uname(&buffer) == 0) - { + if (uname(&buffer) == 0) { sysarch = buffer.machine; - if (tb_strstr(buffer.sysname, "Windows")) - { + if (tb_strstr(buffer.sysname, "Windows")) { if (!tb_strcmp(buffer.machine, "x86_64")) sysarch = "x64"; else if (!tb_strcmp(buffer.machine, "i686") || !tb_strcmp(buffer.machine, "i386")) sysarch = "x86"; - } - else if (!tb_strcmp(buffer.machine, "aarch64")) + } else if (!tb_strcmp(buffer.machine, "aarch64")) sysarch = "arm64"; } #elif defined(TB_CONFIG_OS_WINDOWS) && !defined(TB_COMPILER_LIKE_UNIX) // the GetNativeSystemInfo function type - typedef void (WINAPI *GetNativeSystemInfo_t)(LPSYSTEM_INFO); + typedef void(WINAPI * GetNativeSystemInfo_t)(LPSYSTEM_INFO); // get system info - SYSTEM_INFO systeminfo = {0}; + SYSTEM_INFO systeminfo = { 0 }; GetNativeSystemInfo_t pGetNativeSystemInfo = tb_null; - tb_dynamic_ref_t kernel32 = tb_dynamic_init("kernel32.dll"); - if (kernel32) pGetNativeSystemInfo = (GetNativeSystemInfo_t)tb_dynamic_func(kernel32, "GetNativeSystemInfo"); - if (pGetNativeSystemInfo) pGetNativeSystemInfo(&systeminfo); - else GetSystemInfo(&systeminfo); + tb_dynamic_ref_t kernel32 = tb_dynamic_init("kernel32.dll"); + if (kernel32) + pGetNativeSystemInfo = (GetNativeSystemInfo_t)tb_dynamic_func(kernel32, "GetNativeSystemInfo"); + if (pGetNativeSystemInfo) + pGetNativeSystemInfo(&systeminfo); + else + GetSystemInfo(&systeminfo); // init architecture - switch (systeminfo.wProcessorArchitecture) - { + switch (systeminfo.wProcessorArchitecture) { case PROCESSOR_ARCHITECTURE_AMD64: sysarch = "x64"; break; @@ -1252,17 +1203,17 @@ static tb_void_t xm_engine_init_arch(xm_engine_t* engine) break; } #endif - if (!sysarch) sysarch = xmakearch; + if (!sysarch) + sysarch = xmakearch; lua_pushstring(engine->lua, sysarch); lua_setglobal(engine->lua, "_ARCH"); // init subsystem architecture - tb_char_t const* subarch = sysarch; + tb_char_t const *subarch = sysarch; #if defined(TB_CONFIG_OS_WINDOWS) && !defined(TB_COMPILER_LIKE_UNIX) // get architecture from msys environment - tb_char_t data[64] = {0}; - if (tb_environment_first("MSYSTEM_CARCH", data, sizeof(data))) - { + tb_char_t data[64] = { 0 }; + if (tb_environment_first("MSYSTEM_CARCH", data, sizeof(data))) { if (!tb_strcmp(data, "i686")) subarch = "i386"; else @@ -1273,8 +1224,7 @@ static tb_void_t xm_engine_init_arch(xm_engine_t* engine) lua_setglobal(engine->lua, "_SUBARCH"); } -static tb_void_t xm_engine_init_features(xm_engine_t* engine) -{ +static tb_void_t xm_engine_init_features(xm_engine_t *engine) { // check tb_assert_and_check_return(engine && engine->lua); @@ -1302,12 +1252,11 @@ static tb_void_t xm_engine_init_features(xm_engine_t* engine) lua_setglobal(engine->lua, "_FEATURES"); } -static tb_void_t xm_engine_init_signal(xm_engine_t* engine) -{ +static tb_void_t xm_engine_init_signal(xm_engine_t *engine) { // we enable it to catch the current lua stack in ctrl-c signal handler if XMAKE_PROFILE=stuck - tb_char_t data[64] = {0}; + tb_char_t data[64] = { 0 }; if (!tb_environment_first("XMAKE_PROFILE", data, sizeof(data)) || tb_strcmp(data, "stuck")) - return ; + return; g_lua = engine->lua; #if defined(TB_CONFIG_OS_WINDOWS) @@ -1319,46 +1268,50 @@ static tb_void_t xm_engine_init_signal(xm_engine_t* engine) #if XM_HOOK_LUA_MEMALLOC // udata is unused, it has been used by engine. see xm_engine_bind_to_lua() -static tb_pointer_t xm_engine_lua_realloc(tb_pointer_t udata, tb_pointer_t data, size_t osize, size_t nsize) -{ +static tb_pointer_t xm_engine_lua_realloc(tb_pointer_t udata, tb_pointer_t data, size_t osize, size_t nsize) { tb_pointer_t ptr = tb_null; - if (nsize == 0 && data) tb_free(data); - else if (!data) ptr = tb_malloc((tb_size_t)nsize); - else if (nsize != osize) ptr = tb_ralloc(data, (tb_size_t)nsize); - else ptr = data; + if (nsize == 0 && data) + tb_free(data); + else if (!data) + ptr = tb_malloc((tb_size_t)nsize); + else if (nsize != osize) + ptr = tb_ralloc(data, (tb_size_t)nsize); + else + ptr = data; return ptr; } #endif #ifdef XM_EMBED_ENABLE -static tb_bool_t xm_engine_extract_programfiles_impl(xm_engine_t* engine, tb_char_t const* programdir, tb_byte_t const* data, tb_size_t size) -{ +static tb_bool_t xm_engine_extract_programfiles_impl(xm_engine_t *engine, + tb_char_t const *programdir, + tb_byte_t const *data, + tb_size_t size) { // do decompress - tb_bool_t ok = tb_false; - LZ4F_errorCode_t code; + tb_bool_t ok = tb_false; + LZ4F_errorCode_t code; LZ4F_decompressionContext_t ctx = tb_null; - tb_buffer_t result; - do - { + tb_buffer_t result; + do { tb_buffer_init(&result); code = LZ4F_createDecompressionContext(&ctx, LZ4F_VERSION); - if (LZ4F_isError(code)) break; + if (LZ4F_isError(code)) + break; tb_byte_t buffer[8192]; tb_bool_t failed = tb_false; - while (1) - { - size_t advance = (size_t)size; + while (1) { + size_t advance = (size_t)size; size_t buffer_size = sizeof(buffer); - code = LZ4F_decompress(ctx, buffer, &buffer_size, data, &advance, tb_null); - if (LZ4F_isError(code)) - { + code = LZ4F_decompress(ctx, buffer, &buffer_size, data, &advance, tb_null); + if (LZ4F_isError(code)) { failed = tb_true; break; } - if (buffer_size == 0) break; + if (buffer_size == 0) + break; data += advance; size -= advance; @@ -1370,22 +1323,20 @@ static tb_bool_t xm_engine_extract_programfiles_impl(xm_engine_t* engine, tb_cha } while (0); // extract files to programdir - if (ok) - { - data = tb_buffer_data(&result); - size = tb_buffer_size(&result); - tb_byte_t const* p = data; - tb_byte_t const* e = data + size; - tb_size_t n = 0; - tb_char_t filepath[TB_PATH_MAXN]; - tb_long_t pos = tb_snprintf(filepath, sizeof(filepath), "%s/", programdir); - while (p < e) - { + if (ok) { + data = tb_buffer_data(&result); + size = tb_buffer_size(&result); + tb_byte_t const *p = data; + tb_byte_t const *e = data + size; + tb_size_t n = 0; + tb_char_t filepath[TB_PATH_MAXN]; + tb_long_t pos = tb_snprintf(filepath, sizeof(filepath), "%s/", programdir); + while (p < e) { // get filepath n = (tb_size_t)tb_bits_get_u16_be(p); p += 2; tb_assert_and_check_break(pos + n + 1 < sizeof(filepath)); - tb_strncpy(filepath + pos, (tb_char_t const*)p, n); + tb_strncpy(filepath + pos, (tb_char_t const *)p, n); filepath[pos + n] = '\0'; p += n; @@ -1395,11 +1346,12 @@ static tb_bool_t xm_engine_extract_programfiles_impl(xm_engine_t* engine, tb_cha // write file tb_trace_d("extracting %s, %lu bytes ..", filepath, n); - tb_stream_ref_t stream = tb_stream_init_from_file(filepath, TB_FILE_MODE_RW | TB_FILE_MODE_CREAT | TB_FILE_MODE_TRUNC); + tb_stream_ref_t stream = tb_stream_init_from_file(filepath, + TB_FILE_MODE_RW | TB_FILE_MODE_CREAT | + TB_FILE_MODE_TRUNC); tb_assert_and_check_break(stream); - if (tb_stream_open(stream)) - { + if (tb_stream_open(stream)) { tb_stream_bwrit(stream, p, n); tb_stream_exit(stream); } @@ -1407,18 +1359,14 @@ static tb_bool_t xm_engine_extract_programfiles_impl(xm_engine_t* engine, tb_cha p += n; } ok = (p == e); - if (!ok) - { + if (!ok) { tb_trace_e("extract program files failed"); } - } - else - { + } else { tb_trace_e("decompress program files failed, %s", LZ4F_getErrorName(code)); } - if (ctx) - { + if (ctx) { LZ4F_freeDecompressionContext(ctx); ctx = tb_null; } @@ -1426,19 +1374,16 @@ static tb_bool_t xm_engine_extract_programfiles_impl(xm_engine_t* engine, tb_cha return ok; } -static tb_bool_t xm_engine_extract_programfiles(xm_engine_t* engine, tb_char_t const* programdir) -{ - tb_file_info_t info = {0}; - if (!tb_file_info(programdir, &info)) - { - tb_byte_t const* data = g_xmake_xmz_data; - tb_size_t size = sizeof(g_xmake_xmz_data); +static tb_bool_t xm_engine_extract_programfiles(xm_engine_t *engine, tb_char_t const *programdir) { + tb_file_info_t info = { 0 }; + if (!tb_file_info(programdir, &info)) { + tb_byte_t const *data = g_xmake_xmz_data; + tb_size_t size = sizeof(g_xmake_xmz_data); if (!xm_engine_extract_programfiles_impl(engine, programdir, data, size)) return tb_false; tb_size_t embedcount = engine->embedcount; - for (tb_size_t i = 0; i < embedcount; i++) - { + for (tb_size_t i = 0; i < embedcount; i++) { data = engine->embeddata[i]; size = engine->embedsize[i]; if (!xm_engine_extract_programfiles_impl(engine, programdir, data, size)) @@ -1449,27 +1394,23 @@ static tb_bool_t xm_engine_extract_programfiles(xm_engine_t* engine, tb_char_t c } #endif -static tb_void_t xm_engine_bind_to_lua(lua_State* lua, xm_engine_t* engine) -{ +static tb_void_t xm_engine_bind_to_lua(lua_State *lua, xm_engine_t *engine) { lua_pushlightuserdata(lua, engine); lua_setglobal(lua, "__global_engine"); } // load and execute the main script -static tb_bool_t xm_engine_load_main_script(xm_engine_t* engine, tb_char_t const* mainfile) -{ +static tb_bool_t xm_engine_load_main_script(xm_engine_t *engine, tb_char_t const *mainfile) { #ifdef TB_CONFIG_OS_WINDOWS // use tb_file_init to support unicode file path on windows - tb_bool_t ok = tb_false; + tb_bool_t ok = tb_false; tb_file_ref_t file = tb_null; - tb_byte_t* data = tb_null; + tb_byte_t *data = tb_null; - do - { + do { // open file file = tb_file_init(mainfile, TB_FILE_MODE_RO); - if (!file) - { + if (!file) { tb_printf("error: cannot open file: %s\n", mainfile); break; } @@ -1479,26 +1420,23 @@ static tb_bool_t xm_engine_load_main_script(xm_engine_t* engine, tb_char_t const tb_assert_and_check_break(size); // allocate buffer - data = (tb_byte_t*)tb_malloc(size); + data = (tb_byte_t *)tb_malloc(size); tb_assert_and_check_break(data); // read file content - if (!tb_file_read(file, data, size)) - { + if (!tb_file_read(file, data, size)) { tb_printf("error: cannot read file: %s\n", mainfile); break; } // load lua buffer - if (luaL_loadbuffer(engine->lua, (tb_char_t const*)data, size, mainfile)) - { + if (luaL_loadbuffer(engine->lua, (tb_char_t const *)data, size, mainfile)) { tb_printf("error: %s\n", lua_tostring(engine->lua, -1)); break; } // execute lua script - if (lua_pcall(engine->lua, 0, LUA_MULTRET, 0)) - { + if (lua_pcall(engine->lua, 0, LUA_MULTRET, 0)) { tb_printf("error: %s\n", lua_tostring(engine->lua, -1)); break; } @@ -1507,12 +1445,13 @@ static tb_bool_t xm_engine_load_main_script(xm_engine_t* engine, tb_char_t const } while (0); - if (data) tb_free(data); - if (file) tb_file_exit(file); + if (data) + tb_free(data); + if (file) + tb_file_exit(file); return ok; #else - if (luaL_dofile(engine->lua, mainfile)) - { + if (luaL_dofile(engine->lua, mainfile)) { tb_printf("error: %s\n", lua_tostring(engine->lua, -1)); return tb_false; } @@ -1523,12 +1462,10 @@ static tb_bool_t xm_engine_load_main_script(xm_engine_t* engine, tb_char_t const /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -xm_engine_ref_t xm_engine_init(tb_char_t const* name, xm_engine_lni_initalizer_cb_t lni_initalizer) -{ - tb_bool_t ok = tb_false; - xm_engine_t* engine = tb_null; - do - { +xm_engine_ref_t xm_engine_init(tb_char_t const *name, xm_engine_lni_initalizer_cb_t lni_initalizer) { + tb_bool_t ok = tb_false; + xm_engine_t *engine = tb_null; + do { // init self engine = tb_malloc0_type(xm_engine_t); tb_assert_and_check_break(engine); @@ -1635,14 +1572,28 @@ xm_engine_ref_t xm_engine_init(tb_char_t const* name, xm_engine_lni_initalizer_c xm_engine_init_signal(engine); // get version - tb_version_t const* version = xm_version(); + tb_version_t const *version = xm_version(); tb_assert_and_check_break(version); // init version string - tb_char_t version_cstr[256] = {0}; + tb_char_t version_cstr[256] = { 0 }; if (tb_strcmp(XM_CONFIG_VERSION_BRANCH, "") && tb_strcmp(XM_CONFIG_VERSION_COMMIT, "")) - tb_snprintf(version_cstr, sizeof(version_cstr), "%u.%u.%u+%s.%s", version->major, version->minor, version->alter, XM_CONFIG_VERSION_BRANCH, XM_CONFIG_VERSION_COMMIT); - else tb_snprintf(version_cstr, sizeof(version_cstr), "%u.%u.%u+%llu", version->major, version->minor, version->alter, version->build); + tb_snprintf(version_cstr, + sizeof(version_cstr), + "%u.%u.%u+%s.%s", + version->major, + version->minor, + version->alter, + XM_CONFIG_VERSION_BRANCH, + XM_CONFIG_VERSION_COMMIT); + else + tb_snprintf(version_cstr, + sizeof(version_cstr), + "%u.%u.%u+%llu", + version->major, + version->minor, + version->alter, + version->build); lua_pushstring(engine->lua, version_cstr); lua_setglobal(engine->lua, "_VERSION"); @@ -1661,7 +1612,7 @@ xm_engine_ref_t xm_engine_init(tb_char_t const* name, xm_engine_lni_initalizer_c lua_setglobal(engine->lua, "_VERSION_SHORT"); // init engine name - lua_pushstring(engine->lua, name? name : "xmake"); + lua_pushstring(engine->lua, name ? name : "xmake"); lua_setglobal(engine->lua, "_NAME"); // use luajit as runtime? @@ -1681,17 +1632,16 @@ xm_engine_ref_t xm_engine_init(tb_char_t const* name, xm_engine_lni_initalizer_c * we can get the lni modules for _lni or `import("lib.lni.xxx")` in sandbox */ lua_newtable(engine->lua); - if (lni_initalizer) lni_initalizer((xm_engine_ref_t)engine, engine->lua); + if (lni_initalizer) + lni_initalizer((xm_engine_ref_t)engine, engine->lua); lua_setglobal(engine->lua, "_lni"); #ifdef TB_CONFIG_OS_WINDOWS // enable terminal colors output for windows cmd - HANDLE output = GetStdHandle(STD_OUTPUT_HANDLE); - if (output != INVALID_HANDLE_VALUE) - { + HANDLE output = GetStdHandle(STD_OUTPUT_HANDLE); + if (output != INVALID_HANDLE_VALUE) { DWORD mode; - if (GetConsoleMode(output, &mode)) - { + if (GetConsoleMode(output, &mode)) { // attempt to enable 0x4: ENABLE_VIRTUAL_TERMINAL_PROCESSING if (SetConsoleMode(output, mode | 0x4)) tb_environment_set("COLORTERM", "color256"); @@ -1702,64 +1652,69 @@ xm_engine_ref_t xm_engine_init(tb_char_t const* name, xm_engine_lni_initalizer_c } while (0); - if (!ok) - { - if (engine) xm_engine_exit((xm_engine_ref_t)engine); + if (!ok) { + if (engine) + xm_engine_exit((xm_engine_ref_t)engine); engine = tb_null; } return (xm_engine_ref_t)engine; } -tb_void_t xm_engine_exit(xm_engine_ref_t self) -{ +tb_void_t xm_engine_exit(xm_engine_ref_t self) { // check - xm_engine_t* engine = (xm_engine_t*)self; + xm_engine_t *engine = (xm_engine_t *)self; tb_assert_and_check_return(engine); // exit lua - if (engine->lua) lua_close(engine->lua); + if (engine->lua) + lua_close(engine->lua); engine->lua = tb_null; // exit poller - if (engine->poller) tb_poller_exit(engine->poller); + if (engine->poller) + tb_poller_exit(engine->poller); engine->poller = tb_null; // exit it tb_free(engine); } -tb_int_t xm_engine_main(xm_engine_ref_t self, tb_int_t argc, tb_char_t** argv, tb_char_t** taskargv) -{ +tb_int_t xm_engine_main(xm_engine_ref_t self, tb_int_t argc, tb_char_t **argv, tb_char_t **taskargv) { // check - xm_engine_t* engine = (xm_engine_t*)self; + xm_engine_t *engine = (xm_engine_t *)self; tb_assert_and_check_return_val(engine && engine->lua, -1); #if defined(TB_CONFIG_OS_WINDOWS) && defined(TB_COMPILER_IS_MSVC) // set "stdin" to have unicode mode - if (_isatty(_fileno(stdin))) _setmode(_fileno(stdin), _O_U16TEXT); + if (_isatty(_fileno(stdin))) + _setmode(_fileno(stdin), _O_U16TEXT); #endif // save main arguments to the global variable: _ARGV - if (!xm_engine_save_arguments(engine, argc, argv, taskargv)) return -1; + if (!xm_engine_save_arguments(engine, argc, argv, taskargv)) + return -1; // get the project directory - tb_char_t path[TB_PATH_MAXN] = {0}; - if (!xm_engine_get_project_directory(engine, path, sizeof(path))) return -1; + tb_char_t path[TB_PATH_MAXN] = { 0 }; + if (!xm_engine_get_project_directory(engine, path, sizeof(path))) + return -1; // get the program file - if (!xm_engine_get_program_file(engine, argv, path, sizeof(path))) return -1; + if (!xm_engine_get_program_file(engine, argv, path, sizeof(path))) + return -1; // get the program directory - if (!xm_engine_get_program_directory(engine, path, sizeof(path), path)) return -1; + if (!xm_engine_get_program_directory(engine, path, sizeof(path), path)) + return -1; #ifdef XM_EMBED_ENABLE - if (!xm_engine_extract_programfiles(engine, path)) return -1; + if (!xm_engine_extract_programfiles(engine, path)) + return -1; #endif // append the main script path tb_strcat(path, "/core/_xmake_main.lua"); // exists this script? - if (!tb_file_info(path, tb_null)) - { + if (!tb_file_info(path, tb_null)) { tb_printf("not found main script: %s\n", path); return -1; } @@ -1777,8 +1732,7 @@ tb_int_t xm_engine_main(xm_engine_ref_t self, tb_int_t argc, tb_char_t** argv, t // call the main function lua_getglobal(engine->lua, "_xmake_main"); - if (lua_pcall(engine->lua, 0, 1, -2)) - { + if (lua_pcall(engine->lua, 0, 1, -2)) { tb_printf("error: %s\n", lua_tostring(engine->lua, -1)); return -1; } @@ -1786,10 +1740,9 @@ tb_int_t xm_engine_main(xm_engine_ref_t self, tb_int_t argc, tb_char_t** argv, t // get the error code return (tb_int_t)lua_tonumber(engine->lua, -1); } -tb_void_t xm_engine_register(xm_engine_ref_t self, tb_char_t const* module, luaL_Reg const funcs[]) -{ +tb_void_t xm_engine_register(xm_engine_ref_t self, tb_char_t const *module, luaL_Reg const funcs[]) { // check - xm_engine_t* engine = (xm_engine_t*)self; + xm_engine_t *engine = (xm_engine_t *)self; tb_assert_and_check_return(engine && engine->lua && module && funcs); // do register @@ -1799,10 +1752,9 @@ tb_void_t xm_engine_register(xm_engine_ref_t self, tb_char_t const* module, luaL lua_rawset(engine->lua, -3); } #ifdef XM_EMBED_ENABLE -tb_void_t xm_engine_add_embedfiles(xm_engine_ref_t self, tb_byte_t const* data, tb_size_t size) -{ +tb_void_t xm_engine_add_embedfiles(xm_engine_ref_t self, tb_byte_t const *data, tb_size_t size) { // check - xm_engine_t* engine = (xm_engine_t*)self; + xm_engine_t *engine = (xm_engine_t *)self; tb_assert_and_check_return(engine && engine->embedcount < tb_arrayn(engine->embedsize) && data && size); engine->embeddata[engine->embedcount] = data; @@ -1810,25 +1762,22 @@ tb_void_t xm_engine_add_embedfiles(xm_engine_ref_t self, tb_byte_t const* data, engine->embedcount++; } #endif -lua_State* xm_engine_lua(xm_engine_ref_t self) -{ +lua_State *xm_engine_lua(xm_engine_ref_t self) { // check - xm_engine_t* engine = (xm_engine_t*)self; + xm_engine_t *engine = (xm_engine_t *)self; tb_assert_and_check_return_val(engine, tb_null); return engine->lua; } -tb_poller_ref_t xm_engine_poller(xm_engine_ref_t self) -{ +tb_poller_ref_t xm_engine_poller(xm_engine_ref_t self) { // check - xm_engine_t* engine = (xm_engine_t*)self; + xm_engine_t *engine = (xm_engine_t *)self; tb_assert_and_check_return_val(engine, tb_null); - if (!engine->poller) - { + if (!engine->poller) { // init poller engine->poller_state.lua = engine->lua; - tb_poller_ref_t poller = tb_poller_init(&engine->poller_state); + tb_poller_ref_t poller = tb_poller_init(&engine->poller_state); tb_assert_and_check_return_val(poller, tb_null); // attach poller to the current thread @@ -1837,14 +1786,15 @@ tb_poller_ref_t xm_engine_poller(xm_engine_ref_t self) } return engine->poller; } -tb_int_t xm_engine_run(tb_char_t const* name, tb_int_t argc, tb_char_t** argv, tb_char_t** taskargv, xm_engine_lni_initalizer_cb_t lni_initalizer) -{ +tb_int_t xm_engine_run(tb_char_t const *name, + tb_int_t argc, + tb_char_t **argv, + tb_char_t **taskargv, + xm_engine_lni_initalizer_cb_t lni_initalizer) { tb_int_t ok = -1; - if (xm_init()) - { + if (xm_init()) { xm_engine_ref_t engine = xm_engine_init(name, lni_initalizer); - if (engine) - { + if (engine) { ok = xm_engine_main(engine, argc, argv, taskargv); xm_engine_exit(engine); } @@ -1852,11 +1802,9 @@ tb_int_t xm_engine_run(tb_char_t const* name, tb_int_t argc, tb_char_t** argv, t } return ok; } -xm_engine_ref_t xm_engine_get(lua_State* lua) -{ +xm_engine_ref_t xm_engine_get(lua_State *lua) { tb_assert_and_check_return_val(lua, tb_null); lua_getglobal(lua, "__global_engine"); return (xm_engine_ref_t)lua_touserdata(lua, -1); } - -- cgit v1.3.1 From 39189e3a1bd2979b7b454547b03e5926a8027431 Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 9 Nov 2025 19:54:35 +0800 Subject: remove unused comments --- core/src/xmake/base64/decode.c | 1 - core/src/xmake/base64/encode.c | 1 - core/src/xmake/bloom_filter/bloom_filter_clear.c | 1 - core/src/xmake/bloom_filter/bloom_filter_close.c | 1 - core/src/xmake/bloom_filter/bloom_filter_data.c | 1 - .../src/xmake/bloom_filter/bloom_filter_data_set.c | 1 - core/src/xmake/bloom_filter/bloom_filter_get.c | 1 - core/src/xmake/bloom_filter/bloom_filter_open.c | 1 - core/src/xmake/bloom_filter/bloom_filter_set.c | 1 - core/src/xmake/bloom_filter/bloom_filter_size.c | 1 - core/src/xmake/engine.c | 24 ---------------------- core/src/xmake/fwatcher/add.c | 1 - core/src/xmake/fwatcher/close.c | 1 - core/src/xmake/fwatcher/open.c | 1 - core/src/xmake/fwatcher/remove.c | 1 - core/src/xmake/fwatcher/wait.c | 1 - core/src/xmake/hash/md5.c | 2 -- core/src/xmake/hash/rand128.c | 1 - core/src/xmake/hash/rand32.c | 1 - core/src/xmake/hash/rand64.c | 1 - core/src/xmake/hash/sha.c | 2 -- core/src/xmake/hash/uuid4.c | 1 - core/src/xmake/hash/xxhash.c | 2 -- core/src/xmake/io/file_close.c | 4 ---- core/src/xmake/io/file_flush.c | 2 -- core/src/xmake/io/file_isatty.c | 1 - core/src/xmake/io/file_open.c | 4 ---- core/src/xmake/io/file_rawfd.c | 1 - core/src/xmake/io/file_read.c | 13 ------------ core/src/xmake/io/file_readable.c | 1 - core/src/xmake/io/file_seek.c | 1 - core/src/xmake/io/file_size.c | 1 - core/src/xmake/io/file_write.c | 4 ---- core/src/xmake/io/filelock_close.c | 2 -- core/src/xmake/io/filelock_lock.c | 1 - core/src/xmake/io/filelock_open.c | 1 - core/src/xmake/io/filelock_trylock.c | 1 - core/src/xmake/io/filelock_unlock.c | 1 - core/src/xmake/io/pipe_close.c | 1 - core/src/xmake/io/pipe_connect.c | 1 - core/src/xmake/io/pipe_open.c | 1 - core/src/xmake/io/pipe_openpair.c | 1 - core/src/xmake/io/pipe_read.c | 1 - core/src/xmake/io/pipe_wait.c | 1 - core/src/xmake/io/pipe_write.c | 1 - core/src/xmake/io/poller_insert.c | 1 - core/src/xmake/io/poller_modify.c | 1 - core/src/xmake/io/poller_remove.c | 1 - core/src/xmake/io/poller_spank.c | 1 - core/src/xmake/io/poller_support.c | 1 - core/src/xmake/io/poller_wait.c | 3 --- core/src/xmake/io/socket_accept.c | 1 - core/src/xmake/io/socket_bind.c | 1 - core/src/xmake/io/socket_close.c | 1 - core/src/xmake/io/socket_connect.c | 1 - core/src/xmake/io/socket_ctrl.c | 1 - core/src/xmake/io/socket_kill.c | 1 - core/src/xmake/io/socket_listen.c | 1 - core/src/xmake/io/socket_open.c | 1 - core/src/xmake/io/socket_peeraddr.c | 1 - core/src/xmake/io/socket_rawfd.c | 1 - core/src/xmake/io/socket_recv.c | 1 - core/src/xmake/io/socket_recvfrom.c | 1 - core/src/xmake/io/socket_send.c | 1 - core/src/xmake/io/socket_sendfile.c | 1 - core/src/xmake/io/socket_sendto.c | 1 - core/src/xmake/io/socket_wait.c | 1 - core/src/xmake/io/stdfile.c | 1 - core/src/xmake/libc/byteof.c | 1 - core/src/xmake/libc/dataptr.c | 1 - core/src/xmake/libc/free.c | 1 - core/src/xmake/libc/malloc.c | 1 - core/src/xmake/libc/memcpy.c | 1 - core/src/xmake/libc/memmov.c | 1 - core/src/xmake/libc/memset.c | 1 - core/src/xmake/libc/setbyte.c | 1 - core/src/xmake/libc/strndup.c | 1 - core/src/xmake/lz4/block_compress.c | 1 - core/src/xmake/lz4/block_decompress.c | 1 - core/src/xmake/lz4/compress.c | 1 - core/src/xmake/lz4/compress_file.c | 2 -- core/src/xmake/lz4/compress_stream_close.c | 1 - core/src/xmake/lz4/compress_stream_open.c | 1 - core/src/xmake/lz4/compress_stream_read.c | 1 - core/src/xmake/lz4/compress_stream_write.c | 1 - core/src/xmake/lz4/decompress.c | 1 - core/src/xmake/lz4/decompress_file.c | 2 -- core/src/xmake/lz4/decompress_stream_close.c | 1 - core/src/xmake/lz4/decompress_stream_open.c | 1 - core/src/xmake/lz4/decompress_stream_read.c | 1 - core/src/xmake/lz4/decompress_stream_write.c | 1 - core/src/xmake/lz4/prefix.h | 4 ---- core/src/xmake/os/args.c | 2 -- core/src/xmake/os/argv.c | 1 - core/src/xmake/os/chdir.c | 2 -- core/src/xmake/os/cpdir.c | 1 - core/src/xmake/os/cpfile.c | 1 - core/src/xmake/os/cpuinfo.c | 1 - core/src/xmake/os/curdir.c | 1 - core/src/xmake/os/emptydir.c | 2 -- core/src/xmake/os/exists.c | 1 - core/src/xmake/os/filesize.c | 1 - core/src/xmake/os/find.c | 6 ------ core/src/xmake/os/fscase.c | 1 - core/src/xmake/os/getenv.c | 2 -- core/src/xmake/os/getenvs.c | 3 --- core/src/xmake/os/getown.c | 2 -- core/src/xmake/os/getpid.c | 1 - core/src/xmake/os/getwinsize.c | 2 -- core/src/xmake/os/gid.c | 2 -- core/src/xmake/os/isdir.c | 1 - core/src/xmake/os/isfile.c | 1 - core/src/xmake/os/islink.c | 1 - core/src/xmake/os/link.c | 2 -- core/src/xmake/os/mclock.c | 2 -- core/src/xmake/os/meminfo.c | 1 - core/src/xmake/os/mkdir.c | 2 -- core/src/xmake/os/mtime.c | 1 - core/src/xmake/os/readlink.c | 2 -- core/src/xmake/os/rename.c | 1 - core/src/xmake/os/rmdir.c | 6 ------ core/src/xmake/os/rmfile.c | 1 - core/src/xmake/os/setenv.c | 1 - core/src/xmake/os/signal.c | 1 - core/src/xmake/os/strerror.c | 1 - core/src/xmake/os/syserror.c | 1 - core/src/xmake/os/tmpdir.c | 1 - core/src/xmake/os/touch.c | 1 - core/src/xmake/os/uid.c | 2 -- core/src/xmake/package/loadxmi.c | 1 - core/src/xmake/path/absolute.c | 1 - core/src/xmake/path/directory.c | 1 - core/src/xmake/path/is_absolute.c | 1 - core/src/xmake/path/relative.c | 1 - core/src/xmake/path/translate.c | 1 - core/src/xmake/process/close.c | 1 - core/src/xmake/process/kill.c | 1 - core/src/xmake/process/open.c | 1 - core/src/xmake/process/openv.c | 2 -- core/src/xmake/process/wait.c | 2 -- core/src/xmake/readline/add_history.c | 2 -- core/src/xmake/readline/clear_history.c | 2 -- core/src/xmake/readline/history_list.c | 2 -- core/src/xmake/readline/readline.c | 2 -- core/src/xmake/sandbox/interactive.c | 6 ------ core/src/xmake/semver/compare.c | 2 -- core/src/xmake/semver/parse.c | 2 -- core/src/xmake/semver/satisfies.c | 1 - core/src/xmake/semver/select.c | 3 --- core/src/xmake/semver/semver.c | 1 - core/src/xmake/string/convert.c | 2 -- core/src/xmake/string/endswith.c | 2 -- core/src/xmake/string/lastof.c | 1 - core/src/xmake/string/split.c | 1 - core/src/xmake/string/startswith.c | 2 -- core/src/xmake/string/trim.c | 5 ----- core/src/xmake/thread/thread_exit.c | 1 - core/src/xmake/thread/thread_init.c | 1 - core/src/xmake/thread/thread_resume.c | 1 - core/src/xmake/thread/thread_suspend.c | 1 - core/src/xmake/thread/thread_wait.c | 1 - core/src/xmake/tty/term_mode.c | 1 - core/src/xmake/utils/bin2c.c | 1 - core/src/xmake/winos/ansi.c | 6 ------ core/src/xmake/winos/logical_drives.c | 1 - core/src/xmake/winos/registry_keys.c | 2 -- core/src/xmake/winos/registry_query.c | 2 -- core/src/xmake/winos/registry_values.c | 3 --- core/src/xmake/winos/short_path.c | 1 - core/src/xmake/xmake.c | 5 ----- 170 files changed, 285 deletions(-) (limited to 'core/src/xmake/engine.c') diff --git a/core/src/xmake/base64/decode.c b/core/src/xmake/base64/decode.c index 41555f5cc..cb1b7eb82 100644 --- a/core/src/xmake/base64/decode.c +++ b/core/src/xmake/base64/decode.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_base64_decode(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the string diff --git a/core/src/xmake/base64/encode.c b/core/src/xmake/base64/encode.c index cf2135e56..d896cb55e 100644 --- a/core/src/xmake/base64/encode.c +++ b/core/src/xmake/base64/encode.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_base64_encode(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get data and size diff --git a/core/src/xmake/bloom_filter/bloom_filter_clear.c b/core/src/xmake/bloom_filter/bloom_filter_clear.c index 3f6e36bd0..2657cc5dc 100644 --- a/core/src/xmake/bloom_filter/bloom_filter_clear.c +++ b/core/src/xmake/bloom_filter/bloom_filter_clear.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_bloom_filter_clear(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/bloom_filter/bloom_filter_close.c b/core/src/xmake/bloom_filter/bloom_filter_close.c index 5c916b460..59d3e59a1 100644 --- a/core/src/xmake/bloom_filter/bloom_filter_close.c +++ b/core/src/xmake/bloom_filter/bloom_filter_close.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_bloom_filter_close(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/bloom_filter/bloom_filter_data.c b/core/src/xmake/bloom_filter/bloom_filter_data.c index e37aea966..9d6f34e64 100644 --- a/core/src/xmake/bloom_filter/bloom_filter_data.c +++ b/core/src/xmake/bloom_filter/bloom_filter_data.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_bloom_filter_data(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? 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 a6949d730..984ec6562 100644 --- a/core/src/xmake/bloom_filter/bloom_filter_data_set.c +++ b/core/src/xmake/bloom_filter/bloom_filter_data_set.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_bloom_filter_data_set(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/bloom_filter/bloom_filter_get.c b/core/src/xmake/bloom_filter/bloom_filter_get.c index 755446a09..dd1f8d1e6 100644 --- a/core/src/xmake/bloom_filter/bloom_filter_get.c +++ b/core/src/xmake/bloom_filter/bloom_filter_get.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_bloom_filter_get(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/bloom_filter/bloom_filter_open.c b/core/src/xmake/bloom_filter/bloom_filter_open.c index 68af8ae92..be364be91 100644 --- a/core/src/xmake/bloom_filter/bloom_filter_open.c +++ b/core/src/xmake/bloom_filter/bloom_filter_open.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_bloom_filter_open(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get arguments diff --git a/core/src/xmake/bloom_filter/bloom_filter_set.c b/core/src/xmake/bloom_filter/bloom_filter_set.c index 9387d5354..51d85d0a7 100644 --- a/core/src/xmake/bloom_filter/bloom_filter_set.c +++ b/core/src/xmake/bloom_filter/bloom_filter_set.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_bloom_filter_set(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/bloom_filter/bloom_filter_size.c b/core/src/xmake/bloom_filter/bloom_filter_size.c index 219035fe7..977b455f3 100644 --- a/core/src/xmake/bloom_filter/bloom_filter_size.c +++ b/core/src/xmake/bloom_filter/bloom_filter_size.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_bloom_filter_size(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/engine.c b/core/src/xmake/engine.c index a65395423..7a07d72da 100644 --- a/core/src/xmake/engine.c +++ b/core/src/xmake/engine.c @@ -705,7 +705,6 @@ static tb_byte_t g_xmake_xmz_data[] = { * private implementation */ static tb_bool_t xm_engine_save_arguments(xm_engine_t *engine, tb_int_t argc, tb_char_t **argv, tb_char_t **taskargv) { - // check tb_assert_and_check_return_val(engine && engine->lua && argc >= 1 && argv, tb_false); #if defined(TB_CONFIG_OS_WINDOWS) && !defined(TB_COMPILER_LIKE_UNIX) @@ -745,7 +744,6 @@ static tb_bool_t xm_engine_save_arguments(xm_engine_t *engine, tb_int_t argc, tb } static tb_bool_t xm_engine_get_program_file(xm_engine_t *engine, tb_char_t **argv, tb_char_t *path, tb_size_t maxn) { - // check tb_assert_and_check_return_val(engine && path && maxn, tb_false); /* we cache it, because the current path will be changed in thread. @@ -774,13 +772,11 @@ static tb_bool_t xm_engine_get_program_file(xm_engine_t *engine, tb_char_t **arg tb_wchar_t buf[TB_PATH_MAXN] = { 0 }; tb_size_t size = (tb_size_t)GetModuleFileNameW(tb_null, buf, (DWORD)TB_PATH_MAXN); tb_assert_and_check_break(size < TB_PATH_MAXN); - // end buf[size] = L'\0'; size = tb_wcstombs(path, buf, maxn); tb_assert_and_check_break(size < maxn); path[size] = '\0'; - // ok ok = tb_true; #elif defined(TB_CONFIG_OS_MACOSX) || defined(TB_CONFIG_OS_IOS) @@ -855,9 +851,7 @@ static tb_bool_t xm_engine_get_program_file(xm_engine_t *engine, tb_char_t **arg } while (0); - // ok? if (ok) { - // trace tb_trace_d("programfile: %s", path); // cache it @@ -894,7 +888,6 @@ static tb_bool_t xm_engine_get_program_directory(xm_engine_t *engine, tb_char_t *path, tb_size_t maxn, tb_char_t const *programfile) { - // check tb_assert_and_check_return_val(engine && path && maxn, tb_false); static tb_char_t s_program_directory[TB_PATH_MAXN] = { 0 }; @@ -980,9 +973,7 @@ static tb_bool_t xm_engine_get_program_directory(xm_engine_t *engine, } while (0); - // ok? if (ok) { - // trace tb_trace_d("programdir: %s", path); // cache it @@ -993,12 +984,10 @@ static tb_bool_t xm_engine_get_program_directory(xm_engine_t *engine, lua_setglobal(engine->lua, "_PROGRAM_DIR"); } - // ok? return ok; } static tb_bool_t xm_engine_get_project_directory(xm_engine_t *engine, tb_char_t *path, tb_size_t maxn) { - // check tb_assert_and_check_return_val(engine && path && maxn, tb_false); tb_bool_t ok = tb_false; @@ -1011,14 +1000,12 @@ static tb_bool_t xm_engine_get_project_directory(xm_engine_t *engine, tb_char_t break; } - // trace tb_trace_d("project: %s", path); // save the directory to the global variable: _PROJECT_DIR lua_pushstring(engine->lua, path); lua_setglobal(engine->lua, "_PROJECT_DIR"); - // ok ok = tb_true; } while (0); @@ -1027,7 +1014,6 @@ static tb_bool_t xm_engine_get_project_directory(xm_engine_t *engine, tb_char_t if (!ok) tb_printf("error: not found the project directory!\n"); - // ok? return ok; } @@ -1061,7 +1047,6 @@ static tb_void_t xm_engine_signal_handler(tb_int_t signo) { #endif static tb_void_t xm_engine_init_host(xm_engine_t *engine) { - // check tb_assert_and_check_return(engine && engine->lua); // init system host @@ -1146,7 +1131,6 @@ static __tb_inline__ tb_char_t const *xm_engine_xmake_arch() { } static tb_void_t xm_engine_init_arch(xm_engine_t *engine) { - // check tb_assert_and_check_return(engine && engine->lua); // init xmake arch @@ -1225,7 +1209,6 @@ static tb_void_t xm_engine_init_arch(xm_engine_t *engine) { } static tb_void_t xm_engine_init_features(xm_engine_t *engine) { - // check tb_assert_and_check_return(engine && engine->lua); // init features @@ -1660,7 +1643,6 @@ xm_engine_ref_t xm_engine_init(tb_char_t const *name, xm_engine_lni_initalizer_c return (xm_engine_ref_t)engine; } tb_void_t xm_engine_exit(xm_engine_ref_t self) { - // check xm_engine_t *engine = (xm_engine_t *)self; tb_assert_and_check_return(engine); @@ -1678,7 +1660,6 @@ tb_void_t xm_engine_exit(xm_engine_ref_t self) { tb_free(engine); } tb_int_t xm_engine_main(xm_engine_ref_t self, tb_int_t argc, tb_char_t **argv, tb_char_t **taskargv) { - // check xm_engine_t *engine = (xm_engine_t *)self; tb_assert_and_check_return_val(engine && engine->lua, -1); @@ -1719,7 +1700,6 @@ tb_int_t xm_engine_main(xm_engine_ref_t self, tb_int_t argc, tb_char_t **argv, t return -1; } - // trace tb_trace_d("main: %s", path); // load and execute the main script @@ -1741,7 +1721,6 @@ tb_int_t xm_engine_main(xm_engine_ref_t self, tb_int_t argc, tb_char_t **argv, t return (tb_int_t)lua_tonumber(engine->lua, -1); } tb_void_t xm_engine_register(xm_engine_ref_t self, tb_char_t const *module, luaL_Reg const funcs[]) { - // check xm_engine_t *engine = (xm_engine_t *)self; tb_assert_and_check_return(engine && engine->lua && module && funcs); @@ -1753,7 +1732,6 @@ tb_void_t xm_engine_register(xm_engine_ref_t self, tb_char_t const *module, luaL } #ifdef XM_EMBED_ENABLE tb_void_t xm_engine_add_embedfiles(xm_engine_ref_t self, tb_byte_t const *data, tb_size_t size) { - // check xm_engine_t *engine = (xm_engine_t *)self; tb_assert_and_check_return(engine && engine->embedcount < tb_arrayn(engine->embedsize) && data && size); @@ -1763,14 +1741,12 @@ tb_void_t xm_engine_add_embedfiles(xm_engine_ref_t self, tb_byte_t const *data, } #endif lua_State *xm_engine_lua(xm_engine_ref_t self) { - // check xm_engine_t *engine = (xm_engine_t *)self; tb_assert_and_check_return_val(engine, tb_null); return engine->lua; } tb_poller_ref_t xm_engine_poller(xm_engine_ref_t self) { - // check xm_engine_t *engine = (xm_engine_t *)self; tb_assert_and_check_return_val(engine, tb_null); diff --git a/core/src/xmake/fwatcher/add.c b/core/src/xmake/fwatcher/add.c index cda233104..77c23ea48 100644 --- a/core/src/xmake/fwatcher/add.c +++ b/core/src/xmake/fwatcher/add.c @@ -36,7 +36,6 @@ // fwatcher.add(watchdir, recursion) tb_int_t xm_fwatcher_add(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/fwatcher/close.c b/core/src/xmake/fwatcher/close.c index 8f6a680be..a5501d906 100644 --- a/core/src/xmake/fwatcher/close.c +++ b/core/src/xmake/fwatcher/close.c @@ -36,7 +36,6 @@ // fwatcher.close(p) tb_int_t xm_fwatcher_close(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/fwatcher/open.c b/core/src/xmake/fwatcher/open.c index 05173660e..13ab91d5a 100644 --- a/core/src/xmake/fwatcher/open.c +++ b/core/src/xmake/fwatcher/open.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_fwatcher_open(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // init fwatcher diff --git a/core/src/xmake/fwatcher/remove.c b/core/src/xmake/fwatcher/remove.c index d7ef4d289..6285b0649 100644 --- a/core/src/xmake/fwatcher/remove.c +++ b/core/src/xmake/fwatcher/remove.c @@ -36,7 +36,6 @@ // fwatcher.remove(watchdir) tb_int_t xm_fwatcher_remove(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/fwatcher/wait.c b/core/src/xmake/fwatcher/wait.c index d4e64347f..42b01b8aa 100644 --- a/core/src/xmake/fwatcher/wait.c +++ b/core/src/xmake/fwatcher/wait.c @@ -36,7 +36,6 @@ // fwatcher.wait(p) tb_int_t xm_fwatcher_wait(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/hash/md5.c b/core/src/xmake/hash/md5.c index 91f7eafc9..3c871b063 100644 --- a/core/src/xmake/hash/md5.c +++ b/core/src/xmake/hash/md5.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_hash_md5(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is bytes? get data and size @@ -81,7 +80,6 @@ tb_int_t xm_hash_md5(lua_State *lua) { // read data tb_long_t real = tb_stream_read(stream, data, sizeof(data)); - // ok? if (real > 0) tb_md5_spak(&md5, data, real); // no data? continue it diff --git a/core/src/xmake/hash/rand128.c b/core/src/xmake/hash/rand128.c index bb844aee9..625e75326 100644 --- a/core/src/xmake/hash/rand128.c +++ b/core/src/xmake/hash/rand128.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_hash_rand128(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); static union { diff --git a/core/src/xmake/hash/rand32.c b/core/src/xmake/hash/rand32.c index a8a2dc054..844dd83e7 100644 --- a/core/src/xmake/hash/rand32.c +++ b/core/src/xmake/hash/rand32.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_hash_rand32(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); static tb_uint64_t s_seed = 0; diff --git a/core/src/xmake/hash/rand64.c b/core/src/xmake/hash/rand64.c index 05b861327..0f9e39069 100644 --- a/core/src/xmake/hash/rand64.c +++ b/core/src/xmake/hash/rand64.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_hash_rand64(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); static union { diff --git a/core/src/xmake/hash/sha.c b/core/src/xmake/hash/sha.c index 12d98b860..158a09208 100644 --- a/core/src/xmake/hash/sha.c +++ b/core/src/xmake/hash/sha.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_hash_sha(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get mode @@ -88,7 +87,6 @@ tb_int_t xm_hash_sha(lua_State *lua) { // read data tb_long_t real = tb_stream_read(stream, data, sizeof(data)); - // ok? if (real > 0) tb_sha_spak(&sha, data, real); // no data? continue it diff --git a/core/src/xmake/hash/uuid4.c b/core/src/xmake/hash/uuid4.c index d99e849d8..8712e9efa 100644 --- a/core/src/xmake/hash/uuid4.c +++ b/core/src/xmake/hash/uuid4.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_hash_uuid4(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the name diff --git a/core/src/xmake/hash/xxhash.c b/core/src/xmake/hash/xxhash.c index 49e1199e8..7a55ce63d 100644 --- a/core/src/xmake/hash/xxhash.c +++ b/core/src/xmake/hash/xxhash.c @@ -38,7 +38,6 @@ * implementation */ tb_int_t xm_hash_xxhash(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get mode @@ -115,7 +114,6 @@ tb_int_t xm_hash_xxhash(lua_State *lua) { // read data tb_long_t real = tb_stream_read(stream, data, sizeof(data)); - // ok? if (real > 0) { if (mode == 32 || mode == 64) XM_XXH3_64bits_update(state, data, real); diff --git a/core/src/xmake/io/file_close.c b/core/src/xmake/io/file_close.c index e00946dd0..6547b8156 100644 --- a/core/src/xmake/io/file_close.c +++ b/core/src/xmake/io/file_close.c @@ -36,7 +36,6 @@ // io.file_close(file) tb_int_t xm_io_file_close(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is user data? @@ -49,7 +48,6 @@ tb_int_t xm_io_file_close(lua_State *lua) { // close file if (xm_io_file_is_file(file)) { - // check tb_assert(file->u.file_ref); #ifdef TB_CONFIG_OS_WINDOWS @@ -90,7 +88,6 @@ tb_int_t xm_io_file_close(lua_State *lua) { // gc will free it if no any refs for lua_newuserdata() // ... - // ok lua_pushboolean(lua, tb_true); return 1; } else // for stdfile (gc/close) @@ -102,7 +99,6 @@ tb_int_t xm_io_file_close(lua_State *lua) { // gc will free it if no any refs for lua_newuserdata() // ... - // ok lua_pushboolean(lua, tb_true); return 1; } diff --git a/core/src/xmake/io/file_flush.c b/core/src/xmake/io/file_flush.c index 5aa3e9f58..e5776a60e 100644 --- a/core/src/xmake/io/file_flush.c +++ b/core/src/xmake/io/file_flush.c @@ -39,7 +39,6 @@ static tb_bool_t xm_io_std_flush_impl(xm_io_file_t *file) { } static tb_bool_t xm_io_file_flush_impl(xm_io_file_t *file) { - // check tb_assert_and_check_return_val(xm_io_file_is_file(file), tb_false); #ifdef TB_CONFIG_OS_WINDOWS @@ -61,7 +60,6 @@ static tb_bool_t xm_io_file_flush_impl(xm_io_file_t *file) { // io.file_flush(file) tb_int_t xm_io_file_flush(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is user data? diff --git a/core/src/xmake/io/file_isatty.c b/core/src/xmake/io/file_isatty.c index 645431398..264cabd53 100644 --- a/core/src/xmake/io/file_isatty.c +++ b/core/src/xmake/io/file_isatty.c @@ -36,7 +36,6 @@ // io.file_isatty(file) tb_int_t xm_io_file_isatty(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is user data? diff --git a/core/src/xmake/io/file_open.c b/core/src/xmake/io/file_open.c index 56c0848fd..f4a080077 100644 --- a/core/src/xmake/io/file_open.c +++ b/core/src/xmake/io/file_open.c @@ -44,7 +44,6 @@ * private implementation */ static tb_size_t xm_io_file_detect_charset(tb_byte_t const **data_ptr, tb_long_t size) { - // check tb_assert(data_ptr && *data_ptr); tb_byte_t const *data = *data_ptr; @@ -142,7 +141,6 @@ static tb_size_t xm_io_file_detect_charset(tb_byte_t const **data_ptr, tb_long_t return charset; } static tb_size_t xm_io_file_detect_encoding(tb_stream_ref_t stream, tb_long_t *pbomoff) { - // check tb_assert_and_check_return_val(stream && pbomoff, XM_IO_FILE_ENCODING_BINARY); // detect encoding @@ -163,7 +161,6 @@ static tb_size_t xm_io_file_detect_encoding(tb_stream_ref_t stream, tb_long_t *p // io.file_open(path, modestr) tb_int_t xm_io_file_open(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get file path and mode @@ -261,7 +258,6 @@ tb_int_t xm_io_file_open(lua_State *lua) { if (bomoff > 0 && !tb_stream_seek(stream, bomoff)) break; - // ok open_ok = tb_true; } while (0); diff --git a/core/src/xmake/io/file_rawfd.c b/core/src/xmake/io/file_rawfd.c index f4dc3ffee..c94dc4a98 100644 --- a/core/src/xmake/io/file_rawfd.c +++ b/core/src/xmake/io/file_rawfd.c @@ -52,7 +52,6 @@ * e.g. set VS_UNICODE_OUTPUT=fd to enable vs unicode output, @see https://github.com/xmake-io/xmake/issues/528 */ tb_int_t xm_io_file_rawfd(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is user data? diff --git a/core/src/xmake/io/file_read.c b/core/src/xmake/io/file_read.c index 2f349edb5..2be05a05a 100644 --- a/core/src/xmake/io/file_read.c +++ b/core/src/xmake/io/file_read.c @@ -44,7 +44,6 @@ typedef enum __xm_pushline_state_e { * implementation */ static tb_long_t xm_io_file_buffer_readline(tb_stream_ref_t stream, tb_buffer_ref_t line) { - // check tb_assert_and_check_return_val(stream && line, -1); // read line and reserve crlf @@ -79,7 +78,6 @@ static tb_long_t xm_io_file_buffer_readline(tb_stream_ref_t stream, tb_buffer_re } } - // ok? tb_size_t linesize = tb_buffer_size(line); if (linesize) return linesize; @@ -90,7 +88,6 @@ static tb_int_t xm_io_file_buffer_pushline(tb_buffer_ref_t buf, xm_io_file_t *file, tb_char_t const *continuation, tb_bool_t keep_crlf) { - // check tb_assert(buf && file && continuation && xm_io_file_is_file(file) && file->u.file_ref); // is binary? @@ -166,7 +163,6 @@ static tb_int_t xm_io_file_buffer_pushline(tb_buffer_ref_t buf, return result; } static tb_int_t xm_io_file_read_all_directly(lua_State *lua, xm_io_file_t *file) { - // check tb_assert(lua && file && xm_io_file_is_file(file) && file->u.file_ref); // init buffer @@ -201,7 +197,6 @@ static tb_int_t xm_io_file_read_all_directly(lua_State *lua, xm_io_file_t *file) return 1; } static tb_int_t xm_io_file_read_all(lua_State *lua, xm_io_file_t *file, tb_char_t const *continuation) { - // check tb_assert(lua && file && continuation && xm_io_file_is_file(file) && file->u.file_ref); // is binary? read all directly @@ -242,7 +237,6 @@ static tb_int_t xm_io_file_read_line(lua_State *lua, xm_io_file_t *file, tb_char_t const *continuation, tb_bool_t keep_crlf) { - // check tb_assert(lua && file && continuation && xm_io_file_is_file(file) && file->u.file_ref); // init buffer @@ -278,7 +272,6 @@ static tb_int_t xm_io_file_read_line(lua_State *lua, } static tb_int_t xm_io_file_read_n(lua_State *lua, xm_io_file_t *file, tb_char_t const *continuation, tb_long_t n) { - // check tb_assert(lua && file && continuation && xm_io_file_is_file(file) && file->u.file_ref); // check continuation @@ -314,7 +307,6 @@ static tb_size_t xm_io_file_std_buffer_pushline(tb_buffer_ref_t buf, xm_io_file_t *file, tb_char_t const *continuation, tb_bool_t keep_crlf) { - // check tb_assert(buf && file && continuation && xm_io_file_is_std(file)); // get input buffer @@ -367,7 +359,6 @@ static tb_int_t xm_io_file_std_read_line(lua_State *lua, xm_io_file_t *file, tb_char_t const *continuation, tb_bool_t keep_crlf) { - // check tb_assert(lua && file && continuation && xm_io_file_is_std(file)); // init buffer @@ -403,7 +394,6 @@ static tb_int_t xm_io_file_std_read_line(lua_State *lua, } static tb_int_t xm_io_file_std_read_all(lua_State *lua, xm_io_file_t *file, tb_char_t const *continuation) { - // check tb_assert(lua && file && continuation && xm_io_file_is_std(file)); // init buffer @@ -436,7 +426,6 @@ static tb_int_t xm_io_file_std_read_all(lua_State *lua, xm_io_file_t *file, tb_c } static tb_int_t xm_io_file_std_read_n(lua_State *lua, xm_io_file_t *file, tb_char_t const *continuation, tb_long_t n) { - // check tb_assert(lua && file && continuation && xm_io_file_is_std(file)); // check continuation @@ -466,7 +455,6 @@ static tb_int_t xm_io_file_std_read_n(lua_State *lua, xm_io_file_t *file, tb_cha } static tb_int_t xm_io_file_std_read_num(lua_State *lua, xm_io_file_t *file, tb_char_t const *continuation) { - // check tb_assert(lua && file && continuation && xm_io_file_is_std(file)); // check continuation @@ -490,7 +478,6 @@ static tb_int_t xm_io_file_std_read_num(lua_State *lua, xm_io_file_t *file, tb_c * io.file_read(file, 10) */ tb_int_t xm_io_file_read(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is user data? diff --git a/core/src/xmake/io/file_readable.c b/core/src/xmake/io/file_readable.c index e3cca2dc9..5f9a84329 100644 --- a/core/src/xmake/io/file_readable.c +++ b/core/src/xmake/io/file_readable.c @@ -35,7 +35,6 @@ */ tb_int_t xm_io_file_readable(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is user data? diff --git a/core/src/xmake/io/file_seek.c b/core/src/xmake/io/file_seek.c index ea053302b..421e5cdf1 100644 --- a/core/src/xmake/io/file_seek.c +++ b/core/src/xmake/io/file_seek.c @@ -36,7 +36,6 @@ // io.file_seek(file, [whence [, offset]]) tb_int_t xm_io_file_seek(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is user data? diff --git a/core/src/xmake/io/file_size.c b/core/src/xmake/io/file_size.c index df83a96b9..34f519306 100644 --- a/core/src/xmake/io/file_size.c +++ b/core/src/xmake/io/file_size.c @@ -36,7 +36,6 @@ // io.file_size(file) tb_int_t xm_io_file_size(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is user data? diff --git a/core/src/xmake/io/file_write.c b/core/src/xmake/io/file_write.c index bfe7321f3..5f70e1a49 100644 --- a/core/src/xmake/io/file_write.c +++ b/core/src/xmake/io/file_write.c @@ -34,7 +34,6 @@ * private implementation */ static tb_void_t xm_io_file_write_file_utfbom(xm_io_file_t *file) { - // check tb_assert(file && xm_io_file_is_file(file) && file->u.file_ref); // write bom @@ -60,7 +59,6 @@ static tb_void_t xm_io_file_write_file_directly(xm_io_file_t *file, tb_byte_t co tb_stream_bwrit(file->u.file_ref, data, size); } static tb_void_t xm_io_file_write_file_transcrlf(xm_io_file_t *file, tb_byte_t const *data, tb_size_t size) { - // check tb_assert(file && data && xm_io_file_is_file(file) && file->u.file_ref); #ifdef TB_CONFIG_OS_WINDOWS @@ -105,7 +103,6 @@ static tb_void_t xm_io_file_write_file_transcrlf(xm_io_file_t *file, tb_byte_t c #endif } static tb_void_t xm_io_file_write_std(xm_io_file_t *file, tb_byte_t const *data, tb_size_t size) { - // check tb_assert(file && data && xm_io_file_is_std(file)); // check type @@ -122,7 +119,6 @@ static tb_void_t xm_io_file_write_std(xm_io_file_t *file, tb_byte_t const *data, // io.file_write(file, ...) tb_int_t xm_io_file_write(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is user data? diff --git a/core/src/xmake/io/filelock_close.c b/core/src/xmake/io/filelock_close.c index ad628cb5c..02a2fb039 100644 --- a/core/src/xmake/io/filelock_close.c +++ b/core/src/xmake/io/filelock_close.c @@ -36,7 +36,6 @@ // io.filelock_close(lock) tb_int_t xm_io_filelock_close(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // check lock? @@ -53,6 +52,5 @@ tb_int_t xm_io_filelock_close(lua_State *lua) { // save result: ok lua_pushboolean(lua, tb_true); - // ok return 1; } diff --git a/core/src/xmake/io/filelock_lock.c b/core/src/xmake/io/filelock_lock.c index 109bb6dcd..9e0c2493e 100644 --- a/core/src/xmake/io/filelock_lock.c +++ b/core/src/xmake/io/filelock_lock.c @@ -40,7 +40,6 @@ * shared lock: io.filelock_lock(lock, "/xxxx/filelock", {shared = true}) */ tb_int_t xm_io_filelock_lock(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get option argument diff --git a/core/src/xmake/io/filelock_open.c b/core/src/xmake/io/filelock_open.c index 171c6c86a..e9687ba54 100644 --- a/core/src/xmake/io/filelock_open.c +++ b/core/src/xmake/io/filelock_open.c @@ -38,7 +38,6 @@ * io.filelock_open(path) */ tb_int_t xm_io_filelock_open(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get file path diff --git a/core/src/xmake/io/filelock_trylock.c b/core/src/xmake/io/filelock_trylock.c index d1a204d30..aaf1da246 100644 --- a/core/src/xmake/io/filelock_trylock.c +++ b/core/src/xmake/io/filelock_trylock.c @@ -40,7 +40,6 @@ * shared lock: io.filelock_trylock("/xxxx/filelock", {shared = true}) */ tb_int_t xm_io_filelock_trylock(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get option argument diff --git a/core/src/xmake/io/filelock_unlock.c b/core/src/xmake/io/filelock_unlock.c index 0eaa2bc98..94dfe1b7d 100644 --- a/core/src/xmake/io/filelock_unlock.c +++ b/core/src/xmake/io/filelock_unlock.c @@ -36,7 +36,6 @@ // io.filelock_unlock(lock) tb_int_t xm_io_filelock_unlock(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // check lock? diff --git a/core/src/xmake/io/pipe_close.c b/core/src/xmake/io/pipe_close.c index a3adb6d8c..23e200606 100644 --- a/core/src/xmake/io/pipe_close.c +++ b/core/src/xmake/io/pipe_close.c @@ -36,7 +36,6 @@ // io.pipe_close(pipe) tb_int_t xm_io_pipe_close(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // check pipe? diff --git a/core/src/xmake/io/pipe_connect.c b/core/src/xmake/io/pipe_connect.c index 985817386..f13f612f9 100644 --- a/core/src/xmake/io/pipe_connect.c +++ b/core/src/xmake/io/pipe_connect.c @@ -36,7 +36,6 @@ // io.pipe_connect(pipefile) tb_int_t xm_io_pipe_connect(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // check pipe diff --git a/core/src/xmake/io/pipe_open.c b/core/src/xmake/io/pipe_open.c index d0dbe66e9..d82406dee 100644 --- a/core/src/xmake/io/pipe_open.c +++ b/core/src/xmake/io/pipe_open.c @@ -38,7 +38,6 @@ * io.pipe_open(name, mode, buffsize) */ tb_int_t xm_io_pipe_open(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get pipe name and mode diff --git a/core/src/xmake/io/pipe_openpair.c b/core/src/xmake/io/pipe_openpair.c index c95d13a62..dd2205613 100644 --- a/core/src/xmake/io/pipe_openpair.c +++ b/core/src/xmake/io/pipe_openpair.c @@ -38,7 +38,6 @@ * io.pipe_openpair(mode, buffsize) */ tb_int_t xm_io_pipe_openpair(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get pipe mode diff --git a/core/src/xmake/io/pipe_read.c b/core/src/xmake/io/pipe_read.c index fb82c1ebd..637fb3b7d 100644 --- a/core/src/xmake/io/pipe_read.c +++ b/core/src/xmake/io/pipe_read.c @@ -36,7 +36,6 @@ // real, data_or_errors = io.pipe_read(pipefile, size) tb_int_t xm_io_pipe_read(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // check pipe file diff --git a/core/src/xmake/io/pipe_wait.c b/core/src/xmake/io/pipe_wait.c index 67d189892..785efe950 100644 --- a/core/src/xmake/io/pipe_wait.c +++ b/core/src/xmake/io/pipe_wait.c @@ -36,7 +36,6 @@ // io.pipe_wait(pipefile, events, timeout) tb_int_t xm_io_pipe_wait(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // check pipe? diff --git a/core/src/xmake/io/pipe_write.c b/core/src/xmake/io/pipe_write.c index 9b0869299..2f2865c47 100644 --- a/core/src/xmake/io/pipe_write.c +++ b/core/src/xmake/io/pipe_write.c @@ -36,7 +36,6 @@ // io.pipe_write(pipefile, data, start, last) tb_int_t xm_io_pipe_write(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // check pipe diff --git a/core/src/xmake/io/poller_insert.c b/core/src/xmake/io/poller_insert.c index 2b24b3b1e..81f66cce9 100644 --- a/core/src/xmake/io/poller_insert.c +++ b/core/src/xmake/io/poller_insert.c @@ -37,7 +37,6 @@ // io.poller_insert(obj:otype(), obj:cdata(), events) tb_int_t xm_io_poller_insert(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/io/poller_modify.c b/core/src/xmake/io/poller_modify.c index 77dff2fbf..f9283aecb 100644 --- a/core/src/xmake/io/poller_modify.c +++ b/core/src/xmake/io/poller_modify.c @@ -37,7 +37,6 @@ // io.poller_modify(obj:otype(), obj:cdata(), events) tb_int_t xm_io_poller_modify(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/io/poller_remove.c b/core/src/xmake/io/poller_remove.c index 34242808f..3127bf2b4 100644 --- a/core/src/xmake/io/poller_remove.c +++ b/core/src/xmake/io/poller_remove.c @@ -37,7 +37,6 @@ // io.poller_remove(obj:otype(), obj) tb_int_t xm_io_poller_remove(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/io/poller_spank.c b/core/src/xmake/io/poller_spank.c index 1656a537e..7fdb38605 100644 --- a/core/src/xmake/io/poller_spank.c +++ b/core/src/xmake/io/poller_spank.c @@ -37,7 +37,6 @@ // io.poller_spank() tb_int_t xm_io_poller_spank(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // spank the poller, break the tb_poller_wait() and return all events diff --git a/core/src/xmake/io/poller_support.c b/core/src/xmake/io/poller_support.c index d53cdc1ed..d63f8da34 100644 --- a/core/src/xmake/io/poller_support.c +++ b/core/src/xmake/io/poller_support.c @@ -37,7 +37,6 @@ // io.poller_support(events) tb_int_t xm_io_poller_support(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get events diff --git a/core/src/xmake/io/poller_wait.c b/core/src/xmake/io/poller_wait.c index 141c4640b..f1e4ed7a7 100644 --- a/core/src/xmake/io/poller_wait.c +++ b/core/src/xmake/io/poller_wait.c @@ -38,7 +38,6 @@ static tb_void_t xm_io_poller_event(tb_poller_ref_t poller, tb_poller_object_ref_t object, tb_long_t events, tb_cpointer_t priv) { - // check xm_poller_state_t *state = (xm_poller_state_t *)tb_poller_priv(poller); tb_assert_and_check_return(state && state->lua); @@ -76,7 +75,6 @@ static tb_void_t xm_io_poller_event(tb_poller_ref_t poller, // local events, count = io.poller_wait(timeout) tb_int_t xm_io_poller_wait(lua_State *lua) { - // check tb_poller_ref_t poller = xm_io_poller(lua); tb_assert_and_check_return_val(poller && lua, 0); @@ -101,7 +99,6 @@ tb_int_t xm_io_poller_wait(lua_State *lua) { return 2; } - // failed lua_pop(lua, 1); lua_pushnil(lua); lua_pushinteger(lua, -1); diff --git a/core/src/xmake/io/socket_accept.c b/core/src/xmake/io/socket_accept.c index 5a303ef74..77a6c6c86 100644 --- a/core/src/xmake/io/socket_accept.c +++ b/core/src/xmake/io/socket_accept.c @@ -36,7 +36,6 @@ // local sock = io.socket_accept(sock) tb_int_t xm_io_socket_accept(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/io/socket_bind.c b/core/src/xmake/io/socket_bind.c index 9ba441a6f..d1a30789a 100644 --- a/core/src/xmake/io/socket_bind.c +++ b/core/src/xmake/io/socket_bind.c @@ -36,7 +36,6 @@ // io.socket_bind(sock, addr, port, family) tb_int_t xm_io_socket_bind(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // check socket diff --git a/core/src/xmake/io/socket_close.c b/core/src/xmake/io/socket_close.c index d53228fe7..922987c10 100644 --- a/core/src/xmake/io/socket_close.c +++ b/core/src/xmake/io/socket_close.c @@ -36,7 +36,6 @@ // io.socket_close(sock) tb_int_t xm_io_socket_close(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/io/socket_connect.c b/core/src/xmake/io/socket_connect.c index 63d355fb4..94c2f1e8d 100644 --- a/core/src/xmake/io/socket_connect.c +++ b/core/src/xmake/io/socket_connect.c @@ -36,7 +36,6 @@ // io.socket_connect(sock, addr, port, family) tb_int_t xm_io_socket_connect(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // check socket diff --git a/core/src/xmake/io/socket_ctrl.c b/core/src/xmake/io/socket_ctrl.c index c16f2c20d..0a51d65bc 100644 --- a/core/src/xmake/io/socket_ctrl.c +++ b/core/src/xmake/io/socket_ctrl.c @@ -36,7 +36,6 @@ // io.socket_ctrl(sock, code, value) tb_int_t xm_io_socket_ctrl(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // check socket diff --git a/core/src/xmake/io/socket_kill.c b/core/src/xmake/io/socket_kill.c index eb2956e53..63e110257 100644 --- a/core/src/xmake/io/socket_kill.c +++ b/core/src/xmake/io/socket_kill.c @@ -36,7 +36,6 @@ // local sock = io.socket_kill(sock) tb_int_t xm_io_socket_kill(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/io/socket_listen.c b/core/src/xmake/io/socket_listen.c index 6fece6087..3aa541016 100644 --- a/core/src/xmake/io/socket_listen.c +++ b/core/src/xmake/io/socket_listen.c @@ -36,7 +36,6 @@ // io.socket_listen(sock, backlog) tb_int_t xm_io_socket_listen(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/io/socket_open.c b/core/src/xmake/io/socket_open.c index 4189607c7..cae80d182 100644 --- a/core/src/xmake/io/socket_open.c +++ b/core/src/xmake/io/socket_open.c @@ -38,7 +38,6 @@ * io.socket_open(socktype, family) */ tb_int_t xm_io_socket_open(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get socket type diff --git a/core/src/xmake/io/socket_peeraddr.c b/core/src/xmake/io/socket_peeraddr.c index bcc03c289..e1ad43931 100644 --- a/core/src/xmake/io/socket_peeraddr.c +++ b/core/src/xmake/io/socket_peeraddr.c @@ -44,7 +44,6 @@ /* io.socket_peeraddr(sock) */ tb_int_t xm_io_socket_peeraddr(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/io/socket_rawfd.c b/core/src/xmake/io/socket_rawfd.c index 672a9dafa..6340c0c19 100644 --- a/core/src/xmake/io/socket_rawfd.c +++ b/core/src/xmake/io/socket_rawfd.c @@ -44,7 +44,6 @@ /* io.socket_rawfd(sock) */ tb_int_t xm_io_socket_rawfd(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/io/socket_recv.c b/core/src/xmake/io/socket_recv.c index cecdbb031..ed629a8f5 100644 --- a/core/src/xmake/io/socket_recv.c +++ b/core/src/xmake/io/socket_recv.c @@ -36,7 +36,6 @@ // real, data_or_errors = io.socket_recv(sock, size) tb_int_t xm_io_socket_recv(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // check socket diff --git a/core/src/xmake/io/socket_recvfrom.c b/core/src/xmake/io/socket_recvfrom.c index bc8f53bf8..8601f6302 100644 --- a/core/src/xmake/io/socket_recvfrom.c +++ b/core/src/xmake/io/socket_recvfrom.c @@ -36,7 +36,6 @@ // real, data_or_errors, addr, port = io.socket_recvfrom(sock, size) tb_int_t xm_io_socket_recvfrom(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // check socket diff --git a/core/src/xmake/io/socket_send.c b/core/src/xmake/io/socket_send.c index 1b99d8d08..d83b02add 100644 --- a/core/src/xmake/io/socket_send.c +++ b/core/src/xmake/io/socket_send.c @@ -36,7 +36,6 @@ // io.socket_send(sock, data, start, last) tb_int_t xm_io_socket_send(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // check socket diff --git a/core/src/xmake/io/socket_sendfile.c b/core/src/xmake/io/socket_sendfile.c index b5e6e10d6..0d4be4219 100644 --- a/core/src/xmake/io/socket_sendfile.c +++ b/core/src/xmake/io/socket_sendfile.c @@ -36,7 +36,6 @@ // io.socket_sendfile(sock, file, start, last) tb_int_t xm_io_socket_sendfile(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // check socket diff --git a/core/src/xmake/io/socket_sendto.c b/core/src/xmake/io/socket_sendto.c index cde81febf..15403d4d8 100644 --- a/core/src/xmake/io/socket_sendto.c +++ b/core/src/xmake/io/socket_sendto.c @@ -36,7 +36,6 @@ // io.socket_sendto(sock, data, addr, port) tb_int_t xm_io_socket_sendto(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // check socket diff --git a/core/src/xmake/io/socket_wait.c b/core/src/xmake/io/socket_wait.c index fd9900e21..42674f4f9 100644 --- a/core/src/xmake/io/socket_wait.c +++ b/core/src/xmake/io/socket_wait.c @@ -36,7 +36,6 @@ // io.socket_wait(sock, events, timeout) tb_int_t xm_io_socket_wait(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // check socket? diff --git a/core/src/xmake/io/stdfile.c b/core/src/xmake/io/stdfile.c index 05e1fcf2a..0dcb43501 100644 --- a/core/src/xmake/io/stdfile.c +++ b/core/src/xmake/io/stdfile.c @@ -144,7 +144,6 @@ static xm_io_file_t *xm_io_stdfile_new(lua_State *lua, tb_size_t type) { // io.stdfile(stdin: 1, stdout: 2, stderr: 3) tb_int_t xm_io_stdfile(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get std type diff --git a/core/src/xmake/libc/byteof.c b/core/src/xmake/libc/byteof.c index be8820ff9..dac772e9b 100644 --- a/core/src/xmake/libc/byteof.c +++ b/core/src/xmake/libc/byteof.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_libc_byteof(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get data diff --git a/core/src/xmake/libc/dataptr.c b/core/src/xmake/libc/dataptr.c index 50b063b4e..363853800 100644 --- a/core/src/xmake/libc/dataptr.c +++ b/core/src/xmake/libc/dataptr.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_libc_dataptr(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); tb_pointer_t data = tb_null; diff --git a/core/src/xmake/libc/free.c b/core/src/xmake/libc/free.c index ad12ccfc9..6f0d70f3d 100644 --- a/core/src/xmake/libc/free.c +++ b/core/src/xmake/libc/free.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_libc_free(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // do free diff --git a/core/src/xmake/libc/malloc.c b/core/src/xmake/libc/malloc.c index 8e2380955..faaa00e97 100644 --- a/core/src/xmake/libc/malloc.c +++ b/core/src/xmake/libc/malloc.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_libc_malloc(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // do malloc diff --git a/core/src/xmake/libc/memcpy.c b/core/src/xmake/libc/memcpy.c index 6baf66d39..e0e8b1492 100644 --- a/core/src/xmake/libc/memcpy.c +++ b/core/src/xmake/libc/memcpy.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_libc_memcpy(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // do memcpy diff --git a/core/src/xmake/libc/memmov.c b/core/src/xmake/libc/memmov.c index f43bccea6..66120e168 100644 --- a/core/src/xmake/libc/memmov.c +++ b/core/src/xmake/libc/memmov.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_libc_memmov(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // do memmov diff --git a/core/src/xmake/libc/memset.c b/core/src/xmake/libc/memset.c index 2c0936017..4f8864842 100644 --- a/core/src/xmake/libc/memset.c +++ b/core/src/xmake/libc/memset.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_libc_memset(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // do memset diff --git a/core/src/xmake/libc/setbyte.c b/core/src/xmake/libc/setbyte.c index 7ae959014..d53c30229 100644 --- a/core/src/xmake/libc/setbyte.c +++ b/core/src/xmake/libc/setbyte.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_libc_setbyte(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get data diff --git a/core/src/xmake/libc/strndup.c b/core/src/xmake/libc/strndup.c index d7d1204a0..f61cebb2c 100644 --- a/core/src/xmake/libc/strndup.c +++ b/core/src/xmake/libc/strndup.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_libc_strndup(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // do strndup diff --git a/core/src/xmake/lz4/block_compress.c b/core/src/xmake/lz4/block_compress.c index 2c7f0c00f..53b592a22 100644 --- a/core/src/xmake/lz4/block_compress.c +++ b/core/src/xmake/lz4/block_compress.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_lz4_block_compress(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get data and size diff --git a/core/src/xmake/lz4/block_decompress.c b/core/src/xmake/lz4/block_decompress.c index f2f76a4bf..2a6ed1d20 100644 --- a/core/src/xmake/lz4/block_decompress.c +++ b/core/src/xmake/lz4/block_decompress.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_lz4_block_decompress(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get data and size diff --git a/core/src/xmake/lz4/compress.c b/core/src/xmake/lz4/compress.c index 352945d1f..69af51113 100644 --- a/core/src/xmake/lz4/compress.c +++ b/core/src/xmake/lz4/compress.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_lz4_compress(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get data and size diff --git a/core/src/xmake/lz4/compress_file.c b/core/src/xmake/lz4/compress_file.c index be48184bd..48596e17b 100644 --- a/core/src/xmake/lz4/compress_file.c +++ b/core/src/xmake/lz4/compress_file.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_lz4_compress_file(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the file paths @@ -91,7 +90,6 @@ tb_int_t xm_lz4_compress_file(lua_State *lua) { } xm_lz4_cstream_exit(stream_lz4); - // ok? lua_pushboolean(lua, ok); return 1; } diff --git a/core/src/xmake/lz4/compress_stream_close.c b/core/src/xmake/lz4/compress_stream_close.c index 2bec169d0..d1f534cde 100644 --- a/core/src/xmake/lz4/compress_stream_close.c +++ b/core/src/xmake/lz4/compress_stream_close.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_lz4_compress_stream_close(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/lz4/compress_stream_open.c b/core/src/xmake/lz4/compress_stream_open.c index e4fd1de8b..d4ac50667 100644 --- a/core/src/xmake/lz4/compress_stream_open.c +++ b/core/src/xmake/lz4/compress_stream_open.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_lz4_compress_stream_open(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); xm_lz4_cstream_t *stream = xm_lz4_cstream_init(); diff --git a/core/src/xmake/lz4/compress_stream_read.c b/core/src/xmake/lz4/compress_stream_read.c index 7338ede02..ff1315c3e 100644 --- a/core/src/xmake/lz4/compress_stream_read.c +++ b/core/src/xmake/lz4/compress_stream_read.c @@ -35,7 +35,6 @@ */ tb_int_t xm_lz4_compress_stream_read(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // check handle diff --git a/core/src/xmake/lz4/compress_stream_write.c b/core/src/xmake/lz4/compress_stream_write.c index aa6b87e85..730a4f986 100644 --- a/core/src/xmake/lz4/compress_stream_write.c +++ b/core/src/xmake/lz4/compress_stream_write.c @@ -35,7 +35,6 @@ */ tb_int_t xm_lz4_compress_stream_write(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // check handle diff --git a/core/src/xmake/lz4/decompress.c b/core/src/xmake/lz4/decompress.c index c5382747d..51a50c112 100644 --- a/core/src/xmake/lz4/decompress.c +++ b/core/src/xmake/lz4/decompress.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_lz4_decompress(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get data and size diff --git a/core/src/xmake/lz4/decompress_file.c b/core/src/xmake/lz4/decompress_file.c index b65ee87a0..7d91c5be4 100644 --- a/core/src/xmake/lz4/decompress_file.c +++ b/core/src/xmake/lz4/decompress_file.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_lz4_decompress_file(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the file paths @@ -91,7 +90,6 @@ tb_int_t xm_lz4_decompress_file(lua_State *lua) { } xm_lz4_dstream_exit(stream_lz4); - // ok? lua_pushboolean(lua, ok); return 1; } diff --git a/core/src/xmake/lz4/decompress_stream_close.c b/core/src/xmake/lz4/decompress_stream_close.c index ead2e3493..89c868c53 100644 --- a/core/src/xmake/lz4/decompress_stream_close.c +++ b/core/src/xmake/lz4/decompress_stream_close.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_lz4_decompress_stream_close(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/lz4/decompress_stream_open.c b/core/src/xmake/lz4/decompress_stream_open.c index 673038e80..eb3db7193 100644 --- a/core/src/xmake/lz4/decompress_stream_open.c +++ b/core/src/xmake/lz4/decompress_stream_open.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_lz4_decompress_stream_open(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); xm_lz4_dstream_t *stream = xm_lz4_dstream_init(); diff --git a/core/src/xmake/lz4/decompress_stream_read.c b/core/src/xmake/lz4/decompress_stream_read.c index 5f6486166..85ecdbe9f 100644 --- a/core/src/xmake/lz4/decompress_stream_read.c +++ b/core/src/xmake/lz4/decompress_stream_read.c @@ -35,7 +35,6 @@ */ tb_int_t xm_lz4_decompress_stream_read(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // check handle diff --git a/core/src/xmake/lz4/decompress_stream_write.c b/core/src/xmake/lz4/decompress_stream_write.c index 7fa45544c..4359a41d7 100644 --- a/core/src/xmake/lz4/decompress_stream_write.c +++ b/core/src/xmake/lz4/decompress_stream_write.c @@ -35,7 +35,6 @@ */ tb_int_t xm_lz4_decompress_stream_write(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // check handle diff --git a/core/src/xmake/lz4/prefix.h b/core/src/xmake/lz4/prefix.h index 996e53093..534e5361a 100644 --- a/core/src/xmake/lz4/prefix.h +++ b/core/src/xmake/lz4/prefix.h @@ -131,7 +131,6 @@ static __tb_inline__ tb_long_t xm_lz4_cstream_write(xm_lz4_cstream_t *stream, tb_byte_t const *idata, tb_size_t isize, tb_bool_t end) { - // check tb_assert_and_check_return_val(stream && stream->cctx && idata && isize, -1); tb_assert_and_check_return_val(isize <= stream->write_maxn, -1); tb_assert_and_check_return_val(stream->buffer_size + isize < stream->buffer_maxn, -1); @@ -162,7 +161,6 @@ static __tb_inline__ tb_long_t xm_lz4_cstream_write(xm_lz4_cstream_t *stream, } static __tb_inline__ tb_long_t xm_lz4_cstream_read(xm_lz4_cstream_t *stream, tb_byte_t *odata, tb_size_t osize) { - // check tb_assert_and_check_return_val(stream && stream->cctx && odata && osize, -1); tb_assert_and_check_return_val(osize >= stream->header_size, -1); @@ -224,7 +222,6 @@ static __tb_inline__ tb_long_t xm_lz4_dstream_write(xm_lz4_dstream_t *stream, tb_byte_t const *idata, tb_size_t isize, tb_bool_t end) { - // check tb_assert_and_check_return_val(stream && stream->dctx && idata && isize, -1); // read header first @@ -279,7 +276,6 @@ static __tb_inline__ tb_long_t xm_lz4_dstream_write(xm_lz4_dstream_t *stream, } static __tb_inline__ tb_long_t xm_lz4_dstream_read(xm_lz4_dstream_t *stream, tb_byte_t *odata, tb_size_t osize) { - // check tb_assert_and_check_return_val(stream && stream->dctx && stream->buffer && odata && osize, -1); tb_check_return_val(stream->buffer_size, 0); diff --git a/core/src/xmake/os/args.c b/core/src/xmake/os/args.c index d220e0350..8b2c002c9 100644 --- a/core/src/xmake/os/args.c +++ b/core/src/xmake/os/args.c @@ -35,7 +35,6 @@ */ static tb_void_t tb_os_args_append( tb_string_ref_t result, tb_char_t const *cstr, tb_size_t size, tb_bool_t escape, tb_bool_t nowrap) { - // check tb_assert_and_check_return(size < TB_PATH_MAXN); // need wrap quote? @@ -74,7 +73,6 @@ static tb_void_t tb_os_args_append( */ // os.args({"xx", "yy"}, {escape = true}) tb_int_t xm_os_args(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // escape '\\' characters in global? diff --git a/core/src/xmake/os/argv.c b/core/src/xmake/os/argv.c index 89635fb2d..f7230d057 100644 --- a/core/src/xmake/os/argv.c +++ b/core/src/xmake/os/argv.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_os_argv(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the argument string diff --git a/core/src/xmake/os/chdir.c b/core/src/xmake/os/chdir.c index 537d6506c..73619122c 100644 --- a/core/src/xmake/os/chdir.c +++ b/core/src/xmake/os/chdir.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_os_chdir(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the path @@ -44,6 +43,5 @@ tb_int_t xm_os_chdir(lua_State *lua) { // done os.chdir(path) lua_pushboolean(lua, tb_directory_current_set(path)); - // ok return 1; } diff --git a/core/src/xmake/os/cpdir.c b/core/src/xmake/os/cpdir.c index e2f2b89ee..0df435436 100644 --- a/core/src/xmake/os/cpdir.c +++ b/core/src/xmake/os/cpdir.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_os_cpdir(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the source and destination diff --git a/core/src/xmake/os/cpfile.c b/core/src/xmake/os/cpfile.c index b6597f87f..7291385a7 100644 --- a/core/src/xmake/os/cpfile.c +++ b/core/src/xmake/os/cpfile.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_os_cpfile(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the source and destination diff --git a/core/src/xmake/os/cpuinfo.c b/core/src/xmake/os/cpuinfo.c index a2ac1bbe4..f8ef7d46b 100644 --- a/core/src/xmake/os/cpuinfo.c +++ b/core/src/xmake/os/cpuinfo.c @@ -237,7 +237,6 @@ static tb_float_t xm_os_cpuinfo_usagerate() { * } */ tb_int_t xm_os_cpuinfo(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // init table diff --git a/core/src/xmake/os/curdir.c b/core/src/xmake/os/curdir.c index b2ca8a273..2d27cf905 100644 --- a/core/src/xmake/os/curdir.c +++ b/core/src/xmake/os/curdir.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_os_curdir(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // os.curdir() diff --git a/core/src/xmake/os/emptydir.c b/core/src/xmake/os/emptydir.c index 79ebd9807..aab016d28 100644 --- a/core/src/xmake/os/emptydir.c +++ b/core/src/xmake/os/emptydir.c @@ -34,7 +34,6 @@ * private implementation */ static tb_long_t xm_os_emptydir_walk(tb_char_t const *path, tb_file_info_t const *info, tb_cpointer_t priv) { - // check tb_bool_t *is_emptydir = (tb_bool_t *)priv; tb_assert_and_check_return_val(path && info && is_emptydir, TB_DIRECTORY_WALK_CODE_END); @@ -50,7 +49,6 @@ static tb_long_t xm_os_emptydir_walk(tb_char_t const *path, tb_file_info_t const * implementation */ tb_int_t xm_os_emptydir(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the directory diff --git a/core/src/xmake/os/exists.c b/core/src/xmake/os/exists.c index 403a1285d..9bb244510 100644 --- a/core/src/xmake/os/exists.c +++ b/core/src/xmake/os/exists.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_os_exists(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the path diff --git a/core/src/xmake/os/filesize.c b/core/src/xmake/os/filesize.c index 115ab5665..a99651fbf 100644 --- a/core/src/xmake/os/filesize.c +++ b/core/src/xmake/os/filesize.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_os_filesize(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the path diff --git a/core/src/xmake/os/find.c b/core/src/xmake/os/find.c index 91c5b0261..2ed5611ad 100644 --- a/core/src/xmake/os/find.c +++ b/core/src/xmake/os/find.c @@ -34,7 +34,6 @@ * private implementation */ static tb_long_t xm_os_find_walk(tb_char_t const *path, tb_file_info_t const *info, tb_cpointer_t priv) { - // check tb_value_ref_t tuple = (tb_value_ref_t)priv; tb_assert_and_check_return_val(path && info && tuple, TB_DIRECTORY_WALK_CODE_END); @@ -56,7 +55,6 @@ static tb_long_t xm_os_find_walk(tb_char_t const *path, tb_file_info_t const *in // the count tb_size_t *pcount = &(tuple[3].ul); - // trace tb_trace_d("path[%c]: %s", info->type == TB_FILE_TYPE_DIRECTORY ? 'd' : 'f', path); // we can ignore it directly if this path is file, but we need directory @@ -70,7 +68,6 @@ static tb_long_t xm_os_find_walk(tb_char_t const *path, tb_file_info_t const *in lua_pushstring(lua, path); lua_pushstring(lua, pattern); if (lua_pcall(lua, 2, 1, 0)) { - // trace tb_printf("error: call string.match(%s, %s) failed: %s!\n", path, pattern, lua_tostring(lua, -1)); return TB_DIRECTORY_WALK_CODE_END; } @@ -87,7 +84,6 @@ static tb_long_t xm_os_find_walk(tb_char_t const *path, tb_file_info_t const *in tb_char_t const *rootdir = luaL_checklstring(lua, 1, &rootlen); tb_assert_and_check_return_val(rootdir && rootlen, TB_DIRECTORY_WALK_CODE_END); - // check tb_assert(!tb_strncmp(path, rootdir, rootlen)); tb_assert(rootlen + 1 <= tb_strlen(path)); @@ -108,7 +104,6 @@ static tb_long_t xm_os_find_walk(tb_char_t const *path, tb_file_info_t const *in lua_pushstring(lua, path); lua_pushstring(lua, exclude); if (lua_pcall(lua, 2, 1, 0)) { - // trace tb_printf("error: call string.match(%s, %s) failed: %s!\n", path, exclude, @@ -163,7 +158,6 @@ static tb_long_t xm_os_find_walk(tb_char_t const *path, tb_file_info_t const *in * implementation */ tb_int_t xm_os_find(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the root directory diff --git a/core/src/xmake/os/fscase.c b/core/src/xmake/os/fscase.c index 6fa1c1c4a..b24a36e50 100644 --- a/core/src/xmake/os/fscase.c +++ b/core/src/xmake/os/fscase.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_os_fscase(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); #if ((TB_VERSION_MAJOR * 100) + (TB_VERSION_MINOR * 10) + TB_VERSION_ALTER) >= 174 diff --git a/core/src/xmake/os/getenv.c b/core/src/xmake/os/getenv.c index 84411ae1a..dc5578ebe 100644 --- a/core/src/xmake/os/getenv.c +++ b/core/src/xmake/os/getenv.c @@ -45,7 +45,6 @@ * implementation */ tb_int_t xm_os_getenv(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the name @@ -89,6 +88,5 @@ tb_int_t xm_os_getenv(lua_State *lua) { // exit values tb_string_exit(&values); - // ok return 1; } diff --git a/core/src/xmake/os/getenvs.c b/core/src/xmake/os/getenvs.c index a3bc546b4..70c6af7bf 100644 --- a/core/src/xmake/os/getenvs.c +++ b/core/src/xmake/os/getenvs.c @@ -57,7 +57,6 @@ extern tb_char_t **environ; * implementation */ static tb_void_t xm_os_getenvs_trim(tb_char_t const **sstr, tb_char_t const **estr) { - // check tb_assert(sstr && estr && *sstr && *estr); tb_char_t const *p = *sstr; @@ -77,7 +76,6 @@ static tb_void_t xm_os_getenvs_trim(tb_char_t const **sstr, tb_char_t const **es } static tb_void_t xm_os_getenvs_process_line(lua_State *lua, tb_char_t const *line) { - // check tb_assert_and_check_return(lua && line); tb_size_t n = tb_strlen(line); @@ -124,7 +122,6 @@ static tb_void_t xm_os_getenvs_process_line(lua_State *lua, tb_char_t const *lin } tb_int_t xm_os_getenvs(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // init table diff --git a/core/src/xmake/os/getown.c b/core/src/xmake/os/getown.c index 54e2b589e..ef7846ad1 100644 --- a/core/src/xmake/os/getown.c +++ b/core/src/xmake/os/getown.c @@ -42,7 +42,6 @@ // get owner by a given path tb_int_t xm_os_getown(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the pathname @@ -63,7 +62,6 @@ tb_int_t xm_os_getown(lua_State *lua) { lua_pushinteger(lua, sts.st_gid); lua_settable(lua, -3); - // ok return 1; } diff --git a/core/src/xmake/os/getpid.c b/core/src/xmake/os/getpid.c index 70b63804a..ad1a6f880 100644 --- a/core/src/xmake/os/getpid.c +++ b/core/src/xmake/os/getpid.c @@ -40,7 +40,6 @@ * implementation */ tb_int_t xm_os_getpid(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); #ifdef TB_CONFIG_OS_WINDOWS diff --git a/core/src/xmake/os/getwinsize.c b/core/src/xmake/os/getwinsize.c index 9757867a9..6faef97d0 100644 --- a/core/src/xmake/os/getwinsize.c +++ b/core/src/xmake/os/getwinsize.c @@ -43,7 +43,6 @@ // get console window size tb_int_t xm_os_getwinsize(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // init default window size (we will not consider winsize limit if cannot get it) @@ -80,6 +79,5 @@ tb_int_t xm_os_getwinsize(lua_State *lua) { lua_pushinteger(lua, h); lua_settable(lua, -3); - // ok return 1; } diff --git a/core/src/xmake/os/gid.c b/core/src/xmake/os/gid.c index cd5915cd4..feb13791b 100644 --- a/core/src/xmake/os/gid.c +++ b/core/src/xmake/os/gid.c @@ -41,7 +41,6 @@ // get & set gid tb_int_t xm_os_gid(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); tb_int_t rgidset = -1; @@ -124,7 +123,6 @@ tb_int_t xm_os_gid(lua_State *lua) { lua_pushinteger(lua, egid); lua_settable(lua, -3); - // ok return 1; } diff --git a/core/src/xmake/os/isdir.c b/core/src/xmake/os/isdir.c index 6126ed6a8..f182e029d 100644 --- a/core/src/xmake/os/isdir.c +++ b/core/src/xmake/os/isdir.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_os_isdir(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the path diff --git a/core/src/xmake/os/isfile.c b/core/src/xmake/os/isfile.c index f015b5f59..d7b1d66f2 100644 --- a/core/src/xmake/os/isfile.c +++ b/core/src/xmake/os/isfile.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_os_isfile(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the path diff --git a/core/src/xmake/os/islink.c b/core/src/xmake/os/islink.c index 2de7e24fd..51181ecd2 100644 --- a/core/src/xmake/os/islink.c +++ b/core/src/xmake/os/islink.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_os_islink(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the path diff --git a/core/src/xmake/os/link.c b/core/src/xmake/os/link.c index 696355177..cead7f88c 100644 --- a/core/src/xmake/os/link.c +++ b/core/src/xmake/os/link.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_os_link(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the source and destination @@ -45,6 +44,5 @@ tb_int_t xm_os_link(lua_State *lua) { // do os.link(src, dst) lua_pushboolean(lua, tb_file_link(src, dst)); - // ok return 1; } diff --git a/core/src/xmake/os/mclock.c b/core/src/xmake/os/mclock.c index f6bc138d3..5fa440db6 100644 --- a/core/src/xmake/os/mclock.c +++ b/core/src/xmake/os/mclock.c @@ -36,12 +36,10 @@ // os.mclock() tb_int_t xm_os_mclock(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // save result lua_pushnumber(lua, (lua_Number)tb_mclock()); - // ok return 1; } diff --git a/core/src/xmake/os/meminfo.c b/core/src/xmake/os/meminfo.c index 3c0b71d80..1e6e5f422 100644 --- a/core/src/xmake/os/meminfo.c +++ b/core/src/xmake/os/meminfo.c @@ -159,7 +159,6 @@ static tb_bool_t xm_os_meminfo_stats(tb_int_t *ptotalsize, tb_int_t *pavailsize) * implementation */ tb_int_t xm_os_meminfo(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // init table diff --git a/core/src/xmake/os/mkdir.c b/core/src/xmake/os/mkdir.c index badc50fd6..19507b5aa 100644 --- a/core/src/xmake/os/mkdir.c +++ b/core/src/xmake/os/mkdir.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_os_mkdir(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the path @@ -48,6 +47,5 @@ tb_int_t xm_os_mkdir(lua_State *lua) { else lua_pushboolean(lua, tb_true); - // ok return 1; } diff --git a/core/src/xmake/os/mtime.c b/core/src/xmake/os/mtime.c index a3d9c44de..73014666b 100644 --- a/core/src/xmake/os/mtime.c +++ b/core/src/xmake/os/mtime.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_os_mtime(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the path diff --git a/core/src/xmake/os/readlink.c b/core/src/xmake/os/readlink.c index 26ef78819..603ab7104 100644 --- a/core/src/xmake/os/readlink.c +++ b/core/src/xmake/os/readlink.c @@ -37,7 +37,6 @@ * implementation */ tb_int_t xm_os_readlink(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the path @@ -69,6 +68,5 @@ tb_int_t xm_os_readlink(lua_State *lua) { lua_pushnil(lua); #endif - // ok return 1; } diff --git a/core/src/xmake/os/rename.c b/core/src/xmake/os/rename.c index 2f43797db..0cc469ded 100644 --- a/core/src/xmake/os/rename.c +++ b/core/src/xmake/os/rename.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_os_rename(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the source and destination diff --git a/core/src/xmake/os/rmdir.c b/core/src/xmake/os/rmdir.c index dd549adac..f04ba2a9c 100644 --- a/core/src/xmake/os/rmdir.c +++ b/core/src/xmake/os/rmdir.c @@ -34,7 +34,6 @@ * private implementation */ static tb_long_t xm_os_rmdir_empty(tb_char_t const *path, tb_file_info_t const *info, tb_cpointer_t priv) { - // check tb_bool_t *is_emptydir = (tb_bool_t *)priv; tb_assert_and_check_return_val(path && info && is_emptydir, TB_DIRECTORY_WALK_CODE_END); @@ -47,7 +46,6 @@ static tb_long_t xm_os_rmdir_empty(tb_char_t const *path, tb_file_info_t const * return TB_DIRECTORY_WALK_CODE_CONTINUE; } static tb_long_t xm_os_rmdir_remove(tb_char_t const *path, tb_file_info_t const *info, tb_cpointer_t priv) { - // check tb_assert_and_check_return_val(path, TB_DIRECTORY_WALK_CODE_END); // is directory? @@ -56,7 +54,6 @@ static tb_long_t xm_os_rmdir_remove(tb_char_t const *path, tb_file_info_t const tb_bool_t is_emptydir = tb_true; tb_directory_walk(path, tb_false, tb_true, xm_os_rmdir_empty, &is_emptydir); - // trace tb_trace_d("path: %s, emptydir: %u", path, is_emptydir); // remove empty directory @@ -70,7 +67,6 @@ static tb_long_t xm_os_rmdir_remove(tb_char_t const *path, tb_file_info_t const * implementation */ tb_int_t xm_os_rmdir(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the path @@ -89,10 +85,8 @@ tb_int_t xm_os_rmdir(lua_State *lua) { if (is_emptydir) tb_directory_remove(path); - // trace tb_trace_d("path: %s, emptydir: %u", path, is_emptydir); - // ok? lua_pushboolean(lua, !tb_file_info(path, tb_null)); } else { // os.rmdir(path) diff --git a/core/src/xmake/os/rmfile.c b/core/src/xmake/os/rmfile.c index f4b204e25..2032d4ee2 100644 --- a/core/src/xmake/os/rmfile.c +++ b/core/src/xmake/os/rmfile.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_os_rmfile(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the path diff --git a/core/src/xmake/os/setenv.c b/core/src/xmake/os/setenv.c index 99a9bf44e..be375b2f4 100644 --- a/core/src/xmake/os/setenv.c +++ b/core/src/xmake/os/setenv.c @@ -35,7 +35,6 @@ */ // ok = os.setenv(name, value) tb_int_t xm_os_setenv(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the name and value diff --git a/core/src/xmake/os/signal.c b/core/src/xmake/os/signal.c index c1f43ad6b..4d9e8a4c5 100644 --- a/core/src/xmake/os/signal.c +++ b/core/src/xmake/os/signal.c @@ -101,7 +101,6 @@ static tb_void_t xm_os_signal_handler(tb_int_t signo_native) { * implementation */ tb_int_t xm_os_signal(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); g_lua = lua; tb_int_t handler = XM_OS_SIGFUN; diff --git a/core/src/xmake/os/strerror.c b/core/src/xmake/os/strerror.c index 955ca8e24..c1ae41039 100644 --- a/core/src/xmake/os/strerror.c +++ b/core/src/xmake/os/strerror.c @@ -40,7 +40,6 @@ * implementation */ tb_int_t xm_os_strerror(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get syserror state diff --git a/core/src/xmake/os/syserror.c b/core/src/xmake/os/syserror.c index b96a9894f..3ef2a5c52 100644 --- a/core/src/xmake/os/syserror.c +++ b/core/src/xmake/os/syserror.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_os_syserror(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get syserror state diff --git a/core/src/xmake/os/tmpdir.c b/core/src/xmake/os/tmpdir.c index 68b99ee8f..4396603d4 100644 --- a/core/src/xmake/os/tmpdir.c +++ b/core/src/xmake/os/tmpdir.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_os_tmpdir(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // os.tmpdir() diff --git a/core/src/xmake/os/touch.c b/core/src/xmake/os/touch.c index 4e0bd5af8..5c470440b 100644 --- a/core/src/xmake/os/touch.c +++ b/core/src/xmake/os/touch.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_os_touch(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); tb_char_t const *path = luaL_checkstring(lua, 1); diff --git a/core/src/xmake/os/uid.c b/core/src/xmake/os/uid.c index b6413a5e5..2785437d0 100644 --- a/core/src/xmake/os/uid.c +++ b/core/src/xmake/os/uid.c @@ -41,7 +41,6 @@ // get & set uid tb_int_t xm_os_uid(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); tb_int_t ruidset = -1; @@ -124,7 +123,6 @@ tb_int_t xm_os_uid(lua_State *lua) { lua_pushinteger(lua, euid); lua_settable(lua, -3); - // ok return 1; } diff --git a/core/src/xmake/package/loadxmi.c b/core/src/xmake/package/loadxmi.c index 894141414..15a579f91 100644 --- a/core/src/xmake/package/loadxmi.c +++ b/core/src/xmake/package/loadxmi.c @@ -43,7 +43,6 @@ typedef int (*xm_setup_func_t)(xmi_lua_ops_t *ops); * implementation */ tb_int_t xm_package_loadxmi(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); tb_char_t const *path = luaL_checkstring(lua, 1); diff --git a/core/src/xmake/path/absolute.c b/core/src/xmake/path/absolute.c index 781d2f5e4..9b05bc07d 100644 --- a/core/src/xmake/path/absolute.c +++ b/core/src/xmake/path/absolute.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_path_absolute(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the path diff --git a/core/src/xmake/path/directory.c b/core/src/xmake/path/directory.c index aca226a89..0c7d77f2d 100644 --- a/core/src/xmake/path/directory.c +++ b/core/src/xmake/path/directory.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_path_directory(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the path diff --git a/core/src/xmake/path/is_absolute.c b/core/src/xmake/path/is_absolute.c index 120476242..7ac489e26 100644 --- a/core/src/xmake/path/is_absolute.c +++ b/core/src/xmake/path/is_absolute.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_path_is_absolute(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the path diff --git a/core/src/xmake/path/relative.c b/core/src/xmake/path/relative.c index c6ddad14d..5d3beaaa5 100644 --- a/core/src/xmake/path/relative.c +++ b/core/src/xmake/path/relative.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_path_relative(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the path diff --git a/core/src/xmake/path/translate.c b/core/src/xmake/path/translate.c index 422cd0320..7611d188a 100644 --- a/core/src/xmake/path/translate.c +++ b/core/src/xmake/path/translate.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_path_translate(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the path diff --git a/core/src/xmake/process/close.c b/core/src/xmake/process/close.c index 272a02259..fc57453e6 100644 --- a/core/src/xmake/process/close.c +++ b/core/src/xmake/process/close.c @@ -36,7 +36,6 @@ // process.close(p) tb_int_t xm_process_close(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/process/kill.c b/core/src/xmake/process/kill.c index 7eb4f8fd7..4859027b4 100644 --- a/core/src/xmake/process/kill.c +++ b/core/src/xmake/process/kill.c @@ -36,7 +36,6 @@ // process.kill(p) tb_int_t xm_process_kill(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/process/open.c b/core/src/xmake/process/open.c index 8ed62a0cd..f0885719a 100644 --- a/core/src/xmake/process/open.c +++ b/core/src/xmake/process/open.c @@ -42,7 +42,6 @@ * envs = {"PATH=xxx", "XXX=yyy"}}) */ tb_int_t xm_process_open(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get command diff --git a/core/src/xmake/process/openv.c b/core/src/xmake/process/openv.c index e605822b1..99a6133d0 100644 --- a/core/src/xmake/process/openv.c +++ b/core/src/xmake/process/openv.c @@ -46,7 +46,6 @@ * envs = {"PATH=xxx", "XXX=yyy"}}) */ tb_int_t xm_process_openv(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // check argv @@ -323,6 +322,5 @@ tb_int_t xm_process_openv(lua_State *lua) { tb_free(argv); argv = tb_null; - // ok return 1; } diff --git a/core/src/xmake/process/wait.c b/core/src/xmake/process/wait.c index 2914d87cc..84d3b7079 100644 --- a/core/src/xmake/process/wait.c +++ b/core/src/xmake/process/wait.c @@ -36,7 +36,6 @@ // ok, status = process.wait(proc, timeout) tb_int_t xm_process_wait(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? @@ -62,6 +61,5 @@ tb_int_t xm_process_wait(lua_State *lua) { lua_pushinteger(lua, ok); lua_pushinteger(lua, status); - // ok return 2; } diff --git a/core/src/xmake/readline/add_history.c b/core/src/xmake/readline/add_history.c index f928cc446..8f0c1cf4d 100644 --- a/core/src/xmake/readline/add_history.c +++ b/core/src/xmake/readline/add_history.c @@ -37,7 +37,6 @@ // add_history wrapper tb_int_t xm_readline_add_history(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get history @@ -47,7 +46,6 @@ tb_int_t xm_readline_add_history(lua_State *lua) { // call add_history add_history(history); - // ok return 0; } #endif diff --git a/core/src/xmake/readline/clear_history.c b/core/src/xmake/readline/clear_history.c index 11f7ab30c..0235ea4ee 100644 --- a/core/src/xmake/readline/clear_history.c +++ b/core/src/xmake/readline/clear_history.c @@ -37,7 +37,6 @@ // clear_history wrapper tb_int_t xm_readline_clear_history(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); #ifdef TB_CONFIG_OS_MACOSX @@ -48,7 +47,6 @@ tb_int_t xm_readline_clear_history(lua_State *lua) { clear_history(); #endif - // ok return 0; } diff --git a/core/src/xmake/readline/history_list.c b/core/src/xmake/readline/history_list.c index 56d84e114..45267edd5 100644 --- a/core/src/xmake/readline/history_list.c +++ b/core/src/xmake/readline/history_list.c @@ -37,7 +37,6 @@ // history_list wrapper tb_int_t xm_readline_history_list(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // history list @@ -70,7 +69,6 @@ tb_int_t xm_readline_history_list(lua_State *lua) { } #endif - // ok return 1; } diff --git a/core/src/xmake/readline/readline.c b/core/src/xmake/readline/readline.c index 6675c6de2..b6988e35c 100644 --- a/core/src/xmake/readline/readline.c +++ b/core/src/xmake/readline/readline.c @@ -38,7 +38,6 @@ // readline wrapper tb_int_t xm_readline_readline(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the prompt @@ -55,7 +54,6 @@ tb_int_t xm_readline_readline(lua_State *lua) { } else lua_pushnil(lua); - // ok return 1; } diff --git a/core/src/xmake/sandbox/interactive.c b/core/src/xmake/sandbox/interactive.c index 01bac19b4..9e94f876d 100644 --- a/core/src/xmake/sandbox/interactive.c +++ b/core/src/xmake/sandbox/interactive.c @@ -121,7 +121,6 @@ static tb_int_t xm_sandbox_docall(lua_State *lua, tb_int_t narg, tb_int_t clear) if (status != 0) lua_gc(lua, LUA_GCCOLLECT, 0); - // ok? return status; } @@ -158,7 +157,6 @@ static tb_size_t xm_sandbox_readline(tb_char_t *data, tb_size_t maxn, tb_char_t if (size >= maxn) return 0; - // ok return size; } #else @@ -189,7 +187,6 @@ static tb_int_t xm_sandbox_pushline(lua_State *lua, tb_char_t const *prompt2) { // push line lua_pushstring(lua, data); - // ok return 1; } @@ -228,7 +225,6 @@ static tb_int_t xm_sandbox_loadline(lua_State *lua, tb_int_t top) { // attempt to load "return ..." status = luaL_loadbuffer(lua, data, size + 7, "=stdin"); - // ok? if (status != LUA_ERRSYNTAX) return status; @@ -292,7 +288,6 @@ static tb_int_t xm_sandbox_loadline(lua_State *lua, tb_int_t top) { // sandbox.interactive() tb_int_t xm_sandbox_interactive(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); /* get init stack top @@ -358,6 +353,5 @@ tb_int_t xm_sandbox_interactive(lua_State *lua) { tb_printl(""); tb_print_sync(); - // end return 0; } diff --git a/core/src/xmake/semver/compare.c b/core/src/xmake/semver/compare.c index 87e2356a3..8310b73fc 100644 --- a/core/src/xmake/semver/compare.c +++ b/core/src/xmake/semver/compare.c @@ -36,7 +36,6 @@ // semver.compare("v1.0.1-beta", "1.2") > 0? tb_int_t xm_semver_compare(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the version1 string @@ -66,7 +65,6 @@ tb_int_t xm_semver_compare(lua_State *lua) { // do compare lua_pushinteger(lua, semver_pcmp(&semver1, &semver2)); - // end semver_dtor(&semver1); semver_dtor(&semver2); return 1; diff --git a/core/src/xmake/semver/parse.c b/core/src/xmake/semver/parse.c index e9dc221ee..63bd47f93 100644 --- a/core/src/xmake/semver/parse.c +++ b/core/src/xmake/semver/parse.c @@ -55,7 +55,6 @@ * */ tb_int_t xm_semver_parse(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the version string @@ -70,7 +69,6 @@ tb_int_t xm_semver_parse(lua_State *lua) { return 2; } - // ok lua_pushsemver(lua, &semver); semver_dtor(&semver); return 1; diff --git a/core/src/xmake/semver/satisfies.c b/core/src/xmake/semver/satisfies.c index 55c0decb9..a7c47f4fa 100644 --- a/core/src/xmake/semver/satisfies.c +++ b/core/src/xmake/semver/satisfies.c @@ -39,7 +39,6 @@ * semver.satisfies('1.2.3', '1.x || >=2.5.0 || 5.0.0 - 7.2.3') => true */ tb_int_t xm_semver_satisfies(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the version string diff --git a/core/src/xmake/semver/select.c b/core/src/xmake/semver/select.c index 373a71711..7109bfc83 100644 --- a/core/src/xmake/semver/select.c +++ b/core/src/xmake/semver/select.c @@ -75,7 +75,6 @@ static tb_bool_t xm_semver_select_from_versions_tags1( // exit the popped semver semver_dtor(&top); - // ok return tb_true; } static tb_bool_t xm_semver_select_from_versions_tags2( @@ -173,7 +172,6 @@ static tb_bool_t xm_semver_select_latest_from_versions_tags(lua_State *lua, * local versioninfo, errors = semver.select(">=1.5.0 <1.6", {"1.5.0", "1.5.1"}, {"v1.5.0", ..}, {"latest", "dev"}) */ tb_int_t xm_semver_select(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // select version @@ -260,6 +258,5 @@ tb_int_t xm_semver_select(lua_State *lua) { return 2; } - // ok return 1; } diff --git a/core/src/xmake/semver/semver.c b/core/src/xmake/semver/semver.c index 4fe48e5e9..bd13828fa 100644 --- a/core/src/xmake/semver/semver.c +++ b/core/src/xmake/semver/semver.c @@ -34,7 +34,6 @@ * implementation */ tb_void_t lua_pushsemver(lua_State *lua, semver_t const *semver) { - // check tb_assert(lua && semver); // return a semver table diff --git a/core/src/xmake/string/convert.c b/core/src/xmake/string/convert.c index 65750d95e..88dc5ceb1 100644 --- a/core/src/xmake/string/convert.c +++ b/core/src/xmake/string/convert.c @@ -98,7 +98,6 @@ static xm_charset_entry_ref_t xm_string_charset_find_by_name(tb_char_t const *na * @endcode */ tb_int_t xm_string_convert(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the string and charset types @@ -137,6 +136,5 @@ tb_int_t xm_string_convert(lua_State *lua) { tb_free(dst_data); } - // ok return 1; } diff --git a/core/src/xmake/string/endswith.c b/core/src/xmake/string/endswith.c index 5905610f6..f7e5e1805 100644 --- a/core/src/xmake/string/endswith.c +++ b/core/src/xmake/string/endswith.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_string_endswith(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the string and suffix @@ -47,6 +46,5 @@ tb_int_t xm_string_endswith(lua_State *lua) { // string:endswith(suffix)? lua_pushboolean(lua, string_size >= suffix_size && !tb_strcmp(string + string_size - suffix_size, suffix)); - // ok return 1; } diff --git a/core/src/xmake/string/lastof.c b/core/src/xmake/string/lastof.c index c9df2213d..0d52e01ac 100644 --- a/core/src/xmake/string/lastof.c +++ b/core/src/xmake/string/lastof.c @@ -71,7 +71,6 @@ static tb_void_t xm_string_lastof_chr(lua_State *lua, tb_char_t const *cstr, tb_ * @param substr the substring */ tb_int_t xm_string_lastof(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get string diff --git a/core/src/xmake/string/split.c b/core/src/xmake/string/split.c index be2904f99..56e8a636d 100644 --- a/core/src/xmake/string/split.c +++ b/core/src/xmake/string/split.c @@ -101,7 +101,6 @@ static tb_void_t xm_string_split_chr( * @param limit the limit count */ tb_int_t xm_string_split(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get string diff --git a/core/src/xmake/string/startswith.c b/core/src/xmake/string/startswith.c index c7fe9dcca..04b53ffa7 100644 --- a/core/src/xmake/string/startswith.c +++ b/core/src/xmake/string/startswith.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_string_startswith(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the string and prefix @@ -46,6 +45,5 @@ tb_int_t xm_string_startswith(lua_State *lua) { // string:startswith(prefix)? lua_pushboolean(lua, !tb_strncmp(string, prefix, (tb_size_t)prefix_size)); - // ok return 1; } diff --git a/core/src/xmake/string/trim.c b/core/src/xmake/string/trim.c index d22f86666..c1dcdad8d 100644 --- a/core/src/xmake/string/trim.c +++ b/core/src/xmake/string/trim.c @@ -34,7 +34,6 @@ * private implementation */ static tb_void_t xm_string_trim_space(tb_char_t const **psstr, tb_char_t const **pestr, tb_int_t mode) { - // check tb_assert(psstr && pestr && *psstr && *pestr); tb_char_t const *p = *psstr; @@ -62,7 +61,6 @@ static tb_char_t const *xm_string_ltrim(tb_char_t const *sstr, tb_char_t const *estr, tb_char_t const *ctrim, size_t ntrim) { - // check tb_assert(sstr && estr && ctrim); tb_char_t const *p = sstr; @@ -75,7 +73,6 @@ static tb_char_t const *xm_string_rtrim(tb_char_t const *sstr, tb_char_t const *estr, tb_char_t const *ctrim, size_t ntrim) { - // check tb_assert(sstr && estr && ctrim); tb_char_t const *p = estr - 1; @@ -100,7 +97,6 @@ static tb_char_t const *xm_string_rtrim(tb_char_t const *sstr, * @endcode */ tb_int_t xm_string_trim(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); size_t lstr, ltrim; @@ -127,7 +123,6 @@ tb_int_t xm_string_trim(lua_State *lua) { // no trimed chars tb_check_break(sstr != rsstr || estr != restr); - // ok lua_pushlstring(lua, sstr, estr - sstr); return 1; diff --git a/core/src/xmake/thread/thread_exit.c b/core/src/xmake/thread/thread_exit.c index a91018ac6..ae828805e 100644 --- a/core/src/xmake/thread/thread_exit.c +++ b/core/src/xmake/thread/thread_exit.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_thread_exit(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/thread/thread_init.c b/core/src/xmake/thread/thread_init.c index 60d694ae1..2a792463a 100644 --- a/core/src/xmake/thread/thread_init.c +++ b/core/src/xmake/thread/thread_init.c @@ -81,7 +81,6 @@ static tb_int_t xm_thread_func(tb_cpointer_t priv) { * implementation */ tb_int_t xm_thread_init(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); tb_bool_t ok = tb_false; diff --git a/core/src/xmake/thread/thread_resume.c b/core/src/xmake/thread/thread_resume.c index 9a3630338..45253b418 100644 --- a/core/src/xmake/thread/thread_resume.c +++ b/core/src/xmake/thread/thread_resume.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_thread_resume(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/thread/thread_suspend.c b/core/src/xmake/thread/thread_suspend.c index dcb24c4f6..1df3063ef 100644 --- a/core/src/xmake/thread/thread_suspend.c +++ b/core/src/xmake/thread/thread_suspend.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_thread_suspend(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/thread/thread_wait.c b/core/src/xmake/thread/thread_wait.c index 4a921f39c..8ceb45524 100644 --- a/core/src/xmake/thread/thread_wait.c +++ b/core/src/xmake/thread/thread_wait.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_thread_wait(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/tty/term_mode.c b/core/src/xmake/tty/term_mode.c index 78380de5f..34998c60b 100644 --- a/core/src/xmake/tty/term_mode.c +++ b/core/src/xmake/tty/term_mode.c @@ -41,7 +41,6 @@ * local oldmode = tty.term_mode(stdtype, newmode) */ tb_int_t xm_tty_term_mode(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); #ifdef TB_CONFIG_OS_WINDOWS diff --git a/core/src/xmake/utils/bin2c.c b/core/src/xmake/utils/bin2c.c index fef00fb4e..77a1b2a8c 100644 --- a/core/src/xmake/utils/bin2c.c +++ b/core/src/xmake/utils/bin2c.c @@ -101,7 +101,6 @@ static tb_bool_t xm_utils_bin2c_dump(tb_stream_ref_t istream, * local ok, errors = utils.bin2c(binaryfile, outputfile, linewidth, nozeroend) */ tb_int_t xm_utils_bin2c(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the binaryfile diff --git a/core/src/xmake/winos/ansi.c b/core/src/xmake/winos/ansi.c index 137f18742..48bb9df82 100644 --- a/core/src/xmake/winos/ansi.c +++ b/core/src/xmake/winos/ansi.c @@ -36,7 +36,6 @@ */ static tb_int_t xm_expand_cp(tb_int_t cp) { - // check tb_assert_and_check_return_val(cp >= 0 && cp <= 65535, 0); if (cp == CP_OEMCP) @@ -47,7 +46,6 @@ static tb_int_t xm_expand_cp(tb_int_t cp) { } tb_int_t xm_winos_console_cp(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); tb_int_t n = lua_gettop(lua); @@ -66,7 +64,6 @@ tb_int_t xm_winos_console_cp(lua_State *lua) { } tb_int_t xm_winos_console_output_cp(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); tb_int_t n = lua_gettop(lua); @@ -85,7 +82,6 @@ tb_int_t xm_winos_console_output_cp(lua_State *lua) { } tb_int_t xm_winos_cp_info(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); lua_Integer cp = luaL_checkinteger(lua, 1); @@ -138,7 +134,6 @@ tb_int_t xm_winos_cp_info(lua_State *lua) { } tb_int_t xm_winos_ansi_cp(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); tb_uint_t cp = GetACP(); @@ -147,7 +142,6 @@ tb_int_t xm_winos_ansi_cp(lua_State *lua) { } tb_int_t xm_winos_oem_cp(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); tb_uint_t cp = GetOEMCP(); diff --git a/core/src/xmake/winos/logical_drives.c b/core/src/xmake/winos/logical_drives.c index 48b05886e..7227069b9 100644 --- a/core/src/xmake/winos/logical_drives.c +++ b/core/src/xmake/winos/logical_drives.c @@ -73,6 +73,5 @@ tb_int_t xm_winos_logical_drives(lua_State *lua) { tb_free(data); data = tb_null; - // ok return 1; } diff --git a/core/src/xmake/winos/registry_keys.c b/core/src/xmake/winos/registry_keys.c index 42a37e33d..7daf44ff4 100644 --- a/core/src/xmake/winos/registry_keys.c +++ b/core/src/xmake/winos/registry_keys.c @@ -168,7 +168,6 @@ static tb_void_t xm_winos_registry_enum_keys(xm_winos_registry_enum_info_t *info * end) */ tb_int_t xm_winos_registry_keys(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the arguments @@ -231,7 +230,6 @@ tb_int_t xm_winos_registry_keys(lua_State *lua) { } while (0); - // ok? if (ok) { lua_pushinteger(lua, count); return 1; diff --git a/core/src/xmake/winos/registry_query.c b/core/src/xmake/winos/registry_query.c index 23fda76ff..5e98af2cd 100644 --- a/core/src/xmake/winos/registry_query.c +++ b/core/src/xmake/winos/registry_query.c @@ -46,7 +46,6 @@ typedef BOOL(WINAPI *xm_RegGetValueW_t)( * local value, errors = winos.registry_query("HKEY_LOCAL_MACHINE", "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug", "Debugger") */ tb_int_t xm_winos_registry_query(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the arguments @@ -226,6 +225,5 @@ tb_int_t xm_winos_registry_query(lua_State *lua) { tb_free(value_w); value_w = tb_null; - // ok? return ok ? 1 : 2; } diff --git a/core/src/xmake/winos/registry_values.c b/core/src/xmake/winos/registry_values.c index 1f72d978b..6bda8e690 100644 --- a/core/src/xmake/winos/registry_values.c +++ b/core/src/xmake/winos/registry_values.c @@ -43,7 +43,6 @@ * end) */ tb_int_t xm_winos_registry_values(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the arguments @@ -156,7 +155,6 @@ tb_int_t xm_winos_registry_values(lua_State *lua) { } } - // ok if (i == value_name_num) ok = tb_true; @@ -167,7 +165,6 @@ tb_int_t xm_winos_registry_values(lua_State *lua) { RegCloseKey(keynew); keynew = tb_null; - // ok? if (ok) { lua_pushinteger(lua, count); return 1; diff --git a/core/src/xmake/winos/short_path.c b/core/src/xmake/winos/short_path.c index 5c6e20b30..9c2192787 100644 --- a/core/src/xmake/winos/short_path.c +++ b/core/src/xmake/winos/short_path.c @@ -39,7 +39,6 @@ * local short_path, errors = winos.short_path(long_path) */ tb_int_t xm_winos_short_path(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the arguments diff --git a/core/src/xmake/xmake.c b/core/src/xmake/xmake.c index 89b288c79..8d4a77284 100644 --- a/core/src/xmake/xmake.c +++ b/core/src/xmake/xmake.c @@ -52,7 +52,6 @@ static __tb_inline__ tb_bool_t xm_check_mode(tb_size_t mode) { } #endif - // ok return tb_true; } static __tb_inline__ tb_bool_t xm_version_check(tb_hize_t build) { @@ -60,7 +59,6 @@ static __tb_inline__ tb_bool_t xm_version_check(tb_hize_t build) { tb_version_t const *version = xm_version(); tb_used(version); - // ok if ((build / 100) == (XM_VERSION_BUILD / 100)) { tb_trace_d("version: %s", XM_VERSION_STRING); return tb_true; @@ -76,7 +74,6 @@ static __tb_inline__ tb_bool_t xm_version_check(tb_hize_t build) { * implementation */ tb_bool_t xm_init_(tb_size_t mode, tb_hize_t build) { - // trace tb_trace_d("init: .."); // check mode @@ -95,10 +92,8 @@ tb_bool_t xm_init_(tb_size_t mode, tb_hize_t build) { return tb_false; #endif - // trace tb_trace_d("init: ok"); - // ok return tb_true; } tb_void_t xm_exit() { -- cgit v1.3.1 From bf2da8a3d7f04bf5ffcdce8fd4c334d5421d3494 Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 9 Nov 2025 22:34:50 +0800 Subject: format core --- core/src/xmake/engine.c | 94 ++++++++++++++++++++++-------------- core/src/xmake/io/file_close.c | 6 ++- core/src/xmake/io/file_flush.c | 6 ++- core/src/xmake/io/file_isatty.c | 3 +- core/src/xmake/io/file_open.c | 90 +++++++++++++++++++--------------- core/src/xmake/io/file_rawfd.c | 3 +- core/src/xmake/io/file_read.c | 89 +++++++++++++++++++++------------- core/src/xmake/io/file_readable.c | 8 +-- core/src/xmake/io/file_seek.c | 14 ++++-- core/src/xmake/io/file_size.c | 6 ++- core/src/xmake/io/file_write.c | 16 +++--- core/src/xmake/io/filelock_close.c | 3 +- core/src/xmake/io/filelock_lock.c | 3 +- core/src/xmake/io/filelock_open.c | 8 +-- core/src/xmake/io/filelock_trylock.c | 3 +- core/src/xmake/io/filelock_unlock.c | 3 +- core/src/xmake/io/iscygpty.c | 6 ++- core/src/xmake/io/pipe_close.c | 3 +- core/src/xmake/io/pipe_open.c | 11 +++-- core/src/xmake/io/pipe_openpair.c | 6 ++- core/src/xmake/io/pipe_read.c | 6 ++- core/src/xmake/io/pipe_wait.c | 3 +- core/src/xmake/io/pipe_write.c | 6 ++- core/src/xmake/io/poller.c | 3 +- core/src/xmake/io/poller_wait.c | 8 +-- core/src/xmake/io/socket_accept.c | 8 +-- core/src/xmake/io/socket_close.c | 3 +- core/src/xmake/io/socket_kill.c | 3 +- core/src/xmake/io/socket_listen.c | 3 +- core/src/xmake/io/socket_open.c | 5 +- core/src/xmake/io/socket_peeraddr.c | 8 +-- core/src/xmake/io/socket_recv.c | 6 ++- core/src/xmake/io/socket_recvfrom.c | 6 ++- core/src/xmake/io/socket_send.c | 6 ++- core/src/xmake/io/socket_sendfile.c | 6 ++- core/src/xmake/io/socket_sendto.c | 6 ++- core/src/xmake/io/socket_wait.c | 3 +- core/src/xmake/io/stdfile.c | 14 ++++-- core/src/xmake/xmake.c | 6 ++- 39 files changed, 307 insertions(+), 183 deletions(-) (limited to 'core/src/xmake/engine.c') diff --git a/core/src/xmake/engine.c b/core/src/xmake/engine.c index 7a07d72da..0405fc230 100644 --- a/core/src/xmake/engine.c +++ b/core/src/xmake/engine.c @@ -898,18 +898,20 @@ static tb_bool_t xm_engine_get_program_directory(xm_engine_t *engine, return tb_true; } - tb_bool_t ok = tb_false; + tb_bool_t ok = tb_false; tb_char_t data[TB_PATH_MAXN] = { 0 }; do { #ifdef XM_EMBED_ENABLE tb_size_t embedcount = engine->embedcount; if (embedcount) { tb_uint32_t crc32 = 0; - for (tb_size_t i = 0; i < embedcount; i++) + for (tb_size_t i = 0; i < embedcount; i++) { crc32 += tb_crc32_make(engine->embeddata[i], engine->embedsize[i], 0); + } tb_snprintf(path, maxn, "%s/%x", engine->tmpdir, crc32); - } else + } else { tb_strlcpy(path, engine->tmpdir, maxn); + } ok = tb_true; break; #endif @@ -1011,8 +1013,9 @@ static tb_bool_t xm_engine_get_project_directory(xm_engine_t *engine, tb_char_t } while (0); // failed? - if (!ok) + if (!ok) { tb_printf("error: not found the project directory!\n"); + } return ok; } @@ -1054,12 +1057,13 @@ static tb_void_t xm_engine_init_host(xm_engine_t *engine) { #if defined(__COSMOPOLITAN__) struct utsname buffer; if (uname(&buffer) == 0) { - if (tb_strstr(buffer.sysname, "Darwin")) + if (tb_strstr(buffer.sysname, "Darwin")) { syshost = "macosx"; - else if (tb_strstr(buffer.sysname, "Linux")) + } else if (tb_strstr(buffer.sysname, "Linux")) { syshost = "linux"; - else if (tb_strstr(buffer.sysname, "Windows")) + } else if (tb_strstr(buffer.sysname, "Windows")) { syshost = "windows"; + } } #elif defined(TB_CONFIG_OS_WINDOWS) syshost = "windows"; @@ -1096,8 +1100,9 @@ static tb_void_t xm_engine_init_host(xm_engine_t *engine) { "clang", 5) // clang32/64 on msys2, @see https://github.com/xmake-io/xmake/issues/3060 || !tb_stricmp(data, "ucrt64") // ucrt64 https://www.msys2.org/docs/environments/ - || !tb_stricmp(data, "msys")) // on msys2 + || !tb_stricmp(data, "msys")) { // on msys2 subhost = "msys"; + } } } #endif @@ -1145,12 +1150,14 @@ static tb_void_t xm_engine_init_arch(xm_engine_t *engine) { if (uname(&buffer) == 0) { sysarch = buffer.machine; if (tb_strstr(buffer.sysname, "Windows")) { - if (!tb_strcmp(buffer.machine, "x86_64")) + if (!tb_strcmp(buffer.machine, "x86_64")) { sysarch = "x64"; - else if (!tb_strcmp(buffer.machine, "i686") || !tb_strcmp(buffer.machine, "i386")) + } else if (!tb_strcmp(buffer.machine, "i686") || !tb_strcmp(buffer.machine, "i386")) { sysarch = "x86"; - } else if (!tb_strcmp(buffer.machine, "aarch64")) + } + } else if (!tb_strcmp(buffer.machine, "aarch64")) { sysarch = "arm64"; + } } #elif defined(TB_CONFIG_OS_WINDOWS) && !defined(TB_COMPILER_LIKE_UNIX) // the GetNativeSystemInfo function type @@ -1160,12 +1167,14 @@ static tb_void_t xm_engine_init_arch(xm_engine_t *engine) { SYSTEM_INFO systeminfo = { 0 }; GetNativeSystemInfo_t pGetNativeSystemInfo = tb_null; tb_dynamic_ref_t kernel32 = tb_dynamic_init("kernel32.dll"); - if (kernel32) + if (kernel32) { pGetNativeSystemInfo = (GetNativeSystemInfo_t)tb_dynamic_func(kernel32, "GetNativeSystemInfo"); - if (pGetNativeSystemInfo) + } + if (pGetNativeSystemInfo) { pGetNativeSystemInfo(&systeminfo); - else + } else { GetSystemInfo(&systeminfo); + } // init architecture switch (systeminfo.wProcessorArchitecture) { @@ -1187,8 +1196,9 @@ static tb_void_t xm_engine_init_arch(xm_engine_t *engine) { break; } #endif - if (!sysarch) + if (!sysarch) { sysarch = xmakearch; + } lua_pushstring(engine->lua, sysarch); lua_setglobal(engine->lua, "_ARCH"); @@ -1198,10 +1208,11 @@ static tb_void_t xm_engine_init_arch(xm_engine_t *engine) { // get architecture from msys environment tb_char_t data[64] = { 0 }; if (tb_environment_first("MSYSTEM_CARCH", data, sizeof(data))) { - if (!tb_strcmp(data, "i686")) + if (!tb_strcmp(data, "i686")) { subarch = "i386"; - else + } else { subarch = data; + } } #endif lua_pushstring(engine->lua, subarch); @@ -1238,8 +1249,9 @@ static tb_void_t xm_engine_init_features(xm_engine_t *engine) { static tb_void_t xm_engine_init_signal(xm_engine_t *engine) { // we enable it to catch the current lua stack in ctrl-c signal handler if XMAKE_PROFILE=stuck tb_char_t data[64] = { 0 }; - if (!tb_environment_first("XMAKE_PROFILE", data, sizeof(data)) || tb_strcmp(data, "stuck")) + if (!tb_environment_first("XMAKE_PROFILE", data, sizeof(data)) || tb_strcmp(data, "stuck")) { return; + } g_lua = engine->lua; #if defined(TB_CONFIG_OS_WINDOWS) @@ -1253,14 +1265,15 @@ static tb_void_t xm_engine_init_signal(xm_engine_t *engine) { // udata is unused, it has been used by engine. see xm_engine_bind_to_lua() static tb_pointer_t xm_engine_lua_realloc(tb_pointer_t udata, tb_pointer_t data, size_t osize, size_t nsize) { tb_pointer_t ptr = tb_null; - if (nsize == 0 && data) + if (nsize == 0 && data) { tb_free(data); - else if (!data) + } else if (!data) { ptr = tb_malloc((tb_size_t)nsize); - else if (nsize != osize) + } else if (nsize != osize) { ptr = tb_ralloc(data, (tb_size_t)nsize); - else + } else { ptr = data; + } return ptr; } #endif @@ -1293,8 +1306,9 @@ static tb_bool_t xm_engine_extract_programfiles_impl(xm_engine_t *engine, break; } - if (buffer_size == 0) + if (buffer_size == 0) { break; + } data += advance; size -= advance; @@ -1428,10 +1442,12 @@ static tb_bool_t xm_engine_load_main_script(xm_engine_t *engine, tb_char_t const } while (0); - if (data) + if (data) { tb_free(data); - if (file) + } + if (file) { tb_file_exit(file); + } return ok; #else if (luaL_dofile(engine->lua, mainfile)) { @@ -1560,7 +1576,7 @@ xm_engine_ref_t xm_engine_init(tb_char_t const *name, xm_engine_lni_initalizer_c // init version string tb_char_t version_cstr[256] = { 0 }; - if (tb_strcmp(XM_CONFIG_VERSION_BRANCH, "") && tb_strcmp(XM_CONFIG_VERSION_COMMIT, "")) + if (tb_strcmp(XM_CONFIG_VERSION_BRANCH, "") && tb_strcmp(XM_CONFIG_VERSION_COMMIT, "")) { tb_snprintf(version_cstr, sizeof(version_cstr), "%u.%u.%u+%s.%s", @@ -1569,14 +1585,15 @@ xm_engine_ref_t xm_engine_init(tb_char_t const *name, xm_engine_lni_initalizer_c version->alter, XM_CONFIG_VERSION_BRANCH, XM_CONFIG_VERSION_COMMIT); - else + } else { tb_snprintf(version_cstr, sizeof(version_cstr), "%u.%u.%u+%llu", version->major, version->minor, version->alter, - version->build); + (unsigned long long)version->build); + } lua_pushstring(engine->lua, version_cstr); lua_setglobal(engine->lua, "_VERSION"); @@ -1615,8 +1632,9 @@ xm_engine_ref_t xm_engine_init(tb_char_t const *name, xm_engine_lni_initalizer_c * we can get the lni modules for _lni or `import("lib.lni.xxx")` in sandbox */ lua_newtable(engine->lua); - if (lni_initalizer) + if (lni_initalizer) { lni_initalizer((xm_engine_ref_t)engine, engine->lua); + } lua_setglobal(engine->lua, "_lni"); #ifdef TB_CONFIG_OS_WINDOWS @@ -1626,8 +1644,9 @@ xm_engine_ref_t xm_engine_init(tb_char_t const *name, xm_engine_lni_initalizer_c DWORD mode; if (GetConsoleMode(output, &mode)) { // attempt to enable 0x4: ENABLE_VIRTUAL_TERMINAL_PROCESSING - if (SetConsoleMode(output, mode | 0x4)) + if (SetConsoleMode(output, mode | 0x4)) { tb_environment_set("COLORTERM", "color256"); + } } } #endif @@ -1636,8 +1655,9 @@ xm_engine_ref_t xm_engine_init(tb_char_t const *name, xm_engine_lni_initalizer_c } while (0); if (!ok) { - if (engine) + if (engine) { xm_engine_exit((xm_engine_ref_t)engine); + } engine = tb_null; } return (xm_engine_ref_t)engine; @@ -1647,13 +1667,15 @@ tb_void_t xm_engine_exit(xm_engine_ref_t self) { tb_assert_and_check_return(engine); // exit lua - if (engine->lua) + if (engine->lua) { lua_close(engine->lua); + } engine->lua = tb_null; // exit poller - if (engine->poller) + if (engine->poller) { tb_poller_exit(engine->poller); + } engine->poller = tb_null; // exit it @@ -1665,13 +1687,15 @@ tb_int_t xm_engine_main(xm_engine_ref_t self, tb_int_t argc, tb_char_t **argv, t #if defined(TB_CONFIG_OS_WINDOWS) && defined(TB_COMPILER_IS_MSVC) // set "stdin" to have unicode mode - if (_isatty(_fileno(stdin))) + if (_isatty(_fileno(stdin))) { _setmode(_fileno(stdin), _O_U16TEXT); + } #endif // save main arguments to the global variable: _ARGV - if (!xm_engine_save_arguments(engine, argc, argv, taskargv)) + if (!xm_engine_save_arguments(engine, argc, argv, taskargv)) { return -1; + } // get the project directory tb_char_t path[TB_PATH_MAXN] = { 0 }; diff --git a/core/src/xmake/io/file_close.c b/core/src/xmake/io/file_close.c index 6547b8156..cbcb237af 100644 --- a/core/src/xmake/io/file_close.c +++ b/core/src/xmake/io/file_close.c @@ -72,13 +72,15 @@ tb_int_t xm_io_file_close(lua_State *lua) { file->u.file_ref = tb_null; // exit fstream - if (file->fstream) + if (file->fstream) { tb_stream_exit(file->fstream); + } file->fstream = tb_null; // exit stream - if (file->stream) + if (file->stream) { tb_stream_exit(file->stream); + } file->stream = tb_null; // exit the line cache buffer diff --git a/core/src/xmake/io/file_flush.c b/core/src/xmake/io/file_flush.c index e5776a60e..73652ce20 100644 --- a/core/src/xmake/io/file_flush.c +++ b/core/src/xmake/io/file_flush.c @@ -63,8 +63,9 @@ tb_int_t xm_io_file_flush(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is user data? - if (!lua_isuserdata(lua, 1)) + if (!lua_isuserdata(lua, 1)) { xm_io_return_error(lua, "flush(invalid file)!"); + } // get file xm_io_file_t *file = (xm_io_file_t *)lua_touserdata(lua, 1); @@ -75,6 +76,7 @@ tb_int_t xm_io_file_flush(lua_State *lua) { if (ok) { lua_pushboolean(lua, tb_true); return 1; - } else + } else { xm_io_return_error(lua, "failed to flush file"); + } } diff --git a/core/src/xmake/io/file_isatty.c b/core/src/xmake/io/file_isatty.c index 264cabd53..4f6bf4272 100644 --- a/core/src/xmake/io/file_isatty.c +++ b/core/src/xmake/io/file_isatty.c @@ -39,8 +39,9 @@ tb_int_t xm_io_file_isatty(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is user data? - if (!lua_isuserdata(lua, 1)) + if (!lua_isuserdata(lua, 1)) { xm_io_return_error(lua, "isatty(invalid file)!"); + } // get file xm_io_file_t *file = (xm_io_file_t *)lua_touserdata(lua, 1); diff --git a/core/src/xmake/io/file_open.c b/core/src/xmake/io/file_open.c index f4a080077..901a3f86d 100644 --- a/core/src/xmake/io/file_open.c +++ b/core/src/xmake/io/file_open.c @@ -50,8 +50,9 @@ static tb_size_t xm_io_file_detect_charset(tb_byte_t const **data_ptr, tb_long_t tb_size_t charset = XM_IO_FILE_ENCODING_BINARY; do { // is luajit bitcode? open as binary - if (size >= 3 && data[0] == 27 && data[1] == 'L' && data[2] == 'J') + if (size >= 3 && data[0] == 27 && data[1] == 'L' && data[2] == 'J') { break; + } // utf-8 with bom if (size >= 3 && data[0] == 239 && data[1] == 187 && data[2] == 191) { @@ -80,34 +81,39 @@ static tb_size_t xm_io_file_detect_charset(tb_byte_t const **data_ptr, tb_long_t tb_sint16_t ascii_conf = 0; tb_sint16_t zero_count = 0; for (tb_long_t i = 0; i < (size - 4) && i < CHECK_SIZE; i++) { - if (data[i] == 0) + if (data[i] == 0) { zero_count++; + } - if (data[i] < 0x80) + if (data[i] < 0x80) { ascii_conf++; - else + } else { ascii_conf = TB_MINS16; + } if (i % 2 == 0) { - if (data[i] == 0) + if (data[i] == 0) { utf16be_conf++; - if (data[i + 1] == 0) + } + if (data[i + 1] == 0) { utf16le_conf++; + } } - if (IS_UTF8_TAIL(data[i])) - ; - else if (data[i] < 0x80) + if (IS_UTF8_TAIL(data[i])) { + // continue + } else if (data[i] < 0x80) { utf8_conf++; - else if (data[i] >= 0xc0 && data[i] < 0xe0 && IS_UTF8_TAIL(data[i + 1])) + } else if (data[i] >= 0xc0 && data[i] < 0xe0 && IS_UTF8_TAIL(data[i + 1])) { utf8_conf++; - else if (data[i] >= 0xe0 && data[i] < 0xf0 && IS_UTF8_TAIL(data[i + 1]) && IS_UTF8_TAIL(data[i + 2])) + } else if (data[i] >= 0xe0 && data[i] < 0xf0 && IS_UTF8_TAIL(data[i + 1]) && IS_UTF8_TAIL(data[i + 2])) { utf8_conf++; - else if (data[i] >= 0xf0 && data[i] < 0xf8 && IS_UTF8_TAIL(data[i + 1]) && IS_UTF8_TAIL(data[i + 2]) && - IS_UTF8_TAIL(data[i + 3])) + } else if (data[i] >= 0xf0 && data[i] < 0xf8 && IS_UTF8_TAIL(data[i + 1]) && IS_UTF8_TAIL(data[i + 2]) && + IS_UTF8_TAIL(data[i + 3])) { utf8_conf++; - else + } else { utf8_conf = TB_MINS16; + } } if (ascii_conf > 0 && zero_count <= 1) { @@ -188,44 +194,46 @@ tb_int_t xm_io_file_open(lua_State *lua) { tb_stream_ref_t stream = tb_null; tb_bool_t update = !!tb_strchr(modestr, '+'); tb_size_t encoding = XM_IO_FILE_ENCODING_UNKNOWN; - if (modestr[1] == 'b' || (update && modestr[2] == 'b')) + if (modestr[1] == 'b' || (update && modestr[2] == 'b')) { encoding = XM_IO_FILE_ENCODING_BINARY; - else if (tb_strstr(modestr, "utf8") || tb_strstr(modestr, "utf-8")) + } else if (tb_strstr(modestr, "utf8") || tb_strstr(modestr, "utf-8")) { encoding = TB_CHARSET_TYPE_UTF8; - else if (tb_strstr(modestr, "utf16le") || tb_strstr(modestr, "utf-16le")) + } else if (tb_strstr(modestr, "utf16le") || tb_strstr(modestr, "utf-16le")) { encoding = TB_CHARSET_TYPE_UTF16 | TB_CHARSET_TYPE_LE; - else if (tb_strstr(modestr, "utf16be") || tb_strstr(modestr, "utf-16be")) + } else if (tb_strstr(modestr, "utf16be") || tb_strstr(modestr, "utf-16be")) { encoding = TB_CHARSET_TYPE_UTF16 | TB_CHARSET_TYPE_BE; - else if (tb_strstr(modestr, "utf16") || tb_strstr(modestr, "utf-16")) + } else if (tb_strstr(modestr, "utf16") || tb_strstr(modestr, "utf-16")) { encoding = TB_CHARSET_TYPE_UTF16 | TB_CHARSET_TYPE_NE; - else if (tb_strstr(modestr, "ansi")) + } else if (tb_strstr(modestr, "ansi")) { encoding = TB_CHARSET_TYPE_ANSI; - else if (tb_strstr(modestr, "gbk")) + } else if (tb_strstr(modestr, "gbk")) { encoding = TB_CHARSET_TYPE_GBK; - else if (tb_strstr(modestr, "gb2312")) + } else if (tb_strstr(modestr, "gb2312")) { encoding = TB_CHARSET_TYPE_GB2312; - else if (tb_strstr(modestr, "iso8859")) + } else if (tb_strstr(modestr, "iso8859")) { encoding = TB_CHARSET_TYPE_ISO8859; - else if (modestr[0] == 'w' || modestr[0] == 'a') // set to utf-8 if not specified for the writing mode + } else if (modestr[0] == 'w' || modestr[0] == 'a') { // set to utf-8 if not specified for the writing mode encoding = TB_CHARSET_TYPE_UTF8; - else if (modestr[0] == 'r') // detect encoding if not specified for the reading mode - { + } else if (modestr[0] == 'r') { // detect encoding if not specified for the reading mode stream = tb_stream_init_from_file(path, mode); - if (stream && tb_stream_open(stream)) + if (stream && tb_stream_open(stream)) { encoding = xm_io_file_detect_encoding(stream, &bomoff); - else { - if (stream) + } else { + if (stream) { tb_stream_exit(stream); + } xm_io_return_error(lua, "file not found!"); } - } else + } else { xm_io_return_error(lua, "invalid open mode!"); + } tb_assert_and_check_return_val(encoding != XM_IO_FILE_ENCODING_UNKNOWN, 0); // write data with utf bom? e.g. utf8bom, utf16lebom, utf16bom tb_bool_t utfbom = tb_false; - if (tb_strstr(modestr, "bom")) + if (tb_strstr(modestr, "bom")) { utfbom = tb_true; + } // open file tb_bool_t open_ok = tb_false; @@ -239,24 +247,28 @@ tb_int_t xm_io_file_open(lua_State *lua) { // is transcode? tb_bool_t is_transcode = encoding != TB_CHARSET_TYPE_UTF8 && encoding != XM_IO_FILE_ENCODING_BINARY; if (is_transcode) { - if (modestr[0] == 'r') + if (modestr[0] == 'r') { fstream = tb_stream_init_filter_from_charset(stream, encoding, TB_CHARSET_TYPE_UTF8); - else + } else { fstream = tb_stream_init_filter_from_charset(stream, TB_CHARSET_TYPE_UTF8, encoding); + } tb_assert_and_check_break(fstream); // use fstream as file file_ref = fstream; - } else + } else { file_ref = stream; + } // open file stream - if (!tb_stream_open(file_ref)) + if (!tb_stream_open(file_ref)) { break; + } // skip bom characters if exists - if (bomoff > 0 && !tb_stream_seek(stream, bomoff)) + if (bomoff > 0 && !tb_stream_seek(stream, bomoff)) { break; + } open_ok = tb_true; @@ -265,13 +277,15 @@ tb_int_t xm_io_file_open(lua_State *lua) { // open failed? if (!open_ok) { // exit stream - if (stream) + if (stream) { tb_stream_exit(stream); + } stream = tb_null; // exit charset stream filter - if (fstream) + if (fstream) { tb_stream_exit(fstream); + } fstream = tb_null; // return errors diff --git a/core/src/xmake/io/file_rawfd.c b/core/src/xmake/io/file_rawfd.c index c94dc4a98..419955118 100644 --- a/core/src/xmake/io/file_rawfd.c +++ b/core/src/xmake/io/file_rawfd.c @@ -55,8 +55,9 @@ tb_int_t xm_io_file_rawfd(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is user data? - if (!lua_isuserdata(lua, 1)) + if (!lua_isuserdata(lua, 1)) { xm_io_return_error(lua, "get rawfd for invalid file!"); + } // get file xm_io_file_t *file = (xm_io_file_t *)lua_touserdata(lua, 1); diff --git a/core/src/xmake/io/file_read.c b/core/src/xmake/io/file_read.c index 2be05a05a..0b255f4c1 100644 --- a/core/src/xmake/io/file_read.c +++ b/core/src/xmake/io/file_read.c @@ -79,10 +79,11 @@ static tb_long_t xm_io_file_buffer_readline(tb_stream_ref_t stream, tb_buffer_re } tb_size_t linesize = tb_buffer_size(line); - if (linesize) + if (linesize) { return linesize; - else + } else { return (eof || tb_stream_beof(stream)) ? -1 : 0; + } } static tb_int_t xm_io_file_buffer_pushline(tb_buffer_ref_t buf, xm_io_file_t *file, @@ -122,9 +123,9 @@ static tb_int_t xm_io_file_buffer_pushline(tb_buffer_ref_t buf, tb_assert_and_check_break(data); // no lf found - if (size > 0 && data[size - 1] != '\n') + if (size > 0 && data[size - 1] != '\n') { result = PL_FIN; - else if (size > 1) { + } else if (size > 1) { // crlf? => lf if (!is_binary && data[size - 2] == '\r') { data[size - 2] = '\n'; @@ -137,27 +138,31 @@ static tb_int_t xm_io_file_buffer_pushline(tb_buffer_ref_t buf, 0; // do not keep crlf, strip the last lf - if (!keep_crlf && !has_conline) + if (!keep_crlf && !has_conline) { size--; + } // strip it if has continuation? - if (has_conline) + if (has_conline) { size -= conlen + 1; + } data[size] = '\0'; result = has_conline ? PL_CONL : PL_FIN; } else { // a single '\n' - if (!keep_crlf) + if (!keep_crlf) { size = 0; + } result = PL_FIN; } } while (0); // push line data - if (data && size > 0 && (result == PL_FIN || result == PL_CONL)) + if (data && size > 0 && (result == PL_FIN || result == PL_CONL)) { tb_buffer_memncat(buf, (tb_byte_t const *)data, size); + } // return result return result; @@ -167,8 +172,9 @@ static tb_int_t xm_io_file_read_all_directly(lua_State *lua, xm_io_file_t *file) // init buffer tb_buffer_t buf; - if (!tb_buffer_init(&buf)) + if (!tb_buffer_init(&buf)) { xm_io_return_error(lua, "init buffer failed!"); + } tb_byte_t *data = tb_buffer_resize(&file->rcache, XM_IO_BLOCK_MAXN); if (!data) { @@ -180,19 +186,21 @@ static tb_int_t xm_io_file_read_all_directly(lua_State *lua, xm_io_file_t *file) tb_stream_ref_t stream = file->u.file_ref; while (!tb_stream_beof(stream)) { tb_long_t real = tb_stream_read(stream, data, XM_IO_BLOCK_MAXN); - if (real > 0) + if (real > 0) { tb_buffer_memncat(&buf, data, real); - else if (!real) { + } else if (!real) { real = tb_stream_wait(stream, TB_STREAM_WAIT_READ, -1); tb_check_break(real > 0); - } else + } else { break; + } } - if (tb_buffer_size(&buf)) + if (tb_buffer_size(&buf)) { lua_pushlstring(lua, (tb_char_t const *)tb_buffer_data(&buf), tb_buffer_size(&buf)); - else + } else { lua_pushliteral(lua, ""); + } tb_buffer_exit(&buf); return 1; } @@ -201,23 +209,26 @@ static tb_int_t xm_io_file_read_all(lua_State *lua, xm_io_file_t *file, tb_char_ // is binary? read all directly tb_bool_t is_binary = file->encoding == XM_IO_FILE_ENCODING_BINARY; - if (is_binary) + if (is_binary) { return xm_io_file_read_all_directly(lua, file); + } // init buffer tb_buffer_t buf; - if (!tb_buffer_init(&buf)) + if (!tb_buffer_init(&buf)) { xm_io_return_error(lua, "init buffer failed!"); + } // read all tb_bool_t has_content = tb_false; while (1) { switch (xm_io_file_buffer_pushline(&buf, file, continuation, tb_true)) { case PL_EOF: - if (!has_content) + if (!has_content) { lua_pushliteral(lua, ""); - else + } else { lua_pushlstring(lua, (tb_char_t const *)tb_buffer_data(&buf), tb_buffer_size(&buf)); + } tb_buffer_exit(&buf); return 1; case PL_FIN: @@ -241,18 +252,20 @@ static tb_int_t xm_io_file_read_line(lua_State *lua, // init buffer tb_buffer_t buf; - if (!tb_buffer_init(&buf)) + if (!tb_buffer_init(&buf)) { xm_io_return_error(lua, "init buffer failed!"); + } // read line tb_bool_t has_content = tb_false; while (1) { switch (xm_io_file_buffer_pushline(&buf, file, continuation, keep_crlf)) { case PL_EOF: - if (!has_content) + if (!has_content) { lua_pushnil(lua); - else + } else { lua_pushlstring(lua, (tb_char_t const *)tb_buffer_data(&buf), tb_buffer_size(&buf)); + } tb_buffer_exit(&buf); return 1; case PL_FIN: @@ -275,12 +288,14 @@ static tb_int_t xm_io_file_read_n(lua_State *lua, xm_io_file_t *file, tb_char_t tb_assert(lua && file && continuation && xm_io_file_is_file(file) && file->u.file_ref); // check continuation - if (*continuation != '\0') + if (*continuation != '\0') { xm_io_return_error(lua, "continuation is not supported for read number of bytes"); + } // check encoding - if (file->encoding != XM_IO_FILE_ENCODING_BINARY) + if (file->encoding != XM_IO_FILE_ENCODING_BINARY) { xm_io_return_error(lua, "read number of bytes only allows binary file, reopen with 'rb' and try again"); + } tb_bool_t ok = tb_false; if (n == 0) { @@ -298,8 +313,9 @@ static tb_int_t xm_io_file_read_n(lua_State *lua, xm_io_file_t *file, tb_char_t } } } - if (!ok) + if (!ok) { lua_pushnil(lua); + } return 1; } @@ -313,10 +329,11 @@ static tb_size_t xm_io_file_std_buffer_pushline(tb_buffer_ref_t buf, tb_char_t strbuf[8192]; tb_size_t buflen = 0; tb_size_t result = PL_FAIL; - if (tb_stdfile_gets(file->u.std_ref, strbuf, tb_arrayn(strbuf) - 1)) + if (tb_stdfile_gets(file->u.std_ref, strbuf, tb_arrayn(strbuf) - 1)) { buflen = tb_strlen(strbuf); - else + } else { return PL_EOF; + } tb_size_t conlen = tb_strlen(continuation); if (buflen > 0 && strbuf[buflen - 1] != '\n') { @@ -334,24 +351,28 @@ static tb_size_t xm_io_file_std_buffer_pushline(tb_buffer_ref_t buf, tb_strncmp(continuation, (strbuf + buflen - conlen - 1), conlen) == 0; // do not keep crlf, strip the last lf - if (!keep_crlf && !has_conline) + if (!keep_crlf && !has_conline) { buflen--; + } // strip it if has continuation? - if (has_conline) + if (has_conline) { buflen -= conlen + 1; + } strbuf[buflen] = '\0'; result = has_conline ? PL_CONL : PL_FIN; } else { // a single '\n' - if (!keep_crlf) + if (!keep_crlf) { buflen = 0; + } result = PL_FIN; } - if (result == PL_FIN || result == PL_CONL) + if (result == PL_FIN || result == PL_CONL) { tb_buffer_memncat(buf, (tb_byte_t const *)strbuf, buflen); + } return result; } @@ -363,18 +384,20 @@ static tb_int_t xm_io_file_std_read_line(lua_State *lua, // init buffer tb_buffer_t buf; - if (!tb_buffer_init(&buf)) + if (!tb_buffer_init(&buf)) { xm_io_return_error(lua, "init buffer failed!"); + } // read line tb_bool_t has_content = tb_false; while (1) { switch (xm_io_file_std_buffer_pushline(&buf, file, continuation, keep_crlf)) { case PL_EOF: - if (!has_content) + if (!has_content) { lua_pushnil(lua); - else + } else { lua_pushlstring(lua, (tb_char_t const *)tb_buffer_data(&buf), tb_buffer_size(&buf)); + } tb_buffer_exit(&buf); return 1; case PL_FIN: diff --git a/core/src/xmake/io/file_readable.c b/core/src/xmake/io/file_readable.c index 5f9a84329..78ea82888 100644 --- a/core/src/xmake/io/file_readable.c +++ b/core/src/xmake/io/file_readable.c @@ -38,8 +38,9 @@ tb_int_t xm_io_file_readable(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is user data? - if (!lua_isuserdata(lua, 1)) + if (!lua_isuserdata(lua, 1)) { xm_io_return_error(lua, "read(invalid file)!"); + } // get file xm_io_file_t *file = (xm_io_file_t *)lua_touserdata(lua, 1); @@ -47,10 +48,11 @@ tb_int_t xm_io_file_readable(lua_State *lua) { // has readable data? tb_bool_t ok = tb_false; - if (xm_io_file_is_file(file)) + if (xm_io_file_is_file(file)) { ok = tb_stream_left(file->u.file_ref) > 0; - else + } else { ok = tb_stdfile_readable(file->u.std_ref); + } lua_pushboolean(lua, ok); return 1; } diff --git a/core/src/xmake/io/file_seek.c b/core/src/xmake/io/file_seek.c index 421e5cdf1..c7c043e7a 100644 --- a/core/src/xmake/io/file_seek.c +++ b/core/src/xmake/io/file_seek.c @@ -39,8 +39,9 @@ tb_int_t xm_io_file_seek(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is user data? - if (!lua_isuserdata(lua, 1)) + if (!lua_isuserdata(lua, 1)) { xm_io_return_error(lua, "seek(invalid file)!"); + } // get file xm_io_file_t *file = (xm_io_file_t *)lua_touserdata(lua, 1); @@ -60,10 +61,11 @@ tb_int_t xm_io_file_seek(lua_State *lua) { case 'e': // "end" { tb_hong_t size = tb_stream_size(file->u.file_ref); - if (size > 0 && size + offset <= size) + if (size > 0 && size + offset <= size) { offset = size + offset; - else + } else { xm_io_return_error(lua, "seek failed, invalid offset!"); + } } break; default: // "cur" offset = tb_stream_offset(file->u.file_ref) + offset; @@ -73,8 +75,10 @@ tb_int_t xm_io_file_seek(lua_State *lua) { if (tb_stream_seek(file->u.file_ref, offset)) { lua_pushnumber(lua, (lua_Number)offset); return 1; - } else + } else { xm_io_return_error(lua, "seek failed!"); - } else + } + } else { xm_io_return_error(lua, "seek is not supported on this file"); + } } diff --git a/core/src/xmake/io/file_size.c b/core/src/xmake/io/file_size.c index 34f519306..351bd7ebf 100644 --- a/core/src/xmake/io/file_size.c +++ b/core/src/xmake/io/file_size.c @@ -39,8 +39,9 @@ tb_int_t xm_io_file_size(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is user data? - if (!lua_isuserdata(lua, 1)) + if (!lua_isuserdata(lua, 1)) { xm_io_return_error(lua, "get size for invalid file!"); + } // get file xm_io_file_t *file = (xm_io_file_t *)lua_touserdata(lua, 1); @@ -52,6 +53,7 @@ tb_int_t xm_io_file_size(lua_State *lua) { tb_assert(file->stream); lua_pushnumber(lua, (lua_Number)tb_stream_size(file->stream)); return 1; - } else + } else { xm_io_return_error(lua, "get size for invalid file!"); + } } diff --git a/core/src/xmake/io/file_write.c b/core/src/xmake/io/file_write.c index 5f70e1a49..08655379a 100644 --- a/core/src/xmake/io/file_write.c +++ b/core/src/xmake/io/file_write.c @@ -137,21 +137,23 @@ tb_int_t xm_io_file_write(lua_State *lua) { // get data size_t datasize = 0; tb_byte_t const *data = tb_null; - if (lua_isstring(lua, i)) + if (lua_isstring(lua, i)) { data = (tb_byte_t const *)luaL_checklstring(lua, i, &datasize); - else if (lua_istable(lua, i)) { + } else if (lua_istable(lua, i)) { // get bytes data lua_pushstring(lua, "data"); lua_gettable(lua, i); - if (xm_lua_isinteger(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 (xm_lua_isinteger(lua, -1)) + if (xm_lua_isinteger(lua, -1)) { datasize = (tb_size_t)lua_tointeger(lua, -1); + } lua_pop(lua, 1); // mark as binary data @@ -162,11 +164,11 @@ tb_int_t xm_io_file_write(lua_State *lua) { tb_assert_and_check_break(data); // write data to std or file - if (xm_io_file_is_std(file)) + if (xm_io_file_is_std(file)) { xm_io_file_write_std(file, data, (tb_size_t)datasize); - else if (is_binary) + } else if (is_binary) { xm_io_file_write_file_directly(file, data, (tb_size_t)datasize); - else { + } else { // write utf bom first? if (file->utfbom) { xm_io_file_write_file_utfbom(file); diff --git a/core/src/xmake/io/filelock_close.c b/core/src/xmake/io/filelock_close.c index 02a2fb039..69bea4e39 100644 --- a/core/src/xmake/io/filelock_close.c +++ b/core/src/xmake/io/filelock_close.c @@ -39,8 +39,9 @@ tb_int_t xm_io_filelock_close(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // check lock? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { return 0; + } // get lock tb_filelock_ref_t lock = (tb_filelock_ref_t)xm_lua_topointer(lua, 1); diff --git a/core/src/xmake/io/filelock_lock.c b/core/src/xmake/io/filelock_lock.c index 9e0c2493e..070af2eaf 100644 --- a/core/src/xmake/io/filelock_lock.c +++ b/core/src/xmake/io/filelock_lock.c @@ -53,8 +53,9 @@ tb_int_t xm_io_filelock_lock(lua_State *lua) { } // check lock? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { return 0; + } // get lock tb_filelock_ref_t lock = (tb_filelock_ref_t)xm_lua_topointer(lua, 1); diff --git a/core/src/xmake/io/filelock_open.c b/core/src/xmake/io/filelock_open.c index e9687ba54..2afb173d3 100644 --- a/core/src/xmake/io/filelock_open.c +++ b/core/src/xmake/io/filelock_open.c @@ -47,13 +47,15 @@ tb_int_t xm_io_filelock_open(lua_State *lua) { // init file lock tb_long_t tryn = 2; tb_filelock_ref_t lock = tb_null; - while (!lock && tryn-- > 0) + while (!lock && tryn-- > 0) { lock = tb_filelock_init_from_path(path, tb_file_info(path, tb_null) ? TB_FILE_MODE_RW : TB_FILE_MODE_RW | TB_FILE_MODE_CREAT); - if (lock) + } + if (lock) { xm_lua_pushpointer(lua, (tb_pointer_t)lock); - else + } else { lua_pushnil(lua); + } return 1; } diff --git a/core/src/xmake/io/filelock_trylock.c b/core/src/xmake/io/filelock_trylock.c index aaf1da246..d84024834 100644 --- a/core/src/xmake/io/filelock_trylock.c +++ b/core/src/xmake/io/filelock_trylock.c @@ -53,8 +53,9 @@ tb_int_t xm_io_filelock_trylock(lua_State *lua) { } // check lock? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { return 0; + } // get lock tb_filelock_ref_t lock = (tb_filelock_ref_t)xm_lua_topointer(lua, 1); diff --git a/core/src/xmake/io/filelock_unlock.c b/core/src/xmake/io/filelock_unlock.c index 94dfe1b7d..007bedd54 100644 --- a/core/src/xmake/io/filelock_unlock.c +++ b/core/src/xmake/io/filelock_unlock.c @@ -39,8 +39,9 @@ tb_int_t xm_io_filelock_unlock(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // check lock? - if (!xm_lua_topointer(lua, 1)) + if (!xm_lua_topointer(lua, 1)) { return 0; + } // get lock tb_filelock_ref_t lock = (tb_filelock_ref_t)xm_lua_topointer(lua, 1); diff --git a/core/src/xmake/io/iscygpty.c b/core/src/xmake/io/iscygpty.c index e78a9d8cb..656e86fe7 100644 --- a/core/src/xmake/io/iscygpty.c +++ b/core/src/xmake/io/iscygpty.c @@ -131,8 +131,9 @@ int is_cygpty(HANDLE h) { p = NULL; } if (p != NULL) { - while (*p && isxdigit(*p)) /* Skip 16-digit hexadecimal. */ + while (*p && isxdigit(*p)) { /* Skip 16-digit hexadecimal. */ ++p; + } if (is_wprefix(p, L"-pty")) { p += 4; } else { @@ -140,8 +141,9 @@ int is_cygpty(HANDLE h) { } } if (p != NULL) { - while (*p && isdigit(*p)) /* Skip pty number. */ + while (*p && isdigit(*p)) { /* Skip pty number. */ ++p; + } if (is_wprefix(p, L"-from-master")) { //p += 12; } else if (is_wprefix(p, L"-to-master")) { diff --git a/core/src/xmake/io/pipe_close.c b/core/src/xmake/io/pipe_close.c index 23e200606..aaf708a31 100644 --- a/core/src/xmake/io/pipe_close.c +++ b/core/src/xmake/io/pipe_close.c @@ -39,8 +39,9 @@ tb_int_t xm_io_pipe_close(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // check pipe? - if (!xm_pipe_file_is_valid(lua, 1)) + if (!xm_pipe_file_is_valid(lua, 1)) { return 0; + } // get the pipe file tb_pipe_file_ref_t pipefile = xm_pipe_file_get(lua, 1); diff --git a/core/src/xmake/io/pipe_open.c b/core/src/xmake/io/pipe_open.c index d82406dee..6bfe26347 100644 --- a/core/src/xmake/io/pipe_open.c +++ b/core/src/xmake/io/pipe_open.c @@ -47,21 +47,24 @@ tb_int_t xm_io_pipe_open(lua_State *lua) { // get pipe mode value tb_size_t mode = TB_PIPE_MODE_RO; - if (modestr[0] == 'w') + if (modestr[0] == 'w') { mode = TB_PIPE_MODE_WO; + } // set block mode - if (modestr[1] == 'B') + if (modestr[1] == 'B') { mode |= TB_PIPE_MODE_BLOCK; + } // get buffer size tb_size_t buffsize = (tb_size_t)luaL_checknumber(lua, 3); // open pipe file tb_pipe_file_ref_t pipefile = tb_pipe_file_init(name, mode, buffsize); - if (pipefile) + if (pipefile) { xm_lua_pushpointer(lua, (tb_pointer_t)pipefile); - else + } else { lua_pushnil(lua); + } return 1; } diff --git a/core/src/xmake/io/pipe_openpair.c b/core/src/xmake/io/pipe_openpair.c index dd2205613..bf4829f6c 100644 --- a/core/src/xmake/io/pipe_openpair.c +++ b/core/src/xmake/io/pipe_openpair.c @@ -46,10 +46,12 @@ tb_int_t xm_io_pipe_openpair(lua_State *lua) { // init mode tb_size_t mode[2] = { 0 }; - if (modestr[0] == 'B') + if (modestr[0] == 'B') { mode[0] |= TB_PIPE_MODE_BLOCK; - if (modestr[1] == 'B') + } + if (modestr[1] == 'B') { mode[1] |= TB_PIPE_MODE_BLOCK; + } // get buffer size tb_size_t buffsize = (tb_size_t)luaL_checknumber(lua, 2); diff --git a/core/src/xmake/io/pipe_read.c b/core/src/xmake/io/pipe_read.c index 637fb3b7d..e0e383bfb 100644 --- a/core/src/xmake/io/pipe_read.c +++ b/core/src/xmake/io/pipe_read.c @@ -51,8 +51,9 @@ tb_int_t xm_io_pipe_read(lua_State *lua) { // get data tb_byte_t *data = tb_null; - if (xm_lua_isinteger(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); @@ -62,8 +63,9 @@ tb_int_t xm_io_pipe_read(lua_State *lua) { // get size tb_long_t size = 0; - if (xm_lua_isinteger(lua, 3)) + if (xm_lua_isinteger(lua, 3)) { size = (tb_long_t)lua_tointeger(lua, 3); + } if (size <= 0) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid size(%d)!", (tb_int_t)size); diff --git a/core/src/xmake/io/pipe_wait.c b/core/src/xmake/io/pipe_wait.c index 785efe950..d2979dcdd 100644 --- a/core/src/xmake/io/pipe_wait.c +++ b/core/src/xmake/io/pipe_wait.c @@ -39,8 +39,9 @@ tb_int_t xm_io_pipe_wait(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // check pipe? - if (!xm_pipe_file_is_valid(lua, 1)) + if (!xm_pipe_file_is_valid(lua, 1)) { return 0; + } // get pipe file tb_pipe_file_ref_t pipefile = xm_pipe_file_get(lua, 1); diff --git a/core/src/xmake/io/pipe_write.c b/core/src/xmake/io/pipe_write.c index 2f2865c47..d3098dd60 100644 --- a/core/src/xmake/io/pipe_write.c +++ b/core/src/xmake/io/pipe_write.c @@ -52,10 +52,12 @@ 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 (xm_lua_isinteger(lua, 2)) + 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)) + } + 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); diff --git a/core/src/xmake/io/poller.c b/core/src/xmake/io/poller.c index e4c7cf494..6e155e4a8 100644 --- a/core/src/xmake/io/poller.c +++ b/core/src/xmake/io/poller.c @@ -37,8 +37,9 @@ tb_poller_ref_t xm_io_poller(lua_State *lua) { tb_poller_ref_t poller = tb_null; xm_engine_ref_t engine = xm_engine_get(lua); - if (engine) + if (engine) { poller = xm_engine_poller(engine); + } tb_assert(poller); return poller; } diff --git a/core/src/xmake/io/poller_wait.c b/core/src/xmake/io/poller_wait.c index f1e4ed7a7..dc1418a03 100644 --- a/core/src/xmake/io/poller_wait.c +++ b/core/src/xmake/io/poller_wait.c @@ -46,10 +46,11 @@ static tb_void_t xm_io_poller_event(tb_poller_ref_t poller, lua_newtable(lua); lua_pushinteger(lua, (tb_int_t)object->type); lua_rawseti(lua, -2, 1); - if (priv) + if (priv) { lua_pushstring(lua, (tb_char_t const *)priv); - else + } else { lua_pushlightuserdata(lua, object->ref.ptr); + } lua_rawseti(lua, -2, 2); if (object->type == TB_POLLER_OBJECT_FWATCHER) { lua_newtable(lua); @@ -63,8 +64,9 @@ static tb_void_t xm_io_poller_event(tb_poller_ref_t poller, lua_pushinteger(lua, event->event); lua_settable(lua, -3); } - } else + } else { lua_pushinteger(lua, (tb_int_t)events); + } lua_rawseti(lua, -2, 3); lua_rawseti(lua, -2, ++state->events_count); } diff --git a/core/src/xmake/io/socket_accept.c b/core/src/xmake/io/socket_accept.c index 77a6c6c86..5aed6d263 100644 --- a/core/src/xmake/io/socket_accept.c +++ b/core/src/xmake/io/socket_accept.c @@ -39,8 +39,9 @@ tb_int_t xm_io_socket_accept(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is pointer? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { return 0; + } // get socket tb_socket_ref_t sock = (tb_socket_ref_t)xm_lua_topointer(lua, 1); @@ -48,9 +49,10 @@ tb_int_t xm_io_socket_accept(lua_State *lua) { // accept socket tb_socket_ref_t client = tb_socket_accept(sock, tb_null); - if (client) + if (client) { xm_lua_pushpointer(lua, (tb_pointer_t)client); - else + } else { lua_pushnil(lua); + } return 1; } diff --git a/core/src/xmake/io/socket_close.c b/core/src/xmake/io/socket_close.c index 922987c10..401ffd7b6 100644 --- a/core/src/xmake/io/socket_close.c +++ b/core/src/xmake/io/socket_close.c @@ -39,8 +39,9 @@ tb_int_t xm_io_socket_close(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is pointer? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { return 0; + } // get socket tb_socket_ref_t sock = (tb_socket_ref_t)xm_lua_topointer(lua, 1); diff --git a/core/src/xmake/io/socket_kill.c b/core/src/xmake/io/socket_kill.c index 63e110257..33d36ef18 100644 --- a/core/src/xmake/io/socket_kill.c +++ b/core/src/xmake/io/socket_kill.c @@ -39,8 +39,9 @@ tb_int_t xm_io_socket_kill(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is pointer? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { return 0; + } // get socket tb_socket_ref_t sock = (tb_socket_ref_t)xm_lua_topointer(lua, 1); diff --git a/core/src/xmake/io/socket_listen.c b/core/src/xmake/io/socket_listen.c index 3aa541016..14971e589 100644 --- a/core/src/xmake/io/socket_listen.c +++ b/core/src/xmake/io/socket_listen.c @@ -39,8 +39,9 @@ tb_int_t xm_io_socket_listen(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is pointer? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { return 0; + } // get socket tb_socket_ref_t sock = (tb_socket_ref_t)xm_lua_topointer(lua, 1); diff --git a/core/src/xmake/io/socket_open.c b/core/src/xmake/io/socket_open.c index cae80d182..2ed04ca97 100644 --- a/core/src/xmake/io/socket_open.c +++ b/core/src/xmake/io/socket_open.c @@ -61,9 +61,10 @@ tb_int_t xm_io_socket_open(lua_State *lua) { // init socket tb_socket_ref_t sock = tb_socket_init(socktype, family); - if (sock) + if (sock) { xm_lua_pushpointer(lua, (tb_pointer_t)sock); - else + } else { lua_pushnil(lua); + } return 1; } diff --git a/core/src/xmake/io/socket_peeraddr.c b/core/src/xmake/io/socket_peeraddr.c index e1ad43931..686d46799 100644 --- a/core/src/xmake/io/socket_peeraddr.c +++ b/core/src/xmake/io/socket_peeraddr.c @@ -47,8 +47,9 @@ tb_int_t xm_io_socket_peeraddr(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is pointer? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { xm_io_return_error(lua, "get peer address for invalid sock!"); + } // get socket tb_socket_ref_t sock = (tb_socket_ref_t)xm_lua_topointer(lua, 1); @@ -58,9 +59,10 @@ tb_int_t xm_io_socket_peeraddr(lua_State *lua) { tb_ipaddr_t addr; tb_char_t data[256]; tb_char_t const *cstr = tb_null; - if (tb_socket_peer(sock, &addr) && (cstr = tb_ipaddr_cstr(&addr, data, sizeof(data)))) + if (tb_socket_peer(sock, &addr) && (cstr = tb_ipaddr_cstr(&addr, data, sizeof(data)))) { lua_pushstring(lua, cstr); - else + } else { lua_pushnil(lua); + } return 1; } diff --git a/core/src/xmake/io/socket_recv.c b/core/src/xmake/io/socket_recv.c index ed629a8f5..3ccb9b461 100644 --- a/core/src/xmake/io/socket_recv.c +++ b/core/src/xmake/io/socket_recv.c @@ -51,8 +51,9 @@ tb_int_t xm_io_socket_recv(lua_State *lua) { // get data tb_byte_t *data = tb_null; - if (xm_lua_isinteger(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); @@ -62,8 +63,9 @@ tb_int_t xm_io_socket_recv(lua_State *lua) { // get size tb_long_t size = 0; - if (xm_lua_isinteger(lua, 3)) + if (xm_lua_isinteger(lua, 3)) { size = (tb_long_t)lua_tointeger(lua, 3); + } if (size <= 0) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid size(%d)!", (tb_int_t)size); diff --git a/core/src/xmake/io/socket_recvfrom.c b/core/src/xmake/io/socket_recvfrom.c index 8601f6302..5e212bed8 100644 --- a/core/src/xmake/io/socket_recvfrom.c +++ b/core/src/xmake/io/socket_recvfrom.c @@ -51,8 +51,9 @@ tb_int_t xm_io_socket_recvfrom(lua_State *lua) { // get data tb_byte_t *data = tb_null; - if (xm_lua_isinteger(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); @@ -62,8 +63,9 @@ tb_int_t xm_io_socket_recvfrom(lua_State *lua) { // get size tb_long_t size = 0; - if (xm_lua_isinteger(lua, 3)) + if (xm_lua_isinteger(lua, 3)) { size = (tb_long_t)lua_tointeger(lua, 3); + } if (size <= 0) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid size(%d)!", (tb_int_t)size); diff --git a/core/src/xmake/io/socket_send.c b/core/src/xmake/io/socket_send.c index d83b02add..3a11d0d43 100644 --- a/core/src/xmake/io/socket_send.c +++ b/core/src/xmake/io/socket_send.c @@ -52,10 +52,12 @@ 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 (xm_lua_isinteger(lua, 2)) + 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)) + } + 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); diff --git a/core/src/xmake/io/socket_sendfile.c b/core/src/xmake/io/socket_sendfile.c index 0d4be4219..e12e574d7 100644 --- a/core/src/xmake/io/socket_sendfile.c +++ b/core/src/xmake/io/socket_sendfile.c @@ -85,8 +85,9 @@ tb_int_t xm_io_socket_sendfile(lua_State *lua) { // get start tb_long_t start = 1; - if (lua_isnumber(lua, 3)) + if (lua_isnumber(lua, 3)) { start = (tb_long_t)lua_tonumber(lua, 3); + } if (start < 1 || start > filesize) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid start position(%d)!", (tb_int_t)start); @@ -95,8 +96,9 @@ tb_int_t xm_io_socket_sendfile(lua_State *lua) { // get last tb_long_t last = (tb_long_t)filesize; - if (lua_isnumber(lua, 4)) + if (lua_isnumber(lua, 4)) { last = (tb_long_t)lua_tonumber(lua, 4); + } if (last < start - 1 || last > filesize + start - 1) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid last position(%d)!", (tb_int_t)last); diff --git a/core/src/xmake/io/socket_sendto.c b/core/src/xmake/io/socket_sendto.c index 15403d4d8..ccbbb1cc2 100644 --- a/core/src/xmake/io/socket_sendto.c +++ b/core/src/xmake/io/socket_sendto.c @@ -52,10 +52,12 @@ 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 (xm_lua_isinteger(lua, 2)) + 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)) + } + 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); diff --git a/core/src/xmake/io/socket_wait.c b/core/src/xmake/io/socket_wait.c index 42674f4f9..409d69c91 100644 --- a/core/src/xmake/io/socket_wait.c +++ b/core/src/xmake/io/socket_wait.c @@ -39,8 +39,9 @@ tb_int_t xm_io_socket_wait(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // check socket? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { return 0; + } // get socket tb_socket_ref_t sock = (tb_socket_ref_t)xm_lua_topointer(lua, 1); diff --git a/core/src/xmake/io/stdfile.c b/core/src/xmake/io/stdfile.c index 0dcb43501..ac77b272d 100644 --- a/core/src/xmake/io/stdfile.c +++ b/core/src/xmake/io/stdfile.c @@ -71,8 +71,9 @@ static tb_size_t xm_io_stdfile_isatty(tb_size_t type) { /* we cannot call is_cygpty for stdin, because it will cause io.readable is always true * https://github.com/xmake-io/xmake/issues/2504#issuecomment-1170130756 */ - if (!answer && type != XM_IO_FILE_TYPE_STDIN) + if (!answer && type != XM_IO_FILE_TYPE_STDIN) { answer = is_cygpty(console_handle); + } #else switch (type) { case XM_IO_FILE_TYPE_STDIN: @@ -87,8 +88,9 @@ static tb_size_t xm_io_stdfile_isatty(tb_size_t type) { } #endif - if (answer) + if (answer) { type |= XM_IO_FILE_FLAG_TTY; + } return type; } @@ -97,8 +99,9 @@ static tb_void_t xm_io_stdfile_init_buffer(tb_size_t type) { #if !defined(TB_CONFIG_OS_WINDOWS) struct stat stats; tb_int_t size = BUFSIZ; - if (fstat(fileno(stdout), &stats) != -1) + if (fstat(fileno(stdout), &stats) != -1) { size = stats.st_blksize; + } setvbuf(stdout, tb_null, _IOLBF, size); #endif } @@ -154,8 +157,9 @@ tb_int_t xm_io_stdfile(lua_State *lua) { * @note we need to ensure that it is a singleton in the external lua script, and will only be created once, e.g. io.stdin, io.stdout, io.stderr */ xm_io_file_t *file = xm_io_stdfile_new(lua, type); - if (file) + if (file) { return 1; - else + } else { xm_io_return_error(lua, "invalid stdfile type!"); + } } diff --git a/core/src/xmake/xmake.c b/core/src/xmake/xmake.c index 8d4a77284..c673d776a 100644 --- a/core/src/xmake/xmake.c +++ b/core/src/xmake/xmake.c @@ -77,8 +77,9 @@ tb_bool_t xm_init_(tb_size_t mode, tb_hize_t build) { tb_trace_d("init: .."); // check mode - if (!xm_check_mode(mode)) + if (!xm_check_mode(mode)) { return tb_false; + } // check version xm_version_check(build); @@ -88,8 +89,9 @@ tb_bool_t xm_init_(tb_size_t mode, tb_hize_t build) { if (!tb_init(tb_null, tb_default_allocator(tb_null, 0))) return tb_false; #else // init tbox, since small compilation mode is enabled, it still uses the native allocator - if (!tb_init(tb_null, tb_null)) + if (!tb_init(tb_null, tb_null)) { return tb_false; + } #endif tb_trace_d("init: ok"); -- cgit v1.3.1