Initialize Object, Position

fix #778
thanks @genisaguilar
This commit is contained in:
Justin M. Keyes 2014-05-31 09:08:58 -04:00
parent 4e1ca460e3
commit 005a4254c0
5 changed files with 15 additions and 21 deletions

View File

@ -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) {

View File

@ -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) \

View File

@ -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

View File

@ -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);

View File

@ -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);