diff options
| author | ZyX <kp-pav@yandex.ru> | 2017-11-26 15:54:03 +0300 | 
|---|---|---|
| committer | ZyX <kp-pav@yandex.ru> | 2017-11-26 15:54:03 +0300 | 
| commit | b9c78130587e42ca3b6417b47fb739a166da8eb7 (patch) | |
| tree | 142cf7dd0a87dfb32a20838e7683dd1980e4b3e7 /src/nvim/eval/typval.c | |
| parent | 05a3c12118a6dae0ac8f3603f9ee4d9fd9450cce (diff) | |
| parent | 207b7ca4bc16d52641eaa5244eef25a0dba91dbc (diff) | |
| download | rneovim-b9c78130587e42ca3b6417b47fb739a166da8eb7.tar.gz rneovim-b9c78130587e42ca3b6417b47fb739a166da8eb7.tar.bz2 rneovim-b9c78130587e42ca3b6417b47fb739a166da8eb7.zip  | |
Merge branch 'master' into expression-parser
Diffstat (limited to 'src/nvim/eval/typval.c')
| -rw-r--r-- | src/nvim/eval/typval.c | 50 | 
1 files changed, 47 insertions, 3 deletions
diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index c339a5cdd2..4bc3a85efb 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -374,7 +374,7 @@ void tv_list_append_dict(list_T *const list, dict_T *const dict)  ///                  case string is considered to be usual zero-terminated  ///                  string or NULL “empty” string.  void tv_list_append_string(list_T *const l, const char *const str, -                           const ptrdiff_t len) +                           const ssize_t len)    FUNC_ATTR_NONNULL_ARG(1)  {    if (str == NULL) { @@ -824,7 +824,7 @@ void tv_dict_watcher_add(dict_T *const dict, const char *const key_pattern,  /// @param[in]  cb2  Second callback to check.  ///  /// @return True if they are equal, false otherwise. -bool tv_callback_equal(const Callback *const cb1, const Callback *const cb2) +bool tv_callback_equal(const Callback *cb1, const Callback *cb2)    FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT  {    if (cb1->type != cb2->type) { @@ -843,10 +843,31 @@ bool tv_callback_equal(const Callback *const cb1, const Callback *const cb2)        return true;      }    } -  assert(false); +  abort();    return false;  } +/// Unref/free callback +void callback_free(Callback *callback) +  FUNC_ATTR_NONNULL_ALL +{ +  switch (callback->type) { +    case kCallbackFuncref: { +      func_unref(callback->data.funcref); +      xfree(callback->data.funcref); +      break; +    } +    case kCallbackPartial: { +      partial_unref(callback->data.partial); +      break; +    } +    case kCallbackNone: { +      break; +    } +  } +  callback->type = kCallbackNone; +} +  /// Remove watcher from a dictionary  ///  /// @param  dict  Dictionary to remove watcher from. @@ -1374,6 +1395,29 @@ int tv_dict_add_nr(dict_T *const d, const char *const key,    return OK;  } +/// Add a special 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]  val SpecialVarValue to add. +/// +/// @return OK in case of success, FAIL when key already exists. +int tv_dict_add_special(dict_T *const d, const char *const key, +                        const size_t key_len, SpecialVarValue val) +{ +  dictitem_T *const item = tv_dict_item_alloc_len(key, key_len); + +  item->di_tv.v_lock = VAR_UNLOCKED; +  item->di_tv.v_type = VAR_SPECIAL; +  item->di_tv.vval.v_special = val; +  if (tv_dict_add(d, item) == FAIL) { +    tv_dict_item_free(item); +    return FAIL; +  } +  return OK; +} +  /// Add a string entry to dictionary  ///  /// @param[out]  d  Dictionary to add entry to.  | 
