Skip to content

Commit

Permalink
Merge branch 'luvit:master' into fix/async-arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
javalikescript authored Jan 18, 2025
2 parents 5827281 + 7aeed6f commit bc90207
Show file tree
Hide file tree
Showing 16 changed files with 378 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .ci/install.bat
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Setlocal EnableDelayedExpansion EnableExtensions

if not defined LUAROCKS_URL set LUAROCKS_URL=https://luarocks.github.io/luarocks/releases
if not defined LUAROCKS_REPO set LUAROCKS_REPO=https://luarocks.org
if not defined LUA_URL set LUA_URL=http://www.lua.org/ftp
if not defined LUA_URL set LUA_URL=https://www.lua.org/ftp
if defined NOCOMPAT (
set COMPATFLAG=--nocompat
) else (
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ cmake_minimum_required(VERSION 3.10)
project (luv C ASM)

set(LUV_VERSION_MAJOR 1)
set(LUV_VERSION_MINOR 49)
set(LUV_VERSION_PATCH 2)
set(LUV_VERSION_MINOR 50)
set(LUV_VERSION_PATCH 0)
set(LUV_VERSION ${LUV_VERSION_MAJOR}.${LUV_VERSION_MINOR}.${LUV_VERSION_PATCH})

if(NOT ${CMAKE_VERSION} VERSION_LESS "3.5.0")
Expand Down
4 changes: 0 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
image:
- Visual Studio 2015
- Visual Studio 2022

platform:
Expand All @@ -23,9 +22,6 @@ matrix:
# Skip x86 for LuaRocks tests
- platform: x86
LUAROCKS_VER: 3.8.0
# Only test LuaRocks with latest MSVC
- image: Visual Studio 2015
LUAROCKS_VER: 3.8.0

cache:
- c:\lua -> appveyor.yml
Expand Down
2 changes: 1 addition & 1 deletion deps/libuv
Submodule libuv updated 60 files
+69 −66 .github/workflows/CI-unix.yml
+1 −1 .github/workflows/sanitizer.yml
+1 −0 .mailmap
+3 −1 AUTHORS
+3 −2 CMakeLists.txt
+82 −1 ChangeLog
+1 −0 LINKS.md
+3 −3 MAINTAINERS.md
+2 −1 Makefile.am
+2 −2 SUPPORTED_PLATFORMS.md
+1 −1 configure.ac
+5 −0 docs/src/fs_event.rst
+11 −0 docs/src/misc.rst
+25 −0 docs/src/threading.rst
+2 −0 docs/src/threadpool.rst
+9 −5 docs/src/timer.rst
+14 −0 docs/src/udp.rst
+12 −0 include/uv.h
+6 −0 include/uv/errno.h
+4 −1 include/uv/unix.h
+2 −2 include/uv/version.h
+1 −9 include/uv/win.h
+3 −0 src/fs-poll.c
+1 −1 src/idna.c
+1 −0 src/threadpool.c
+83 −0 src/unix/async.c
+47 −3 src/unix/core.c
+2 −18 src/unix/darwin-proctitle.c
+24 −0 src/unix/internal.h
+17 −12 src/unix/kqueue.c
+45 −30 src/unix/linux.c
+9 −21 src/unix/pipe.c
+98 −0 src/unix/thread.c
+201 −186 src/unix/udp.c
+22 −0 src/uv-common.c
+20 −0 src/uv-common.h
+8 −102 src/win/core.c
+4 −0 src/win/fs-event.c
+197 −8 src/win/fs.c
+9 −3 src/win/pipe.c
+74 −0 src/win/thread.c
+20 −1 src/win/udp.c
+68 −24 src/win/util.c
+0 −13 src/win/winapi.c
+54 −54 src/win/winapi.h
+0 −41 src/win/winsock.h
+14 −0 test/runner.c
+8 −1 test/test-fs-event.c
+54 −0 test/test-fs.c
+19 −7 test/test-idna.c
+10 −0 test/test-list.h
+9 −0 test/test-pipe-getsockname.c
+16 −0 test/test-platform-output.c
+2 −4 test/test-spawn.c
+189 −0 test/test-thread-name.c
+10 −0 test/test-thread.c
+3 −2 test/test-udp-mmsg.c
+17 −2 test/test-udp-multicast-join.c
+1 −0 test/test-udp-multicast-join6.c
+34 −6 test/test-udp-try-send.c
2 changes: 1 addition & 1 deletion deps/luajit
Submodule luajit updated 207 files
113 changes: 113 additions & 0 deletions docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -2469,6 +2469,54 @@ completed immediately.

**Returns:** `integer` or `fail`

### `uv.udp_try_send2(udp, messages, flags)`

> method form `udp:try_send2(messages, flags)`
**Parameters:**
- `udp`: `uv_udp_t userdata`
- `messages`: `table`
- `[1, 2, 3, ..., n]` : `table`
- `data` : `buffer`
- `addr` : `table`
- `ip` : `string`
- `port` : `integer`
- `flags`: `nil` (see below)
- `port`: `integer`

Like `uv.udp_try_send()`, but can send multiple datagrams.
Lightweight abstraction around `sendmmsg(2)`, with a `sendmsg(2)` fallback loop
for platforms that do not support the former. The `udp` handle must be fully
initialized, either from a `uv.udp_bind` call, another call that will bind
automatically (`udp_send`, `udp_try_send`, etc), or from `uv.udp_connect`.

`messages` should be an array-like table, where `addr` must be specified
if the `udp` has not been connected via `udp_connect`. Otherwise, `addr`
must be `nil`.

`flags` is reserved for future extension and must currently be `nil` or `0` or
`{}`.

Returns the number of messages sent successfully. An error will only be returned
if the first datagram failed to be sent.

**Returns:** `integer` or `fail`

```lua
-- If client:connect(...) was not called
local addr = { ip = "127.0.0.1", port = 1234 }
client:try_send2({
{ data = "Message 1", addr = addr },
{ data = "Message 2", addr = addr },
})

-- If client:connect(...) was called
client:try_send2({
{ data = "Message 1" },
{ data = "Message 2" },
})
```

### `uv.udp_recv_start(udp, callback)`

> method form `udp:recv_start(callback)`
Expand Down Expand Up @@ -3568,6 +3616,41 @@ Waits for the `thread` to finish executing its entry function.

**Returns:** `boolean` or `fail`

### `uv.thread_detach(thread)`

> method form `thread:detach()`
**Parameters:**
- `thread`: `luv_thread_t userdata`

Detaches a thread. Detached threads automatically release their resources upon
termination, eliminating the need for the application to call `uv.thread_join`.

**Returns:** `boolean` or `fail`

### `uv.thread_setname(name)`

**Parameters:**
- `name`: `string`

Sets the name of the current thread. Different platforms define different limits
on the max number of characters a thread name can be: Linux, IBM i (16), macOS
(64), Windows (32767), and NetBSD (32), etc. The name will be truncated
if `name` is larger than the limit of the platform.

**Returns:** `0` or `fail`

### `uv.thread_getname(thread)`

> method form `thread:getname()`
**Parameters:**
- `thread`: `luv_thread_t userdata`

Gets the name of the thread specified by `thread`.

**Returns:** `string` or `fail`

### `uv.sleep(msec)`

**Parameters:**
Expand Down Expand Up @@ -3679,6 +3762,36 @@ Returns the resource usage.
- `nvcsw` : `integer` (voluntary context switches)
- `nivcsw` : `integer` (involuntary context switches)

### `uv.getrusage_thread()`

Gets the resource usage measures for the calling thread.

**Note** Not supported on all platforms. May return `ENOTSUP`.
On macOS and Windows not all fields are set (the unsupported fields are filled
with zeroes).

**Returns:** `table` or `fail`
- `utime` : `table` (user CPU time used)
- `sec` : `integer`
- `usec` : `integer`
- `stime` : `table` (system CPU time used)
- `sec` : `integer`
- `usec` : `integer`
- `maxrss` : `integer` (maximum resident set size)
- `ixrss` : `integer` (integral shared memory size)
- `idrss` : `integer` (integral unshared data size)
- `isrss` : `integer` (integral unshared stack size)
- `minflt` : `integer` (page reclaims (soft page faults))
- `majflt` : `integer` (page faults (hard page faults))
- `nswap` : `integer` (swaps)
- `inblock` : `integer` (block input operations)
- `oublock` : `integer` (block output operations)
- `msgsnd` : `integer` (IPC messages sent)
- `msgrcv` : `integer` (IPC messages received)
- `nsignals` : `integer` (signals received)
- `nvcsw` : `integer` (voluntary context switches)
- `nivcsw` : `integer` (involuntary context switches)

### `uv.available_parallelism()`

Returns an estimate of the default amount of parallelism a program should use. Always returns a non-zero value.
Expand Down
25 changes: 19 additions & 6 deletions src/luv.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ static const luaL_Reg luv_functions[] = {
{"udp_set_ttl", luv_udp_set_ttl},
{"udp_send", luv_udp_send},
{"udp_try_send", luv_udp_try_send},
#if LUV_UV_VERSION_GEQ(1, 50, 0)
{"udp_try_send2", luv_udp_try_send2},
#endif
{"udp_recv_start", luv_udp_recv_start},
{"udp_recv_stop", luv_udp_recv_stop},
#if LUV_UV_VERSION_GEQ(1, 27, 0)
Expand Down Expand Up @@ -330,6 +333,9 @@ static const luaL_Reg luv_functions[] = {
{"setgid", luv_setgid},
#endif
{"getrusage", luv_getrusage},
#if LUV_UV_VERSION_GEQ(1, 50, 0)
{"getrusage_thread", luv_getrusage_thread},
#endif
{"guess_handle", luv_guess_handle},
{"hrtime", luv_hrtime},
{"interface_addresses", luv_interface_addresses},
Expand Down Expand Up @@ -396,6 +402,11 @@ static const luaL_Reg luv_functions[] = {
{"thread_getpriority", luv_thread_getpriority},
{"thread_setpriority", luv_thread_setpriority},
#endif
#if LUV_UV_VERSION_GEQ(1, 50, 0)
{"thread_detach", luv_thread_detach},
{"thread_getname", luv_thread_getname},
{"thread_setname", luv_thread_setname},
#endif

#if LUV_UV_VERSION_GEQ(1, 49, 0)
{"utf16_length_as_wtf8", luv_utf16_length_as_wtf8},
Expand Down Expand Up @@ -585,6 +596,9 @@ static const luaL_Reg luv_udp_methods[] = {
{"set_ttl", luv_udp_set_ttl},
{"send", luv_udp_send},
{"try_send", luv_udp_try_send},
#if LUV_UV_VERSION_GEQ(1, 50, 0)
{"try_send2", luv_udp_try_send2},
#endif
{"recv_start", luv_udp_recv_start},
{"recv_stop", luv_udp_recv_stop},
#if LUV_UV_VERSION_GEQ(1, 27, 0)
Expand Down Expand Up @@ -838,6 +852,11 @@ static int loop_gc(lua_State *L) {
while (uv_loop_close(loop)) {
uv_run(loop, UV_RUN_DEFAULT);
}
/* do cleanup in main thread */
lua_getglobal(L, "_THREAD");
if (lua_isnil(L, -1))
luv_work_cleanup();
lua_pop(L, 1);
return 0;
}

Expand Down Expand Up @@ -885,12 +904,6 @@ LUALIB_API int luaopen_luv (lua_State* L) {
if (ret < 0) {
return luaL_error(L, "%s: %s\n", uv_err_name(ret), uv_strerror(ret));
}

/* do cleanup in main thread */
lua_getglobal(L, "_THREAD");
if (lua_isnil(L, -1))
atexit(luv_work_cleanup);
lua_pop(L, 1);
}
// pcall is NULL, luv use default callback routine
if (ctx->cb_pcall==NULL) {
Expand Down
4 changes: 4 additions & 0 deletions src/luv.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@
#define MAX_TITLE_LENGTH (8192)
#endif

#ifndef MAX_THREAD_NAME_LENGTH
#define MAX_THREAD_NAME_LENGTH (8192)
#endif

// luv flags to control luv_CFpcall routine
#define LUVF_CALLBACK_NOEXIT 0x01 // Don't exit when LUA_ERRMEM
#define LUVF_CALLBACK_NOTRACEBACK 0x02 // Don't traceback when error
Expand Down
54 changes: 34 additions & 20 deletions src/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,61 +165,75 @@ static void luv_push_timeval_table(lua_State* L, const uv_timeval_t* t) {
lua_setfield(L, -2, "usec");
}

static int luv_getrusage(lua_State* L) {
uv_rusage_t rusage;
int ret = uv_getrusage(&rusage);
if (ret < 0) return luv_error(L, ret);
static void luv_push_rusage_table(lua_State* L, const uv_rusage_t* rusage) {
lua_createtable(L, 0, 16);
// user CPU time used
luv_push_timeval_table(L, &rusage.ru_utime);
luv_push_timeval_table(L, &rusage->ru_utime);
lua_setfield(L, -2, "utime");
// system CPU time used
luv_push_timeval_table(L, &rusage.ru_stime);
luv_push_timeval_table(L, &rusage->ru_stime);
lua_setfield(L, -2, "stime");
// maximum resident set size
lua_pushinteger(L, rusage.ru_maxrss);
lua_pushinteger(L, rusage->ru_maxrss);
lua_setfield(L, -2, "maxrss");
// integral shared memory size
lua_pushinteger(L, rusage.ru_ixrss);
lua_pushinteger(L, rusage->ru_ixrss);
lua_setfield(L, -2, "ixrss");
// integral unshared data size
lua_pushinteger(L, rusage.ru_idrss);
lua_pushinteger(L, rusage->ru_idrss);
lua_setfield(L, -2, "idrss");
// integral unshared stack size
lua_pushinteger(L, rusage.ru_isrss);
lua_pushinteger(L, rusage->ru_isrss);
lua_setfield(L, -2, "isrss");
// page reclaims (soft page faults)
lua_pushinteger(L, rusage.ru_minflt);
lua_pushinteger(L, rusage->ru_minflt);
lua_setfield(L, -2, "minflt");
// page faults (hard page faults)
lua_pushinteger(L, rusage.ru_majflt);
lua_pushinteger(L, rusage->ru_majflt);
lua_setfield(L, -2, "majflt");
// swaps
lua_pushinteger(L, rusage.ru_nswap);
lua_pushinteger(L, rusage->ru_nswap);
lua_setfield(L, -2, "nswap");
// block input operations
lua_pushinteger(L, rusage.ru_inblock);
lua_pushinteger(L, rusage->ru_inblock);
lua_setfield(L, -2, "inblock");
// block output operations
lua_pushinteger(L, rusage.ru_oublock);
lua_pushinteger(L, rusage->ru_oublock);
lua_setfield(L, -2, "oublock");
// IPC messages sent
lua_pushinteger(L, rusage.ru_msgsnd);
lua_pushinteger(L, rusage->ru_msgsnd);
lua_setfield(L, -2, "msgsnd");
// IPC messages received
lua_pushinteger(L, rusage.ru_msgrcv);
lua_pushinteger(L, rusage->ru_msgrcv);
lua_setfield(L, -2, "msgrcv");
// signals received
lua_pushinteger(L, rusage.ru_nsignals);
lua_pushinteger(L, rusage->ru_nsignals);
lua_setfield(L, -2, "nsignals");
// voluntary context switches
lua_pushinteger(L, rusage.ru_nvcsw);
lua_pushinteger(L, rusage->ru_nvcsw);
lua_setfield(L, -2, "nvcsw");
// involuntary context switches
lua_pushinteger(L, rusage.ru_nivcsw);
lua_pushinteger(L, rusage->ru_nivcsw);
lua_setfield(L, -2, "nivcsw");
}

static int luv_getrusage(lua_State* L) {
uv_rusage_t rusage;
int ret = uv_getrusage(&rusage);
if (ret < 0) return luv_error(L, ret);
luv_push_rusage_table(L, &rusage);
return 1;
}

#if LUV_UV_VERSION_GEQ(1, 50, 0)
static int luv_getrusage_thread(lua_State *L) {
uv_rusage_t rusage;
int ret = uv_getrusage_thread(&rusage);
if (ret < 0) return luv_error(L, ret);
luv_push_rusage_table(L, &rusage);
return 1;
}
#endif

#if LUV_UV_VERSION_GEQ(1, 44, 0)
static int luv_available_parallelism(lua_State* L) {
Expand Down
4 changes: 1 addition & 3 deletions src/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static lua_State *vm_acquire(uv_loop_t* loop) {
static void vm_release(lua_State* L) { lua_close(L); }


static lua_State* luv_thread_acquire_vm() {
static lua_State* luv_thread_acquire_vm(void) {
lua_State* L = vm_acquire(NULL); /* create state */

lua_pushboolean(L, 1);
Expand Down Expand Up @@ -111,9 +111,7 @@ static void call_walk(uv_timer_t* handle) {
int main(int argc, char *argv[]) {

lua_State* L;
int index;
int res;
int errfunc;
uv_loop_t loop;
uv_timer_t timer_handle;

Expand Down
Loading

0 comments on commit bc90207

Please sign in to comment.