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

V1.45 #649

Merged
merged 17 commits into from
May 20, 2023
Merged

V1.45 #649

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
4 changes: 4 additions & 0 deletions .ci/bindcov.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
unbound_functions=0
skipped=()

# waiting on these being documented
# https://github.com/libuv/libuv/issues/4007
skipped+=(uv_os_get_passwd2 uv_os_get_group uv_os_free_group)

# false positives
skipped+=(uv_thread_create uv_thread_create_ex)

Expand Down
9 changes: 0 additions & 9 deletions .ci/pthread_create.supp

This file was deleted.

71 changes: 71 additions & 0 deletions .ci/valgrind_mem.supp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
luv_push_stats_table
Memcheck:Cond
fun:luv_push_stats_table
}
{
tostringbuff
Memcheck:Value8
fun:_itoa_word
fun:__vfprintf_internal
fun:__vsnprintf_internal
fun:snprintf
fun:tostringbuff
}
{
tostringbuff Conditional jump or move depends on uninitialised value(s)
Memcheck:Cond
fun:_itoa_word
fun:__vfprintf_internal
fun:__vsnprintf_internal
fun:snprintf
fun:tostringbuff
}
{
addnum2buff Conditional jump or move depends on uninitialised value(s)
Memcheck:Cond
fun:__vfprintf_internal
fun:__vsnprintf_internal
fun:snprintf
fun:tostringbuff
fun:addnum2buff
fun:luaO_pushvfstring
fun:lua_pushfstring
fun:luaL_tolstring
fun:luaB_tostring
fun:precallC
fun:luaD_precall
fun:luaV_execute
}
{
luv_fs_read
Memcheck:Cond
fun:malloc
fun:luv_fs_read
}
{
luv_fulfill_req
Memcheck:Cond
fun:luaV_execute
fun:ccall
fun:luaD_callnoyield
fun:f_call
fun:luaD_rawrunprotected
fun:luaD_pcall
fun:lua_pcallk
fun:luv_fulfill_req
}
{
Conditional jump or move depends on uninitialised value(s)
Memcheck:Cond
fun:luaV_execute
fun:ccall
fun:luaD_callnoyield
fun:f_call
fun:luaD_rawrunprotected
fun:luaD_pcall
fun:lua_pcallk
fun:luv_cfpcall
fun:luv_fulfill_req
fun:luv_fs_cb
}
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
- name: Build
run: make
- name: Test
run: valgrind --suppressions=.ci/pthread_create.supp --error-exitcode=1 --leak-check=full --child-silent-after-fork=yes --keep-debuginfo=yes ./build/lua -e "collectgarbage('setpause', 0); collectgarbage('setstepmul', 10000000000000)" tests/run.lua
run: valgrind --suppressions=.ci/valgrind_mem.supp --error-exitcode=1 --leak-check=full --child-silent-after-fork=yes --keep-debuginfo=yes --track-origins=yes ./build/lua -e "collectgarbage('setpause', 0); collectgarbage('setstepmul', 10000000000000)" tests/run.lua

process-cleanup-test:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -144,7 +144,7 @@ jobs:
- name: Build with Luarocks (alternate rockspec)
run: |
mkdir ${{github.workspace}}/build/lib
cp ${{github.workspace}}/build/deps/libuv/libuv_a.a ${{github.workspace}}/build/lib/libuv.a
cp ${{github.workspace}}/build/deps/libuv/libuv.a ${{github.workspace}}/build/lib/libuv.a
cp -a ${{github.workspace}}/deps/libuv/include ${{github.workspace}}/build
luarocks make rockspecs/$(ls rockspecs) LIBUV_DIR=${{github.workspace}}/build LUA_COMPAT53_INCDIR=${{github.workspace}}/deps/lua-compat-5.3/c-api
test $PWD = `lua -e "print(require'luv'.cwd())"`
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ for:
- luarocks remove luv
# Test the alternate rockspec
- mkdir build\lib
- cp build.luarocks\deps\libuv\Release\uv_a.lib build\lib\uv.lib
- cp build.luarocks\deps\libuv\Release\libuv.lib build\lib\uv.lib
- cp -a deps\libuv\include build
- ps: luarocks make rockspecs\$(ls rockspecs) LIBUV_DIR=build LUA_COMPAT53_INCDIR=deps/lua-compat-5.3/c-api CFLAGS="/nologo /MT /O2"
- ps: if("$(Get-Location)" -eq $(lua -e "print(require'luv'.cwd())")) { "LuaRocks test OK" } else { "LuaRocks test failed"; exit 1 }
Expand Down
2 changes: 1 addition & 1 deletion deps/libuv
Submodule libuv updated 272 files
2 changes: 1 addition & 1 deletion deps/lua
Submodule lua updated 75 files
+1 −1 all
+123 −126 lapi.c
+10 −7 lapi.h
+31 −25 lauxlib.c
+88 −49 lcode.c
+2 −2 lcorolib.c
+43 −37 ldebug.c
+1 −1 ldebug.h
+128 −101 ldo.c
+13 −4 ldo.h
+6 −2 ldump.c
+27 −27 lfunc.c
+3 −3 lfunc.h
+57 −49 lgc.c
+11 −8 lgc.h
+3 −3 llex.c
+17 −4 llimits.h
+5 −5 lmathlib.c
+41 −27 lmem.c
+7 −2 loadlib.c
+24 −14 lobject.c
+17 −2 lobject.h
+1 −1 lopcodes.h
+17 −19 loslib.c
+16 −15 lparser.c
+35 −30 lstate.c
+15 −10 lstate.h
+1 −1 lstrlib.c
+4 −4 ltable.c
+0 −1 ltable.h
+1 −1 ltablib.c
+18 −18 ltests.c
+7 −0 ltests.h
+19 −19 ltm.c
+3 −2 ltm.h
+26 −13 lua.c
+16 −11 lua.h
+10 −3 luaconf.h
+5 −3 lundump.c
+16 −11 lutf8lib.c
+148 −87 lvm.c
+5 −0 lvm.h
+7 −3 makefile
+1 −1 manual/2html
+173 −100 manual/manual.of
+17 −3 onelua.c
+1 −0 testes/all.lua
+61 −51 testes/api.lua
+23 −11 testes/attrib.lua
+1 −1 testes/big.lua
+12 −0 testes/bitwise.lua
+49 −19 testes/calls.lua
+4 −2 testes/closure.lua
+3 −3 testes/code.lua
+45 −16 testes/constructs.lua
+41 −30 testes/coroutine.lua
+26 −0 testes/cstack.lua
+18 −9 testes/db.lua
+55 −36 testes/errors.lua
+3 −0 testes/events.lua
+13 −2 testes/files.lua
+23 −19 testes/gc.lua
+5 −5 testes/libs/makefile
+17 −16 testes/literals.lua
+47 −3 testes/locals.lua
+32 −7 testes/main.lua
+3 −3 testes/math.lua
+30 −10 testes/nextvar.lua
+17 −15 testes/pm.lua
+12 −11 testes/sort.lua
+10 −5 testes/strings.lua
+1 −1 testes/tpack.lua
+12 −2 testes/utf8.lua
+9 −9 testes/vararg.lua
+6 −6 testes/verybig.lua
2 changes: 1 addition & 1 deletion deps/lua-compat-5.3
104 changes: 104 additions & 0 deletions docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -3286,6 +3286,60 @@ equivalent to the `__eq` metamethod.

**Returns:** `boolean`

### `uv.thread_setaffinity(thread, affinity, [get_old_affinity])`

> method form `thread:setaffinity(affinity, [get_old_affinity])`

**Parameters:**
- `thread`: `luv_thread_t userdata`
- `affinity`: `table`
- `[1, 2, 3, ..., n]` : `boolean`
- `get_old_affinity`: `boolean`

Sets the specified thread's affinity setting. `affinity` must be an array-like
table where each of the keys correspond to a CPU number and the values are
booleans that represent whether the `thread` should be eligible to run on that
CPU. The length of the `affinity` table must be greater than or equal to
`uv.cpumask_size()`. If `get_old_affinity` is `true`, the previous affinity
settings for the `thread` will be returned. Otherwise, `true` is returned after
a successful call.

**Note:** Thread affinity setting is not atomic on Windows. Unsupported on macOS.

**Returns:** `table` or `boolean` or `fail`
- `[1, 2, 3, ..., n]` : `boolean`

### `uv.thread_getaffinity(thread, [mask_size])`

> method form `thread:getaffinity([mask_size])`

**Parameters:**
- `thread`: `luv_thread_t userdata`
- `mask_size`: `integer`

Gets the specified thread's affinity setting.

If `mask_size` is provided, it must be greater than or equal to
`uv.cpumask_size()`. If the `mask_size` parameter is omitted, then the return
of `uv.cpumask_size()` will be used. Returns an array-like table where each of
the keys correspond to a CPU number and the values are booleans that represent
whether the `thread` is eligible to run on that CPU.

**Note:** Thread affinity getting is not atomic on Windows. Unsupported on macOS.

**Returns:** `table` or `fail`
- `[1, 2, 3, ..., n]` : `boolean`

### `uv.thread_getcpu()`

Gets the CPU number on which the calling thread is running.

**Note:** The first CPU will be returned as the number 1, not 0. This allows for
the number to correspond with the table keys used in `uv.thread_getaffinity` and
`uv.thread_setaffinity`.

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

### `uv.thread_self()`

Returns the handle for the thread in which this is called.
Expand Down Expand Up @@ -3373,6 +3427,15 @@ greater than the total system memory.

**Returns:** `number`

### `uv.get_available_memory()`

Gets the amount of free memory that is still available to the process (in
bytes). This differs from `uv.get_free_memory()` in that it takes into account
any limits imposed by the OS. If there is no such constraint, or the constraint
is unknown, the amount returned will be identical to `uv.get_free_memory()`.

**Returns:** `number`

### `uv.resident_set_memory()`

Returns the resident set size (RSS) for the current process.
Expand Down Expand Up @@ -3433,6 +3496,13 @@ CPU found.
- `idle` : `number`
- `irq` : `number`

### `uv.cpumask_size()`

Returns the maximum size of the mask used for process/thread affinities, or
`ENOTSUP` if affinities are not supported on the current platform.

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

### `uv.getpid()`

**Deprecated:** Please use `uv.os_getpid()` instead.
Expand Down Expand Up @@ -3484,6 +3554,24 @@ time between intervals.

**Returns:** `number`

### `uv.clock_gettime(clock_id)`

**Parameters:**
- `clock_id`: `string`

Obtain the current system time from a high-resolution real-time or monotonic
clock source. `clock_id` can be the string `"monotonic"` or `"realtime"`.

The real-time clock counts from the UNIX epoch (1970-01-01) and is subject
to time adjustments; it can jump back in time.

The monotonic clock counts from an arbitrary point in the past and never
jumps back in time.

**Returns:** `table` or `fail`
- `sec`: `integer`
- `nsec`: `integer`

### `uv.uptime()`

Returns the current system uptime in seconds.
Expand Down Expand Up @@ -3738,6 +3826,22 @@ time until calling `loop_configure` with `"metrics_idle_time"`.

**Returns:** `number`

### `uv.metrics_info()`

Get the metrics table from current set of event loop metrics.

**Returns:** `table`

The table contains event loop metrics. It is recommended to retrieve these
metrics in a uv_prepare_cb in order to make sure there are no inconsistencies
with the metrics counters.

- `loop_count` : `integer`
- `events` : `integer`
- `events_waiting` : `integer`

**Note**: New in libuv version 1.45.0.

---

[luv]: https://github.com/luvit/luv
Expand Down
3 changes: 3 additions & 0 deletions rockspecs/luv-scm-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ build = {
'userenv';
'ws2_32';
'advapi32';
'Dbghelp';
"Ole32";
"Shell32";
Comment on lines +82 to +84
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

};
};
};
Expand Down
3 changes: 2 additions & 1 deletion src/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ static int luv_fs_read(lua_State* L) {
// -1 offset means "the current file offset is used and updated"
int64_t offset = -1;
int ref;
char* data;
// both offset and callback are optional
if (luv_is_callable(L, 3) && lua_isnoneornil(L, 4)) {
ref = luv_check_continuation(L, 3);
Expand All @@ -516,7 +517,7 @@ static int luv_fs_read(lua_State* L) {
offset = luaL_optinteger(L, 3, offset);
ref = luv_check_continuation(L, 4);
}
char* data = (char*)malloc(len);
data = (char*)malloc(len);
if (!data) {
luaL_unref(L, LUA_REGISTRYINDEX, ref);
return luaL_error(L, "Failure to allocate buffer");
Expand Down
13 changes: 13 additions & 0 deletions src/luv.c
Original file line number Diff line number Diff line change
Expand Up @@ -372,12 +372,22 @@ static const luaL_Reg luv_functions[] = {
{"random", luv_random},
#endif
{"sleep", luv_sleep},
#if LUV_UV_VERSION_GEQ(1, 45, 0)
{"cpumask_size", luv_cpumask_size},
{"get_available_memory", luv_get_available_memory},
{"clock_gettime", luv_clock_gettime},
#endif

// thread.c
{"new_thread", luv_new_thread},
{"thread_equal", luv_thread_equal},
{"thread_self", luv_thread_self},
{"thread_join", luv_thread_join},
#if LUV_UV_VERSION_GEQ(1, 45, 0)
{"thread_getaffinity", luv_thread_getaffinity},
{"thread_setaffinity", luv_thread_setaffinity},
{"thread_getcpu", luv_thread_getcpu},
#endif

// work.c
{"new_work", luv_new_work},
Expand All @@ -392,6 +402,9 @@ static const luaL_Reg luv_functions[] = {
#if LUV_UV_VERSION_GEQ(1, 39, 0)
{"metrics_idle_time", luv_metrics_idle_time},
#endif
#if LUV_UV_VERSION_GEQ(1, 45, 0)
{"metrics_info", luv_metrics_info},
#endif

{NULL, NULL}
};
Expand Down
24 changes: 24 additions & 0 deletions src/metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,27 @@ static int luv_metrics_idle_time(lua_State* L) {
return 1;
}
#endif

#if LUV_UV_VERSION_GEQ(1, 45, 0)
static int luv_metrics_info(lua_State *L) {
uv_metrics_t metrics;
int ret = uv_metrics_info(luv_loop(L), &metrics);
if (ret < 0) return luv_error(L, ret);

lua_newtable(L);

lua_pushliteral(L, "loop_count");
lua_pushinteger(L, metrics.loop_count);
lua_rawset(L, -3);

lua_pushliteral(L, "events");
lua_pushinteger(L, metrics.events);
lua_rawset(L, -3);

lua_pushliteral(L, "events_waiting");
lua_pushinteger(L, metrics.events_waiting);
lua_rawset(L, -3);

return 1;
}
#endif
32 changes: 32 additions & 0 deletions src/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -750,3 +750,35 @@ static int luv_random(lua_State* L) {
}
}
#endif

#if LUV_UV_VERSION_GEQ(1, 45, 0)
static int luv_cpumask_size(lua_State* L) {
int ret = uv_cpumask_size();
if (ret < 0) return luv_error(L, ret);
lua_pushinteger(L, ret);
return 1;
}

static int luv_get_available_memory(lua_State* L) {
lua_pushnumber(L, uv_get_available_memory());
return 1;
}

// These are the same order as uv_membership which also starts at 0
static const char *const luv_clock_id_opts[] = {
"monotonic", "realtime", NULL
};

static int luv_clock_gettime(lua_State* L) {
uv_clock_id clock_id = (uv_clock_id)luaL_checkoption(L, 1, NULL, luv_clock_id_opts);
uv_timespec64_t timespec;
int ret = uv_clock_gettime(clock_id, &timespec);
if (ret < 0) return luv_error(L, ret);
lua_createtable(L, 0, 2);
lua_pushinteger(L, timespec.tv_sec);
lua_setfield(L, -2, "sec");
lua_pushinteger(L, timespec.tv_nsec);
lua_setfield(L, -2, "nsec");
return 1;
}
#endif
Loading