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; Error stub = ERROR_INIT;
Boolean ret = find_buffer_by_handle(buffer, &stub) != NULL; Boolean ret = find_buffer_by_handle(buffer, &stub) != NULL;
xfree(stub.msg); api_clear_error(&stub);
return ret; return ret;
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -411,38 +411,38 @@ static void handle_request(Channel *channel, msgpack_object *request)
channel->id); channel->id);
call_set_error(channel, buf); call_set_error(channel, buf);
} }
} else { api_clear_error(&error);
// Retrieve the request handler return;
MsgpackRpcRequestHandler handler; }
msgpack_object *method = msgpack_rpc_method(request); // Retrieve the request handler
MsgpackRpcRequestHandler handler;
if (method) { msgpack_object *method = msgpack_rpc_method(request);
handler = msgpack_rpc_get_handler_for(method->via.bin.ptr,
method->via.bin.size); if (method) {
} else { handler = msgpack_rpc_get_handler_for(method->via.bin.ptr,
handler.fn = msgpack_rpc_handle_missing_method; method->via.bin.size);
handler.async = true; } 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; Array args = ARRAY_DICT_INIT;
handler.async = true; 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; RequestEvent *event_data = xmalloc(sizeof(RequestEvent));
event_data->args = args; event_data->channel = channel;
event_data->request_id = request_id; event_data->handler = handler;
incref(channel); event_data->args = args;
if (handler.async) { event_data->request_id = request_id;
on_request_event((void **)&event_data); incref(channel);
} else { if (handler.async) {
multiqueue_put(channel->events, on_request_event, 1, event_data); 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) static void on_request_event(void **argv)
@ -469,7 +469,7 @@ static void on_request_event(void **argv)
api_free_array(args); api_free_array(args);
decref(channel); decref(channel);
xfree(e); xfree(e);
xfree(error.msg); api_clear_error(&error);
} }
static bool channel_write(Channel *channel, WBuffer *buffer) static bool channel_write(Channel *channel, WBuffer *buffer)
@ -518,7 +518,7 @@ static void send_error(Channel *channel, uint64_t id, char *err)
&e, &e,
NIL, NIL,
&out_buffer)); &out_buffer));
xfree(e.msg); api_clear_error(&e);
} }
static void send_request(Channel *channel, 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,
false, false,
&err); &err);
xfree(err.msg); api_clear_error(&err);
} }
static int term_settermprop(VTermProp prop, VTermValue *val, void *data) 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 */ \ /* Only called from terminal_open where curbuf->terminal is the */ \
/* context */ \ /* context */ \
o = dict_get_value(curbuf->b_vars, cstr_as_string(k), &err); \ o = dict_get_value(curbuf->b_vars, cstr_as_string(k), &err); \
xfree(err.msg); \ api_clear_error(&err); \
if (o.type == kObjectTypeNil) { \ if (o.type == kObjectTypeNil) { \
Error err2 = ERROR_INIT; \ o = dict_get_value(&globvardict, cstr_as_string(k), &err); \
o = dict_get_value(&globvardict, cstr_as_string(k), &err2); \ api_clear_error(&err); \
xfree(err2.msg); \
} \ } \
} while (0) } 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) { if (nvim_get_option(cstr_as_string("ttimeout"), &err).data.boolean) {
ms = nvim_get_option(cstr_as_string("ttimeoutlen"), &err).data.integer; ms = nvim_get_option(cstr_as_string("ttimeoutlen"), &err).data.integer;
} }
xfree(err.msg); api_clear_error(&err);
return (int)ms; return (int)ms;
} }