diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2021-08-22 17:29:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-22 17:29:17 +0200 |
commit | 649dbb3b15949aee9d9e25cd39cca1e3e3a4ee45 (patch) | |
tree | dc153c0cf6ac08e6f0f5508dcc2603618f314ef6 /src/nvim/lua/executor.c | |
parent | db1b0ee3b30fd4cd323907c7f24bd575c22e68f0 (diff) | |
parent | de21e6ef3d9af96d2b71e54d8148d28b5fc9f22e (diff) | |
download | rneovim-649dbb3b15949aee9d9e25cd39cca1e3e3a4ee45.tar.gz rneovim-649dbb3b15949aee9d9e25cd39cca1e3e3a4ee45.tar.bz2 rneovim-649dbb3b15949aee9d9e25cd39cca1e3e3a4ee45.zip |
Merge pull request #15457 from bfredl/oldmap
refactor(map): remove extra-allocating map_new/map_free functions
Diffstat (limited to 'src/nvim/lua/executor.c')
-rw-r--r-- | src/nvim/lua/executor.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 8779d16116..cbc2273bc9 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -68,7 +68,8 @@ typedef struct { } #if __has_feature(address_sanitizer) - PMap(handle_T) *nlua_ref_markers = NULL; + static PMap(handle_T) nlua_ref_markers = MAP_INIT; + static bool nlua_track_refs = false; # define NLUA_TRACK_REFS #endif @@ -568,7 +569,7 @@ void nlua_init(void) #ifdef NLUA_TRACK_REFS const char *env = os_getenv("NVIM_LUA_NOTRACK"); if (!env || !*env) { - nlua_ref_markers = pmap_new(handle_T)(); + nlua_track_refs = true; } #endif @@ -599,10 +600,10 @@ void nlua_free_all_mem(void) fprintf(stderr, "%d lua references were leaked!", nlua_refcount); } - if (nlua_ref_markers) { + if (nlua_track_refs) { // in case there are leaked luarefs, leak the associated memory // to get LeakSanitizer stacktraces on exit - pmap_free(handle_T)(nlua_ref_markers); + pmap_destroy(handle_T)(&nlua_ref_markers); } #endif @@ -1001,9 +1002,9 @@ LuaRef nlua_ref(lua_State *lstate, int index) if (ref > 0) { nlua_refcount++; #ifdef NLUA_TRACK_REFS - if (nlua_ref_markers) { + if (nlua_track_refs) { // dummy allocation to make LeakSanitizer track our luarefs - pmap_put(handle_T)(nlua_ref_markers, ref, xmalloc(3)); + pmap_put(handle_T)(&nlua_ref_markers, ref, xmalloc(3)); } #endif } @@ -1017,8 +1018,8 @@ void nlua_unref(lua_State *lstate, LuaRef ref) nlua_refcount--; #ifdef NLUA_TRACK_REFS // NB: don't remove entry from map to track double-unref - if (nlua_ref_markers) { - xfree(pmap_get(handle_T)(nlua_ref_markers, ref)); + if (nlua_track_refs) { + xfree(pmap_get(handle_T)(&nlua_ref_markers, ref)); } #endif luaL_unref(lstate, LUA_REGISTRYINDEX, ref); |