From 4be6c6cf0ddf5e31d4103cb5df06651ba6f4897b Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 11 Feb 2023 11:05:57 +0100 Subject: refactor: replace char_u with char (#21901) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/shada.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/shada.c') diff --git a/src/nvim/shada.c b/src/nvim/shada.c index 90a01aaf97..98f10c0082 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -2579,7 +2579,7 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer, ShaDaReadDef { STATIC_CSTR_AS_STRING("pid"), INTEGER_OBJ((Integer)os_get_pid()) }, { STATIC_CSTR_AS_STRING("encoding"), - STRING_OBJ(cstr_as_string((char *)p_enc)) }, + STRING_OBJ(cstr_as_string(p_enc)) }, }), } } -- cgit From 063e93864a7e99ac1c4781bbe4ea63c0adb075a8 Mon Sep 17 00:00:00 2001 From: Lucas Merritt Date: Fri, 24 Mar 2023 22:11:14 -0600 Subject: refactor(PVS/V1048): remove duplicated assignments (#21873) --- src/nvim/shada.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/shada.c') diff --git a/src/nvim/shada.c b/src/nvim/shada.c index 98f10c0082..3f816d0172 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -3602,7 +3602,6 @@ shada_read_next_item_start: ret = spm_ret; goto shada_read_next_item_error; } - ret = kSDReadStatusMalformed; entry->data = sd_default_values[type_u64].data; switch ((ShadaEntryType)type_u64) { case kSDItemHeader: -- cgit From 9408f2dcf7cade2631688300e9b58eed6bc5219a Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Fri, 7 Apr 2023 19:40:57 +0200 Subject: refactor: remove redundant const char * casts --- src/nvim/shada.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/nvim/shada.c') diff --git a/src/nvim/shada.c b/src/nvim/shada.c index 3f816d0172..72e71ff46f 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -1491,7 +1491,7 @@ static char *shada_filename(const char *file) // If shell is not performing them then they should be done in main.c // where arguments are parsed, *not here*. expand_env((char *)file, &(NameBuff[0]), MAXPATHL); - file = (const char *)&(NameBuff[0]); + file = &(NameBuff[0]); } } return xstrdup(file); @@ -1548,9 +1548,9 @@ static ShaDaWriteResult shada_pack_entry(msgpack_packer *const packer, ShadaEntr if (!HASHITEM_EMPTY(hi)) { \ todo--; \ dictitem_T *const di = TV_DICT_HI2DI(hi); \ - const size_t key_len = strlen((const char *)hi->hi_key); \ + const size_t key_len = strlen(hi->hi_key); \ msgpack_pack_str(spacker, key_len); \ - msgpack_pack_str_body(spacker, (const char *)hi->hi_key, key_len); \ + msgpack_pack_str_body(spacker, hi->hi_key, key_len); \ if (encode_vim_to_msgpack(spacker, &di->di_tv, \ _("additional data of ShaDa " what)) \ == FAIL) { \ @@ -2208,7 +2208,7 @@ static inline ShaDaWriteResult shada_read_when_writing(ShaDaReadDef *const sd_re shada_free_shada_entry(&entry); break; } - const char *const fname = (const char *)entry.data.filemark.fname; + const char *const fname = entry.data.filemark.fname; khiter_t k; int kh_ret; k = kh_put(file_marks, &wms->file_marks, fname, &kh_ret); @@ -2714,17 +2714,17 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer, ShaDaReadDef const char *fname; if (fm.fmark.fnum == 0) { assert(fm.fname != NULL); - if (shada_removable((const char *)fm.fname)) { + if (shada_removable(fm.fname)) { continue; } - fname = (const char *)fm.fname; + fname = fm.fname; } else { const buf_T *const buf = buflist_findnr(fm.fmark.fnum); if (buf == NULL || buf->b_ffname == NULL || in_bufset(&removable_bufs, buf)) { continue; } - fname = (const char *)buf->b_ffname; + fname = buf->b_ffname; } const PossiblyFreedShadaEntry pf_entry = { .can_free_entry = false, @@ -2761,7 +2761,7 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer, ShaDaReadDef continue; } const void *local_marks_iter = NULL; - const char *const fname = (const char *)buf->b_ffname; + const char *const fname = buf->b_ffname; khiter_t k; int kh_ret; k = kh_put(file_marks, &wms->file_marks, fname, &kh_ret); -- cgit From 2d78e656b715119ca11d131a1a932f22f1b4ad36 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Fri, 7 Apr 2023 21:43:00 +0200 Subject: refactor: remove redundant casts --- src/nvim/shada.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/shada.c') diff --git a/src/nvim/shada.c b/src/nvim/shada.c index 72e71ff46f..2d5eee7eec 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -4009,7 +4009,7 @@ static bool shada_removable(const char *name) char part[MAXPATHL + 1]; bool retval = false; - char *new_name = home_replace_save(NULL, (char *)name); + char *new_name = home_replace_save(NULL, name); for (p = p_shada; *p;) { (void)copy_option_part(&p, part, ARRAY_SIZE(part), ", "); if (part[0] == 'r') { -- cgit From 0451391ec514eb83c7e366b80fcab21de9f8d4ed Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 10 Apr 2023 22:49:32 +0800 Subject: fix(mark): properly init mark views (#22996) --- src/nvim/shada.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/nvim/shada.c') diff --git a/src/nvim/shada.c b/src/nvim/shada.c index 2d5eee7eec..78499922bf 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -1307,6 +1307,7 @@ static void shada_read(ShaDaReadDef *const sd_reader, const int flags) .mark = cur_entry.data.filemark.mark, .fnum = (buf == NULL ? 0 : buf->b_fnum), .timestamp = cur_entry.timestamp, + .view = INIT_FMARKV, .additional_data = cur_entry.data.filemark.additional_data, }, }; @@ -1388,6 +1389,7 @@ static void shada_read(ShaDaReadDef *const sd_reader, const int flags) .mark = cur_entry.data.filemark.mark, .fnum = 0, .timestamp = cur_entry.timestamp, + .view = INIT_FMARKV, .additional_data = cur_entry.data.filemark.additional_data, }; if (cur_entry.type == kSDItemLocalMark) { -- cgit From f39b33ee491a4a8d4b08425e582dd0dd53617edf Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 16 Apr 2023 11:46:17 +0800 Subject: vim-patch:9.0.0411: only created files can be cleaned up with one call MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Only created files can be cleaned up with one call. Solution: Add flags to mkdir() to delete with a deferred function. Expand the writefile() name to a full path to handle changing directory. https://github.com/vim/vim/commit/6f14da15ac900589f2f413d77898b9bff3b31ece vim-patch:8.2.3742: dec mouse test fails without gnome terminfo entry Problem: Dec mouse test fails without gnome terminfo entry. Solution: Check if there is a gnome entry. Also fix 'acd' test on MS-Windows. (Dominique Pellé, closes vim/vim#9282) https://github.com/vim/vim/commit/f589fd3e1047cdf90566b68aaf9a13389e54d26a Cherry-pick test_autochdir.vim changes from patch 9.0.0313. Cherry-pick test_autocmd.vim changes from patch 9.0.0323. Co-authored-by: Bram Moolenaar --- src/nvim/shada.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/shada.c') diff --git a/src/nvim/shada.c b/src/nvim/shada.c index 78499922bf..fcb8a15cde 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -3042,7 +3042,7 @@ shada_write_file_nomerge: {} if (!os_isdir(fname)) { int ret; char *failed_dir; - if ((ret = os_mkdir_recurse(fname, 0700, &failed_dir)) != 0) { + if ((ret = os_mkdir_recurse(fname, 0700, &failed_dir, NULL)) != 0) { semsg(_(SERR "Failed to create directory %s " "for writing ShaDa file: %s"), failed_dir, os_strerror(ret)); -- cgit From a1b045f60a22d366e255dfff1c54ed42ebe49284 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Wed, 26 Apr 2023 18:28:49 +0200 Subject: refactor(clang-tidy): remove redundant casts --- src/nvim/shada.c | 82 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 41 insertions(+), 41 deletions(-) (limited to 'src/nvim/shada.c') diff --git a/src/nvim/shada.c b/src/nvim/shada.c index fcb8a15cde..ae9e9463de 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -1641,21 +1641,21 @@ static ShaDaWriteResult shada_pack_entry(msgpack_packer *const packer, ShadaEntr break; } case kSDItemSearchPattern: { - const size_t map_size = (size_t)( - 1 // Search pattern is always present - + ONE_IF_NOT_DEFAULT(entry, search_pattern.magic) - + ONE_IF_NOT_DEFAULT(entry, search_pattern.is_last_used) - + ONE_IF_NOT_DEFAULT(entry, search_pattern.smartcase) - + ONE_IF_NOT_DEFAULT(entry, search_pattern.has_line_offset) - + ONE_IF_NOT_DEFAULT(entry, search_pattern.place_cursor_at_end) - + ONE_IF_NOT_DEFAULT(entry, - search_pattern.is_substitute_pattern) - + ONE_IF_NOT_DEFAULT(entry, search_pattern.highlighted) - + ONE_IF_NOT_DEFAULT(entry, search_pattern.offset) - + ONE_IF_NOT_DEFAULT(entry, search_pattern.search_backward) - // finally, additional data: - + (size_t)( - entry.data.search_pattern.additional_data + const size_t map_size = ( + 1 // Search pattern is always present + + ONE_IF_NOT_DEFAULT(entry, search_pattern.magic) + + ONE_IF_NOT_DEFAULT(entry, search_pattern.is_last_used) + + ONE_IF_NOT_DEFAULT(entry, search_pattern.smartcase) + + ONE_IF_NOT_DEFAULT(entry, search_pattern.has_line_offset) + + ONE_IF_NOT_DEFAULT(entry, search_pattern.place_cursor_at_end) + + ONE_IF_NOT_DEFAULT(entry, + search_pattern.is_substitute_pattern) + + ONE_IF_NOT_DEFAULT(entry, search_pattern.highlighted) + + ONE_IF_NOT_DEFAULT(entry, search_pattern.offset) + + ONE_IF_NOT_DEFAULT(entry, search_pattern.search_backward) + // finally, additional data: + + ( + entry.data.search_pattern.additional_data ? entry.data.search_pattern.additional_data->dv_hashtab.ht_used : 0)); msgpack_pack_map(spacker, map_size); @@ -1682,14 +1682,14 @@ static ShaDaWriteResult shada_pack_entry(msgpack_packer *const packer, ShadaEntr case kSDItemGlobalMark: case kSDItemLocalMark: case kSDItemJump: { - const size_t map_size = (size_t)( - 1 // File name - + ONE_IF_NOT_DEFAULT(entry, filemark.mark.lnum) - + ONE_IF_NOT_DEFAULT(entry, filemark.mark.col) - + ONE_IF_NOT_DEFAULT(entry, filemark.name) - // Additional entries, if any: - + (size_t)( - entry.data.filemark.additional_data == NULL + const size_t map_size = ( + 1 // File name + + ONE_IF_NOT_DEFAULT(entry, filemark.mark.lnum) + + ONE_IF_NOT_DEFAULT(entry, filemark.mark.col) + + ONE_IF_NOT_DEFAULT(entry, filemark.name) + // Additional entries, if any: + + ( + entry.data.filemark.additional_data == NULL ? 0 : entry.data.filemark.additional_data->dv_hashtab.ht_used)); msgpack_pack_map(spacker, map_size); @@ -1715,14 +1715,14 @@ static ShaDaWriteResult shada_pack_entry(msgpack_packer *const packer, ShadaEntr break; } case kSDItemRegister: { - const size_t map_size = (size_t)(2 // Register contents and name - + ONE_IF_NOT_DEFAULT(entry, reg.type) - + ONE_IF_NOT_DEFAULT(entry, reg.width) - + ONE_IF_NOT_DEFAULT(entry, reg.is_unnamed) - // Additional entries, if any: - + (size_t)(entry.data.reg.additional_data == NULL - ? 0 - : entry.data.reg.additional_data->dv_hashtab.ht_used)); + const size_t map_size = (2 // Register contents and name + + ONE_IF_NOT_DEFAULT(entry, reg.type) + + ONE_IF_NOT_DEFAULT(entry, reg.width) + + ONE_IF_NOT_DEFAULT(entry, reg.is_unnamed) + // Additional entries, if any: + + (entry.data.reg.additional_data == NULL + ? 0 + : entry.data.reg.additional_data->dv_hashtab.ht_used)); msgpack_pack_map(spacker, map_size); PACK_STATIC_STR(REG_KEY_CONTENTS); msgpack_pack_array(spacker, entry.data.reg.contents_size); @@ -1753,16 +1753,16 @@ static ShaDaWriteResult shada_pack_entry(msgpack_packer *const packer, ShadaEntr case kSDItemBufferList: msgpack_pack_array(spacker, entry.data.buffer_list.size); for (size_t i = 0; i < entry.data.buffer_list.size; i++) { - const size_t map_size = (size_t)( - 1 // Buffer name - + (size_t)(entry.data.buffer_list.buffers[i].pos.lnum - != default_pos.lnum) - + (size_t)(entry.data.buffer_list.buffers[i].pos.col - != default_pos.col) - // Additional entries, if any: - + (size_t)( - entry.data.buffer_list.buffers[i].additional_data - == NULL + const size_t map_size = ( + 1 // Buffer name + + (size_t)(entry.data.buffer_list.buffers[i].pos.lnum + != default_pos.lnum) + + (size_t)(entry.data.buffer_list.buffers[i].pos.col + != default_pos.col) + // Additional entries, if any: + + ( + entry.data.buffer_list.buffers[i].additional_data + == NULL ? 0 : (entry.data.buffer_list.buffers[i].additional_data ->dv_hashtab.ht_used))); -- 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/shada.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/shada.c') diff --git a/src/nvim/shada.c b/src/nvim/shada.c index ae9e9463de..c405b8ca5f 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -3168,8 +3168,8 @@ int shada_read_everything(const char *const fname, const bool forceit, const boo { return shada_read_file(fname, kShaDaWantInfo|kShaDaWantMarks|kShaDaGetOldfiles - |(forceit?kShaDaForceit:0) - |(missing_ok?0:kShaDaMissingError)); + |(forceit ? kShaDaForceit : 0) + |(missing_ok ? 0 : kShaDaMissingError)); } static void shada_free_shada_entry(ShadaEntry *const entry) -- 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/shada.c | 208 ++++++++++++++++++++++--------------------------------- 1 file changed, 81 insertions(+), 127 deletions(-) (limited to 'src/nvim/shada.c') diff --git a/src/nvim/shada.c b/src/nvim/shada.c index c405b8ca5f..d3a0b12e5e 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -16,7 +16,6 @@ #include #include "auto/config.h" -#include "klib/khash.h" #include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" #include "nvim/ascii.h" @@ -35,6 +34,7 @@ #include "nvim/globals.h" #include "nvim/hashtab.h" #include "nvim/macros.h" +#include "nvim/map.h" #include "nvim/mark.h" #include "nvim/mbyte.h" #include "nvim/memory.h" @@ -62,19 +62,6 @@ # include ENDIAN_INCLUDE_FILE #endif -// Note: when using bufset hash pointers are intentionally casted to uintptr_t -// and not to khint32_t or khint64_t: this way compiler must give a warning -// (-Wconversion) when types change. -#ifdef ARCH_32 -KHASH_SET_INIT_INT(bufset) -#elif defined(ARCH_64) -KHASH_SET_INIT_INT64(bufset) -#else -# error Not a 64- or 32-bit architecture -#endif -KHASH_MAP_INIT_STR(fnamebufs, buf_T *) -KHASH_SET_INIT_STR(strset) - #define SEARCH_KEY_MAGIC "sm" #define SEARCH_KEY_SMARTCASE "sc" #define SEARCH_KEY_HAS_LINE_OFFSET "sl" @@ -305,8 +292,6 @@ typedef struct hm_llist_entry { struct hm_llist_entry *prev; ///< Pointer to previous entry or NULL. } HMLListEntry; -KHASH_MAP_INIT_STR(hmll_entries, HMLListEntry *) - /// Sized linked list structure for history merger typedef struct { HMLListEntry *entries; ///< Pointer to the start of the allocated array of @@ -318,9 +303,8 @@ typedef struct { HMLListEntry *last_free_entry; ///< Last unused element in entries array. size_t size; ///< Number of allocated entries. size_t num_entries; ///< Number of entries already used. - khash_t(hmll_entries) contained_entries; ///< Hash mapping all history entry - ///< strings to corresponding entry - ///< pointers. + PMap(cstr_t) contained_entries; ///< Map all history entry strings to + ///< corresponding entry pointers. } HMLList; typedef struct { @@ -348,8 +332,6 @@ typedef struct { Timestamp greatest_timestamp; ///< Greatest timestamp among marks. } FileMarks; -KHASH_MAP_INIT_STR(file_marks, FileMarks) - /// State structure used by shada_write /// /// Before actually writing most of the data is read to this structure. @@ -363,8 +345,8 @@ typedef struct { PossiblyFreedShadaEntry search_pattern; ///< Last search pattern. PossiblyFreedShadaEntry sub_search_pattern; ///< Last s/ search pattern. PossiblyFreedShadaEntry replacement; ///< Last s// replacement string. - khash_t(strset) dumped_variables; ///< Names of already dumped variables. - khash_t(file_marks) file_marks; ///< All file marks. + Set(cstr_t) dumped_variables; ///< Names of already dumped variables. + PMap(cstr_t) file_marks; ///< All file marks. } WriteMergerState; struct sd_read_def; @@ -504,7 +486,7 @@ static inline void hmll_init(HMLList *const hmll, const size_t size) .free_entry = NULL, .size = size, .num_entries = 0, - .contained_entries = KHASH_EMPTY_TABLE(hmll_entries), + .contained_entries = MAP_INIT, }; hmll->last_free_entry = hmll->entries; } @@ -535,10 +517,10 @@ static inline void hmll_remove(HMLList *const hmll, HMLListEntry *const hmll_ent assert(hmll->free_entry == NULL); hmll->free_entry = hmll_entry; } - const khiter_t k = kh_get(hmll_entries, &hmll->contained_entries, - hmll_entry->data.data.history_item.string); - assert(k != kh_end(&hmll->contained_entries)); - kh_del(hmll_entries, &hmll->contained_entries, k); + ptr_t val = pmap_del(cstr_t)(&hmll->contained_entries, + hmll_entry->data.data.history_item.string, NULL); + assert(val); + (void)val; if (hmll_entry->next == NULL) { hmll->last = hmll_entry->prev; } else { @@ -586,11 +568,11 @@ static inline void hmll_insert(HMLList *const hmll, HMLListEntry *hmll_entry, co } target_entry->data = data; target_entry->can_free_entry = can_free_entry; - int kh_ret; - const khiter_t k = kh_put(hmll_entries, &hmll->contained_entries, - data.data.history_item.string, &kh_ret); - if (kh_ret > 0) { - kh_val(&hmll->contained_entries, k) = target_entry; + bool new_item = false; + ptr_t *val = pmap_put_ref(cstr_t)(&hmll->contained_entries, data.data.history_item.string, + NULL, &new_item); + if (new_item) { + *val = target_entry; } hmll->num_entries++; target_entry->prev = hmll_entry; @@ -614,7 +596,7 @@ static inline void hmll_insert(HMLList *const hmll, HMLListEntry *hmll_entry, co static inline void hmll_dealloc(HMLList *const hmll) FUNC_ATTR_NONNULL_ALL { - kh_dealloc(hmll_entries, &hmll->contained_entries); + map_destroy(cstr_t, &hmll->contained_entries); xfree(hmll->entries); } @@ -771,30 +753,6 @@ static void close_file(void *cookie) } } -/// Check whether buffer is in the given set -/// -/// @param[in] set Set to check within. -/// @param[in] buf Buffer to find. -/// -/// @return true or false. -static inline bool in_bufset(const khash_t(bufset) *const set, const buf_T *buf) - FUNC_ATTR_PURE -{ - return kh_get(bufset, set, (uintptr_t)buf) != kh_end(set); -} - -/// Check whether string is in the given set -/// -/// @param[in] set Set to check within. -/// @param[in] buf Buffer to find. -/// -/// @return true or false. -static inline bool in_strset(const khash_t(strset) *const set, char *str) - FUNC_ATTR_PURE -{ - return kh_get(strset, set, str) != kh_end(set); -} - /// Msgpack callback for writing to ShaDaWriteDef* static int msgpack_sd_writer_write(void *data, const char *buf, size_t len) { @@ -930,10 +888,11 @@ static void hms_insert(HistoryMergerState *const hms_p, const ShadaEntry entry, } } HMLList *const hmll = &hms_p->hmll; - const khiter_t k = kh_get(hmll_entries, &hms_p->hmll.contained_entries, - entry.data.history_item.string); - if (k != kh_end(&hmll->contained_entries)) { - HMLListEntry *const existing_entry = kh_val(&hmll->contained_entries, k); + cstr_t *key_alloc = NULL; + ptr_t *val = pmap_ref(cstr_t)(&hms_p->hmll.contained_entries, entry.data.history_item.string, + &key_alloc); + if (val) { + HMLListEntry *const existing_entry = *val; if (entry.timestamp > existing_entry->data.timestamp) { hmll_remove(hmll, existing_entry); } else if (!do_iter && entry.timestamp == existing_entry->data.timestamp) { @@ -944,7 +903,7 @@ static void hms_insert(HistoryMergerState *const hms_p, const ShadaEntry entry, existing_entry->data = entry; existing_entry->can_free_entry = can_free_entry; // Previous key was freed above, as part of freeing the ShaDa entry. - kh_key(&hmll->contained_entries, k) = entry.data.history_item.string; + *key_alloc = entry.data.history_item.string; return; } else { return; @@ -1046,24 +1005,27 @@ static inline void hms_dealloc(HistoryMergerState *const hms_p) /// @param[in] fname File name to find. /// /// @return Pointer to the buffer or NULL. -static buf_T *find_buffer(khash_t(fnamebufs) *const fname_bufs, const char *const fname) +static buf_T *find_buffer(PMap(cstr_t) *const fname_bufs, const char *const fname) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { - int kh_ret; - khint_t k = kh_put(fnamebufs, fname_bufs, fname, &kh_ret); - if (!kh_ret) { - return kh_val(fname_bufs, k); + cstr_t *key_alloc = NULL; + bool new_item = false; + buf_T **ref = (buf_T **)pmap_put_ref(cstr_t)(fname_bufs, fname, &key_alloc, &new_item); + if (new_item) { + *key_alloc = xstrdup(fname); + } else { + return *ref; // item already existed (can be a NULL value) } - kh_key(fname_bufs, k) = xstrdup(fname); + FOR_ALL_BUFFERS(buf) { if (buf->b_ffname != NULL) { if (path_fnamecmp(fname, buf->b_ffname) == 0) { - kh_val(fname_bufs, k) = buf; + *ref = buf; return buf; } } } - kh_val(fname_bufs, k) = NULL; + *ref = NULL; return NULL; } @@ -1163,9 +1125,9 @@ static void shada_read(ShaDaReadDef *const sd_reader, const int flags) } } ShadaEntry cur_entry; - khash_t(bufset) cl_bufs = KHASH_EMPTY_TABLE(bufset); - khash_t(fnamebufs) fname_bufs = KHASH_EMPTY_TABLE(fnamebufs); - khash_t(strset) oldfiles_set = KHASH_EMPTY_TABLE(strset); + Set(ptr_t) cl_bufs = SET_INIT; + PMap(cstr_t) fname_bufs = MAP_INIT; + Set(cstr_t) oldfiles_set = SET_INIT; if (get_old_files && (oldfiles_list == NULL || force)) { oldfiles_list = tv_list_alloc(kListLenUnknown); set_vim_var_list(VV_OLDFILES, oldfiles_list); @@ -1359,8 +1321,7 @@ static void shada_read(ShaDaReadDef *const sd_reader, const int flags) break; case kSDItemChange: case kSDItemLocalMark: { - if (get_old_files && !in_strset(&oldfiles_set, - cur_entry.data.filemark.fname)) { + if (get_old_files && !set_has(cstr_t, &oldfiles_set, cur_entry.data.filemark.fname)) { char *fname = cur_entry.data.filemark.fname; if (want_marks) { // Do not bother with allocating memory for the string if already @@ -1368,8 +1329,7 @@ static void shada_read(ShaDaReadDef *const sd_reader, const int flags) // want_marks is set because this way it may be used for a mark. fname = xstrdup(fname); } - int kh_ret; - (void)kh_put(strset, &oldfiles_set, fname, &kh_ret); + set_put(cstr_t, &oldfiles_set, fname); tv_list_append_allocated_string(oldfiles_list, fname); if (!want_marks) { // Avoid free because this string was already used. @@ -1398,8 +1358,7 @@ static void shada_read(ShaDaReadDef *const sd_reader, const int flags) break; } } else { - int kh_ret; - (void)kh_put(bufset, &cl_bufs, (uintptr_t)buf, &kh_ret); + set_put(ptr_t, &cl_bufs, buf); #define SDE_TO_FMARK(entry) fm #define AFTERFREE(entry) (entry).data.filemark.fname = NULL #define DUMMY_IDX_ADJ(i) @@ -1440,18 +1399,18 @@ shada_read_main_cycle_end: if (cl_bufs.n_occupied) { FOR_ALL_TAB_WINDOWS(tp, wp) { (void)tp; - if (in_bufset(&cl_bufs, wp->w_buffer)) { + if (set_has(ptr_t, &cl_bufs, wp->w_buffer)) { wp->w_changelistidx = wp->w_buffer->b_changelistlen; } } } - kh_dealloc(bufset, &cl_bufs); + set_destroy(ptr_t, &cl_bufs); const char *key; - kh_foreach_key(&fname_bufs, key, { - xfree((void *)key); + map_foreach_key(&fname_bufs, key, { + xfree((char *)key); }) - kh_dealloc(fnamebufs, &fname_bufs); - kh_dealloc(strset, &oldfiles_set); + map_destroy(cstr_t, &fname_bufs); + set_destroy(cstr_t, &oldfiles_set); } /// Default shada file location: cached path @@ -2154,7 +2113,7 @@ static inline ShaDaWriteResult shada_read_when_writing(ShaDaReadDef *const sd_re break; } case kSDItemVariable: - if (!in_strset(&wms->dumped_variables, entry.data.global_var.name)) { + if (!set_has(cstr_t, &wms->dumped_variables, entry.data.global_var.name)) { ret = shada_pack_entry(packer, entry, 0); } shada_free_shada_entry(&entry); @@ -2211,13 +2170,12 @@ static inline ShaDaWriteResult shada_read_when_writing(ShaDaReadDef *const sd_re break; } const char *const fname = entry.data.filemark.fname; - khiter_t k; - int kh_ret; - k = kh_put(file_marks, &wms->file_marks, fname, &kh_ret); - FileMarks *const filemarks = &kh_val(&wms->file_marks, k); - if (kh_ret > 0) { - CLEAR_POINTER(filemarks); + cstr_t *key = NULL; + ptr_t *val = pmap_put_ref(cstr_t)(&wms->file_marks, fname, &key, NULL); + if (*val == NULL) { + *val = xcalloc(1, sizeof(FileMarks)); } + FileMarks *const filemarks = *val; if (entry.timestamp > filemarks->greatest_timestamp) { filemarks->greatest_timestamp = entry.timestamp; } @@ -2237,9 +2195,8 @@ static inline ShaDaWriteResult shada_read_when_writing(ShaDaReadDef *const sd_re break; } if (wms_entry->can_free_entry) { - if (kh_key(&wms->file_marks, k) - == wms_entry->data.data.filemark.fname) { - kh_key(&wms->file_marks, k) = entry.data.filemark.fname; + if (*key == wms_entry->data.data.filemark.fname) { + *key = entry.data.filemark.fname; } shada_free_shada_entry(&wms_entry->data); } @@ -2281,11 +2238,11 @@ static inline ShaDaWriteResult shada_read_when_writing(ShaDaReadDef *const sd_re /// @param[in] removable_bufs Cache of buffers ignored due to their location. /// /// @return true or false. -static inline bool ignore_buf(const buf_T *const buf, khash_t(bufset) *const removable_bufs) +static inline bool ignore_buf(const buf_T *const buf, Set(ptr_t) *const removable_bufs) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_ALWAYS_INLINE { return (buf->b_ffname == NULL || !buf->b_p_bl || bt_quickfix(buf) \ - || bt_terminal(buf) || in_bufset(removable_bufs, buf)); + || bt_terminal(buf) || set_has(ptr_t, removable_bufs, (ptr_t)buf)); } /// Get list of buffers to write to the shada file @@ -2293,7 +2250,7 @@ static inline bool ignore_buf(const buf_T *const buf, khash_t(bufset) *const rem /// @param[in] removable_bufs Buffers which are ignored /// /// @return ShadaEntry List of buffers to save, kSDItemBufferList entry. -static inline ShadaEntry shada_get_buflist(khash_t(bufset) *const removable_bufs) +static inline ShadaEntry shada_get_buflist(Set(ptr_t) *const removable_bufs) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_ALWAYS_INLINE { int max_bufs = get_shada_parameter('%'); @@ -2461,12 +2418,11 @@ static inline void replace_numbered_mark(WriteMergerState *const wms, const size /// Find buffers ignored due to their location. /// /// @param[out] removable_bufs Cache of buffers ignored due to their location. -static inline void find_removable_bufs(khash_t(bufset) *removable_bufs) +static inline void find_removable_bufs(Set(ptr_t) *removable_bufs) { FOR_ALL_BUFFERS(buf) { if (buf->b_ffname != NULL && shada_removable(buf->b_ffname)) { - int kh_ret; - (void)kh_put(bufset, removable_bufs, (uintptr_t)buf, &kh_ret); + set_put(ptr_t, removable_bufs, (ptr_t)buf); } } } @@ -2518,7 +2474,7 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer, ShaDaReadDef max_reg_lines = get_shada_parameter('"'); } const bool dump_registers = (max_reg_lines != 0); - khash_t(bufset) removable_bufs = KHASH_EMPTY_TABLE(bufset); + Set(ptr_t) removable_bufs = SET_INIT; const size_t max_kbyte = (size_t)max_kbyte_i; const size_t num_marked_files = (size_t)get_shada_parameter('\''); const bool dump_global_marks = get_shada_parameter('f') != 0; @@ -2662,8 +2618,7 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer, ShaDaReadDef tv_clear(&vartv); tv_clear(&tgttv); if (spe_ret == kSDWriteSuccessful) { - int kh_ret; - (void)kh_put(strset, &wms->dumped_variables, name, &kh_ret); + set_put(cstr_t, &wms->dumped_variables, name); } } while (var_iter != NULL); } @@ -2723,7 +2678,7 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer, ShaDaReadDef } else { const buf_T *const buf = buflist_findnr(fm.fmark.fnum); if (buf == NULL || buf->b_ffname == NULL - || in_bufset(&removable_bufs, buf)) { + || set_has(ptr_t, &removable_bufs, (ptr_t)buf)) { continue; } fname = buf->b_ffname; @@ -2759,18 +2714,16 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer, ShaDaReadDef // Initialize buffers if (num_marked_files > 0) { FOR_ALL_BUFFERS(buf) { - if (buf->b_ffname == NULL || in_bufset(&removable_bufs, buf)) { + if (buf->b_ffname == NULL || set_has(ptr_t, &removable_bufs, buf)) { continue; } const void *local_marks_iter = NULL; const char *const fname = buf->b_ffname; - khiter_t k; - int kh_ret; - k = kh_put(file_marks, &wms->file_marks, fname, &kh_ret); - FileMarks *const filemarks = &kh_val(&wms->file_marks, k); - if (kh_ret > 0) { - CLEAR_POINTER(filemarks); + ptr_t *val = pmap_put_ref(cstr_t)(&wms->file_marks, fname, NULL, NULL); + if (*val == NULL) { + *val = xcalloc(1, sizeof(FileMarks)); } + FileMarks *const filemarks = *val; do { fmark_T fm; char name = NUL; @@ -2887,16 +2840,14 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer, ShaDaReadDef PACK_WMS_ENTRY(wms->replacement); #undef PACK_WMS_ENTRY - const size_t file_markss_size = kh_size(&wms->file_marks); + const size_t file_markss_size = map_size(&wms->file_marks); FileMarks **const all_file_markss = xmalloc(file_markss_size * sizeof(*all_file_markss)); FileMarks **cur_file_marks = all_file_markss; - for (khint_t i = kh_begin(&wms->file_marks); i != kh_end(&wms->file_marks); - i++) { - if (kh_exist(&wms->file_marks, i)) { - *cur_file_marks++ = &kh_val(&wms->file_marks, i); - } - } + ptr_t val; + map_foreach_value(ptr_t, &wms->file_marks, val, { + *cur_file_marks++ = val; + }) qsort((void *)all_file_markss, file_markss_size, sizeof(*all_file_markss), &compare_file_marks); const size_t file_markss_to_dump = MIN(num_marked_files, file_markss_size); @@ -2949,10 +2900,13 @@ shada_write_exit: hms_dealloc(&wms->hms[i]); } } - kh_dealloc(file_marks, &wms->file_marks); - kh_dealloc(bufset, &removable_bufs); + map_foreach_value(ptr_t, &wms->file_marks, val, { + xfree(val); + }) + map_destroy(cstr_t, &wms->file_marks); + set_destroy(ptr_t, &removable_bufs); msgpack_packer_free(packer); - kh_dealloc(strset, &wms->dumped_variables); + set_destroy(cstr_t, &wms->dumped_variables); xfree(wms); return ret; } @@ -4035,7 +3989,7 @@ static bool shada_removable(const char *name) /// /// @return number of jumplist entries static inline size_t shada_init_jumps(PossiblyFreedShadaEntry *jumps, - khash_t(bufset) *const removable_bufs) + Set(ptr_t) *const removable_bufs) { // Initialize jump list size_t jumps_size = 0; @@ -4056,7 +4010,7 @@ static inline size_t shada_init_jumps(PossiblyFreedShadaEntry *jumps, ? NULL : buflist_findnr(fm.fmark.fnum)); if (buf != NULL - ? in_bufset(removable_bufs, buf) + ? set_has(ptr_t, removable_bufs, (ptr_t)buf) : fm.fmark.fnum != 0) { continue; } @@ -4111,7 +4065,7 @@ void shada_encode_regs(msgpack_sbuffer *const sbuf) void shada_encode_jumps(msgpack_sbuffer *const sbuf) FUNC_ATTR_NONNULL_ALL { - khash_t(bufset) removable_bufs = KHASH_EMPTY_TABLE(bufset); + Set(ptr_t) removable_bufs = SET_INIT; find_removable_bufs(&removable_bufs); PossiblyFreedShadaEntry jumps[JUMPLISTSIZE]; size_t jumps_size = shada_init_jumps(jumps, &removable_bufs); @@ -4130,7 +4084,7 @@ void shada_encode_jumps(msgpack_sbuffer *const sbuf) void shada_encode_buflist(msgpack_sbuffer *const sbuf) FUNC_ATTR_NONNULL_ALL { - khash_t(bufset) removable_bufs = KHASH_EMPTY_TABLE(bufset); + Set(ptr_t) removable_bufs = SET_INIT; find_removable_bufs(&removable_bufs); ShadaEntry buflist_entry = shada_get_buflist(&removable_bufs); msgpack_packer packer; -- cgit From cfd4fdfea4d0e68ea50ad412b88b5289ded6fd6f Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Tue, 23 May 2023 14:25:10 +0600 Subject: refactor(api): new helper macros Adds new API helper macros `CSTR_AS_OBJ()`, `STATIC_CSTR_AS_OBJ()`, and `STATIC_CSTR_TO_OBJ()`, which cleans up a lot of the current code. These macros will also be used extensively in the upcoming option refactor PRs because then API Objects will be used to get/set options. This PR also modifies pre-existing code to use old API helper macros like `CSTR_TO_OBJ()` to make them cleaner. --- src/nvim/shada.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/shada.c') diff --git a/src/nvim/shada.c b/src/nvim/shada.c index d3a0b12e5e..db911f4bfd 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -2529,15 +2529,15 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer, ShaDaReadDef .capacity = 5, .items = ((KeyValuePair[]) { { STATIC_CSTR_AS_STRING("generator"), - STRING_OBJ(STATIC_CSTR_AS_STRING("nvim")) }, + STATIC_CSTR_AS_OBJ("nvim") }, { STATIC_CSTR_AS_STRING("version"), - STRING_OBJ(cstr_as_string(longVersion)) }, + CSTR_AS_OBJ(longVersion) }, { STATIC_CSTR_AS_STRING("max_kbyte"), INTEGER_OBJ((Integer)max_kbyte) }, { STATIC_CSTR_AS_STRING("pid"), INTEGER_OBJ((Integer)os_get_pid()) }, { STATIC_CSTR_AS_STRING("encoding"), - STRING_OBJ(cstr_as_string(p_enc)) }, + CSTR_AS_OBJ(p_enc) }, }), } } -- cgit From 2f17ef1fc4b96cf1106fd95ba090d34a2e4b977b Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 22 Jun 2023 04:09:14 -0700 Subject: fix(messages): use "Vimscript" instead of "VimL" #24111 followup to #24109 fix #16150 --- src/nvim/shada.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/shada.c') diff --git a/src/nvim/shada.c b/src/nvim/shada.c index db911f4bfd..f8c448dce0 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -3396,7 +3396,7 @@ static ShaDaReadResult msgpack_read_uint64(ShaDaReadDef *const sd_reader, const if (msgpack_to_vim(obj, &adtv) == FAIL \ || adtv.v_type != VAR_DICT) { \ semsg(_(READERR(name, \ - "cannot be converted to a VimL dictionary")), \ + "cannot be converted to a Vimscript dictionary")), \ initial_fpos); \ ga_clear(&ad_ga); \ tv_clear(&adtv); \ @@ -3420,7 +3420,7 @@ static ShaDaReadResult msgpack_read_uint64(ShaDaReadDef *const sd_reader, const }; \ typval_T aetv; \ if (msgpack_to_vim(obj, &aetv) == FAIL) { \ - semsg(_(READERR(name, "cannot be converted to a VimL list")), \ + semsg(_(READERR(name, "cannot be converted to a Vimscript list")), \ initial_fpos); \ tv_clear(&aetv); \ goto shada_read_next_item_error; \ @@ -3819,7 +3819,7 @@ shada_read_next_item_start: } else if (msgpack_to_vim(unpacked.data.via.array.ptr[1], &(entry->data.global_var.value)) == FAIL) { semsg(_(READERR("variable", "has value that cannot " - "be converted to the VimL value")), initial_fpos); + "be converted to the Vimscript value")), initial_fpos); goto shada_read_next_item_error; } break; -- cgit From ee56daebb6468075e743db0d605cb3f2a1699419 Mon Sep 17 00:00:00 2001 From: Maria José Solano Date: Wed, 30 Aug 2023 19:15:49 -0700 Subject: fix(shada): update deleted marks (#24936) Fix #4295 Close #16067 Co-authored-by: chentau --- src/nvim/shada.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src/nvim/shada.c') diff --git a/src/nvim/shada.c b/src/nvim/shada.c index f8c448dce0..49136402ac 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -2160,6 +2160,12 @@ static inline ShaDaWriteResult shada_read_when_writing(ShaDaReadDef *const sd_re shada_free_shada_entry(&entry); break; } + if (wms->global_marks[idx].data.type == kSDItemMissing) { + if (namedfm[idx].fmark.timestamp >= entry.timestamp) { + shada_free_shada_entry(&entry); + break; + } + } COMPARE_WITH_ENTRY(&wms->global_marks[idx], entry); } break; @@ -2189,6 +2195,7 @@ static inline ShaDaWriteResult shada_read_when_writing(ShaDaReadDef *const sd_re entry; } else { PossiblyFreedShadaEntry *const wms_entry = &filemarks->marks[idx]; + bool set_wms = true; if (wms_entry->data.type != kSDItemMissing) { if (wms_entry->data.timestamp >= entry.timestamp) { shada_free_shada_entry(&entry); @@ -2200,8 +2207,23 @@ static inline ShaDaWriteResult shada_read_when_writing(ShaDaReadDef *const sd_re } shada_free_shada_entry(&wms_entry->data); } + } else { + FOR_ALL_BUFFERS(buf) { + if (buf->b_ffname != NULL + && path_fnamecmp(entry.data.filemark.fname, buf->b_ffname) == 0) { + fmark_T fm; + mark_get(buf, curwin, &fm, kMarkBufLocal, (int)entry.data.filemark.name); + if (fm.timestamp >= entry.timestamp) { + set_wms = false; + shada_free_shada_entry(&entry); + break; + } + } + } + } + if (set_wms) { + *wms_entry = pfs_entry; } - *wms_entry = pfs_entry; } } else { #define AFTERFREE_DUMMY(entry) -- cgit From 5970157e1d22fd5e05ae5d3bd949f807fb7a744c Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 17 May 2023 16:08:06 +0200 Subject: refactor(map): enhanced implementation, Clean Code™, etc etc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This involves two redesigns of the map.c implementations: 1. Change of macro style and code organization The old khash.h and map.c implementation used huge #define blocks with a lot of backslash line continuations. This instead uses the "implementation file" .c.h pattern. Such a file is meant to be included multiple times, with different macros set prior to inclusion as parameters. we already use this pattern e.g. for eval/typval_encode.c.h to implement different typval encoders reusing a similar structure. We can structure this code into two parts. one that only depends on key type and is enough to implement sets, and one which depends on both key and value to implement maps (as a wrapper around sets, with an added value[] array) 2. Separate the main hash buckets from the key / value arrays Change the hack buckets to only contain an index into separate key / value arrays This is a common pattern in modern, state of the art hashmap implementations. Even though this leads to one more allocated array, it is this often is a net reduction of memory consumption. Consider key+value consuming at least 12 bytes per pair. On average, we will have twice as many buckets per item. Thus old implementation: 2*12 = 24 bytes per item New implementation 1*12 + 2*4 = 20 bytes per item And the difference gets bigger with larger items. One might think we have pulled a fast one here, as wouldn't the average size of the new key/value arrays be 1.5 slots per items due to amortized grows? But remember, these arrays are fully dense, and thus the accessed memory, measured in _cache lines_, the unit which actually matters, will be the fully used memory but just rounded up to the nearest cache line boundary. This has some other interesting properties, such as an insert-only set/map will be fully ordered by insert only. Preserving this ordering in face of deletions is more tricky tho. As we currently don't use ordered maps, the "delete" operation maintains compactness of the item arrays in the simplest way by breaking the ordering. It would be possible to implement an order-preserving delete although at some cost, like allowing the items array to become non-dense until the next rehash. Finally, in face of these two major changes, all code used in khash.h has been integrated into map.c and friends. Given the heavy edits it makes no sense to "layer" the code into a vendored and a wrapper part. Rather, the layered cake follows the specialization depth: code shared for all maps, code specialized to a key type (and its equivalence relation), and finally code specialized to value+key type. --- src/nvim/shada.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/nvim/shada.c') diff --git a/src/nvim/shada.c b/src/nvim/shada.c index 49136402ac..e302c05b1c 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -1396,7 +1396,7 @@ shada_read_main_cycle_end: hms_dealloc(&hms[i]); } } - if (cl_bufs.n_occupied) { + if (cl_bufs.h.n_occupied) { FOR_ALL_TAB_WINDOWS(tp, wp) { (void)tp; if (set_has(ptr_t, &cl_bufs, wp->w_buffer)) { @@ -1600,7 +1600,7 @@ static ShaDaWriteResult shada_pack_entry(msgpack_packer *const packer, ShadaEntr break; } case kSDItemSearchPattern: { - const size_t map_size = ( + size_t entry_map_size = ( 1 // Search pattern is always present + ONE_IF_NOT_DEFAULT(entry, search_pattern.magic) + ONE_IF_NOT_DEFAULT(entry, search_pattern.is_last_used) @@ -1617,7 +1617,7 @@ static ShaDaWriteResult shada_pack_entry(msgpack_packer *const packer, ShadaEntr entry.data.search_pattern.additional_data ? entry.data.search_pattern.additional_data->dv_hashtab.ht_used : 0)); - msgpack_pack_map(spacker, map_size); + msgpack_pack_map(spacker, entry_map_size); PACK_STATIC_STR(SEARCH_KEY_PAT); PACK_BIN(cstr_as_string(entry.data.search_pattern.pat)); PACK_BOOL(entry, SEARCH_KEY_MAGIC, magic); @@ -1641,7 +1641,7 @@ static ShaDaWriteResult shada_pack_entry(msgpack_packer *const packer, ShadaEntr case kSDItemGlobalMark: case kSDItemLocalMark: case kSDItemJump: { - const size_t map_size = ( + size_t entry_map_size = ( 1 // File name + ONE_IF_NOT_DEFAULT(entry, filemark.mark.lnum) + ONE_IF_NOT_DEFAULT(entry, filemark.mark.col) @@ -1651,7 +1651,7 @@ static ShaDaWriteResult shada_pack_entry(msgpack_packer *const packer, ShadaEntr entry.data.filemark.additional_data == NULL ? 0 : entry.data.filemark.additional_data->dv_hashtab.ht_used)); - msgpack_pack_map(spacker, map_size); + msgpack_pack_map(spacker, entry_map_size); PACK_STATIC_STR(KEY_FILE); PACK_BIN(cstr_as_string(entry.data.filemark.fname)); if (!CHECK_DEFAULT(entry, filemark.mark.lnum)) { @@ -1674,7 +1674,7 @@ static ShaDaWriteResult shada_pack_entry(msgpack_packer *const packer, ShadaEntr break; } case kSDItemRegister: { - const size_t map_size = (2 // Register contents and name + size_t entry_map_size = (2 // Register contents and name + ONE_IF_NOT_DEFAULT(entry, reg.type) + ONE_IF_NOT_DEFAULT(entry, reg.width) + ONE_IF_NOT_DEFAULT(entry, reg.is_unnamed) @@ -1682,7 +1682,7 @@ static ShaDaWriteResult shada_pack_entry(msgpack_packer *const packer, ShadaEntr + (entry.data.reg.additional_data == NULL ? 0 : entry.data.reg.additional_data->dv_hashtab.ht_used)); - msgpack_pack_map(spacker, map_size); + msgpack_pack_map(spacker, entry_map_size); PACK_STATIC_STR(REG_KEY_CONTENTS); msgpack_pack_array(spacker, entry.data.reg.contents_size); for (size_t i = 0; i < entry.data.reg.contents_size; i++) { @@ -1712,7 +1712,7 @@ static ShaDaWriteResult shada_pack_entry(msgpack_packer *const packer, ShadaEntr case kSDItemBufferList: msgpack_pack_array(spacker, entry.data.buffer_list.size); for (size_t i = 0; i < entry.data.buffer_list.size; i++) { - const size_t map_size = ( + size_t entry_map_size = ( 1 // Buffer name + (size_t)(entry.data.buffer_list.buffers[i].pos.lnum != default_pos.lnum) @@ -1725,7 +1725,7 @@ static ShaDaWriteResult shada_pack_entry(msgpack_packer *const packer, ShadaEntr ? 0 : (entry.data.buffer_list.buffers[i].additional_data ->dv_hashtab.ht_used))); - msgpack_pack_map(spacker, map_size); + msgpack_pack_map(spacker, entry_map_size); PACK_STATIC_STR(KEY_FILE); PACK_BIN(cstr_as_string(entry.data.buffer_list.buffers[i].fname)); if (entry.data.buffer_list.buffers[i].pos.lnum != 1) { @@ -2867,7 +2867,7 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer, ShaDaReadDef xmalloc(file_markss_size * sizeof(*all_file_markss)); FileMarks **cur_file_marks = all_file_markss; ptr_t val; - map_foreach_value(ptr_t, &wms->file_marks, val, { + map_foreach_value(&wms->file_marks, val, { *cur_file_marks++ = val; }) qsort((void *)all_file_markss, file_markss_size, sizeof(*all_file_markss), @@ -2922,7 +2922,7 @@ shada_write_exit: hms_dealloc(&wms->hms[i]); } } - map_foreach_value(ptr_t, &wms->file_marks, val, { + map_foreach_value(&wms->file_marks, val, { xfree(val); }) map_destroy(cstr_t, &wms->file_marks); -- cgit From af7d317f3ff31d5ac5d8724b5057a422e1451b54 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Tue, 26 Sep 2023 22:36:08 +0200 Subject: refactor: remove long long is 32-bits even on 64-bit windows which makes the type suboptimal for a codebase meant to be cross-platform. --- src/nvim/shada.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/shada.c') diff --git a/src/nvim/shada.c b/src/nvim/shada.c index e302c05b1c..658312d3b4 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -2506,7 +2506,7 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer, ShaDaReadDef for (HistoryType i = 0; i < HIST_COUNT; i++) { long num_saved = get_shada_parameter(hist_type2char(i)); if (num_saved == -1) { - num_saved = p_hi; + num_saved = (long)p_hi; } if (num_saved > 0) { dump_history = true; -- cgit From bc13bc154aa574e0bb58a50f2e0ca4570efa57c3 Mon Sep 17 00:00:00 2001 From: bfredl Date: Fri, 29 Sep 2023 16:10:54 +0200 Subject: refactor(message): smsg_attr -> smsg --- src/nvim/shada.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/shada.c') diff --git a/src/nvim/shada.c b/src/nvim/shada.c index 658312d3b4..4fe9498af9 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -795,7 +795,7 @@ static int shada_read_file(const char *const file, const int flags) if (p_verbose > 1) { verbose_enter(); - smsg(_("Reading ShaDa file \"%s\"%s%s%s%s"), + smsg(0, _("Reading ShaDa file \"%s\"%s%s%s%s"), fname, (flags & kShaDaWantInfo) ? _(" info") : "", (flags & kShaDaWantMarks) ? _(" marks") : "", @@ -3049,7 +3049,7 @@ shada_write_file_nomerge: {} if (p_verbose > 1) { verbose_enter(); - smsg(_("Writing ShaDa file \"%s\""), fname); + smsg(0, _("Writing ShaDa file \"%s\""), fname); verbose_leave(); } -- 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/shada.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/shada.c') diff --git a/src/nvim/shada.c b/src/nvim/shada.c index 4fe9498af9..09531cd7f2 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -25,7 +25,6 @@ #include "nvim/eval/decode.h" #include "nvim/eval/encode.h" #include "nvim/eval/typval.h" -#include "nvim/eval/typval_defs.h" #include "nvim/ex_cmds.h" #include "nvim/ex_docmd.h" #include "nvim/fileio.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/shada.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/shada.c') diff --git a/src/nvim/shada.c b/src/nvim/shada.c index 09531cd7f2..14d35d9b59 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -42,6 +42,7 @@ #include "nvim/normal.h" #include "nvim/ops.h" #include "nvim/option.h" +#include "nvim/option_vars.h" #include "nvim/os/fileio.h" #include "nvim/os/fs_defs.h" #include "nvim/os/os.h" -- cgit From 09a17f91d0d362c6e58bfdbe3ccdeacffb0b44b9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 2 Oct 2023 10:45:33 +0800 Subject: refactor: move cmdline completion types to cmdexpand_defs.h (#25465) --- src/nvim/shada.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/nvim/shada.c') diff --git a/src/nvim/shada.c b/src/nvim/shada.c index 14d35d9b59..cd1d016c7b 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -1564,15 +1564,14 @@ static ShaDaWriteResult shada_pack_entry(msgpack_packer *const packer, ShadaEntr break; } case kSDItemVariable: { - if (entry.data.global_var.value.v_type == VAR_TYPE_BLOB) { + if (entry.data.global_var.value.v_type == VAR_BLOB) { // Strings and Blobs both pack as msgpack BINs; differentiate them by // storing an additional VAR_TYPE_BLOB element alongside Blobs list_T *const list = tv_list_alloc(1); tv_list_append_number(list, VAR_TYPE_BLOB); entry.data.global_var.additional_elements = list; } - const size_t arr_size = 2 + (size_t)( - tv_list_len(entry.data.global_var.additional_elements)); + const size_t arr_size = 2 + (size_t)(tv_list_len(entry.data.global_var.additional_elements)); msgpack_pack_array(spacker, arr_size); const String varname = cstr_as_string(entry.data.global_var.name); PACK_BIN(varname); -- cgit From 5f03a1eaabfc8de2b3a9c666fcd604763f41e152 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 20 Oct 2023 15:10:33 +0200 Subject: build(lint): remove unnecessary clint.py rules Uncrustify is the source of truth where possible. Remove any redundant checks from clint.py. --- src/nvim/shada.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/shada.c') diff --git a/src/nvim/shada.c b/src/nvim/shada.c index cd1d016c7b..6a398c167d 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -1505,7 +1505,7 @@ static ShaDaWriteResult shada_pack_entry(msgpack_packer *const packer, ShadaEntr dict_T *const d = (src); \ if (d != NULL) { \ size_t todo = d->dv_hashtab.ht_used; \ - for (const hashitem_T *hi= d->dv_hashtab.ht_array; todo; hi++) { \ + for (const hashitem_T *hi = d->dv_hashtab.ht_array; todo; hi++) { \ if (!HASHITEM_EMPTY(hi)) { \ todo--; \ dictitem_T *const di = TV_DICT_HI2DI(hi); \ -- cgit From acc646ad8fc3ef11fcc63b69f3d8484e4a91accd Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 29 Sep 2023 14:58:48 +0200 Subject: refactor: the long goodbye long is 32 bits on windows, while it is 64 bits on other architectures. This makes the type suboptimal for a codebase meant to be cross-platform. Replace it with more appropriate integer types. --- src/nvim/shada.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/nvim/shada.c') diff --git a/src/nvim/shada.c b/src/nvim/shada.c index 6a398c167d..0729368b9c 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -2503,9 +2503,9 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer, ShaDaReadDef // Initialize history merger for (HistoryType i = 0; i < HIST_COUNT; i++) { - long num_saved = get_shada_parameter(hist_type2char(i)); + int num_saved = get_shada_parameter(hist_type2char(i)); if (num_saved == -1) { - num_saved = (long)p_hi; + num_saved = (int)p_hi; } if (num_saved > 0) { dump_history = true; @@ -3338,7 +3338,6 @@ static ShaDaReadResult msgpack_read_uint64(ShaDaReadDef *const sd_reader, const #define ID(s) s #define BINDUP(b) xmemdupz((b).ptr, (b).size) #define TOINT(s) ((int)(s)) -#define TOLONG(s) ((long)(s)) #define TOCHAR(s) ((char)(s)) #define TOU8(s) ((uint8_t)(s)) #define TOSIZE(s) ((size_t)(s)) @@ -3964,7 +3963,6 @@ shada_read_next_item_error: #undef BINDUP #undef TOCHAR #undef TOINT -#undef TOLONG #undef TYPED_KEY #undef INT_KEY #undef INTEGER_KEY -- 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/shada.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/nvim/shada.c') diff --git a/src/nvim/shada.c b/src/nvim/shada.c index 0729368b9c..97d9ae07a5 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.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 - #include #include #include @@ -3896,7 +3893,7 @@ shada_read_next_item_start: // XXX: Temporarily reassign `i` because the macros depend on it. const size_t j = i; { - for (i = 0; i < unpacked_2.data.via.map.size; i++) { // -V535 + for (i = 0; i < unpacked_2.data.via.map.size; i++) { CHECK_KEY_IS_STR(unpacked_2, "buffer list entry") INTEGER_KEY(unpacked_2, "buffer list entry", KEY_LNUM, entry->data.buffer_list.buffers[j].pos.lnum) -- cgit From ac1113ded5f8f09dd99a9894d7a7e795626fb728 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 13 Nov 2023 23:40:37 +0100 Subject: refactor: follow style guide - reduce variable scope - prefer initialization over declaration and assignment --- src/nvim/shada.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/nvim/shada.c') diff --git a/src/nvim/shada.c b/src/nvim/shada.c index 97d9ae07a5..ae208ad30c 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -3977,12 +3977,11 @@ shada_read_next_item_error: static bool shada_removable(const char *name) FUNC_ATTR_WARN_UNUSED_RESULT { - char *p; char part[MAXPATHL + 1]; bool retval = false; char *new_name = home_replace_save(NULL, name); - for (p = p_shada; *p;) { + for (char *p = p_shada; *p;) { (void)copy_option_part(&p, part, ARRAY_SIZE(part), ", "); if (part[0] == 'r') { home_replace(NULL, part + 1, NameBuff, MAXPATHL, true); -- cgit From a6e3d93421ba13c407a96fac9cc01fa41ec7ad98 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Thu, 16 Nov 2023 10:59:11 +0100 Subject: refactor: enable formatting for ternaries This requires removing the "Inner expression should be aligned" rule from clint as it prevents essentially any formatting regarding ternary operators. --- src/nvim/shada.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/nvim/shada.c') diff --git a/src/nvim/shada.c b/src/nvim/shada.c index ae208ad30c..f0db569125 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -1611,8 +1611,8 @@ static ShaDaWriteResult shada_pack_entry(msgpack_packer *const packer, ShadaEntr // finally, additional data: + ( entry.data.search_pattern.additional_data - ? entry.data.search_pattern.additional_data->dv_hashtab.ht_used - : 0)); + ? entry.data.search_pattern.additional_data->dv_hashtab.ht_used + : 0)); msgpack_pack_map(spacker, entry_map_size); PACK_STATIC_STR(SEARCH_KEY_PAT); PACK_BIN(cstr_as_string(entry.data.search_pattern.pat)); @@ -1645,8 +1645,8 @@ static ShaDaWriteResult shada_pack_entry(msgpack_packer *const packer, ShadaEntr // Additional entries, if any: + ( entry.data.filemark.additional_data == NULL - ? 0 - : entry.data.filemark.additional_data->dv_hashtab.ht_used)); + ? 0 + : entry.data.filemark.additional_data->dv_hashtab.ht_used)); msgpack_pack_map(spacker, entry_map_size); PACK_STATIC_STR(KEY_FILE); PACK_BIN(cstr_as_string(entry.data.filemark.fname)); @@ -1718,9 +1718,9 @@ static ShaDaWriteResult shada_pack_entry(msgpack_packer *const packer, ShadaEntr + ( entry.data.buffer_list.buffers[i].additional_data == NULL - ? 0 - : (entry.data.buffer_list.buffers[i].additional_data - ->dv_hashtab.ht_used))); + ? 0 + : (entry.data.buffer_list.buffers[i].additional_data + ->dv_hashtab.ht_used))); msgpack_pack_map(spacker, entry_map_size); PACK_STATIC_STR(KEY_FILE); PACK_BIN(cstr_as_string(entry.data.buffer_list.buffers[i].fname)); @@ -2346,8 +2346,8 @@ static inline void add_search_pattern(PossiblyFreedShadaEntry *const ret_pse, : pat.off.line), .place_cursor_at_end = ( is_substitute_pattern - ? defaults.data.search_pattern.place_cursor_at_end - : pat.off.end), + ? defaults.data.search_pattern.place_cursor_at_end + : pat.off.end), .offset = (is_substitute_pattern ? defaults.data.search_pattern.offset : pat.off.off), -- cgit From 488038580934f301c1528a14548ec0cabd16c2cd Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 10 Nov 2023 14:06:04 +0100 Subject: build: adjust clang-tidy warning exclusion logic Enable all clang-tidy warnings by default instead of disabling them. This ensures that we don't miss useful warnings on each clang-tidy version upgrade. A drawback of this is that it will force us to either fix or adjust the warnings as soon as possible. --- src/nvim/shada.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/shada.c') diff --git a/src/nvim/shada.c b/src/nvim/shada.c index f0db569125..81b6bf2ff9 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -54,8 +54,8 @@ #include "nvim/vim.h" #ifdef HAVE_BE64TOH -# define _BSD_SOURCE 1 -# define _DEFAULT_SOURCE 1 +# define _BSD_SOURCE 1 // NOLINT(bugprone-reserved-identifier) +# define _DEFAULT_SOURCE 1 // NOLINT(bugprone-reserved-identifier) # include ENDIAN_INCLUDE_FILE #endif -- cgit From 38a20dd89f91c45ec8589bf1c50d50732882d38a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 27 Nov 2023 20:58:37 +0800 Subject: build(IWYU): replace most private mappings with pragmas (#26247) --- src/nvim/shada.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/shada.c') diff --git a/src/nvim/shada.c b/src/nvim/shada.c index 81b6bf2ff9..9a0d322a9a 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -41,7 +41,7 @@ #include "nvim/option.h" #include "nvim/option_vars.h" #include "nvim/os/fileio.h" -#include "nvim/os/fs_defs.h" +#include "nvim/os/fs.h" #include "nvim/os/os.h" #include "nvim/os/time.h" #include "nvim/path.h" -- 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/shada.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/shada.c') diff --git a/src/nvim/shada.c b/src/nvim/shada.c index 9a0d322a9a..fbb5d835a5 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -25,6 +25,7 @@ #include "nvim/ex_cmds.h" #include "nvim/ex_docmd.h" #include "nvim/fileio.h" +#include "nvim/func_attr.h" #include "nvim/garray.h" #include "nvim/gettext.h" #include "nvim/globals.h" -- cgit From f4aedbae4cb1f206f5b7c6142697b71dd473059b Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 18:39:38 +0100 Subject: build(IWYU): fix includes for undo_defs.h --- src/nvim/shada.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/shada.c') diff --git a/src/nvim/shada.c b/src/nvim/shada.c index fbb5d835a5..8078f950c7 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -46,7 +46,7 @@ #include "nvim/os/os.h" #include "nvim/os/time.h" #include "nvim/path.h" -#include "nvim/pos.h" +#include "nvim/pos_defs.h" #include "nvim/regexp.h" #include "nvim/search.h" #include "nvim/shada.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/shada.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/shada.c') diff --git a/src/nvim/shada.c b/src/nvim/shada.c index 8078f950c7..be898142f0 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -15,7 +15,7 @@ #include "auto/config.h" #include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" -#include "nvim/ascii.h" +#include "nvim/ascii_defs.h" #include "nvim/buffer.h" #include "nvim/cmdhist.h" #include "nvim/eval.h" @@ -30,8 +30,8 @@ #include "nvim/gettext.h" #include "nvim/globals.h" #include "nvim/hashtab.h" -#include "nvim/macros.h" -#include "nvim/map.h" +#include "nvim/macros_defs.h" +#include "nvim/map_defs.h" #include "nvim/mark.h" #include "nvim/mbyte.h" #include "nvim/memory.h" @@ -52,7 +52,7 @@ #include "nvim/shada.h" #include "nvim/strings.h" #include "nvim/version.h" -#include "nvim/vim.h" +#include "nvim/vim_defs.h" #ifdef HAVE_BE64TOH # define _BSD_SOURCE 1 // NOLINT(bugprone-reserved-identifier) -- cgit