diff options
Diffstat (limited to 'src/nvim/shada.c')
-rw-r--r-- | src/nvim/shada.c | 154 |
1 files changed, 75 insertions, 79 deletions
diff --git a/src/nvim/shada.c b/src/nvim/shada.c index d7bda03116..cd3b967a9f 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -151,8 +151,8 @@ typedef enum { kSDItemBufferList = 9, ///< Buffer list. kSDItemLocalMark = 10, ///< Buffer-local mark. kSDItemChange = 11, ///< Item from buffer change list. -#define SHADA_LAST_ENTRY ((uint64_t)kSDItemChange) } ShadaEntryType; +#define SHADA_LAST_ENTRY ((uint64_t)kSDItemChange) /// Possible results when reading ShaDa file typedef enum { @@ -512,8 +512,8 @@ static inline void hmll_init(HMLList *const hmll, const size_t size) /// /// @return `for` cycle header (use `HMLL_FORALL(hmll, cur_entry) {body}`). #define HMLL_FORALL(hmll, cur_entry, code) \ - for (HMLListEntry *cur_entry = (hmll)->first; cur_entry != NULL; \ - cur_entry = cur_entry->next) { \ + for (HMLListEntry *(cur_entry) = (hmll)->first; (cur_entry) != NULL; \ + (cur_entry) = (cur_entry)->next) { \ code \ } \ @@ -550,7 +550,6 @@ static inline void hmll_remove(HMLList *const hmll, HMLListEntry *const hmll_ent } } - /// Insert entry to the linked list /// /// @param[out] hmll List to insert to. @@ -831,7 +830,7 @@ static int shada_read_file(const char *const file, const int flags) ShaDaReadDef sd_reader; const int of_ret = open_shada_file_for_reading(fname, &sd_reader); - if (p_verbose > 0) { + if (p_verbose > 1) { verbose_enter(); smsg(_("Reading ShaDa file \"%s\"%s%s%s%s"), fname, @@ -1053,7 +1052,7 @@ static buf_T *find_buffer(khash_t(fnamebufs) *const fname_bufs, const char *cons kh_key(fname_bufs, k) = xstrdup(fname); FOR_ALL_BUFFERS(buf) { if (buf->b_ffname != NULL) { - if (fnamecmp(fname, buf->b_ffname) == 0) { + if (FNAMECMP(fname, buf->b_ffname) == 0) { kh_val(fname_bufs, k) = buf; return buf; } @@ -1073,13 +1072,13 @@ static inline bool marks_equal(const pos_T a, const pos_T b) entry, fname_cond, free_func, fin_func, \ idxadj_func, afterfree_func) \ do { \ - const int jl_len = (int)jumps_size; \ + const int jl_len = (int)(jumps_size); \ int i; \ for (i = jl_len; i > 0; i--) { \ - const jumps_type jl_entry = jumps[i - 1]; \ - if (jl_entry.timestamp_attr <= entry.timestamp) { \ - if (marks_equal(jl_entry.mark_attr, entry.data.filemark.mark) \ - && fname_cond) { \ + const jumps_type jl_entry = (jumps)[i - 1]; \ + if (jl_entry.timestamp_attr <= (entry).timestamp) { \ + if (marks_equal(jl_entry.mark_attr, (entry).data.filemark.mark) \ + && (fname_cond)) { \ i = -1; \ } \ break; \ @@ -1087,30 +1086,30 @@ static inline bool marks_equal(const pos_T a, const pos_T b) } \ if (i > 0) { \ if (jl_len == JUMPLISTSIZE) { \ - free_func(jumps[0]); \ + free_func((jumps)[0]); \ i--; \ if (i > 0) { \ - memmove(&jumps[0], &jumps[1], sizeof(jumps[1]) * (size_t)i); \ + memmove(&(jumps)[0], &(jumps)[1], sizeof((jumps)[1]) * (size_t)i); \ } \ } else if (i != jl_len) { \ - memmove(&jumps[i + 1], &jumps[i], \ - sizeof(jumps[0]) * (size_t)(jl_len - i)); \ + memmove(&(jumps)[i + 1], &(jumps)[i], \ + sizeof((jumps)[0]) * (size_t)(jl_len - i)); \ } \ } else if (i == 0) { \ if (jl_len == JUMPLISTSIZE) { \ i = -1; \ } else if (jl_len > 0) { \ - memmove(&jumps[1], &jumps[0], sizeof(jumps[0]) * (size_t)jl_len); \ + memmove(&(jumps)[1], &(jumps)[0], sizeof((jumps)[0]) * (size_t)jl_len); \ } \ } \ if (i != -1) { \ - jumps[i] = fin_func(entry); \ + (jumps)[i] = fin_func(entry); \ if (jl_len < JUMPLISTSIZE) { \ - jumps_size++; \ + (jumps_size)++; \ } \ idxadj_func(i); \ } else { \ - shada_free_shada_entry(&entry); \ + shada_free_shada_entry(&(entry)); \ afterfree_func(entry); \ } \ } while (0) @@ -1238,7 +1237,7 @@ static void shada_read(ShaDaReadDef *const sd_reader, const int flags) // string is close to useless: you can only use it with :& or :~ and // that’s all because s//~ is not available until the first call to // regtilde. Vim was not calling this for some reason. - (void)(char *)regtilde((char_u *)cur_entry.data.sub_string.sub, p_magic); + (void)(char *)regtilde((char_u *)cur_entry.data.sub_string.sub, p_magic, false); // Do not free shada entry: its allocated memory was saved above. break; case kSDItemHistoryEntry: @@ -1265,7 +1264,7 @@ static void shada_read(ShaDaReadDef *const sd_reader, const int flags) } } if (!op_reg_set(cur_entry.data.reg.name, (yankreg_T) { - .y_array = (char_u **)cur_entry.data.reg.contents, + .y_array = cur_entry.data.reg.contents, .y_size = cur_entry.data.reg.contents_size, .y_type = cur_entry.data.reg.type, .y_width = (colnr_T)cur_entry.data.reg.width, @@ -1289,9 +1288,7 @@ static void shada_read(ShaDaReadDef *const sd_reader, const int flags) XFREE_CLEAR(cur_entry.data.filemark.fname); } xfmark_T fm = (xfmark_T) { - .fname = (char_u *)(buf == NULL - ? cur_entry.data.filemark.fname - : NULL), + .fname = buf == NULL ? cur_entry.data.filemark.fname : NULL, .fmark = { .mark = cur_entry.data.filemark.mark, .fnum = (buf == NULL ? 0 : buf->b_fnum), @@ -1307,7 +1304,7 @@ static void shada_read(ShaDaReadDef *const sd_reader, const int flags) } else { #define SDE_TO_XFMARK(entry) fm #define ADJUST_IDX(i) \ - if (curwin->w_jumplistidx >= i \ + if (curwin->w_jumplistidx >= (i) \ && curwin->w_jumplistidx + 1 <= curwin->w_jumplistlen) { \ curwin->w_jumplistidx++; \ } @@ -1331,11 +1328,11 @@ static void shada_read(ShaDaReadDef *const sd_reader, const int flags) char *const sfname = (char *)path_try_shorten_fname((char_u *)cur_entry.data.buffer_list.buffers[i].fname); buf_T *const buf = - buflist_new((char_u *)cur_entry.data.buffer_list.buffers[i].fname, (char_u *)sfname, 0, - BLN_LISTED); + buflist_new(cur_entry.data.buffer_list.buffers[i].fname, sfname, 0, BLN_LISTED); if (buf != NULL) { + fmarkv_T view = INIT_FMARKV; RESET_FMARK(&buf->b_last_cursor, - cur_entry.data.buffer_list.buffers[i].pos, 0); + cur_entry.data.buffer_list.buffers[i].pos, 0, view); buflist_setfpos(buf, curwin, buf->b_last_cursor.mark.lnum, buf->b_last_cursor.mark.col, false); buf->additional_data = @@ -1449,7 +1446,7 @@ static const char *shada_get_default_file(void) FUNC_ATTR_WARN_UNUSED_RESULT { if (default_shada_file == NULL) { - char *shada_dir = stdpaths_user_data_subpath("shada", 0, false); + char *shada_dir = stdpaths_user_state_subpath("shada", 0, false); default_shada_file = concat_fnames_realloc(shada_dir, "main.shada", true); } return default_shada_file; @@ -1550,7 +1547,7 @@ static ShaDaWriteResult shada_pack_entry(msgpack_packer *const packer, ShadaEntr } \ } while (0) #define CHECK_DEFAULT(entry, attr) \ - (sd_default_values[entry.type].data.attr == entry.data.attr) + (sd_default_values[(entry).type].data.attr == (entry).data.attr) #define ONE_IF_NOT_DEFAULT(entry, attr) \ ((size_t)(!CHECK_DEFAULT(entry, attr))) switch (entry.type) { @@ -1640,7 +1637,7 @@ static ShaDaWriteResult shada_pack_entry(msgpack_packer *const packer, ShadaEntr do { \ if (!CHECK_DEFAULT(entry, search_pattern.attr)) { \ PACK_STATIC_STR(name); \ - if (sd_default_values[entry.type].data.search_pattern.attr) { \ + if (sd_default_values[(entry).type].data.search_pattern.attr) { \ msgpack_pack_false(spacker); \ } else { \ msgpack_pack_true(spacker); \ @@ -2224,12 +2221,12 @@ static inline ShaDaWriteResult shada_read_when_writing(ShaDaReadDef *const sd_re } else { #define FREE_POSSIBLY_FREED_SHADA_ENTRY(entry) \ do { \ - if (entry.can_free_entry) { \ - shada_free_shada_entry(&entry.data); \ + if ((entry).can_free_entry) { \ + shada_free_shada_entry(&(entry).data); \ } \ } while (0) #define SDE_TO_PFSDE(entry) \ - ((PossiblyFreedShadaEntry) { .can_free_entry = true, .data = entry }) + ((PossiblyFreedShadaEntry) { .can_free_entry = true, .data = (entry) }) #define AFTERFREE_DUMMY(entry) #define DUMMY_IDX_ADJ(i) MERGE_JUMPS(filemarks->changes_size, filemarks->changes, @@ -2309,7 +2306,7 @@ static inline ShadaEntry shada_get_buflist(khash_t(bufset) *const removable_bufs } buflist_entry.data.buffer_list.buffers[i] = (struct buffer_list_buffer) { .pos = buf->b_last_cursor.mark, - .fname = (char *)buf->b_ffname, + .fname = buf->b_ffname, .additional_data = buf->additional_data, }; i++; @@ -2400,7 +2397,7 @@ static inline void shada_initialize_registers(WriteMergerState *const wms, int m .timestamp = reg.timestamp, .data = { .reg = { - .contents = (char **)reg.y_array, + .contents = reg.y_array, .contents_size = reg.y_size, .type = reg.y_type, .width = (size_t)(reg.y_type == kMTBlockWise ? reg.y_width : 0), @@ -2447,7 +2444,7 @@ static inline void replace_numbered_mark(WriteMergerState *const wms, const size static inline void find_removable_bufs(khash_t(bufset) *removable_bufs) { FOR_ALL_BUFFERS(buf) { - if (buf->b_ffname != NULL && shada_removable((char *)buf->b_ffname)) { + if (buf->b_ffname != NULL && shada_removable(buf->b_ffname)) { int kh_ret; (void)kh_put(bufset, removable_bufs, (uintptr_t)buf, &kh_ret); } @@ -2806,7 +2803,7 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer, ShaDaReadDef .mark = curwin->w_cursor, .name = '0', .additional_data = NULL, - .fname = (char *)curbuf->b_ffname, + .fname = curbuf->b_ffname, } } }, @@ -2817,8 +2814,8 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer, ShaDaReadDef #define PACK_WMS_ARRAY(wms_array) \ do { \ for (size_t i_ = 0; i_ < ARRAY_SIZE(wms_array); i_++) { \ - if (wms_array[i_].data.type != kSDItemMissing) { \ - if (shada_pack_pfreed_entry(packer, wms_array[i_], max_kbyte) \ + if ((wms_array)[i_].data.type != kSDItemMissing) { \ + if (shada_pack_pfreed_entry(packer, (wms_array)[i_], max_kbyte) \ == kSDWriteFailed) { \ ret = kSDWriteFailed; \ goto shada_write_exit; \ @@ -2838,7 +2835,7 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer, ShaDaReadDef } #define PACK_WMS_ENTRY(wms_entry) \ do { \ - if (wms_entry.data.type != kSDItemMissing) { \ + if ((wms_entry).data.type != kSDItemMissing) { \ if (shada_pack_pfreed_entry(packer, wms_entry, max_kbyte) \ == kSDWriteFailed) { \ ret = kSDWriteFailed; \ @@ -3000,7 +2997,7 @@ shada_write_file_open: {} } if (nomerge) { shada_write_file_nomerge: {} - char *const tail = (char *)path_tail_with_sep((char_u *)fname); + char *const tail = path_tail_with_sep(fname); if (tail != fname) { const char tail_save = *tail; *tail = NUL; @@ -3036,7 +3033,7 @@ shada_write_file_nomerge: {} return FAIL; } - if (p_verbose > 0) { + if (p_verbose > 1) { verbose_enter(); smsg(_("Writing ShaDa file \"%s\""), fname); verbose_leave(); @@ -3302,7 +3299,7 @@ static ShaDaReadResult msgpack_read_uint64(ShaDaReadDef *const sd_reader, const uint64_t buf = 0; char *buf_u8 = (char *)&buf; ShaDaReadResult fl_ret; - if ((fl_ret = fread_len(sd_reader, &(buf_u8[sizeof(buf)-length]), length)) + if ((fl_ret = fread_len(sd_reader, &(buf_u8[sizeof(buf) - length]), length)) != kSDReadStatusSuccess) { return fl_ret; } @@ -3315,16 +3312,16 @@ static ShaDaReadResult msgpack_read_uint64(ShaDaReadDef *const sd_reader, const RERR "Error while reading ShaDa file: " \ entry_name " entry at position %" PRIu64 " " \ error_desc -#define CHECK_KEY(key, expected) ( \ - key.via.str.size == sizeof(expected) - 1 \ - && STRNCMP(key.via.str.ptr, expected, sizeof(expected) - 1) == 0) +#define CHECK_KEY(key, \ + expected) ((key).via.str.size == (sizeof(expected) - 1) \ + && STRNCMP((key).via.str.ptr, expected, (sizeof(expected) - 1)) == 0) #define CLEAR_GA_AND_ERROR_OUT(ga) \ do { \ - ga_clear(&ga); \ + ga_clear(&(ga)); \ goto shada_read_next_item_error; \ } while (0) #define ID(s) s -#define BINDUP(b) xmemdupz(b.ptr, b.size) +#define BINDUP(b) xmemdupz((b).ptr, (b).size) #define TOINT(s) ((int)(s)) #define TOLONG(s) ((long)(s)) #define TOCHAR(s) ((char)(s)) @@ -3337,28 +3334,31 @@ static ShaDaReadResult msgpack_read_uint64(ShaDaReadDef *const sd_reader, const semsg(_(READERR(entry_name, error_desc)), initial_fpos); \ CLEAR_GA_AND_ERROR_OUT(ad_ga); \ } \ - tgt = proc(obj.via.attr); \ + (tgt) = proc((obj).via.attr); \ } while (0) #define CHECK_KEY_IS_STR(un, entry_name) \ - if (un.data.via.map.ptr[i].key.type != MSGPACK_OBJECT_STR) { \ + if ((un).data.via.map.ptr[i].key.type != MSGPACK_OBJECT_STR) { \ semsg(_(READERR(entry_name, "has key which is not a string")), \ initial_fpos); \ CLEAR_GA_AND_ERROR_OUT(ad_ga); \ - } else if (un.data.via.map.ptr[i].key.via.str.size == 0) { \ + } else if ((un).data.via.map.ptr[i].key.via.str.size == 0) { \ semsg(_(READERR(entry_name, "has empty key")), initial_fpos); \ CLEAR_GA_AND_ERROR_OUT(ad_ga); \ } -#define CHECKED_KEY(un, entry_name, name, error_desc, tgt, condition, attr, \ - proc) \ - else if (CHECK_KEY( /* NOLINT(readability/braces) */ \ - un.data.via.map.ptr[i].key, name)) { \ - CHECKED_ENTRY(condition, "has " name " key value " error_desc, \ - entry_name, un.data.via.map.ptr[i].val, \ - tgt, attr, proc); \ +#define CHECKED_KEY(un, entry_name, name, error_desc, tgt, condition, attr, proc) \ + else if (CHECK_KEY((un).data.via.map.ptr[i].key, name)) /* NOLINT(readability/braces) */ \ + { \ + CHECKED_ENTRY(condition, \ + "has " name " key value " error_desc, \ + entry_name, \ + (un).data.via.map.ptr[i].val, \ + tgt, \ + attr, \ + proc); \ } #define TYPED_KEY(un, entry_name, name, type_name, tgt, objtype, attr, proc) \ CHECKED_KEY(un, entry_name, name, "which is not " type_name, tgt, \ - un.data.via.map.ptr[i].val.type == MSGPACK_OBJECT_##objtype, \ + (un).data.via.map.ptr[i].val.type == MSGPACK_OBJECT_##objtype, \ attr, proc) #define BOOLEAN_KEY(un, entry_name, name, tgt) \ TYPED_KEY(un, entry_name, name, "a boolean", tgt, BOOLEAN, boolean, ID) @@ -3369,25 +3369,23 @@ static ShaDaReadResult msgpack_read_uint64(ShaDaReadDef *const sd_reader, const BIN_CONVERTED) #define INT_KEY(un, entry_name, name, tgt, proc) \ CHECKED_KEY(un, entry_name, name, "which is not an integer", tgt, \ - ((un.data.via.map.ptr[i].val.type \ + (((un).data.via.map.ptr[i].val.type \ == MSGPACK_OBJECT_POSITIVE_INTEGER) \ - || (un.data.via.map.ptr[i].val.type \ + || ((un).data.via.map.ptr[i].val.type \ == MSGPACK_OBJECT_NEGATIVE_INTEGER)), \ i64, proc) #define INTEGER_KEY(un, entry_name, name, tgt) \ INT_KEY(un, entry_name, name, tgt, TOINT) -#define LONG_KEY(un, entry_name, name, tgt) \ - INT_KEY(un, entry_name, name, tgt, TOLONG) #define ADDITIONAL_KEY(un) \ else { /* NOLINT(readability/braces) */ \ ga_grow(&ad_ga, 1); \ memcpy(((char *)ad_ga.ga_data) + ((size_t)ad_ga.ga_len \ - * sizeof(*un.data.via.map.ptr)), \ - un.data.via.map.ptr + i, \ - sizeof(*un.data.via.map.ptr)); \ + * sizeof(*(un).data.via.map.ptr)), \ + (un).data.via.map.ptr + i, \ + sizeof(*(un).data.via.map.ptr)); \ ad_ga.ga_len++; \ } -#define BIN_CONVERTED(b) (xmemdupz((b.ptr), (b.size))) +#define BIN_CONVERTED(b) (xmemdupz(((b).ptr), ((b).size))) #define SET_ADDITIONAL_DATA(tgt, name) \ do { \ if (ad_ga.ga_len) { \ @@ -3410,7 +3408,7 @@ static ShaDaReadResult msgpack_read_uint64(ShaDaReadDef *const sd_reader, const tv_clear(&adtv); \ goto shada_read_next_item_error; \ } \ - tgt = adtv.vval.v_dict; \ + (tgt) = adtv.vval.v_dict; \ } \ ga_clear(&ad_ga); \ } while (0) @@ -3641,7 +3639,7 @@ shada_read_next_item_start: "mark", unpacked.data.via.map.ptr[i].val, entry->data.filemark.name, u64, TOCHAR); } - LONG_KEY(unpacked, "mark", KEY_LNUM, entry->data.filemark.mark.lnum) + INTEGER_KEY(unpacked, "mark", KEY_LNUM, entry->data.filemark.mark.lnum) INTEGER_KEY(unpacked, "mark", KEY_COL, entry->data.filemark.mark.col) STRING_KEY(unpacked, "mark", KEY_FILE, entry->data.filemark.fname) ADDITIONAL_KEY(unpacked) @@ -3888,8 +3886,8 @@ shada_read_next_item_start: { for (i = 0; i < unpacked_2.data.via.map.size; i++) { // -V535 CHECK_KEY_IS_STR(unpacked_2, "buffer list entry") - LONG_KEY(unpacked_2, "buffer list entry", KEY_LNUM, - entry->data.buffer_list.buffers[j].pos.lnum) + INTEGER_KEY(unpacked_2, "buffer list entry", KEY_LNUM, + entry->data.buffer_list.buffers[j].pos.lnum) INTEGER_KEY(unpacked_2, "buffer list entry", KEY_COL, entry->data.buffer_list.buffers[j].pos.col) STRING_KEY(unpacked_2, "buffer list entry", KEY_FILE, @@ -3957,7 +3955,6 @@ shada_read_next_item_error: #undef TYPED_KEY #undef INT_KEY #undef INTEGER_KEY -#undef LONG_KEY #undef TOU8 #undef TOSIZE #undef SET_ADDITIONAL_DATA @@ -3976,11 +3973,11 @@ static bool shada_removable(const char *name) char part[MAXPATHL + 1]; bool retval = false; - char *new_name = (char *)home_replace_save(NULL, (char_u *)name); + char *new_name = home_replace_save(NULL, (char *)name); for (p = (char *)p_shada; *p;) { - (void)copy_option_part((char_u **)&p, (char_u *)part, ARRAY_SIZE(part), ", "); + (void)copy_option_part(&p, part, ARRAY_SIZE(part), ", "); if (part[0] == 'r') { - home_replace(NULL, (char_u *)(part + 1), (char_u *)NameBuff, MAXPATHL, true); + home_replace(NULL, part + 1, (char *)NameBuff, MAXPATHL, true); size_t n = STRLEN(NameBuff); if (mb_strnicmp((char_u *)NameBuff, (char_u *)new_name, n) == 0) { retval = true; @@ -4027,9 +4024,8 @@ static inline size_t shada_init_jumps(PossiblyFreedShadaEntry *jumps, : fm.fmark.fnum != 0) { continue; } - const char *const fname = (char *)(fm.fmark.fnum == 0 - ? (fm.fname == NULL ? NULL : fm.fname) - : buf ? buf->b_ffname : NULL); + const char *const fname = + (fm.fmark.fnum == 0 ? (fm.fname == NULL ? NULL : fm.fname) : buf ? buf->b_ffname : NULL); if (fname == NULL) { continue; } |