aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api/private/helpers.c
diff options
context:
space:
mode:
authorBjörn Linse <bjorn.linse@gmail.com>2016-09-14 11:17:07 +0200
committerBjörn Linse <bjorn.linse@gmail.com>2016-09-15 10:44:38 +0200
commitcd08e6cf72b52fb23aa4556889f35759062c5bf9 (patch)
treea581b0162b847d20f142706c9085bcf405cc0697 /src/nvim/api/private/helpers.c
parentc61bf43a90238f20716d48554ddc536b485ec1bf (diff)
downloadrneovim-cd08e6cf72b52fb23aa4556889f35759062c5bf9.tar.gz
rneovim-cd08e6cf72b52fb23aa4556889f35759062c5bf9.tar.bz2
rneovim-cd08e6cf72b52fb23aa4556889f35759062c5bf9.zip
api: make nvim[_obj]_set_var and _del_var not return the old value
Diffstat (limited to 'src/nvim/api/private/helpers.c')
-rw-r--r--src/nvim/api/private/helpers.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c
index 3735139a07..fc114bae16 100644
--- a/src/nvim/api/private/helpers.c
+++ b/src/nvim/api/private/helpers.c
@@ -104,10 +104,11 @@ Object dict_get_value(dict_T *dict, String key, Error *err)
/// @param value The new value
/// @param del Delete key in place of setting it. Argument `value` is ignored in
/// this case.
+/// @param retval If true the old value will be converted and returned.
/// @param[out] err Details of an error that may have occurred
-/// @return the old value, if any
+/// @return The old value if `retval` is true and the key was present, else NIL
Object dict_set_value(dict_T *dict, String key, Object value, bool del,
- Error *err)
+ bool retval, Error *err)
{
Object rv = OBJECT_INIT;
@@ -135,7 +136,9 @@ Object dict_set_value(dict_T *dict, String key, Object value, bool del,
api_set_error(err, Validation, _("Key \"%s\" doesn't exist"), key.data);
} else {
// Return the old value
- rv = vim_to_object(&di->di_tv);
+ if (retval) {
+ rv = vim_to_object(&di->di_tv);
+ }
// Delete the entry
hashitem_T *hi = hash_find(&dict->dv_hashtab, di->di_key);
hash_remove(&dict->dv_hashtab, hi);
@@ -156,7 +159,9 @@ Object dict_set_value(dict_T *dict, String key, Object value, bool del,
dict_add(dict, di);
} else {
// Return the old value
- rv = vim_to_object(&di->di_tv);
+ if (retval) {
+ rv = vim_to_object(&di->di_tv);
+ }
clear_tv(&di->di_tv);
}