diff options
Diffstat (limited to 'src/nvim/eval/typval.c')
-rw-r--r-- | src/nvim/eval/typval.c | 62 |
1 files changed, 42 insertions, 20 deletions
diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index 069cdced34..9328f53dbd 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -5,7 +5,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <sys/types.h> +#include <uv.h> #include "nvim/ascii_defs.h" #include "nvim/assert_defs.h" @@ -20,10 +20,11 @@ #include "nvim/eval/vars.h" #include "nvim/garray.h" #include "nvim/garray_defs.h" -#include "nvim/gettext.h" +#include "nvim/gettext_defs.h" #include "nvim/globals.h" #include "nvim/hashtab.h" -#include "nvim/lib/queue.h" +#include "nvim/hashtab_defs.h" +#include "nvim/lib/queue_defs.h" #include "nvim/lua/executor.h" #include "nvim/macros_defs.h" #include "nvim/mbyte.h" @@ -622,13 +623,14 @@ tv_list_copy_error: listitem_T *tv_list_check_range_index_one(list_T *const l, int *const n1, const bool quiet) { listitem_T *li = tv_list_find_index(l, n1); - if (li == NULL) { - if (!quiet) { - semsg(_(e_list_index_out_of_range_nr), (int64_t)(*n1)); - } - return NULL; + if (li != NULL) { + return li; } - return li; + + if (!quiet) { + semsg(_(e_list_index_out_of_range_nr), (int64_t)(*n1)); + } + return NULL; } /// Check that "n2" can be used as the second index in a range of list "l". @@ -1633,11 +1635,13 @@ static listitem_T *tv_list_find_index(list_T *const l, int *const idx) FUNC_ATTR_WARN_UNUSED_RESULT { listitem_T *li = tv_list_find(l, *idx); - if (li == NULL) { - if (*idx < 0) { - *idx = 0; - li = tv_list_find(l, *idx); - } + if (li != NULL) { + return li; + } + + if (*idx < 0) { + *idx = 0; + li = tv_list_find(l, *idx); } return li; } @@ -1801,10 +1805,10 @@ void callback_copy(Callback *dest, Callback *src) } /// Generate a string description of a callback -char *callback_to_string(Callback *cb) +char *callback_to_string(Callback *cb, Arena *arena) { if (cb->type == kCallbackLua) { - return nlua_funcref_str(cb->data.luaref); + return nlua_funcref_str(cb->data.luaref, arena); } const size_t msglen = 100; @@ -2129,10 +2133,12 @@ void tv_dict_free_dict(dict_T *const d) void tv_dict_free(dict_T *const d) FUNC_ATTR_NONNULL_ALL { - if (!tv_in_free_unref_items) { - tv_dict_free_contents(d); - tv_dict_free_dict(d); + if (tv_in_free_unref_items) { + return; } + + tv_dict_free_contents(d); + tv_dict_free_dict(d); } /// Unreference a dictionary @@ -2910,7 +2916,7 @@ static int tv_blob_index(const blob_T *blob, int len, varnumber_T idx, typval_T return OK; } -int tv_blob_slice_or_index(const blob_T *blob, int is_range, varnumber_T n1, varnumber_T n2, +int tv_blob_slice_or_index(const blob_T *blob, bool is_range, varnumber_T n1, varnumber_T n2, bool exclusive, typval_T *rettv) { int len = tv_blob_len(rettv->vval.v_blob); @@ -4345,6 +4351,22 @@ int tv_check_for_string_or_number_arg(const typval_T *const args, const int idx) return OK; } +/// Give an error and return FAIL unless "args[idx]" is a buffer number. +/// Buffer number can be a number or a string. +int tv_check_for_buffer_arg(const typval_T *const args, const int idx) + FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE +{ + return tv_check_for_string_or_number_arg(args, idx); +} + +/// Give an error and return FAIL unless "args[idx]" is a line number. +/// Line number can be a number or a string. +int tv_check_for_lnum_arg(const typval_T *const args, const int idx) + FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE +{ + return tv_check_for_string_or_number_arg(args, idx); +} + /// Give an error and return FAIL unless "args[idx]" is a string or a list. int tv_check_for_string_or_list_arg(const typval_T *const args, const int idx) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE |