mirror of
https://github.com/neovim/neovim.git
synced 2025-10-05 09:26:30 +00:00
shada: Fix all linter errors in src/nvim/shada.*
This commit is an example of fixing incorrect code which previously passed through linter.
This commit is contained in:
113
src/nvim/shada.c
113
src/nvim/shada.c
@@ -207,9 +207,9 @@ enum SRNIFlags {
|
||||
kSDReadUndisableableData = (
|
||||
(1 << kSDItemSearchPattern)
|
||||
| (1 << kSDItemSubString)
|
||||
| (1 << kSDItemJump)), ///< Data reading which cannot be disabled by &shada
|
||||
///< or other options except for disabling reading
|
||||
///< ShaDa as a whole.
|
||||
| (1 << kSDItemJump)), ///< Data reading which cannot be disabled by
|
||||
///< &shada or other options except for disabling
|
||||
///< reading ShaDa as a whole.
|
||||
kSDReadRegisters = (1 << kSDItemRegister), ///< Determines whether registers
|
||||
///< should be read (may only be
|
||||
///< disabled when writing, but
|
||||
@@ -446,7 +446,7 @@ typedef struct sd_write_def {
|
||||
.attr = { __VA_ARGS__ } \
|
||||
} \
|
||||
}
|
||||
#define DEFAULT_POS {1, 0, 0}
|
||||
#define DEFAULT_POS { 1, 0, 0 }
|
||||
static const pos_T default_pos = DEFAULT_POS;
|
||||
static const ShadaEntry sd_default_values[] = {
|
||||
[kSDItemMissing] = { .type = kSDItemMissing, .timestamp = 0 },
|
||||
@@ -533,11 +533,14 @@ static inline void hmll_init(HMLList *const hmll, const size_t size)
|
||||
///
|
||||
/// @param hmll Pointer to the list.
|
||||
/// @param cur_entry Name of the variable to iterate over.
|
||||
/// @param code Code to execute on each iteration.
|
||||
///
|
||||
/// @return `for` cycle header (use `HMLL_FORALL(hmll, cur_entry) {body}`).
|
||||
#define HMLL_FORALL(hmll, cur_entry) \
|
||||
#define HMLL_FORALL(hmll, cur_entry, code) \
|
||||
for (HMLListEntry *cur_entry = (hmll)->first; cur_entry != NULL; \
|
||||
cur_entry = cur_entry->next)
|
||||
cur_entry = cur_entry->next) { \
|
||||
code \
|
||||
} \
|
||||
|
||||
/// Remove entry from the linked list
|
||||
///
|
||||
@@ -633,11 +636,14 @@ static inline void hmll_insert(HMLList *const hmll,
|
||||
/// @param hmll Pointer to the list.
|
||||
/// @param cur_entry Name of the variable to iterate over, must be already
|
||||
/// defined.
|
||||
/// @param code Code to execute on each iteration.
|
||||
///
|
||||
/// @return `for` cycle header (use `HMLL_FORALL(hmll, cur_entry) {body}`).
|
||||
#define HMLL_ITER_BACK(hmll, cur_entry) \
|
||||
#define HMLL_ITER_BACK(hmll, cur_entry, code) \
|
||||
for (cur_entry = (hmll)->last; cur_entry != NULL; \
|
||||
cur_entry = cur_entry->prev)
|
||||
cur_entry = cur_entry->prev) { \
|
||||
code \
|
||||
}
|
||||
|
||||
/// Free linked list
|
||||
///
|
||||
@@ -1074,11 +1080,11 @@ static void hms_insert(HistoryMergerState *const hms_p, const ShadaEntry entry,
|
||||
}
|
||||
}
|
||||
HMLListEntry *insert_after;
|
||||
HMLL_ITER_BACK(hmll, insert_after) {
|
||||
HMLL_ITER_BACK(hmll, insert_after, {
|
||||
if (insert_after->data.timestamp <= entry.timestamp) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
})
|
||||
hmll_insert(hmll, insert_after, entry, can_free_entry);
|
||||
}
|
||||
|
||||
@@ -1136,14 +1142,14 @@ static inline void hms_to_he_array(const HistoryMergerState *const hms_p,
|
||||
FUNC_ATTR_NONNULL_ALL
|
||||
{
|
||||
histentry_T *hist = hist_array;
|
||||
HMLL_FORALL(&hms_p->hmll, cur_entry) {
|
||||
HMLL_FORALL(&hms_p->hmll, cur_entry, {
|
||||
hist->timestamp = cur_entry->data.timestamp;
|
||||
hist->hisnum = (int) (hist - hist_array) + 1;
|
||||
hist->hisstr = (char_u *) cur_entry->data.data.history_item.string;
|
||||
hist->additional_elements =
|
||||
cur_entry->data.data.history_item.additional_elements;
|
||||
hist++;
|
||||
}
|
||||
})
|
||||
*new_hisnum = (int) (hist - hist_array);
|
||||
*new_hisidx = *new_hisnum - 1;
|
||||
}
|
||||
@@ -1161,10 +1167,11 @@ static inline void hms_dealloc(HistoryMergerState *const hms_p)
|
||||
///
|
||||
/// @param[in] hms_p Merger structure to iterate over.
|
||||
/// @param[out] cur_entry Name of the iterator variable.
|
||||
/// @param code Code to execute on each iteration.
|
||||
///
|
||||
/// @return for cycle header. Use `HMS_ITER(hms_p, cur_entry) {body}`.
|
||||
#define HMS_ITER(hms_p, cur_entry) \
|
||||
HMLL_FORALL(&((hms_p)->hmll), cur_entry)
|
||||
#define HMS_ITER(hms_p, cur_entry, code) \
|
||||
HMLL_FORALL(&((hms_p)->hmll), cur_entry, code)
|
||||
|
||||
/// Find buffer for given buffer name (cached)
|
||||
///
|
||||
@@ -2895,7 +2902,7 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer,
|
||||
for (size_t i = 0; i < HIST_COUNT; i++) {
|
||||
if (dump_one_history[i]) {
|
||||
hms_insert_whole_neovim_history(&wms->hms[i]);
|
||||
HMS_ITER(&wms->hms[i], cur_entry) {
|
||||
HMS_ITER(&wms->hms[i], cur_entry, {
|
||||
if (!shada_pack_encoded_entry(
|
||||
packer, &sd_writer->sd_conv, (PossiblyFreedShadaEntry) {
|
||||
.data = cur_entry->data,
|
||||
@@ -2904,7 +2911,7 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer,
|
||||
ret = kSDWriteFailed;
|
||||
break;
|
||||
}
|
||||
}
|
||||
})
|
||||
hms_dealloc(&wms->hms[i]);
|
||||
if (ret == kSDWriteFailed) {
|
||||
goto shada_write_exit;
|
||||
@@ -3379,7 +3386,6 @@ static inline char *get_converted_string(const vimconv_T *const sd_conv,
|
||||
tgt = proc(obj.via.attr); \
|
||||
} while (0)
|
||||
#define CHECK_KEY_IS_STR(entry_name) \
|
||||
do { \
|
||||
if (unpacked.data.via.map.ptr[i].key.type != MSGPACK_OBJECT_STR) { \
|
||||
emsgu(_(READERR(entry_name, "has key which is not a string")), \
|
||||
initial_fpos); \
|
||||
@@ -3387,10 +3393,10 @@ static inline char *get_converted_string(const vimconv_T *const sd_conv,
|
||||
} else if (unpacked.data.via.map.ptr[i].key.via.str.size == 0) { \
|
||||
emsgu(_(READERR(entry_name, "has empty key")), initial_fpos); \
|
||||
CLEAR_GA_AND_ERROR_OUT(ad_ga); \
|
||||
} \
|
||||
} while (0)
|
||||
}
|
||||
#define CHECKED_KEY(entry_name, name, error_desc, tgt, condition, attr, proc) \
|
||||
if (CHECK_KEY(unpacked.data.via.map.ptr[i].key, name)) { \
|
||||
else if (CHECK_KEY( /* NOLINT(readability/braces) */ \
|
||||
unpacked.data.via.map.ptr[i].key, name)) { \
|
||||
CHECKED_ENTRY( \
|
||||
condition, "has " name " key value " error_desc, \
|
||||
entry_name, unpacked.data.via.map.ptr[i].val, \
|
||||
@@ -3410,17 +3416,17 @@ static inline char *get_converted_string(const vimconv_T *const sd_conv,
|
||||
#define INT_KEY(entry_name, name, tgt, proc) \
|
||||
CHECKED_KEY( \
|
||||
entry_name, name, "which is not an integer", tgt, \
|
||||
(unpacked.data.via.map.ptr[i].val.type \
|
||||
== MSGPACK_OBJECT_POSITIVE_INTEGER \
|
||||
|| unpacked.data.via.map.ptr[i].val.type \
|
||||
== MSGPACK_OBJECT_NEGATIVE_INTEGER), \
|
||||
((unpacked.data.via.map.ptr[i].val.type \
|
||||
== MSGPACK_OBJECT_POSITIVE_INTEGER) \
|
||||
|| (unpacked.data.via.map.ptr[i].val.type \
|
||||
== MSGPACK_OBJECT_NEGATIVE_INTEGER)), \
|
||||
i64, proc)
|
||||
#define INTEGER_KEY(entry_name, name, tgt) \
|
||||
INT_KEY(entry_name, name, tgt, TOINT)
|
||||
#define LONG_KEY(entry_name, name, tgt) \
|
||||
INT_KEY(entry_name, name, tgt, TOLONG)
|
||||
#define ADDITIONAL_KEY \
|
||||
{ \
|
||||
else { /* NOLINT(readability/braces) */ \
|
||||
ga_grow(&ad_ga, 1); \
|
||||
memcpy(((char *)ad_ga.ga_data) + ((size_t) ad_ga.ga_len \
|
||||
* sizeof(*unpacked.data.via.map.ptr)), \
|
||||
@@ -3625,37 +3631,27 @@ shada_read_next_item_start:
|
||||
garray_T ad_ga;
|
||||
ga_init(&ad_ga, sizeof(*(unpacked.data.via.map.ptr)), 1);
|
||||
for (size_t i = 0; i < unpacked.data.via.map.size; i++) {
|
||||
CHECK_KEY_IS_STR("search pattern");
|
||||
CHECK_KEY_IS_STR("search pattern")
|
||||
BOOLEAN_KEY("search pattern", SEARCH_KEY_MAGIC,
|
||||
entry->data.search_pattern.magic)
|
||||
else
|
||||
BOOLEAN_KEY("search pattern", SEARCH_KEY_SMARTCASE,
|
||||
entry->data.search_pattern.smartcase)
|
||||
else
|
||||
BOOLEAN_KEY("search pattern", SEARCH_KEY_HAS_LINE_OFFSET,
|
||||
entry->data.search_pattern.has_line_offset)
|
||||
else
|
||||
BOOLEAN_KEY("search pattern", SEARCH_KEY_PLACE_CURSOR_AT_END,
|
||||
entry->data.search_pattern.place_cursor_at_end)
|
||||
else
|
||||
BOOLEAN_KEY("search pattern", SEARCH_KEY_IS_LAST_USED,
|
||||
entry->data.search_pattern.is_last_used)
|
||||
else
|
||||
BOOLEAN_KEY("search pattern", SEARCH_KEY_IS_SUBSTITUTE_PATTERN,
|
||||
entry->data.search_pattern.is_substitute_pattern)
|
||||
else
|
||||
BOOLEAN_KEY("search pattern", SEARCH_KEY_HIGHLIGHTED,
|
||||
entry->data.search_pattern.highlighted)
|
||||
else
|
||||
BOOLEAN_KEY("search pattern", SEARCH_KEY_BACKWARD,
|
||||
entry->data.search_pattern.search_backward)
|
||||
else
|
||||
INTEGER_KEY("search pattern", SEARCH_KEY_OFFSET,
|
||||
entry->data.search_pattern.offset)
|
||||
else
|
||||
CONVERTED_STRING_KEY("search pattern", SEARCH_KEY_PAT,
|
||||
entry->data.search_pattern.pat)
|
||||
else
|
||||
ADDITIONAL_KEY
|
||||
}
|
||||
if (entry->data.search_pattern.pat == NULL) {
|
||||
@@ -3677,7 +3673,7 @@ shada_read_next_item_start:
|
||||
garray_T ad_ga;
|
||||
ga_init(&ad_ga, sizeof(*(unpacked.data.via.map.ptr)), 1);
|
||||
for (size_t i = 0; i < unpacked.data.via.map.size; i++) {
|
||||
CHECK_KEY_IS_STR("mark");
|
||||
CHECK_KEY_IS_STR("mark")
|
||||
if (CHECK_KEY(unpacked.data.via.map.ptr[i].key, KEY_NAME_CHAR)) {
|
||||
if (type_u64 == kSDItemJump || type_u64 == kSDItemChange) {
|
||||
emsgu(_(READERR("mark", "has n key which is only valid for "
|
||||
@@ -3690,15 +3686,11 @@ shada_read_next_item_start:
|
||||
"has n key value which is not an unsigned integer",
|
||||
"mark", unpacked.data.via.map.ptr[i].val,
|
||||
entry->data.filemark.name, u64, TOCHAR);
|
||||
} else {
|
||||
LONG_KEY("mark", KEY_LNUM, entry->data.filemark.mark.lnum)
|
||||
else
|
||||
INTEGER_KEY("mark", KEY_COL, entry->data.filemark.mark.col)
|
||||
else
|
||||
STRING_KEY("mark", KEY_FILE, entry->data.filemark.fname)
|
||||
else
|
||||
ADDITIONAL_KEY
|
||||
}
|
||||
LONG_KEY("mark", KEY_LNUM, entry->data.filemark.mark.lnum)
|
||||
INTEGER_KEY("mark", KEY_COL, entry->data.filemark.mark.col)
|
||||
STRING_KEY("mark", KEY_FILE, entry->data.filemark.fname)
|
||||
ADDITIONAL_KEY
|
||||
}
|
||||
if (entry->data.filemark.fname == NULL) {
|
||||
emsgu(_(READERR("mark", "is missing file name")), initial_fpos);
|
||||
@@ -3723,22 +3715,13 @@ shada_read_next_item_start:
|
||||
garray_T ad_ga;
|
||||
ga_init(&ad_ga, sizeof(*(unpacked.data.via.map.ptr)), 1);
|
||||
for (size_t i = 0; i < unpacked.data.via.map.size; i++) {
|
||||
CHECK_KEY_IS_STR("register");
|
||||
TYPED_KEY("register", REG_KEY_TYPE, "an unsigned integer",
|
||||
entry->data.reg.type, POSITIVE_INTEGER, u64, TOU8)
|
||||
else
|
||||
TYPED_KEY("register", KEY_NAME_CHAR, "an unsigned integer",
|
||||
entry->data.reg.name, POSITIVE_INTEGER, u64, TOCHAR)
|
||||
else
|
||||
TYPED_KEY("register", REG_KEY_WIDTH, "an unsigned integer",
|
||||
entry->data.reg.width, POSITIVE_INTEGER, u64, TOSIZE)
|
||||
else
|
||||
CHECK_KEY_IS_STR("register")
|
||||
if (CHECK_KEY(unpacked.data.via.map.ptr[i].key,
|
||||
REG_KEY_CONTENTS)) {
|
||||
if (unpacked.data.via.map.ptr[i].val.type != MSGPACK_OBJECT_ARRAY) {
|
||||
emsgu(_(READERR(
|
||||
"register",
|
||||
"has " REG_KEY_CONTENTS " key with non-array value")),
|
||||
emsgu(_(READERR("register",
|
||||
"has " REG_KEY_CONTENTS
|
||||
" key with non-array value")),
|
||||
initial_fpos);
|
||||
CLEAR_GA_AND_ERROR_OUT(ad_ga);
|
||||
}
|
||||
@@ -3762,9 +3745,14 @@ shada_read_next_item_start:
|
||||
for (size_t i = 0; i < arr.size; i++) {
|
||||
entry->data.reg.contents[i] = BIN_CONVERTED(arr.ptr[i].via.bin);
|
||||
}
|
||||
} else {
|
||||
ADDITIONAL_KEY
|
||||
}
|
||||
TYPED_KEY("register", REG_KEY_TYPE, "an unsigned integer",
|
||||
entry->data.reg.type, POSITIVE_INTEGER, u64, TOU8)
|
||||
TYPED_KEY("register", KEY_NAME_CHAR, "an unsigned integer",
|
||||
entry->data.reg.name, POSITIVE_INTEGER, u64, TOCHAR)
|
||||
TYPED_KEY("register", REG_KEY_WIDTH, "an unsigned integer",
|
||||
entry->data.reg.width, POSITIVE_INTEGER, u64, TOSIZE)
|
||||
ADDITIONAL_KEY
|
||||
}
|
||||
if (entry->data.reg.contents == NULL) {
|
||||
emsgu(_(READERR("register", "has missing " REG_KEY_CONTENTS " array")),
|
||||
@@ -3953,16 +3941,13 @@ shada_read_next_item_hist_no_conv:
|
||||
const size_t j = i;
|
||||
{
|
||||
for (size_t i = 0; i < unpacked.data.via.map.size; i++) {
|
||||
CHECK_KEY_IS_STR("buffer list entry");
|
||||
CHECK_KEY_IS_STR("buffer list entry")
|
||||
LONG_KEY("buffer list entry", KEY_LNUM,
|
||||
entry->data.buffer_list.buffers[j].pos.lnum)
|
||||
else
|
||||
INTEGER_KEY("buffer list entry", KEY_COL,
|
||||
entry->data.buffer_list.buffers[j].pos.col)
|
||||
else
|
||||
STRING_KEY("buffer list entry", KEY_FILE,
|
||||
entry->data.buffer_list.buffers[j].fname)
|
||||
else
|
||||
ADDITIONAL_KEY
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user