mirror of
https://github.com/neovim/neovim.git
synced 2025-09-27 21:48:35 +00:00
fix(env.c): drop envmap, free os_getenv() result #32683
Problem: vim.uv.os_setenv gets "stuck" per-key. #32550 Caused by the internal `envmap` cache. #7920 :echo $FOO <-- prints nothing :lua vim.uv.os_setenv("FOO", "bar") :echo $FOO <-- prints bar (as expected) :lua vim.uv.os_setenv("FOO", "fizz") :echo $FOO <-- prints bar, still (not expected. Should be "fizz") :lua vim.uv.os_unsetenv("FOO") :echo $FOO <-- prints bar, still (not expected. Should be nothing) :lua vim.uv.os_setenv("FOO", "buzz") :echo $FOO <-- prints bar, still (not expected. Should be "buzz") Solution: - Remove the `envmap` cache. - Callers to `os_getenv` must free the result. - Update all call-sites. - Introduce `os_getenv_noalloc`. - Extend `os_env_exists()` the `nonempty` parameter.
This commit is contained in:
@@ -831,8 +831,7 @@ static bool nlua_state_init(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL
|
||||
void nlua_init(char **argv, int argc, int lua_arg0)
|
||||
{
|
||||
#ifdef NLUA_TRACK_REFS
|
||||
const char *env = os_getenv("NVIM_LUA_NOTRACK");
|
||||
if (!env || !*env) {
|
||||
if (os_env_exists("NVIM_LUA_NOTRACK", true)) {
|
||||
nlua_track_refs = true;
|
||||
}
|
||||
#endif
|
||||
@@ -1283,7 +1282,7 @@ static int nlua_empty_dict_tostring(lua_State *lstate)
|
||||
/// @param lstate Lua interpreter state.
|
||||
static int nlua_getenv(lua_State *lstate)
|
||||
{
|
||||
lua_pushstring(lstate, os_getenv(luaL_checkstring(lstate, 1)));
|
||||
lua_pushstring(lstate, os_getenv_noalloc(luaL_checkstring(lstate, 1)));
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user