if (d == NULL)
return FAIL;
- rettv->vval.v_dict = d;
- rettv->v_type = VAR_DICT;
+ rettv_dict_set(rettv, d);
rettv->v_lock = 0;
- ++d->dv_refcount;
return OK;
}
+/*
+ * Set a dictionary as the return value
+ */
+ void
+rettv_dict_set(typval_T *rettv, dict_T *d)
+{
+ rettv->v_type = VAR_DICT;
+ rettv->vval.v_dict = d;
+ if (d != NULL)
+ ++d->dv_refcount;
+}
+
/*
* Free a Dictionary, including all non-container items it contains.
* Ignores the reference count.
*arg = skipwhite(*arg + 1);
if (evaluate)
- {
- rettv->v_type = VAR_DICT;
- rettv->vval.v_dict = d;
- ++d->dv_refcount;
- }
+ rettv_dict_set(rettv, d);
return OK;
}
&& get_tv_number_chk(&argvars[2], &error)
&& !error)
{
- rettv->v_type = VAR_LIST;
- rettv->vval.v_list = NULL;
+ rettv_list_set(rettv, NULL);
}
s = get_tv_string(&argvars[0]);
}
}
else if (STRCMP(what, "dict") == 0)
- {
- rettv->v_type = VAR_DICT;
- rettv->vval.v_dict = pt->pt_dict;
- if (pt->pt_dict != NULL)
- ++pt->pt_dict->dv_refcount;
- }
+ rettv_dict_set(rettv, pt->pt_dict);
else if (STRCMP(what, "args") == 0)
{
rettv->v_type = VAR_LIST;
if (opts != NULL)
{
- rettv->v_type = VAR_DICT;
- rettv->vval.v_dict = opts;
- ++opts->dv_refcount;
+ rettv_dict_set(rettv, opts);
done = TRUE;
}
}
{
if (get_tv_number_chk(&argvars[2], &error))
{
- rettv->v_type = VAR_LIST;
- rettv->vval.v_list = NULL;
+ rettv_list_set(rettv, NULL);
}
if (argvars[3].v_type != VAR_UNKNOWN
&& get_tv_number_chk(&argvars[3], &error))
{
if (get_tv_number_chk(&argvars[3], &error))
{
- rettv->v_type = VAR_LIST;
- rettv->vval.v_list = NULL;
+ rettv_list_set(rettv, NULL);
}
if (argvars[4].v_type != VAR_UNKNOWN
&& get_tv_number_chk(&argvars[4], &error))
list_append(l, li);
li = ni;
}
- rettv->vval.v_list = l;
- rettv->v_type = VAR_LIST;
- ++l->lv_refcount;
+ rettv_list_set(rettv, l);
l->lv_idx = l->lv_len - l->lv_idx - 1;
}
}
(char_u *)(sort ? N_("sort() argument") : N_("uniq() argument")),
TRUE))
goto theend;
- rettv->vval.v_list = l;
- rettv->v_type = VAR_LIST;
- ++l->lv_refcount;
+ rettv_list_set(rettv, l);
len = list_len(l);
if (len <= 1)
char_u str[NUMBUFLEN];
#endif
- rettv->v_type = VAR_LIST;
- rettv->vval.v_list = NULL;
+ rettv_list_set(rettv, NULL);
#if defined(FEAT_SYN_HL) && defined(FEAT_CONCEAL)
lnum = get_tv_lnum(argvars); /* -1 on type error */
int id;
#endif
- rettv->v_type = VAR_LIST;
- rettv->vval.v_list = NULL;
+ rettv_list_set(rettv, NULL);
#ifdef FEAT_SYN_HL
lnum = get_tv_lnum(argvars); /* -1 on type error */
list_append(list, li);
}
- ++list->lv_refcount;
- rettv->v_type = VAR_LIST;
- rettv->vval.v_list = list;
+ rettv_list_set(rettv, list);
list = NULL;
}
else
static void
f_test_null_dict(typval_T *argvars UNUSED, typval_T *rettv)
{
- rettv->v_type = VAR_DICT;
- rettv->vval.v_dict = NULL;
+ rettv_dict_set(rettv, NULL);
}
#ifdef FEAT_JOB_CHANNEL
static void
f_test_null_list(typval_T *argvars UNUSED, typval_T *rettv)
{
- rettv->v_type = VAR_LIST;
- rettv->vval.v_list = NULL;
+ rettv_list_set(rettv, NULL);
}
static void
if (l == NULL)
return FAIL;
- rettv->vval.v_list = l;
- rettv->v_type = VAR_LIST;
rettv->v_lock = 0;
- ++l->lv_refcount;
+ rettv_list_set(rettv, l);
return OK;
}
+/*
+ * Set a list as the return value
+ */
+ void
+rettv_list_set(typval_T *rettv, list_T *l)
+{
+ rettv->v_type = VAR_LIST;
+ rettv->vval.v_list = l;
+ if (l != NULL)
+ ++l->lv_refcount;
+}
+
/*
* Unreference a list: decrement the reference count and free it when it
* becomes zero.
*arg = skipwhite(*arg + 1);
if (evaluate)
- {
- rettv->v_type = VAR_LIST;
- rettv->vval.v_list = l;
- ++l->lv_refcount;
- }
+ rettv_list_set(rettv, l);
return OK;
}