diff options
-rw-r--r-- | src/nvim/eval.c | 12 | ||||
-rw-r--r-- | src/nvim/eval.h | 4 | ||||
-rw-r--r-- | src/nvim/eval/decode.c | 55 | ||||
-rw-r--r-- | src/nvim/message.h | 2 |
4 files changed, 41 insertions, 32 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 4919cc2ce8..22a12d353a 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -5482,8 +5482,9 @@ static int list_join_inner(garray_T *const gap, list_T *const l, char *s; size_t len; s = encode_tv2echo(&item->li_tv, &len); - if (s == NULL) + if (s == NULL) { return FAIL; + } sumlen += (int) len; @@ -8317,9 +8318,9 @@ static void f_deepcopy(typval_T *argvars, typval_T *rettv) if (argvars[1].v_type != VAR_UNKNOWN) noref = get_tv_number_chk(&argvars[1], NULL); - if (noref < 0 || noref > 1) + if (noref < 0 || noref > 1) { EMSG(_(e_invarg)); - else { + } else { var_item_copy(NULL, &argvars[0], rettv, true, (noref == 0 ? get_copyID() : 0)); @@ -11960,8 +11961,9 @@ static void find_some_match(typval_T *argvars, typval_T *rettv, int type) } xfree(tofree); tofree = str = (char_u *) encode_tv2echo(&li->li_tv, NULL); - if (str == NULL) + if (str == NULL) { break; + } } match = vim_regexec_nl(®match, str, (colnr_T)startcol); @@ -17400,7 +17402,7 @@ void free_tv(typval_T *varp) switch (varp->v_type) { case VAR_FUNC: func_unref(varp->vval.v_string); - /*FALLTHROUGH*/ + // FALLTHROUGH case VAR_STRING: xfree(varp->vval.v_string); break; diff --git a/src/nvim/eval.h b/src/nvim/eval.h index c2b67cd12e..50c11011c6 100644 --- a/src/nvim/eval.h +++ b/src/nvim/eval.h @@ -53,7 +53,9 @@ EXTERN ufunc_T dumuf; #define HIKEY2UF(p) ((ufunc_T *)(p - (dumuf.uf_name - (char_u *)&dumuf))) #define HI2UF(hi) HIKEY2UF((hi)->hi_key) -/* Defines for Vim variables. These must match vimvars[] in eval.c! */ +/// Defines for Vim variables +/// +/// Order must match order in vimvars[] table in eval.c. typedef enum { VV_COUNT, VV_COUNT1, diff --git a/src/nvim/eval/decode.c b/src/nvim/eval/decode.c index de89f9c132..29a1b2a82a 100644 --- a/src/nvim/eval/decode.c +++ b/src/nvim/eval/decode.c @@ -69,6 +69,8 @@ static inline void create_special_dict(typval_T *const rettv, }; } +#define DICT_LEN(dict) (dict)->dv_hashtab.ht_used + /// Helper function used for working with stack vectors used by JSON decoder /// /// @param[in] obj New object. @@ -158,8 +160,7 @@ static inline int json_decoder_pop(ValuesStackItem obj, return FAIL; } else if (!obj.didcomma && (last_container.special_val == NULL - && (last_container.container.vval.v_dict->dv_hashtab.ht_used - != 0))) { + && (DICT_LEN(last_container.container.vval.v_dict) != 0))) { EMSG2(_("E474: Expected comma before dictionary key: %s"), val_location); clear_tv(&obj.val); return FAIL; @@ -191,6 +192,25 @@ static inline int json_decoder_pop(ValuesStackItem obj, return OK; } +#define OBJ(obj_tv, is_sp_string) \ + ((ValuesStackItem) { \ + .is_special_string = (is_sp_string), \ + .val = (obj_tv), \ + .didcomma = didcomma, \ + .didcolon = didcolon, \ + }) +#define POP(obj_tv, is_sp_string) \ + do { \ + if (json_decoder_pop(OBJ(obj_tv, is_sp_string), &stack, &container_stack, \ + &p, &next_map_special, &didcomma, &didcolon) \ + == FAIL) { \ + goto json_decode_string_fail; \ + } \ + if (next_map_special) { \ + goto json_decode_string_cycle_start; \ + } \ + } while (0) + /// Convert JSON string into VimL object /// /// @param[in] buf String to convert. UTF-8 encoding is assumed. @@ -215,24 +235,6 @@ int json_decode_string(const char *const buf, const size_t len, bool didcomma = false; bool didcolon = false; bool next_map_special = false; -#define OBJ(obj_tv, is_sp_string) \ - ((ValuesStackItem) { \ - .is_special_string = (is_sp_string), \ - .val = (obj_tv), \ - .didcomma = didcomma, \ - .didcolon = didcolon, \ - }) -#define POP(obj_tv, is_sp_string) \ - do { \ - if (json_decoder_pop(OBJ(obj_tv, is_sp_string), &stack, &container_stack, \ - &p, &next_map_special, &didcomma, &didcolon) \ - == FAIL) { \ - goto json_decode_string_fail; \ - } \ - if (next_map_special) { \ - goto json_decode_string_cycle_start; \ - } \ - } while (0) const char *p = buf; for (; p < e; p++) { json_decode_string_cycle_start: @@ -268,7 +270,8 @@ json_decode_string_cycle_start: goto json_decode_string_after_cycle; } else { if (json_decoder_pop(kv_pop(stack), &stack, &container_stack, &p, - &next_map_special, &didcomma, &didcolon) == FAIL) { + &next_map_special, &didcomma, &didcolon) + == FAIL) { goto json_decode_string_fail; } assert(!next_map_special); @@ -293,8 +296,7 @@ json_decode_string_cycle_start: goto json_decode_string_fail; } else if (last_container.special_val == NULL ? (last_container.container.v_type == VAR_DICT - ? (last_container.container.vval.v_dict->dv_hashtab.ht_used - == 0) + ? (DICT_LEN(last_container.container.vval.v_dict) == 0) : (last_container.container.vval.v_list->lv_len == 0)) : (last_container.special_val->lv_len == 0)) { EMSG2(_("E474: Leading comma: %s"), p); @@ -686,8 +688,6 @@ json_decode_string_cycle_start: break; } } -#undef POP -#undef OBJ json_decode_string_after_cycle: for (; p < e; p++) { switch (*p) { @@ -722,6 +722,11 @@ json_decode_string_ret: return ret; } +#undef POP +#undef OBJ + +#undef DICT_LEN + /// Convert msgpack object to a VimL one int msgpack_to_vim(const msgpack_object mobj, typval_T *const rettv) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT diff --git a/src/nvim/message.h b/src/nvim/message.h index 9249596bec..0cd0ede2c4 100644 --- a/src/nvim/message.h +++ b/src/nvim/message.h @@ -41,7 +41,7 @@ /// Like #EMSG, but for messages with two "%s" inside #define EMSG3(s, p, q) emsg3((char_u *)(s), (char_u *)(p), \ - (char_u *)(q)) + (char_u *)(q)) /// Like #EMSG, but for messages with one "%" PRId64 inside #define EMSGN(s, n) emsgn((char_u *)(s), (int64_t)(n)) |