From 69bb145cea56067e6e82ed0a130a51c0d611e540 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 4 Feb 2023 20:14:31 +0800 Subject: refactor(exit): pass error message to preserve_exit() (#22097) Problem: 1. Some calls to preserve_exit() don't put a message in IObuff, so the IObuff printed by preserve_exit() contains unrelated information. 2. If a TUI client runs out of memory or receives a deadly signal, the error message is shown on alternate screen and cannot be easily seen because the TUI exits alternate screen soon afterwards. Solution: Pass error message to preserve_exit() and exit alternate screen before printing it. Note that this doesn't fix the problem that server error messages cannot be easily seen on exit. This is tracked in #21608 and #21843. --- src/nvim/memory.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'src/nvim/memory.c') diff --git a/src/nvim/memory.c b/src/nvim/memory.c index 5356300382..4e799dfd08 100644 --- a/src/nvim/memory.c +++ b/src/nvim/memory.c @@ -121,9 +121,7 @@ void *xmalloc(size_t size) { void *ret = try_malloc(size); if (!ret) { - os_errmsg(e_outofmem); - os_errmsg("\n"); - preserve_exit(); + preserve_exit(e_outofmem); } return ret; } @@ -152,9 +150,7 @@ void *xcalloc(size_t count, size_t size) try_to_free_memory(); ret = calloc(allocated_count, allocated_size); if (!ret) { - os_errmsg(e_outofmem); - os_errmsg("\n"); - preserve_exit(); + preserve_exit(e_outofmem); } } return ret; @@ -174,9 +170,7 @@ void *xrealloc(void *ptr, size_t size) try_to_free_memory(); ret = realloc(ptr, allocated_size); if (!ret) { - os_errmsg(e_outofmem); - os_errmsg("\n"); - preserve_exit(); + preserve_exit(e_outofmem); } } return ret; @@ -194,8 +188,7 @@ void *xmallocz(size_t size) { size_t total_size = size + 1; if (total_size < size) { - os_errmsg(_("Vim: Data too large to fit into virtual memory space\n")); - preserve_exit(); + preserve_exit(_("Vim: Data too large to fit into virtual memory space\n")); } void *ret = xmalloc(total_size); -- cgit From 1adad44b7ce6574f505f4cf5df3c8e21c0747f93 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 5 Mar 2023 16:52:47 +0800 Subject: vim-patch:9.0.0749: alloc/free of buffer for each quickfix entry is inefficient Problem: Alloc/free of buffer for each quickfix entry is inefficient. Solution: Use a shared grow array. (Yegappan Lakshmanan, closes vim/vim#11365) https://github.com/vim/vim/commit/975a665d4811649a51e2c6a97a6ce096290d87ae Co-authored-by: Yegappan Lakshmanan --- src/nvim/memory.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'src/nvim/memory.c') diff --git a/src/nvim/memory.c b/src/nvim/memory.c index 4e799dfd08..ffeafbdf2c 100644 --- a/src/nvim/memory.c +++ b/src/nvim/memory.c @@ -755,11 +755,7 @@ void free_all_mem(void) p_hi = 0; init_history(); - qf_free_all(NULL); - // Free all location lists - FOR_ALL_TAB_WINDOWS(tab, win) { - qf_free_all(win); - } + free_quickfix(); // Close all script inputs. close_all_scripts(); -- cgit From 3b0df1780e2c8526bda5dead18ee7cc45925caba Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Wed, 26 Apr 2023 23:23:44 +0200 Subject: refactor: uncrustify Notable changes: replace all infinite loops to `while(true)` and remove `int` from `unsigned int`. --- src/nvim/memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/memory.c') diff --git a/src/nvim/memory.c b/src/nvim/memory.c index ffeafbdf2c..b9a26e1ac6 100644 --- a/src/nvim/memory.c +++ b/src/nvim/memory.c @@ -782,7 +782,7 @@ void free_all_mem(void) first_tabpage = NULL; // message history - for (;;) { + while (true) { if (delete_first_msg() == FAIL) { break; } -- cgit From e2fdd53d8c015913e8be4ff708fc3488558c8906 Mon Sep 17 00:00:00 2001 From: bfredl Date: Sun, 14 May 2023 18:45:56 +0200 Subject: refactor(map): avoid duplicated khash_t types for values This reduces the total number of khash_t instantiations from 22 to 8. Make the khash internal functions take the size of values as a runtime parameter. This is abstracted with typesafe Map containers which are still specialized for both key, value type. Introduce `Set(key)` type for when there is no value. Refactor shada.c to use Map/Set instead of khash directly. This requires `map_ref` operation to be more flexible. Return pointers to both key and value, plus an indicator for new_item. As a bonus, `map_key` is now redundant. Instead of Map(cstr_t, FileMarks), use a pointer map as the FileMarks struct is humongous. Make `event_strings` actually work like an intern pool instead of wtf it was doing before. --- src/nvim/memory.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/nvim/memory.c') diff --git a/src/nvim/memory.c b/src/nvim/memory.c index b9a26e1ac6..1f550ffb01 100644 --- a/src/nvim/memory.c +++ b/src/nvim/memory.c @@ -664,6 +664,7 @@ char *arena_memdupz(Arena *arena, const char *buf, size_t size) # include "nvim/getchar.h" # include "nvim/grid.h" # include "nvim/mark.h" +# include "nvim/msgpack_rpc/channel.h" # include "nvim/ops.h" # include "nvim/option.h" # include "nvim/os/os.h" @@ -823,6 +824,7 @@ void free_all_mem(void) ui_free_all_mem(); nlua_free_all_mem(); + rpc_free_all_mem(); // should be last, in case earlier free functions deallocates arenas arena_free_reuse_blks(); -- cgit From c48f94d1f30056272ed030ad3f4529055ac07853 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 28 May 2023 16:34:47 +0200 Subject: build: remove LOG_LIST_ACTIONS option and related code It has not been used for a long time and the likelihood of it still working is low. --- src/nvim/memory.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/memory.c') diff --git a/src/nvim/memory.c b/src/nvim/memory.c index 1f550ffb01..6b4d290863 100644 --- a/src/nvim/memory.c +++ b/src/nvim/memory.c @@ -816,7 +816,6 @@ void free_all_mem(void) grid_free_all_mem(); clear_hl_tables(false); - list_free_log(); check_quickfix_busy(); -- cgit From cf8b2c0e74fd5e723b0c15c2ce84e6900fd322d3 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 12:05:28 +0800 Subject: build(iwyu): add a few more _defs.h mappings (#25435) --- src/nvim/memory.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/memory.c') diff --git a/src/nvim/memory.c b/src/nvim/memory.c index 6b4d290863..9ae27e027d 100644 --- a/src/nvim/memory.c +++ b/src/nvim/memory.c @@ -656,7 +656,6 @@ char *arena_memdupz(Arena *arena, const char *buf, size_t size) # include "nvim/cmdhist.h" # include "nvim/diff.h" # include "nvim/edit.h" -# include "nvim/eval/typval.h" # include "nvim/ex_cmds.h" # include "nvim/ex_docmd.h" # include "nvim/ex_getln.h" -- cgit From dc6d0d2daf69e2fdadda81feb97906dbc962a239 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 14:41:34 +0800 Subject: refactor: reorganize option header files (#25437) - Move vimoption_T to option.h - option_defs.h is for option-related types - option_vars.h corresponds to Vim's option.h - option_defs.h and option_vars.h don't include each other --- src/nvim/memory.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/memory.c') diff --git a/src/nvim/memory.c b/src/nvim/memory.c index 9ae27e027d..997f465f02 100644 --- a/src/nvim/memory.c +++ b/src/nvim/memory.c @@ -29,6 +29,7 @@ #include "nvim/memfile.h" #include "nvim/memory.h" #include "nvim/message.h" +#include "nvim/option_vars.h" #include "nvim/sign.h" #include "nvim/ui.h" #include "nvim/usercmd.h" -- cgit From ddef39299f357d3131644647379e88a69749bf40 Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 19 Sep 2023 14:30:02 +0200 Subject: refactor(grid): do arabic shaping in one place The 'arabicshape' feature of vim is a transformation of unicode text to make arabic and some related scripts look better at display time. In particular the content of a cell will be adjusted depending on the (original) content of the cells just before and after it. This is implemented by the arabic_shape() function in nvim. Before this commit, shaping was invoked in four different contexts: - when rendering buffer text in win_line() - in line_putchar() for rendering virtual text - as part of grid_line_puts, used by messages and statuslines and similar - as part of draw_cmdline() for drawing the cmdline This replaces all these with a post-processing step in grid_put_linebuf(), which has become the entry point for all text rendering after recent refactors. An aim of this is to make the handling of multibyte text yet simpler. One of the main reasons multibyte chars needs to be "parsed" into codepoint arrays of composing chars is so that these could be inspected for the purpose of shaping. This can likely be vastly simplified in many contexts where only the total length (in bytes) and width of composed char is needed. --- src/nvim/memory.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/nvim/memory.c') diff --git a/src/nvim/memory.c b/src/nvim/memory.c index 997f465f02..fdfd63e25f 100644 --- a/src/nvim/memory.c +++ b/src/nvim/memory.c @@ -767,8 +767,6 @@ void free_all_mem(void) // Free all option values. Must come after closing windows. free_all_options(); - free_arshape_buf(); - // Clear registers. clear_registers(); ResetRedobuff(); -- cgit From 74581ec7ebd5f9b3d47f6b1ee04a87327ad730a1 Mon Sep 17 00:00:00 2001 From: bfredl Date: Thu, 9 Nov 2023 10:20:54 +0100 Subject: refactor(drawline): avoid xmalloc/xfree cycles on each screenline --- src/nvim/memory.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/nvim/memory.c') diff --git a/src/nvim/memory.c b/src/nvim/memory.c index fdfd63e25f..27b1bfc105 100644 --- a/src/nvim/memory.c +++ b/src/nvim/memory.c @@ -17,6 +17,7 @@ #include "nvim/buffer_updates.h" #include "nvim/context.h" #include "nvim/decoration_provider.h" +#include "nvim/drawline.h" #include "nvim/eval.h" #include "nvim/gettext.h" #include "nvim/globals.h" @@ -818,6 +819,7 @@ void free_all_mem(void) check_quickfix_busy(); decor_free_all_mem(); + drawline_free_all_mem(); ui_free_all_mem(); nlua_free_all_mem(); -- cgit From 353a4be7e84fdc101318215bdcc8a7e780d737fe Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 12 Nov 2023 13:13:58 +0100 Subject: build: remove PVS We already have an extensive suite of static analysis tools we use, which causes a fair bit of redundancy as we get duplicate warnings. PVS is also prone to give false warnings which creates a lot of work to identify and disable. --- src/nvim/memory.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/nvim/memory.c') diff --git a/src/nvim/memory.c b/src/nvim/memory.c index 27b1bfc105..4c7e42321d 100644 --- a/src/nvim/memory.c +++ b/src/nvim/memory.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - // Various routines dealing with allocation and deallocation of memory. #include -- cgit From bb4b4576e384c71890b4df4fa4f1ae76fad3a59d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 16 Nov 2023 10:55:54 +0800 Subject: refactor: iwyu (#26062) --- src/nvim/memory.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/memory.c') diff --git a/src/nvim/memory.c b/src/nvim/memory.c index 4c7e42321d..732c9ca39d 100644 --- a/src/nvim/memory.c +++ b/src/nvim/memory.c @@ -657,7 +657,6 @@ char *arena_memdupz(Arena *arena, const char *buf, size_t size) # include "nvim/edit.h" # include "nvim/ex_cmds.h" # include "nvim/ex_docmd.h" -# include "nvim/ex_getln.h" # include "nvim/file_search.h" # include "nvim/getchar.h" # include "nvim/grid.h" -- cgit From 574d25642fc9ca65b396633aeab6e2d32778b642 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 27 Nov 2023 17:21:58 +0800 Subject: refactor: move Arena and ArenaMem to memory_defs.h (#26240) --- src/nvim/memory.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/nvim/memory.c') diff --git a/src/nvim/memory.c b/src/nvim/memory.c index 732c9ca39d..eee8e25086 100644 --- a/src/nvim/memory.c +++ b/src/nvim/memory.c @@ -577,7 +577,9 @@ void alloc_block(Arena *arena) static size_t arena_align_offset(uint64_t off) { +#define ARENA_ALIGN MAX(sizeof(void *), sizeof(double)) return ((off + (ARENA_ALIGN - 1)) & ~(ARENA_ALIGN - 1)); +#undef ARENA_ALIGN } /// @param arena if NULL, do a global allocation. caller must then free the value! -- cgit From 8b428ca8b79ebb7b36c3e403ff3bcb6924a635a6 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 16:00:21 +0100 Subject: build(IWYU): fix includes for func_attr.h --- src/nvim/memory.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/memory.c') diff --git a/src/nvim/memory.c b/src/nvim/memory.c index eee8e25086..c6b741fd00 100644 --- a/src/nvim/memory.c +++ b/src/nvim/memory.c @@ -16,6 +16,7 @@ #include "nvim/decoration_provider.h" #include "nvim/drawline.h" #include "nvim/eval.h" +#include "nvim/func_attr.h" #include "nvim/gettext.h" #include "nvim/globals.h" #include "nvim/highlight.h" -- cgit From 79b6ff28ad1204fbb4199b9092f5c578d88cb28e Mon Sep 17 00:00:00 2001 From: dundargoc Date: Tue, 28 Nov 2023 20:31:00 +0100 Subject: refactor: fix headers with IWYU --- src/nvim/memory.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/memory.c') diff --git a/src/nvim/memory.c b/src/nvim/memory.c index c6b741fd00..5eb4a548fb 100644 --- a/src/nvim/memory.c +++ b/src/nvim/memory.c @@ -10,7 +10,7 @@ #include "nvim/api/extmark.h" #include "nvim/arglist.h" -#include "nvim/ascii.h" +#include "nvim/ascii_defs.h" #include "nvim/buffer_updates.h" #include "nvim/context.h" #include "nvim/decoration_provider.h" @@ -32,7 +32,7 @@ #include "nvim/sign.h" #include "nvim/ui.h" #include "nvim/usercmd.h" -#include "nvim/vim.h" +#include "nvim/vim_defs.h" #ifdef UNIT_TESTING # define malloc(size) mem_malloc(size) -- cgit From a6cba103cebce535279db197f9efeb34e9d1171f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 29 Nov 2023 20:32:40 +0800 Subject: refactor: move some constants out of vim_defs.h (#26298) --- src/nvim/memory.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/memory.c') diff --git a/src/nvim/memory.c b/src/nvim/memory.c index 5eb4a548fb..a13091793c 100644 --- a/src/nvim/memory.c +++ b/src/nvim/memory.c @@ -30,6 +30,7 @@ #include "nvim/message.h" #include "nvim/option_vars.h" #include "nvim/sign.h" +#include "nvim/state_defs.h" #include "nvim/ui.h" #include "nvim/usercmd.h" #include "nvim/vim_defs.h" -- cgit From 86cc791debba09c8ed1aa0d863be844108866a38 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 29 Nov 2023 23:10:21 +0800 Subject: refactor: move function macros out of vim_defs.h (#26300) --- src/nvim/memory.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/nvim/memory.c') diff --git a/src/nvim/memory.c b/src/nvim/memory.c index a13091793c..df6c81fe0d 100644 --- a/src/nvim/memory.c +++ b/src/nvim/memory.c @@ -213,6 +213,18 @@ void *xmemdupz(const void *data, size_t len) return memcpy(xmallocz(len), data, len); } +#ifndef HAVE_STRNLEN +size_t xstrnlen(const char *s, size_t n) + FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE +{ + const char *end = memchr(s, '\0', n); + if (end == NULL) { + return n; + } + return (size_t)(end - s); +} +#endif + /// A version of strchr() that returns a pointer to the terminating NUL if it /// doesn't find `c`. /// @@ -496,13 +508,6 @@ bool strequal(const char *a, const char *b) return (a == NULL && b == NULL) || (a && b && strcmp(a, b) == 0); } -/// Case-insensitive `strequal`. -bool striequal(const char *a, const char *b) - FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT -{ - return (a == NULL && b == NULL) || (a && b && STRICMP(a, b) == 0); -} - // Avoid repeating the error message many times (they take 1 second each). // Did_outofmem_msg is reset when a character is read. void do_outofmem_msg(size_t size) -- cgit