diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 332b7425d2..1637374459 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -253,11 +253,10 @@ end: Object buffer_get_var(Buffer buffer, String name, Error *err) { - Object rv; buf_T *buf = find_buffer(buffer, err); if (!buf) { - return rv; + return (Object) OBJECT_INIT; } return dict_get_value(buf->b_vars, name, err); @@ -265,11 +264,10 @@ Object buffer_get_var(Buffer buffer, String name, Error *err) Object buffer_set_var(Buffer buffer, String name, Object value, Error *err) { - Object rv; buf_T *buf = find_buffer(buffer, err); if (!buf) { - return rv; + return (Object) OBJECT_INIT; } return dict_set_value(buf->b_vars, name, value, err); @@ -277,11 +275,10 @@ Object buffer_set_var(Buffer buffer, String name, Object value, Error *err) Object buffer_get_option(Buffer buffer, String name, Error *err) { - Object rv; buf_T *buf = find_buffer(buffer, err); if (!buf) { - return rv; + return (Object) OBJECT_INIT; } return get_option_from(buf, SREQ_BUF, name, err); @@ -363,7 +360,7 @@ void buffer_insert(Buffer buffer, Integer lnum, StringArray lines, Error *err) Position buffer_get_mark(Buffer buffer, String name, Error *err) { - Position rv; + Position rv = POSITION_INIT; buf_T *buf = find_buffer(buffer, err); if (!buf) { diff --git a/src/nvim/api/private/defs.h b/src/nvim/api/private/defs.h index fbf9018043..ab806941f4 100644 --- a/src/nvim/api/private/defs.h +++ b/src/nvim/api/private/defs.h @@ -7,6 +7,8 @@ #define ARRAY_DICT_INIT {.size = 0, .items = NULL} #define STRING_INIT {.data = NULL, .size = 0} +#define OBJECT_INIT { .type = kObjectTypeNil } +#define POSITION_INIT { .row = 0, .col = 0 } #define REMOTE_TYPE(type) typedef uint64_t type #define TYPED_ARRAY_OF(type) \ diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 705e16b13f..c9bc849af0 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -83,7 +83,7 @@ bool try_end(Error *err) Object dict_get_value(dict_T *dict, String key, Error *err) { - Object rv; + Object rv = OBJECT_INIT; hashitem_T *hi; dictitem_T *di; char *k = xstrndup(key.data, key.size); @@ -103,7 +103,7 @@ Object dict_get_value(dict_T *dict, String key, Error *err) Object dict_set_value(dict_T *dict, String key, Object value, Error *err) { - Object rv = {.type = kObjectTypeNil}; + Object rv = OBJECT_INIT; if (dict->dv_lock) { set_api_error("Dictionary is locked", err); @@ -166,7 +166,7 @@ Object dict_set_value(dict_T *dict, String key, Object value, Error *err) Object get_option_from(void *from, int type, String name, Error *err) { - Object rv = {.type = kObjectTypeNil}; + Object rv = OBJECT_INIT; if (name.size == 0) { set_api_error("Empty option name", err); @@ -424,7 +424,7 @@ static bool object_to_vim(Object obj, typval_T *tv, Error *err) static Object vim_to_object_rec(typval_T *obj, PMap(ptr_t) *lookup) { - Object rv = {.type = kObjectTypeNil}; + Object rv = OBJECT_INIT; if (obj->v_type == VAR_LIST || obj->v_type == VAR_DICT) { // Container object, add it to the lookup table diff --git a/src/nvim/api/tabpage.c b/src/nvim/api/tabpage.c index b7243c68a8..ce52466d12 100644 --- a/src/nvim/api/tabpage.c +++ b/src/nvim/api/tabpage.c @@ -42,11 +42,10 @@ WindowArray tabpage_get_windows(Tabpage tabpage, Error *err) Object tabpage_get_var(Tabpage tabpage, String name, Error *err) { - Object rv; tabpage_T *tab = find_tab(tabpage, err); if (!tab) { - return rv; + return (Object) OBJECT_INIT; } return dict_get_value(tab->tp_vars, name, err); @@ -54,11 +53,10 @@ Object tabpage_get_var(Tabpage tabpage, String name, Error *err) Object tabpage_set_var(Tabpage tabpage, String name, Object value, Error *err) { - Object rv; tabpage_T *tab = find_tab(tabpage, err); if (!tab) { - return rv; + return (Object) OBJECT_INIT; } return dict_set_value(tab->tp_vars, name, value, err); diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index 60de6ea219..fd13557e3b 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -133,11 +133,10 @@ void window_set_width(Window window, Integer width, Error *err) Object window_get_var(Window window, String name, Error *err) { - Object rv; win_T *win = find_window(window, err); if (!win) { - return rv; + return (Object) OBJECT_INIT; } return dict_get_value(win->w_vars, name, err); @@ -145,11 +144,10 @@ Object window_get_var(Window window, String name, Error *err) Object window_set_var(Window window, String name, Object value, Error *err) { - Object rv; win_T *win = find_window(window, err); if (!win) { - return rv; + return (Object) OBJECT_INIT; } return dict_set_value(win->w_vars, name, value, err); @@ -157,11 +155,10 @@ Object window_set_var(Window window, String name, Object value, Error *err) Object window_get_option(Window window, String name, Error *err) { - Object rv; win_T *win = find_window(window, err); if (!win) { - return rv; + return (Object) OBJECT_INIT; } return get_option_from(win, SREQ_WIN, name, err);