aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/eval/typval.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2025-01-03 20:12:15 +0800
committerzeertzjq <zeertzjq@outlook.com>2025-01-07 09:15:10 +0800
commitd5308637bf1aac2b97fccf73a0ffdef304eaa1d6 (patch)
treeacb03c837290a225f1fcb7f73b4ae1306d1e7589 /src/nvim/eval/typval.c
parent06ff5480ce274daf3b7ad9950a587099200dc8ff (diff)
downloadrneovim-d5308637bf1aac2b97fccf73a0ffdef304eaa1d6.tar.gz
rneovim-d5308637bf1aac2b97fccf73a0ffdef304eaa1d6.tar.bz2
rneovim-d5308637bf1aac2b97fccf73a0ffdef304eaa1d6.zip
vim-patch:9.1.0984: exception handling can be improved
Problem: exception handling can be improved Solution: add v:stacktrace and getstacktrace() closes: vim/vim#16360 https://github.com/vim/vim/commit/663d18d6102f40d14e36096ec590445e61026ed6 Co-authored-by: ichizok <gclient.gaap@gmail.com> Co-authored-by: Naruhiko Nishino <naru123456789@gmail.com>
Diffstat (limited to 'src/nvim/eval/typval.c')
-rw-r--r--src/nvim/eval/typval.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c
index cbb6b5644f..ed1031577c 100644
--- a/src/nvim/eval/typval.c
+++ b/src/nvim/eval/typval.c
@@ -2633,6 +2633,30 @@ int tv_dict_add_allocated_str(dict_T *const d, const char *const key, const size
return OK;
}
+/// Add a function entry to dictionary.
+///
+/// @param[out] d Dictionary to add entry to.
+/// @param[in] key Key to add.
+/// @param[in] key_len Key length.
+/// @param[in] fp Function to add.
+///
+/// @return OK in case of success, FAIL when key already exists.
+int tv_dict_add_func(dict_T *const d, const char *const key, const size_t key_len,
+ ufunc_T *const fp)
+ FUNC_ATTR_NONNULL_ARG(1, 2, 4)
+{
+ dictitem_T *const item = tv_dict_item_alloc_len(key, key_len);
+
+ item->di_tv.v_type = VAR_FUNC;
+ item->di_tv.vval.v_string = xstrdup(fp->uf_name);
+ if (tv_dict_add(d, item) == FAIL) {
+ tv_dict_item_free(item);
+ return FAIL;
+ }
+ func_ref(item->di_tv.vval.v_string);
+ return OK;
+}
+
//{{{2 Operations on the whole dict
/// Clear all the keys of a Dictionary. "d" remains a valid empty Dictionary.