summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorruki <[email protected]>2020-08-04 00:33:36 +0800
committerruki <[email protected]>2020-08-04 00:33:36 +0800
commit8b08fbb9f5f0f54dd1232f4bf387932116dde47f (patch)
tree4fd29d81f1bbd9d5beb7397e15340c40e0f00284 /core/src
parent03573469f84c12aa8f62b3c777f409c5bd8a679c (diff)
remove lightuserdata for file
Diffstat (limited to 'core/src')
-rw-r--r--core/src/xmake/io/file_close.c4
-rw-r--r--core/src/xmake/io/file_open.c5
2 files changed, 3 insertions, 6 deletions
diff --git a/core/src/xmake/io/file_close.c b/core/src/xmake/io/file_close.c
index 6b4380bdf..98b2f1506 100644
--- a/core/src/xmake/io/file_close.c
+++ b/core/src/xmake/io/file_close.c
@@ -81,8 +81,8 @@ tb_int_t xm_io_file_close(lua_State* lua)
tb_buffer_exit(&file->rcache);
tb_buffer_exit(&file->wcache);
- // exit file
- tb_free(file);
+ // gc will free it if no any refs for lua_newuserdata()
+ // ...
// ok
lua_pushboolean(lua, tb_true);
diff --git a/core/src/xmake/io/file_open.c b/core/src/xmake/io/file_open.c
index 1c520a180..a342d4809 100644
--- a/core/src/xmake/io/file_open.c
+++ b/core/src/xmake/io/file_open.c
@@ -275,7 +275,7 @@ tb_int_t xm_io_file_open(lua_State* lua)
}
// make file
- xm_io_file_t* file = tb_malloc0_type(xm_io_file_t);
+ xm_io_file_t* file = (xm_io_file_t*)lua_newuserdata(lua, sizeof(xm_io_file_t));
tb_assert_and_check_return_val(file, 0);
// init file
@@ -289,8 +289,5 @@ tb_int_t xm_io_file_open(lua_State* lua)
// init the read/write line cache buffer
tb_buffer_init(&file->rcache);
tb_buffer_init(&file->wcache);
-
- // ok
- lua_pushlightuserdata(lua, (tb_pointer_t)file);
return 1;
}