diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2023-11-30 20:35:25 +0000 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2023-11-30 20:35:25 +0000 |
commit | 1b7b916b7631ddf73c38e3a0070d64e4636cb2f3 (patch) | |
tree | cd08258054db80bb9a11b1061bb091c70b76926a /src/nvim/memory.c | |
parent | eaa89c11d0f8aefbb512de769c6c82f61a8baca3 (diff) | |
parent | 4a8bf24ac690004aedf5540fa440e788459e5e34 (diff) | |
download | rneovim-aucmd_textputpost.tar.gz rneovim-aucmd_textputpost.tar.bz2 rneovim-aucmd_textputpost.zip |
Merge remote-tracking branch 'upstream/master' into aucmd_textputpostaucmd_textputpost
Diffstat (limited to 'src/nvim/memory.c')
-rw-r--r-- | src/nvim/memory.c | 63 |
1 files changed, 29 insertions, 34 deletions
diff --git a/src/nvim/memory.c b/src/nvim/memory.c index 5356300382..df6c81fe0d 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 <assert.h> @@ -13,11 +10,13 @@ #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" +#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" @@ -29,10 +28,12 @@ #include "nvim/memfile.h" #include "nvim/memory.h" #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.h" +#include "nvim/vim_defs.h" #ifdef UNIT_TESTING # define malloc(size) mem_malloc(size) @@ -121,9 +122,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 +151,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 +171,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 +189,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); @@ -219,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`. /// @@ -502,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) @@ -585,7 +584,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! @@ -663,14 +664,13 @@ 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" # include "nvim/file_search.h" # 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" @@ -762,11 +762,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(); @@ -777,8 +773,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(); @@ -793,7 +787,7 @@ void free_all_mem(void) first_tabpage = NULL; // message history - for (;;) { + while (true) { if (delete_first_msg() == FAIL) { break; } @@ -826,14 +820,15 @@ void free_all_mem(void) grid_free_all_mem(); clear_hl_tables(false); - list_free_log(); check_quickfix_busy(); decor_free_all_mem(); + drawline_free_all_mem(); 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(); |