refactor: object_to_vim() cannot fail

Since the parent commit, object_to_vim() can't fail, so callers don't
need to check its result.
This commit is contained in:
Justin M. Keyes
2023-12-07 13:01:42 +01:00
parent cca6c4c698
commit a16218d4c6
7 changed files with 15 additions and 46 deletions

View File

@@ -258,9 +258,7 @@ Object vim_to_object(typval_T *obj)
/// @param tv Conversion result is placed here. On failure member v_type is
/// set to VAR_UNKNOWN (no allocation was made for this variable).
/// @param err Error object.
///
/// @returns true if conversion is successful, otherwise false.
bool object_to_vim(Object obj, typval_T *tv, Error *err)
void object_to_vim(Object obj, typval_T *tv, Error *err)
{
tv->v_type = VAR_UNKNOWN;
tv->v_lock = VAR_UNLOCKED;
@@ -307,12 +305,7 @@ bool object_to_vim(Object obj, typval_T *tv, Error *err)
for (uint32_t i = 0; i < obj.data.array.size; i++) {
Object item = obj.data.array.items[i];
typval_T li_tv;
if (!object_to_vim(item, &li_tv, err)) {
tv_list_free(list);
return false;
}
object_to_vim(item, &li_tv, err);
tv_list_append_owned_tv(list, li_tv);
}
tv_list_ref(list);
@@ -329,14 +322,7 @@ bool object_to_vim(Object obj, typval_T *tv, Error *err)
KeyValuePair item = obj.data.dictionary.items[i];
String key = item.key;
dictitem_T *const di = tv_dict_item_alloc(key.data);
if (!object_to_vim(item.value, &di->di_tv, err)) {
// cleanup
tv_dict_item_free(di);
tv_dict_free(dict);
return false;
}
object_to_vim(item.value, &di->di_tv, err);
tv_dict_add(dict, di);
}
dict->dv_refcount++;
@@ -353,6 +339,4 @@ bool object_to_vim(Object obj, typval_T *tv, Error *err)
break;
}
}
return true;
}

View File

@@ -253,9 +253,7 @@ Object dict_set_var(dict_T *dict, String key, Object value, bool del, bool retva
typval_T tv;
// Convert the object to a vimscript type in the temporary variable
if (!object_to_vim(value, &tv, err)) {
return rv;
}
object_to_vim(value, &tv, err);
typval_T oldtv = TV_INITIAL_VALUE;

View File

@@ -207,9 +207,7 @@ static Object _call_function(String fn, Array args, dict_T *self, Error *err)
typval_T vim_args[MAX_FUNC_ARGS + 1];
size_t i = 0; // also used for freeing the variables
for (; i < args.size; i++) {
if (!object_to_vim(args.items[i], &vim_args[i], err)) {
goto free_vim_args;
}
object_to_vim(args.items[i], &vim_args[i], err);
}
// Initialize `force_abort` and `suppress_errthrow` at the top level.
@@ -243,7 +241,6 @@ static Object _call_function(String fn, Array args, dict_T *self, Error *err)
tv_clear(&rettv);
recursive--;
free_vim_args:
while (i > 0) {
tv_clear(&vim_args[--i]);
}
@@ -297,9 +294,7 @@ Object nvim_call_dict_function(Object dict, String fn, Array args, Error *err)
mustfree = true;
break;
case kObjectTypeDictionary:
if (!object_to_vim(dict, &rettv, err)) {
goto end;
}
object_to_vim(dict, &rettv, err);
break;
default:
api_set_error(err, kErrorTypeValidation,