diff options
| author | OpportunityLiu <[email protected]> | 2019-07-02 10:55:05 +0800 |
|---|---|---|
| committer | OpportunityLiu <[email protected]> | 2019-07-02 10:55:05 +0800 |
| commit | b0c2771fd052116bf009788ab7fde3878ce6e3da (patch) | |
| tree | 02d1c2f477d60260d35238bd5ca40c81ad91ad0b /core/src | |
| parent | 51afeebaa78f2dbb9307f53a2533d68cd5491b33 (diff) | |
add asserts
Diffstat (limited to 'core/src')
| -rw-r--r-- | core/src/xmake/io/file_read.c | 18 | ||||
| -rw-r--r-- | core/src/xmake/io/file_write.c | 8 | ||||
| -rw-r--r-- | core/src/xmake/io/std.c | 3 |
3 files changed, 17 insertions, 12 deletions
diff --git a/core/src/xmake/io/file_read.c b/core/src/xmake/io/file_read.c index 754a40fdf..4fb0ee597 100644 --- a/core/src/xmake/io/file_read.c +++ b/core/src/xmake/io/file_read.c @@ -211,6 +211,8 @@ typedef enum __pushline_state_e static tb_int_t buffer_pushline(luaL_Buffer* buf, xm_io_file* file, tb_char_t const* continuation, tb_bool_t keep_crlf) { + tb_assert(lua && file && continuation && xm_io_file_is_file(file) && !xm_io_file_is_closed(file)); + tb_size_t charset = file->encoding; tb_bool_t binary = charset == XM_IO_FILE_ENCODING_BINARY || charset == XM_IO_FILE_ENCODING_UNKNOWN; if (binary) @@ -353,7 +355,7 @@ static tb_int_t buffer_pushline(luaL_Buffer* buf, xm_io_file* file, tb_char_t co static tb_int_t read_all(lua_State* lua, xm_io_file* file, tb_char_t const* continuation) { - tb_assert(lua && file && continuation); + tb_assert(lua && file && continuation && xm_io_file_is_file(file) && !xm_io_file_is_closed(file)); luaL_Buffer sbuf, *buf = &sbuf; luaL_buffinit(lua, buf); @@ -376,7 +378,7 @@ static tb_int_t read_all(lua_State* lua, xm_io_file* file, tb_char_t const* cont static tb_int_t read_line(lua_State* lua, xm_io_file* file, tb_char_t const* continuation, tb_bool_t keep_crlf) { - tb_assert(lua && file && continuation); + tb_assert(lua && file && continuation && xm_io_file_is_file(file) && !xm_io_file_is_closed(file)); luaL_Buffer sbuf, *buf = &sbuf; luaL_buffinit(lua, buf); @@ -399,7 +401,7 @@ static tb_int_t read_line(lua_State* lua, xm_io_file* file, tb_char_t const* con static tb_int_t read_n(lua_State* lua, xm_io_file* file, tb_char_t const* continuation, tb_long_t n) { - tb_assert(lua && file && continuation); + tb_assert(lua && file && continuation && xm_io_file_is_file(file) && !xm_io_file_is_closed(file)); if (*continuation != '\0') xm_io_file_error(lua, "continuation is not supported for read number of bytes"); tb_size_t charset = file->encoding; @@ -438,7 +440,7 @@ static tb_int_t read_n(lua_State* lua, xm_io_file* file, tb_char_t const* contin static tb_size_t std_buffer_pushline(luaL_Buffer* buf, xm_io_file* file, tb_char_t const* continuation, tb_bool_t keep_crlf) { - tb_assert(lua && file && continuation); + tb_assert(lua && file && continuation && xm_io_file_is_std(file) && !xm_io_file_is_closed(file)); tb_char_t strbuf[8192]; tb_size_t buflen = 0; @@ -488,7 +490,7 @@ static tb_size_t std_buffer_pushline(luaL_Buffer* buf, xm_io_file* file, tb_char static tb_int_t std_read_line(lua_State* lua, xm_io_file* file, tb_char_t const* continuation, tb_bool_t keep_crlf) { - tb_assert(lua && file && continuation); + tb_assert(lua && file && continuation && xm_io_file_is_std(file) && !xm_io_file_is_closed(file)); luaL_Buffer sbuf, *buf = &sbuf; luaL_buffinit(lua, buf); @@ -511,7 +513,7 @@ static tb_int_t std_read_line(lua_State* lua, xm_io_file* file, tb_char_t const* static tb_int_t std_read_all(lua_State* lua, xm_io_file* file, tb_char_t const* continuation) { - tb_assert(lua && file && continuation); + tb_assert(lua && file && continuation && xm_io_file_is_std(file) && !xm_io_file_is_closed(file)); luaL_Buffer sbuf, *buf = &sbuf; luaL_buffinit(lua, buf); @@ -534,7 +536,7 @@ static tb_int_t std_read_all(lua_State* lua, xm_io_file* file, tb_char_t const* static tb_int_t std_read_n(lua_State* lua, xm_io_file* file, tb_char_t const* continuation, tb_long_t n) { - tb_assert(lua && file && continuation); + tb_assert(lua && file && continuation && xm_io_file_is_std(file) && !xm_io_file_is_closed(file)); if (*continuation != '\0') xm_io_file_error(lua, "continuation is not supported for std streams"); if (n == 0) @@ -584,7 +586,7 @@ static tb_int_t std_read_n(lua_State* lua, xm_io_file* file, tb_char_t const* co static tb_int_t std_read_num(lua_State* lua, xm_io_file* file, tb_char_t const* continuation) { - tb_assert(lua && file && continuation); + tb_assert(lua && file && continuation && xm_io_file_is_std(file) && !xm_io_file_is_closed(file)); if (*continuation != '\0') xm_io_file_error(lua, "continuation is not supported for std streams"); tb_double_t d; diff --git a/core/src/xmake/io/file_write.c b/core/src/xmake/io/file_write.c index c7a8b74fa..2c1e49453 100644 --- a/core/src/xmake/io/file_write.c +++ b/core/src/xmake/io/file_write.c @@ -43,13 +43,13 @@ static tb_void_t direct_write(xm_io_file* file, tb_char_t const* data, tb_size_t size) { - tb_assert(file && data); + tb_assert(file && data && xm_io_file_is_file(file) && !xm_io_file_is_closed(file)); tb_file_writ(file->file_ref, (tb_byte_t const*)data, size); } static tb_void_t transcode_write(xm_io_file* file, tb_char_t const* data, tb_size_t size) { - tb_assert(file && data); + tb_assert(file && data && xm_io_file_is_file(file) && !xm_io_file_is_closed(file)); tb_buffer_t buf; tb_assert_and_check_return(tb_buffer_init(&buf)); @@ -64,10 +64,10 @@ static tb_void_t transcode_write(xm_io_file* file, tb_char_t const* data, tb_siz static tb_void_t std_write(xm_io_file* file, tb_char_t const* data, tb_size_t size) { - tb_assert(file && data); + tb_assert(file && data && xm_io_file_is_std(file) && !xm_io_file_is_closed(file)); tb_size_t type = (file->type & ~XM_IO_FILE_FLAG_TTY); - tb_assert_and_check_return(type != XM_IO_FILE_TYPE_STDIN); + tb_check_return(type != XM_IO_FILE_TYPE_STDIN); #ifdef TB_CONFIG_OS_WINDOWS HANDLE handle = INVALID_HANDLE_VALUE; diff --git a/core/src/xmake/io/std.c b/core/src/xmake/io/std.c index 0e5ed2e12..d97ae3ef8 100644 --- a/core/src/xmake/io/std.c +++ b/core/src/xmake/io/std.c @@ -98,6 +98,9 @@ static void xm_init(lua_State* lua, tb_size_t type) case XM_IO_FILE_TYPE_STDERR: path = "/dev/stderr"; break; } #endif + + tb_assert(name && path && fp); + xm_io_file* file = xm_io_newfile(lua); lua_setfield(lua, -2, name); file->encoding = TB_CHARSET_TYPE_UTF8; |
