api_clear_error()

This commit is contained in:
Justin M. Keyes 2017-04-23 15:59:59 +02:00
parent 5c9860a0a2
commit 2a49163103
9 changed files with 48 additions and 47 deletions

View File

@ -640,7 +640,7 @@ Boolean nvim_buf_is_valid(Buffer buffer)
{
Error stub = ERROR_INIT;
Boolean ret = find_buffer_by_handle(buffer, &stub) != NULL;
xfree(stub.msg);
api_clear_error(&stub);
return ret;
}

View File

@ -800,7 +800,8 @@ void api_free_dictionary(Dictionary value)
xfree(value.items);
}
void api_free_error(Error *value)
void api_clear_error(Error *value)
FUNC_ATTR_NONNULL_ALL
{
xfree(value->msg);
value->msg = NULL;

View File

@ -194,7 +194,7 @@ Boolean nvim_tabpage_is_valid(Tabpage tabpage)
{
Error stub = ERROR_INIT;
Boolean ret = find_tab_by_handle(tabpage, &stub) != NULL;
xfree(stub.msg);
api_clear_error(&stub);
return ret;
}

View File

@ -799,7 +799,7 @@ Array nvim_call_atomic(uint64_t channel_id, Array calls, Error *err)
validation_error:
api_free_array(results);
theend:
api_free_error(&nested_error);
api_clear_error(&nested_error);
return rv;
}

View File

@ -388,7 +388,7 @@ Boolean nvim_win_is_valid(Window window)
{
Error stub = ERROR_INIT;
Boolean ret = find_window_by_handle(window, &stub) != NULL;
xfree(stub.msg);
api_clear_error(&stub);
return ret;
}

View File

@ -6524,7 +6524,7 @@ static void api_wrapper(typval_T *argvars, typval_T *rettv, FunPtr fptr)
end:
api_free_array(args);
api_free_object(result);
xfree(err.msg);
api_clear_error(&err);
}
/*
@ -13795,7 +13795,7 @@ static void f_rpcrequest(typval_T *argvars, typval_T *rettv, FunPtr fptr)
end:
api_free_object(result);
xfree(err.msg);
api_clear_error(&err);
}
// "rpcstart()" function (DEPRECATED)
@ -16528,13 +16528,14 @@ static void f_termopen(typval_T *argvars, typval_T *rettv, FunPtr fptr)
Error err = ERROR_INIT;
dict_set_var(curbuf->b_vars, cstr_as_string("terminal_job_id"),
INTEGER_OBJ(rettv->vval.v_number), false, false, &err);
api_clear_error(&err);
dict_set_var(curbuf->b_vars, cstr_as_string("terminal_job_pid"),
INTEGER_OBJ(pid), false, false, &err);
api_clear_error(&err);
Terminal *term = terminal_open(topts);
data->term = term;
data->refcount++;
xfree(err.msg);
return;
}

View File

@ -411,38 +411,38 @@ static void handle_request(Channel *channel, msgpack_object *request)
channel->id);
call_set_error(channel, buf);
}
} else {
// Retrieve the request handler
MsgpackRpcRequestHandler handler;
msgpack_object *method = msgpack_rpc_method(request);
if (method) {
handler = msgpack_rpc_get_handler_for(method->via.bin.ptr,
method->via.bin.size);
} else {
handler.fn = msgpack_rpc_handle_missing_method;
handler.async = true;
}
Array args = ARRAY_DICT_INIT;
if (!msgpack_rpc_to_array(msgpack_rpc_args(request), &args)) {
handler.fn = msgpack_rpc_handle_invalid_arguments;
handler.async = true;
}
RequestEvent *event_data = xmalloc(sizeof(RequestEvent));
event_data->channel = channel;
event_data->handler = handler;
event_data->args = args;
event_data->request_id = request_id;
incref(channel);
if (handler.async) {
on_request_event((void **)&event_data);
} else {
multiqueue_put(channel->events, on_request_event, 1, event_data);
}
api_clear_error(&error);
return;
}
// Retrieve the request handler
MsgpackRpcRequestHandler handler;
msgpack_object *method = msgpack_rpc_method(request);
if (method) {
handler = msgpack_rpc_get_handler_for(method->via.bin.ptr,
method->via.bin.size);
} else {
handler.fn = msgpack_rpc_handle_missing_method;
handler.async = true;
}
Array args = ARRAY_DICT_INIT;
if (!msgpack_rpc_to_array(msgpack_rpc_args(request), &args)) {
handler.fn = msgpack_rpc_handle_invalid_arguments;
handler.async = true;
}
RequestEvent *event_data = xmalloc(sizeof(RequestEvent));
event_data->channel = channel;
event_data->handler = handler;
event_data->args = args;
event_data->request_id = request_id;
incref(channel);
if (handler.async) {
on_request_event((void **)&event_data);
} else {
multiqueue_put(channel->events, on_request_event, 1, event_data);
}
xfree(error.msg);
}
static void on_request_event(void **argv)
@ -469,7 +469,7 @@ static void on_request_event(void **argv)
api_free_array(args);
decref(channel);
xfree(e);
xfree(error.msg);
api_clear_error(&error);
}
static bool channel_write(Channel *channel, WBuffer *buffer)
@ -518,7 +518,7 @@ static void send_error(Channel *channel, uint64_t id, char *err)
&e,
NIL,
&out_buffer));
xfree(e.msg);
api_clear_error(&e);
}
static void send_request(Channel *channel,

View File

@ -640,7 +640,7 @@ static void buf_set_term_title(buf_T *buf, char *title)
false,
false,
&err);
xfree(err.msg);
api_clear_error(&err);
}
static int term_settermprop(VTermProp prop, VTermValue *val, void *data)
@ -1225,11 +1225,10 @@ static bool is_focused(Terminal *term)
/* Only called from terminal_open where curbuf->terminal is the */ \
/* context */ \
o = dict_get_value(curbuf->b_vars, cstr_as_string(k), &err); \
xfree(err.msg); \
api_clear_error(&err); \
if (o.type == kObjectTypeNil) { \
Error err2 = ERROR_INIT; \
o = dict_get_value(&globvardict, cstr_as_string(k), &err2); \
xfree(err2.msg); \
o = dict_get_value(&globvardict, cstr_as_string(k), &err); \
api_clear_error(&err); \
} \
} while (0)

View File

@ -228,7 +228,7 @@ static int get_key_code_timeout(void)
if (nvim_get_option(cstr_as_string("ttimeout"), &err).data.boolean) {
ms = nvim_get_option(cstr_as_string("ttimeoutlen"), &err).data.integer;
}
xfree(err.msg);
api_clear_error(&err);
return (int)ms;
}