Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use uv helper to get handle/request struct size #569

Merged
merged 2 commits into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/async.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/check.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/dns.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
72 changes: 36 additions & 36 deletions src/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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;
Expand All @@ -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);
}
Expand All @@ -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);
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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);
}
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/fs_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/fs_poll.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/idle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading