mirror of
https://github.com/neovim/neovim.git
synced 2026-08-27 17:41:48 +00:00
fix(lua): vim.wait(math.huge) fails #36885
Problem:
`nlua_wait()` uses `luaL_checkinteger()` which doesn't support
`math.huge` since it's double type. On PUC Lua this fails with
'number has no integer representation' error and on LuaJIT this
overflows int.
Solution:
Use `luaL_checknumber()` and handle `math.huge`.
(cherry picked from commit bc0635a9fc)
This commit is contained in:
committed by
github-actions[bot]
parent
c1c0078138
commit
9acbf5102f
@@ -3,6 +3,7 @@
|
|||||||
#include <lauxlib.h>
|
#include <lauxlib.h>
|
||||||
#include <lua.h>
|
#include <lua.h>
|
||||||
#include <lualib.h>
|
#include <lualib.h>
|
||||||
|
#include <math.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -437,10 +438,19 @@ static int nlua_wait(lua_State *lstate)
|
|||||||
return luaL_error(lstate, e_fast_api_disabled, "vim.wait");
|
return luaL_error(lstate, e_fast_api_disabled, "vim.wait");
|
||||||
}
|
}
|
||||||
|
|
||||||
intptr_t timeout = luaL_checkinteger(lstate, 1);
|
double timeout_number = luaL_checknumber(lstate, 1);
|
||||||
if (timeout < 0) {
|
if (timeout_number < 0) {
|
||||||
return luaL_error(lstate, "timeout must be >= 0");
|
return luaL_error(lstate, "timeout must be >= 0");
|
||||||
}
|
}
|
||||||
|
int64_t timeout;
|
||||||
|
if (isinf(timeout_number) || timeout_number > (double)INT64_MAX) {
|
||||||
|
timeout = INT64_MAX;
|
||||||
|
} else {
|
||||||
|
if (isnan(timeout_number) || timeout_number != trunc(timeout_number)) {
|
||||||
|
return luaL_error(lstate, "timeout has no integer representation");
|
||||||
|
}
|
||||||
|
timeout = (int64_t)timeout_number;
|
||||||
|
}
|
||||||
|
|
||||||
int lua_top = lua_gettop(lstate);
|
int lua_top = lua_gettop(lstate);
|
||||||
|
|
||||||
@@ -496,7 +506,7 @@ static int nlua_wait(lua_State *lstate)
|
|||||||
|
|
||||||
LOOP_PROCESS_EVENTS_UNTIL(&main_loop,
|
LOOP_PROCESS_EVENTS_UNTIL(&main_loop,
|
||||||
loop_events,
|
loop_events,
|
||||||
(int)timeout,
|
timeout,
|
||||||
got_int || (is_function ? nlua_wait_condition(lstate,
|
got_int || (is_function ? nlua_wait_condition(lstate,
|
||||||
&pcall_status,
|
&pcall_status,
|
||||||
&callback_result)
|
&callback_result)
|
||||||
|
|||||||
@@ -3768,7 +3768,8 @@ stack traceback:
|
|||||||
exec_lua([[
|
exec_lua([[
|
||||||
function _G.Wait()
|
function _G.Wait()
|
||||||
vim.rpcnotify(vim.g.channel, 'ready')
|
vim.rpcnotify(vim.g.channel, 'ready')
|
||||||
local _, interrupted = vim.wait(4000)
|
-- handles math.huge #36854
|
||||||
|
local _, interrupted = vim.wait(math.huge)
|
||||||
vim.rpcnotify(vim.g.channel, 'wait', interrupted)
|
vim.rpcnotify(vim.g.channel, 'wait', interrupted)
|
||||||
end
|
end
|
||||||
]])
|
]])
|
||||||
@@ -3782,7 +3783,7 @@ stack traceback:
|
|||||||
exec_lua([[
|
exec_lua([[
|
||||||
function _G.Wait()
|
function _G.Wait()
|
||||||
vim.rpcnotify(vim.g.channel, 'ready')
|
vim.rpcnotify(vim.g.channel, 'ready')
|
||||||
local _, interrupted = vim.wait(4000, function() end)
|
local _, interrupted = vim.wait(math.huge, function() end)
|
||||||
vim.rpcnotify(vim.g.channel, 'wait', interrupted)
|
vim.rpcnotify(vim.g.channel, 'wait', interrupted)
|
||||||
end
|
end
|
||||||
]])
|
]])
|
||||||
|
|||||||
Reference in New Issue
Block a user