From fafd31527a7ebedfaaaee6a2d26fcd977d532beb Mon Sep 17 00:00:00 2001 From: Sid Date: Wed, 29 Sep 2021 10:48:31 +0800 Subject: [PATCH 1/2] uv_handle_size() instead of sizeof(*handle) --- src/async.c | 2 +- src/check.c | 2 +- src/fs_event.c | 2 +- src/fs_poll.c | 2 +- src/idle.c | 2 +- src/pipe.c | 2 +- src/poll.c | 4 ++-- src/prepare.c | 2 +- src/process.c | 2 +- src/signal.c | 2 +- src/tcp.c | 2 +- src/timer.c | 2 +- src/tty.c | 2 +- src/udp.c | 2 +- 14 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/async.c b/src/async.c index c27be20e..db25ce45 100644 --- a/src/async.c +++ b/src/async.c @@ -36,7 +36,7 @@ static int luv_new_async(lua_State* L) { int ret; luv_ctx_t* ctx = luv_context(L); luaL_checktype(L, 1, LUA_TFUNCTION); - handle = (uv_async_t*)luv_newuserdata(L, sizeof(*handle)); + handle = (uv_async_t*)luv_newuserdata(L, uv_handle_size(UV_ASYNC)); ret = uv_async_init(ctx->loop, handle, luv_async_cb); if (ret < 0) { lua_pop(L, 1); diff --git a/src/check.c b/src/check.c index 77f2ac53..25b533cb 100644 --- a/src/check.c +++ b/src/check.c @@ -24,7 +24,7 @@ static uv_check_t* luv_check_check(lua_State* L, int index) { static int luv_new_check(lua_State* L) { luv_ctx_t* ctx = luv_context(L); - uv_check_t* handle = (uv_check_t*)luv_newuserdata(L, sizeof(*handle)); + uv_check_t* handle = (uv_check_t*)luv_newuserdata(L, uv_handle_size(UV_CHECK)); int ret = uv_check_init(ctx->loop, handle); if (ret < 0) { lua_pop(L, 1); diff --git a/src/fs_event.c b/src/fs_event.c index 0bb4d633..1779e795 100644 --- a/src/fs_event.c +++ b/src/fs_event.c @@ -25,7 +25,7 @@ static uv_fs_event_t* luv_check_fs_event(lua_State* L, int index) { static int luv_new_fs_event(lua_State* L) { luv_ctx_t* ctx = luv_context(L); - uv_fs_event_t* handle = (uv_fs_event_t*)luv_newuserdata(L, sizeof(*handle)); + uv_fs_event_t* handle = (uv_fs_event_t*)luv_newuserdata(L, uv_handle_size(UV_FS_EVENT)); int ret = uv_fs_event_init(ctx->loop, handle); if (ret < 0) { lua_pop(L, 1); diff --git a/src/fs_poll.c b/src/fs_poll.c index e0c6d839..723b9c29 100644 --- a/src/fs_poll.c +++ b/src/fs_poll.c @@ -25,7 +25,7 @@ static uv_fs_poll_t* luv_check_fs_poll(lua_State* L, int index) { static int luv_new_fs_poll(lua_State* L) { luv_ctx_t* ctx = luv_context(L); - uv_fs_poll_t* handle = (uv_fs_poll_t*)luv_newuserdata(L, sizeof(*handle)); + uv_fs_poll_t* handle = (uv_fs_poll_t*)luv_newuserdata(L, uv_handle_size(UV_FS_POLL)); int ret = uv_fs_poll_init(ctx->loop, handle); if (ret < 0) { lua_pop(L, 1); diff --git a/src/idle.c b/src/idle.c index 725945e7..fa543ac5 100644 --- a/src/idle.c +++ b/src/idle.c @@ -24,7 +24,7 @@ static uv_idle_t* luv_check_idle(lua_State* L, int index) { static int luv_new_idle(lua_State* L) { luv_ctx_t* ctx = luv_context(L); - uv_idle_t* handle = (uv_idle_t*)luv_newuserdata(L, sizeof(*handle)); + uv_idle_t* handle = (uv_idle_t*)luv_newuserdata(L, uv_handle_size(UV_IDLE)); int ret = uv_idle_init(ctx->loop, handle); if (ret < 0) { lua_pop(L, 1); diff --git a/src/pipe.c b/src/pipe.c index 9dcb3835..38780ace 100644 --- a/src/pipe.c +++ b/src/pipe.c @@ -27,7 +27,7 @@ static int luv_new_pipe(lua_State* L) { int ipc, ret; luv_ctx_t* ctx = luv_context(L); ipc = luv_optboolean(L, 1, 0); - handle = (uv_pipe_t*)luv_newuserdata(L, sizeof(*handle)); + handle = (uv_pipe_t*)luv_newuserdata(L, uv_handle_size(UV_NAMED_PIPE)); ret = uv_pipe_init(ctx->loop, handle, ipc); if (ret < 0) { lua_pop(L, 1); diff --git a/src/poll.c b/src/poll.c index 1a8597d4..972de9cf 100644 --- a/src/poll.c +++ b/src/poll.c @@ -25,7 +25,7 @@ static uv_poll_t* luv_check_poll(lua_State* L, int index) { static int luv_new_poll(lua_State* L) { luv_ctx_t* ctx = luv_context(L); int fd = luaL_checkinteger(L, 1); - uv_poll_t* handle = (uv_poll_t*)luv_newuserdata(L, sizeof(*handle)); + uv_poll_t* handle = (uv_poll_t*)luv_newuserdata(L, uv_handle_size(UV_POLL)); int ret = uv_poll_init(ctx->loop, handle, fd); if (ret < 0) { lua_pop(L, 1); @@ -38,7 +38,7 @@ static int luv_new_poll(lua_State* L) { static int luv_new_socket_poll(lua_State* L) { luv_ctx_t* ctx = luv_context(L); int fd = luaL_checkinteger(L, 1); - uv_poll_t* handle = (uv_poll_t*)luv_newuserdata(L, sizeof(*handle)); + uv_poll_t* handle = (uv_poll_t*)luv_newuserdata(L, uv_handle_size(UV_POLL)); int ret = uv_poll_init_socket(ctx->loop, handle, fd); if (ret < 0) { lua_pop(L, 1); diff --git a/src/prepare.c b/src/prepare.c index 6f8ae07b..ada86557 100644 --- a/src/prepare.c +++ b/src/prepare.c @@ -24,7 +24,7 @@ static uv_prepare_t* luv_check_prepare(lua_State* L, int index) { static int luv_new_prepare(lua_State* L) { luv_ctx_t* ctx = luv_context(L); - uv_prepare_t* handle = (uv_prepare_t*)luv_newuserdata(L, sizeof(*handle)); + uv_prepare_t* handle = (uv_prepare_t*)luv_newuserdata(L, uv_handle_size(UV_PREPARE)); int ret = uv_prepare_init(ctx->loop, handle); if (ret < 0) { lua_pop(L, 1); diff --git a/src/process.c b/src/process.c index 2fb37a99..6e429af8 100644 --- a/src/process.c +++ b/src/process.c @@ -277,7 +277,7 @@ static int luv_spawn(lua_State* L) { // the uv_process_t userdata doesn't get treated as the 3rd argument lua_settop(L, 3); - handle = (uv_process_t*)luv_newuserdata(L, sizeof(*handle)); + handle = (uv_process_t*)luv_newuserdata(L, uv_handle_size(UV_PROCESS)); handle->type = UV_PROCESS; handle->data = luv_setup_handle(L, ctx); diff --git a/src/signal.c b/src/signal.c index 4a1fa04a..2008d796 100644 --- a/src/signal.c +++ b/src/signal.c @@ -24,7 +24,7 @@ static uv_signal_t* luv_check_signal(lua_State* L, int index) { static int luv_new_signal(lua_State* L) { luv_ctx_t* ctx = luv_context(L); - uv_signal_t* handle = (uv_signal_t*)luv_newuserdata(L, sizeof(*handle)); + uv_signal_t* handle = (uv_signal_t*)luv_newuserdata(L, uv_handle_size(UV_SIGNAL)); int ret = uv_signal_init(ctx->loop, handle); if (ret < 0) { lua_pop(L, 1); diff --git a/src/tcp.c b/src/tcp.c index 51286a32..a6bb95d9 100644 --- a/src/tcp.c +++ b/src/tcp.c @@ -27,7 +27,7 @@ static int luv_new_tcp(lua_State* L) { int ret; luv_ctx_t* ctx = luv_context(L); lua_settop(L, 1); - handle = (uv_tcp_t*)luv_newuserdata(L, sizeof(*handle)); + handle = (uv_tcp_t*)luv_newuserdata(L, uv_handle_size(UV_TCP)); #if LUV_UV_VERSION_GEQ(1, 7, 0) if (lua_isnoneornil(L, 1)) { ret = uv_tcp_init(ctx->loop, handle); diff --git a/src/timer.c b/src/timer.c index 3c843751..c5943fe7 100644 --- a/src/timer.c +++ b/src/timer.c @@ -24,7 +24,7 @@ static uv_timer_t* luv_check_timer(lua_State* L, int index) { static int luv_new_timer(lua_State* L) { luv_ctx_t* ctx = luv_context(L); - uv_timer_t* handle = (uv_timer_t*) luv_newuserdata(L, sizeof(*handle)); + uv_timer_t* handle = (uv_timer_t*) luv_newuserdata(L, uv_handle_size(UV_TIMER)); int ret = uv_timer_init(ctx->loop, handle); if (ret < 0) { lua_pop(L, 1); diff --git a/src/tty.c b/src/tty.c index 93c1c1e9..5b6ac268 100644 --- a/src/tty.c +++ b/src/tty.c @@ -29,7 +29,7 @@ static int luv_new_tty(lua_State* L) { uv_file fd = luaL_checkinteger(L, 1); luaL_checktype(L, 2, LUA_TBOOLEAN); readable = lua_toboolean(L, 2); - handle = (uv_tty_t*)luv_newuserdata(L, sizeof(*handle)); + handle = (uv_tty_t*)luv_newuserdata(L, uv_handle_size(UV_TTY)); ret = uv_tty_init(ctx->loop, handle, fd, readable); if (ret < 0) { lua_pop(L, 1); diff --git a/src/udp.c b/src/udp.c index ae2fce2b..d017a0e0 100644 --- a/src/udp.c +++ b/src/udp.c @@ -25,7 +25,7 @@ static uv_udp_t* luv_check_udp(lua_State* L, int index) { static int luv_new_udp(lua_State* L) { luv_ctx_t* ctx = luv_context(L); lua_settop(L, 1); - uv_udp_t* handle = (uv_udp_t*)luv_newuserdata(L, sizeof(*handle)); + uv_udp_t* handle = (uv_udp_t*)luv_newuserdata(L, uv_handle_size(UV_UDP)); int ret; #if LUV_UV_VERSION_GEQ(1, 39, 0) // TODO: This default can potentially be increased, but it's From 9ea42cf621590aa3895c58c8a34411f36b62c330 Mon Sep 17 00:00:00 2001 From: Sid Date: Wed, 29 Sep 2021 11:18:41 +0800 Subject: [PATCH 2/2] uv_req_size() instead of sizeof(*req) --- src/dns.c | 4 +-- src/fs.c | 72 ++++++++++++++++++++++++++-------------------------- src/misc.c | 2 +- src/pipe.c | 2 +- src/stream.c | 6 ++--- src/tcp.c | 2 +- src/udp.c | 2 +- 7 files changed, 45 insertions(+), 45 deletions(-) diff --git a/src/dns.c b/src/dns.c index da9b4fdb..fbc8c405 100644 --- a/src/dns.c +++ b/src/dns.c @@ -192,7 +192,7 @@ static int luv_getaddrinfo(lua_State* L) { return luaL_argerror(L, 4, "callback must be provided"); } #endif - req = (uv_getaddrinfo_t*)lua_newuserdata(L, sizeof(*req)); + req = (uv_getaddrinfo_t*)lua_newuserdata(L, uv_req_size(UV_GETADDRINFO)); req->data = luv_setup_req(L, ctx, ref); ret = uv_getaddrinfo(ctx->loop, req, ref == LUA_NOREF ? NULL : luv_getaddrinfo_cb, node, service, hints); @@ -295,7 +295,7 @@ static int luv_getnameinfo(lua_State* L) { } #endif - req = (uv_getnameinfo_t*)lua_newuserdata(L, sizeof(*req)); + req = (uv_getnameinfo_t*)lua_newuserdata(L, uv_req_size(UV_GETNAMEINFO)); req->data = luv_setup_req(L, ctx, ref); ret = uv_getnameinfo(ctx->loop, req, ref == LUA_NOREF ? NULL : luv_getnameinfo_cb, (struct sockaddr*)&addr, flags); diff --git a/src/fs.c b/src/fs.c index 321189e9..0c36dccd 100644 --- a/src/fs.c +++ b/src/fs.c @@ -459,7 +459,7 @@ static int luv_fs_close(lua_State* L) { luv_ctx_t* ctx = luv_context(L); uv_file file = luaL_checkinteger(L, 1); int ref = luv_check_continuation(L, 2); - uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, sizeof(*req)); + uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, uv_req_size(UV_FS)); req->data = luv_setup_req(L, ctx, ref); FS_CALL(close, req, file); } @@ -470,7 +470,7 @@ static int luv_fs_open(lua_State* L) { int flags = luv_check_flags(L, 2); int mode = luaL_checkinteger(L, 3); int ref = luv_check_continuation(L, 4); - uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, sizeof(*req)); + uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, uv_req_size(UV_FS)); req->data = luv_setup_req(L, ctx, ref); FS_CALL(open, req, path, flags, mode); } @@ -496,7 +496,7 @@ static int luv_fs_read(lua_State* L) { return luaL_error(L, "Failure to allocate buffer"); } uv_buf_t buf = uv_buf_init(data, len); - uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, sizeof(*req)); + uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, uv_req_size(UV_FS)); req->data = luv_setup_req(L, ctx, ref); // TODO: find out why we can't just use req->ptr for the base ((luv_req_t*)req->data)->data = buf.base; @@ -507,7 +507,7 @@ static int luv_fs_unlink(lua_State* L) { luv_ctx_t* ctx = luv_context(L); const char* path = luaL_checkstring(L, 1); int ref = luv_check_continuation(L, 2); - uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, sizeof(*req)); + uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, uv_req_size(UV_FS)); req->data = luv_setup_req(L, ctx, ref); FS_CALL(unlink, req, path); } @@ -526,7 +526,7 @@ static int luv_fs_write(lua_State* L) { offset = luaL_optinteger(L, 3, offset); ref = luv_check_continuation(L, 4); } - uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, sizeof(*req)); + uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, uv_req_size(UV_FS)); req->data = luv_setup_req(L, ctx, ref); size_t count; uv_buf_t* bufs = luv_check_bufs(L, 2, &count, (luv_req_t*)req->data); @@ -541,7 +541,7 @@ static int luv_fs_mkdir(lua_State* L) { const char* path = luaL_checkstring(L, 1); int mode = luaL_checkinteger(L, 2); int ref = luv_check_continuation(L, 3); - uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, sizeof(*req)); + uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, uv_req_size(UV_FS)); req->data = luv_setup_req(L, ctx, ref); FS_CALL(mkdir, req, path, mode); } @@ -550,7 +550,7 @@ static int luv_fs_mkdtemp(lua_State* L) { luv_ctx_t* ctx = luv_context(L); const char* tpl = luaL_checkstring(L, 1); int ref = luv_check_continuation(L, 2); - uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, sizeof(*req)); + uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, uv_req_size(UV_FS)); req->data = luv_setup_req(L, ctx, ref); FS_CALL(mkdtemp, req, tpl); } @@ -560,7 +560,7 @@ static int luv_fs_mkstemp(lua_State* L) { luv_ctx_t* ctx = luv_context(L); const char* tpl = luaL_checkstring(L, 1); int ref = luv_check_continuation(L, 2); - uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, sizeof(*req)); + uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, uv_req_size(UV_FS)); req->data = luv_setup_req(L, ctx, ref); FS_CALL(mkstemp, req, tpl); } @@ -570,7 +570,7 @@ static int luv_fs_rmdir(lua_State* L) { luv_ctx_t* ctx = luv_context(L); const char* path = luaL_checkstring(L, 1); int ref = luv_check_continuation(L, 2); - uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, sizeof(*req)); + uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, uv_req_size(UV_FS)); req->data = luv_setup_req(L, ctx, ref); FS_CALL(rmdir, req, path); } @@ -580,7 +580,7 @@ static int luv_fs_scandir(lua_State* L) { const char* path = luaL_checkstring(L, 1); int flags = 0; // TODO: find out what these flags are. int ref = luv_check_continuation(L, 2); - uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, sizeof(*req)); + uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, uv_req_size(UV_FS)); req->data = luv_setup_req(L, ctx, ref); FS_CALL(scandir, req, path, flags); } @@ -603,7 +603,7 @@ static int luv_fs_stat(lua_State* L) { luv_ctx_t* ctx = luv_context(L); const char* path = luaL_checkstring(L, 1); int ref = luv_check_continuation(L, 2); - uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, sizeof(*req)); + uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, uv_req_size(UV_FS)); req->data = luv_setup_req(L, ctx, ref); FS_CALL(stat, req, path); } @@ -612,7 +612,7 @@ static int luv_fs_fstat(lua_State* L) { luv_ctx_t* ctx = luv_context(L); uv_file file = luaL_checkinteger(L, 1); int ref = luv_check_continuation(L, 2); - uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, sizeof(*req)); + uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, uv_req_size(UV_FS)); req->data = luv_setup_req(L, ctx, ref); FS_CALL(fstat, req, file); } @@ -621,7 +621,7 @@ static int luv_fs_lstat(lua_State* L) { luv_ctx_t* ctx = luv_context(L); const char* path = luaL_checkstring(L, 1); int ref = luv_check_continuation(L, 2); - uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, sizeof(*req)); + uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, uv_req_size(UV_FS)); req->data = luv_setup_req(L, ctx, ref); FS_CALL(lstat, req, path); } @@ -631,7 +631,7 @@ static int luv_fs_rename(lua_State* L) { const char* path = luaL_checkstring(L, 1); const char* new_path = luaL_checkstring(L, 2); int ref = luv_check_continuation(L, 3); - uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, sizeof(*req)); + uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, uv_req_size(UV_FS)); req->data = luv_setup_req(L, ctx, ref); // ref the dest path so that we can print it in the error message lua_pushvalue(L, 2); @@ -643,7 +643,7 @@ static int luv_fs_fsync(lua_State* L) { luv_ctx_t* ctx = luv_context(L); uv_file file = luaL_checkinteger(L, 1); int ref = luv_check_continuation(L, 2); - uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, sizeof(*req)); + uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, uv_req_size(UV_FS)); req->data = luv_setup_req(L, ctx, ref); FS_CALL(fsync, req, file); } @@ -652,7 +652,7 @@ static int luv_fs_fdatasync(lua_State* L) { luv_ctx_t* ctx = luv_context(L); uv_file file = luaL_checkinteger(L, 1); int ref = luv_check_continuation(L, 2); - uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, sizeof(*req)); + uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, uv_req_size(UV_FS)); req->data = luv_setup_req(L, ctx, ref); FS_CALL(fdatasync, req, file); } @@ -662,7 +662,7 @@ static int luv_fs_ftruncate(lua_State* L) { uv_file file = luaL_checkinteger(L, 1); int64_t offset = luaL_checkinteger(L, 2); int ref = luv_check_continuation(L, 3); - uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, sizeof(*req)); + uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, uv_req_size(UV_FS)); req->data = luv_setup_req(L, ctx, ref); FS_CALL(ftruncate, req, file, offset); } @@ -674,7 +674,7 @@ static int luv_fs_sendfile(lua_State* L) { int64_t in_offset = luaL_checkinteger(L, 3); size_t length = luaL_checkinteger(L, 4); int ref = luv_check_continuation(L, 5); - uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, sizeof(*req)); + uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, uv_req_size(UV_FS)); req->data = luv_setup_req(L, ctx, ref); FS_CALL(sendfile, req, out_fd, in_fd, in_offset, length); } @@ -684,7 +684,7 @@ static int luv_fs_access(lua_State* L) { const char* path = luaL_checkstring(L, 1); int amode = luv_check_amode(L, 2); int ref = luv_check_continuation(L, 3); - uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, sizeof(*req)); + uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, uv_req_size(UV_FS)); req->data = luv_setup_req(L, ctx, ref); FS_CALL(access, req, path, amode); } @@ -694,7 +694,7 @@ static int luv_fs_chmod(lua_State* L) { const char* path = luaL_checkstring(L, 1); int mode = luaL_checkinteger(L, 2); int ref = luv_check_continuation(L, 3); - uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, sizeof(*req)); + uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, uv_req_size(UV_FS)); req->data = luv_setup_req(L, ctx, ref); FS_CALL(chmod, req, path, mode); } @@ -704,7 +704,7 @@ static int luv_fs_fchmod(lua_State* L) { uv_file file = luaL_checkinteger(L, 1); int mode = luaL_checkinteger(L, 2); int ref = luv_check_continuation(L, 3); - uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, sizeof(*req)); + uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, uv_req_size(UV_FS)); req->data = luv_setup_req(L, ctx, ref); FS_CALL(fchmod, req, file, mode); } @@ -715,7 +715,7 @@ static int luv_fs_utime(lua_State* L) { double atime = luaL_checknumber(L, 2); double mtime = luaL_checknumber(L, 3); int ref = luv_check_continuation(L, 4); - uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, sizeof(*req)); + uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, uv_req_size(UV_FS)); req->data = luv_setup_req(L, ctx, ref); FS_CALL(utime, req, path, atime, mtime); } @@ -726,7 +726,7 @@ static int luv_fs_futime(lua_State* L) { double atime = luaL_checknumber(L, 2); double mtime = luaL_checknumber(L, 3); int ref = luv_check_continuation(L, 4); - uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, sizeof(*req)); + uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, uv_req_size(UV_FS)); req->data = luv_setup_req(L, ctx, ref); FS_CALL(futime, req, file, atime, mtime); } @@ -738,7 +738,7 @@ static int luv_fs_lutime(lua_State* L) { double atime = luaL_checknumber(L, 2); double mtime = luaL_checknumber(L, 3); int ref = luv_check_continuation(L, 4); - uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, sizeof(*req)); + uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, uv_req_size(UV_FS)); req->data = luv_setup_req(L, ctx, ref); FS_CALL(lutime, req, path, atime, mtime); } @@ -749,7 +749,7 @@ static int luv_fs_link(lua_State* L) { const char* path = luaL_checkstring(L, 1); const char* new_path = luaL_checkstring(L, 2); int ref = luv_check_continuation(L, 3); - uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, sizeof(*req)); + uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, uv_req_size(UV_FS)); req->data = luv_setup_req(L, ctx, ref); // ref the dest path so that we can print it in the error message lua_pushvalue(L, 2); @@ -783,7 +783,7 @@ static int luv_fs_symlink(lua_State* L) { } ref = luv_check_continuation(L, 4); } - req = (uv_fs_t*)lua_newuserdata(L, sizeof(*req)); + req = (uv_fs_t*)lua_newuserdata(L, uv_req_size(UV_FS)); req->data = luv_setup_req(L, ctx, ref); // ref the dest path so that we can print it in the error message lua_pushvalue(L, 2); @@ -795,7 +795,7 @@ static int luv_fs_readlink(lua_State* L) { luv_ctx_t* ctx = luv_context(L); const char* path = luaL_checkstring(L, 1); int ref = luv_check_continuation(L, 2); - uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, sizeof(*req)); + uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, uv_req_size(UV_FS)); req->data = luv_setup_req(L, ctx, ref); FS_CALL(readlink, req, path); } @@ -805,7 +805,7 @@ static int luv_fs_realpath(lua_State* L) { luv_ctx_t* ctx = luv_context(L); const char* path = luaL_checkstring(L, 1); int ref = luv_check_continuation(L, 2); - uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, sizeof(*req)); + uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, uv_req_size(UV_FS)); req->data = luv_setup_req(L, ctx, ref); FS_CALL(realpath, req, path); } @@ -817,7 +817,7 @@ static int luv_fs_chown(lua_State* L) { uv_uid_t uid = luaL_checkinteger(L, 2); uv_uid_t gid = luaL_checkinteger(L, 3); int ref = luv_check_continuation(L, 4); - uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, sizeof(*req)); + uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, uv_req_size(UV_FS)); req->data = luv_setup_req(L, ctx, ref); FS_CALL(chown, req, path, uid, gid); } @@ -828,7 +828,7 @@ static int luv_fs_fchown(lua_State* L) { uv_uid_t uid = luaL_checkinteger(L, 2); uv_uid_t gid = luaL_checkinteger(L, 3); int ref = luv_check_continuation(L, 4); - uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, sizeof(*req)); + uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, uv_req_size(UV_FS)); req->data = luv_setup_req(L, ctx, ref); FS_CALL(fchown, req, file, uid, gid); } @@ -840,7 +840,7 @@ static int luv_fs_lchown(lua_State* L) { uv_uid_t uid = luaL_checkinteger(L, 2); uv_uid_t gid = luaL_checkinteger(L, 3); int ref = luv_check_continuation(L, 4); - uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, sizeof(*req)); + uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, uv_req_size(UV_FS)); req->data = luv_setup_req(L, ctx, ref); FS_CALL(lchown, req, path, uid, gid); } @@ -878,7 +878,7 @@ static int luv_fs_copyfile(lua_State*L) { } ref = luv_check_continuation(L, 4); } - req = (uv_fs_t*)lua_newuserdata(L, sizeof(*req)); + req = (uv_fs_t*)lua_newuserdata(L, uv_req_size(UV_FS)); req->data = luv_setup_req(L, ctx, ref); // ref the dest path so that we can print it in the error message lua_pushvalue(L, 2); @@ -898,7 +898,7 @@ static int luv_fs_opendir(lua_State* L) { const char* path = luaL_checkstring(L, 1); int ref = luv_check_continuation(L, 2); size_t nentries = luaL_optinteger(L, 3, 1); - uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, sizeof(*req)); + uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, uv_req_size(UV_FS)); req->data = luv_setup_req(L, ctx, ref); //make data_ref to nentries @@ -914,7 +914,7 @@ static int luv_fs_readdir(lua_State* L) { uv_dir_t* dir = luv_check_dir(L, 1); int ref = luv_check_continuation(L, 2); - req = (uv_fs_t*)lua_newuserdata(L, sizeof(*req)); + req = (uv_fs_t*)lua_newuserdata(L, uv_req_size(UV_FS)); req->data = luv_setup_req(L, ctx, ref); FS_CALL(readdir, req, dir); } @@ -923,7 +923,7 @@ static int luv_fs_closedir(lua_State* L) { luv_ctx_t* ctx = luv_context(L); uv_dir_t* dir = luv_check_dir(L, 1); int ref = luv_check_continuation(L, 2); - uv_fs_t *req = (uv_fs_t*)lua_newuserdata(L, sizeof(*req)); + uv_fs_t *req = (uv_fs_t*)lua_newuserdata(L, uv_req_size(UV_FS)); req->data = luv_setup_req(L, ctx, ref); lua_pushfstring(L, "uv_dir:%p", dir); lua_pushnil(L); @@ -962,7 +962,7 @@ static int luv_fs_statfs(lua_State* L) { luv_ctx_t* ctx = luv_context(L); const char* path = luaL_checkstring(L, 1); int ref = luv_check_continuation(L, 2); - uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, sizeof(*req)); + uv_fs_t* req = (uv_fs_t*)lua_newuserdata(L, uv_req_size(UV_FS)); req->data = luv_setup_req(L, ctx, ref); FS_CALL(statfs, req, path); } diff --git a/src/misc.c b/src/misc.c index d1b06a8a..0bf71d5c 100644 --- a/src/misc.c +++ b/src/misc.c @@ -728,7 +728,7 @@ static int luv_random(lua_State* L) { // ref buffer int buf_ref = luaL_ref(L, LUA_REGISTRYINDEX); - uv_random_t* req = (uv_random_t*)lua_newuserdata(L, sizeof(*req)); + uv_random_t* req = (uv_random_t*)lua_newuserdata(L, uv_req_size(UV_RANDOM)); req->data = luv_setup_req(L, ctx, cb_ref); ((luv_req_t*)req->data)->req_ref = buf_ref; diff --git a/src/pipe.c b/src/pipe.c index 38780ace..aeac40b0 100644 --- a/src/pipe.c +++ b/src/pipe.c @@ -56,7 +56,7 @@ static int luv_pipe_connect(lua_State* L) { uv_pipe_t* handle = luv_check_pipe(L, 1); const char* name = luaL_checkstring(L, 2); int ref = luv_check_continuation(L, 3); - uv_connect_t* req = (uv_connect_t*)lua_newuserdata(L, sizeof(*req)); + uv_connect_t* req = (uv_connect_t*)lua_newuserdata(L, uv_req_size(UV_CONNECT)); req->data = luv_setup_req(L, ctx, ref); uv_pipe_connect(req, handle, name, luv_connect_cb); return 1; diff --git a/src/stream.c b/src/stream.c index 170d9df1..aecd06a5 100644 --- a/src/stream.c +++ b/src/stream.c @@ -46,7 +46,7 @@ static int luv_shutdown(lua_State* L) { luv_ctx_t* ctx = luv_context(L); uv_stream_t* handle = luv_check_stream(L, 1); int ref = luv_check_continuation(L, 2); - uv_shutdown_t* req = (uv_shutdown_t*)lua_newuserdata(L, sizeof(*req)); + uv_shutdown_t* req = (uv_shutdown_t*)lua_newuserdata(L, uv_req_size(UV_SHUTDOWN)); int ret; req->data = luv_setup_req(L, ctx, ref); ret = uv_shutdown(req, handle, luv_shutdown_cb); @@ -142,7 +142,7 @@ static int luv_write(lua_State* L) { uv_write_t* req; int ret, ref; ref = luv_check_continuation(L, 3); - req = (uv_write_t *)lua_newuserdata(L, sizeof(*req)); + req = (uv_write_t *)lua_newuserdata(L, uv_req_size(UV_WRITE)); req->data = (luv_req_t*)luv_setup_req(L, ctx, ref); size_t count; uv_buf_t* bufs = luv_check_bufs(L, 2, &count, (luv_req_t*)req->data); @@ -164,7 +164,7 @@ static int luv_write2(lua_State* L) { uv_stream_t* send_handle; send_handle = luv_check_stream(L, 3); ref = luv_check_continuation(L, 4); - req = (uv_write_t *)lua_newuserdata(L, sizeof(*req)); + req = (uv_write_t *)lua_newuserdata(L, uv_req_size(UV_WRITE)); req->data = luv_setup_req(L, ctx, ref); size_t count; uv_buf_t* bufs = luv_check_bufs(L, 2, &count, (luv_req_t*)req->data); diff --git a/src/tcp.c b/src/tcp.c index a6bb95d9..c346b7f1 100644 --- a/src/tcp.c +++ b/src/tcp.c @@ -190,7 +190,7 @@ static int luv_tcp_connect(lua_State* L) { } ref = luv_check_continuation(L, 4); - req = (uv_connect_t*)lua_newuserdata(L, sizeof(*req)); + req = (uv_connect_t*)lua_newuserdata(L, uv_req_size(UV_CONNECT)); req->data = luv_setup_req(L, lhandle->ctx, ref); ret = uv_tcp_connect(req, handle, (struct sockaddr*)&addr, luv_connect_cb); if (ret < 0) { diff --git a/src/udp.c b/src/udp.c index d017a0e0..d13372ff 100644 --- a/src/udp.c +++ b/src/udp.c @@ -294,7 +294,7 @@ static int luv_udp_send(lua_State* L) { luv_handle_t* lhandle = handle->data; addr_ptr = luv_check_addr(L, &addr, 3, 4); ref = luv_check_continuation(L, 5); - req = (uv_udp_send_t*)lua_newuserdata(L, sizeof(*req)); + req = (uv_udp_send_t*)lua_newuserdata(L, uv_req_size(UV_UDP_SEND)); req->data = luv_setup_req(L, lhandle->ctx, ref); size_t count; uv_buf_t* bufs = luv_check_bufs(L, 2, &count, (luv_req_t*)req->data);