aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/eval
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2017-03-13 13:43:01 +0300
committerZyX <kp-pav@yandex.ru>2017-03-29 10:08:45 +0300
commit43e9fad1c8835a3136f4db53c82608e034df2a5e (patch)
tree0bb67dc5b9ddb1f84f6984f1e75a6c2bf29fad4d /src/nvim/eval
parent270a3889af024485fa7b63f34c4dd3f92f6e0f98 (diff)
downloadrneovim-43e9fad1c8835a3136f4db53c82608e034df2a5e.tar.gz
rneovim-43e9fad1c8835a3136f4db53c82608e034df2a5e.tar.bz2
rneovim-43e9fad1c8835a3136f4db53c82608e034df2a5e.zip
eval: Use tv_is_func in place of ==VAR_FUNC||==VAR_PARTIAL
Also fixes same error as in vim/vim#1557
Diffstat (limited to 'src/nvim/eval')
-rw-r--r--src/nvim/eval/typval.c9
-rw-r--r--src/nvim/eval/typval.h15
2 files changed, 18 insertions, 6 deletions
diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c
index d9feb2d88e..620da0032e 100644
--- a/src/nvim/eval/typval.c
+++ b/src/nvim/eval/typval.c
@@ -1250,8 +1250,7 @@ bool tv_dict_get_callback(dict_T *const d,
return true;
}
- if (di->di_tv.v_type != VAR_FUNC && di->di_tv.v_type != VAR_STRING
- && di->di_tv.v_type != VAR_PARTIAL) {
+ if (!tv_is_func(di->di_tv) && di->di_tv.v_type != VAR_STRING) {
emsgf(_("E6000: Argument is not a function or function name"));
return false;
}
@@ -1418,7 +1417,7 @@ void tv_dict_extend(dict_T *const d1, dict_T *const d2,
// Disallow replacing a builtin function in l: and g:.
// Check the key to be valid when adding to any scope.
if (d1->dv_scope == VAR_DEF_SCOPE
- && di2->di_tv.v_type == VAR_FUNC
+ && tv_is_func(di2->di_tv)
&& !var_check_func_name((const char *)di2->di_key, di1 == NULL)) {
break;
}
@@ -2101,9 +2100,7 @@ bool tv_equal(typval_T *const tv1, typval_T *const tv2, const bool ic,
// TODO(ZyX-I): Make this not recursive
static int recursive_cnt = 0; // Catch recursive loops.
- if (!((tv1->v_type == VAR_FUNC || tv1->v_type == VAR_PARTIAL)
- && (tv2->v_type == VAR_FUNC || tv2->v_type == VAR_PARTIAL))
- && tv1->v_type != tv2->v_type) {
+ if (!(tv_is_func(*tv1) && tv_is_func(*tv2)) && tv1->v_type != tv2->v_type) {
return false;
}
diff --git a/src/nvim/eval/typval.h b/src/nvim/eval/typval.h
index fa0105197f..7eab22bc12 100644
--- a/src/nvim/eval/typval.h
+++ b/src/nvim/eval/typval.h
@@ -408,6 +408,21 @@ static inline DictWatcher *tv_dict_watcher_node_data(QUEUE *q)
return QUEUE_DATA(q, DictWatcher, node);
}
+static inline bool tv_is_func(const typval_T tv)
+ FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_ALWAYS_INLINE FUNC_ATTR_CONST;
+
+/// Check whether given typval_T contains a function
+///
+/// That is, whether it contains VAR_FUNC or VAR_PARTIAL.
+///
+/// @param[in] tv Typval to check.
+///
+/// @return True if it is a function or a partial, false otherwise.
+static inline bool tv_is_func(const typval_T tv)
+{
+ return tv.v_type == VAR_FUNC || tv.v_type == VAR_PARTIAL;
+}
+
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "eval/typval.h.generated.h"
#endif