aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2017-12-24 02:11:46 +0300
committerZyX <kp-pav@yandex.ru>2017-12-24 14:09:36 +0300
commit608c3d7baf2745b188bc42f9f45ad1bb188a4828 (patch)
treedb4cd569824b9971a9831264571a0f9d16bf75d5
parent6bf3dc77c484f757d37c22694e1278abc014278f (diff)
downloadrneovim-608c3d7baf2745b188bc42f9f45ad1bb188a4828.tar.gz
rneovim-608c3d7baf2745b188bc42f9f45ad1bb188a4828.tar.bz2
rneovim-608c3d7baf2745b188bc42f9f45ad1bb188a4828.zip
eval/typval: Remove tv_list_item_free() as it is unused
-rw-r--r--src/nvim/eval/typval.c15
-rw-r--r--test/unit/eval/helpers.lua8
-rw-r--r--test/unit/eval/typval_spec.lua115
3 files changed, 46 insertions, 92 deletions
diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c
index 751f1e7aec..a49c34e957 100644
--- a/src/nvim/eval/typval.c
+++ b/src/nvim/eval/typval.c
@@ -58,18 +58,6 @@ static listitem_T *tv_list_item_alloc(void)
return xmalloc(sizeof(listitem_T));
}
-/// Free a list item
-///
-/// Also clears the value. Does not touch watchers.
-///
-/// @param[out] item Item to free.
-void tv_list_item_free(listitem_T *const item)
- FUNC_ATTR_NONNULL_ALL
-{
- tv_clear(TV_LIST_ITEM_TV(item));
- xfree(item);
-}
-
/// Remove a list item from a List and free it
///
/// Also clears the value.
@@ -80,7 +68,8 @@ void tv_list_item_remove(list_T *const l, listitem_T *const item)
FUNC_ATTR_NONNULL_ALL
{
tv_list_remove_items(l, item, item);
- tv_list_item_free(item);
+ tv_clear(TV_LIST_ITEM_TV(item));
+ xfree(item);
}
//{{{2 List watchers
diff --git a/test/unit/eval/helpers.lua b/test/unit/eval/helpers.lua
index 1a3210e1fd..6babd4be77 100644
--- a/test/unit/eval/helpers.lua
+++ b/test/unit/eval/helpers.lua
@@ -28,8 +28,13 @@ local function tv_list_item_alloc()
return ffi.cast('listitem_T*', eval.xmalloc(ffi.sizeof('listitem_T')))
end
+local function tv_list_item_free(li)
+ eval.tv_clear(li.li_tv)
+ eval.xfree(li)
+end
+
local function li_alloc(nogc)
- local gcfunc = eval.tv_list_item_free
+ local gcfunc = tv_list_item_free
if nogc then gcfunc = nil end
local li = ffi.gc(tv_list_item_alloc(), gcfunc)
li.li_next = nil
@@ -537,6 +542,7 @@ return {
typvalt=typvalt,
li_alloc=li_alloc,
+ tv_list_item_free=tv_list_item_free,
dict_iter=dict_iter,
list_iter=list_iter,
diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua
index 2ae69ec04b..0536839b71 100644
--- a/test/unit/eval/typval_spec.lua
+++ b/test/unit/eval/typval_spec.lua
@@ -41,6 +41,7 @@ local tbl2callback = eval_helpers.tbl2callback
local dict_watchers = eval_helpers.dict_watchers
local concat_tables = global_helpers.concat_tables
+local map = global_helpers.map
local lib = cimport('./src/nvim/eval/typval.h', './src/nvim/memory.h',
'./src/nvim/mbyte.h', './src/nvim/garray.h',
@@ -121,118 +122,76 @@ end
describe('typval.c', function()
describe('list', function()
describe('item', function()
- describe('alloc()/free()', function()
+ describe('remove()', function()
itp('works', function()
- local li = li_alloc(true)
- neq(nil, li)
- lib.tv_list_item_free(li)
- alloc_log:check({
- a.li(li),
- a.freed(li),
- })
- end)
- itp('also frees the value', function()
- local li
- local s
- local l
- local tv
- li = li_alloc(true)
- li.li_tv.v_type = lib.VAR_NUMBER
- li.li_tv.vval.v_number = 10
- lib.tv_list_item_free(li)
- alloc_log:check({
- a.li(li),
- a.freed(li),
- })
-
- li = li_alloc(true)
- li.li_tv.v_type = lib.VAR_FLOAT
- li.li_tv.vval.v_float = 10.5
- lib.tv_list_item_free(li)
- alloc_log:check({
- a.li(li),
- a.freed(li),
- })
-
- li = li_alloc(true)
- li.li_tv.v_type = lib.VAR_STRING
- li.li_tv.vval.v_string = nil
- lib.tv_list_item_free(li)
+ local l = list(1, 2, 3, 4, 5, 6, 7)
+ neq(nil, l)
+ local lis = list_items(l)
alloc_log:check({
- a.li(li),
- a.freed(alloc_log.null),
- a.freed(li),
+ a.list(l),
+ a.li(lis[1]),
+ a.li(lis[2]),
+ a.li(lis[3]),
+ a.li(lis[4]),
+ a.li(lis[5]),
+ a.li(lis[6]),
+ a.li(lis[7]),
})
- li = li_alloc(true)
- li.li_tv.v_type = lib.VAR_STRING
- s = to_cstr_nofree('test')
- li.li_tv.vval.v_string = s
- lib.tv_list_item_free(li)
+ lib.tv_list_item_remove(l, lis[1])
alloc_log:check({
- a.li(li),
- a.str(s, #('test')),
- a.freed(s),
- a.freed(li),
+ a.freed(table.remove(lis, 1)),
})
+ eq(lis, list_items(l))
- li = li_alloc(true)
- li.li_tv.v_type = lib.VAR_LIST
- l = ffi.gc(list(), nil)
- l.lv_refcount = 2
- li.li_tv.vval.v_list = l
- lib.tv_list_item_free(li)
+ lib.tv_list_item_remove(l, lis[6])
alloc_log:check({
- a.li(li),
- a.list(l),
- a.freed(li),
+ a.freed(table.remove(lis)),
})
- eq(1, l.lv_refcount)
+ eq(lis, list_items(l))
- li = li_alloc(true)
- tv = lua2typvalt({})
- tv.vval.v_dict.dv_refcount = 2
- li.li_tv = tv
- lib.tv_list_item_free(li)
+ lib.tv_list_item_remove(l, lis[3])
alloc_log:check({
- a.li(li),
- a.dict(tv.vval.v_dict),
- a.freed(li),
+ a.freed(table.remove(lis, 3)),
})
- eq(1, tv.vval.v_dict.dv_refcount)
+ eq(lis, list_items(l))
end)
- end)
- describe('remove()', function()
- itp('works', function()
- local l = list(1, 2, 3, 4, 5, 6, 7)
+ itp('also frees the value', function()
+ local l = list('a', 'b', 'c', 'd')
neq(nil, l)
local lis = list_items(l)
alloc_log:check({
a.list(l),
+ a.str(lis[1].li_tv.vval.v_string, 1),
a.li(lis[1]),
+ a.str(lis[2].li_tv.vval.v_string, 1),
a.li(lis[2]),
+ a.str(lis[3].li_tv.vval.v_string, 1),
a.li(lis[3]),
+ a.str(lis[4].li_tv.vval.v_string, 1),
a.li(lis[4]),
- a.li(lis[5]),
- a.li(lis[6]),
- a.li(lis[7]),
})
+ local strings = map(function(li) return li.li_tv.vval.v_string end,
+ lis)
lib.tv_list_item_remove(l, lis[1])
alloc_log:check({
+ a.freed(table.remove(strings, 1)),
a.freed(table.remove(lis, 1)),
})
eq(lis, list_items(l))
- lib.tv_list_item_remove(l, lis[6])
+ lib.tv_list_item_remove(l, lis[2])
alloc_log:check({
- a.freed(table.remove(lis)),
+ a.freed(table.remove(strings, 2)),
+ a.freed(table.remove(lis, 2)),
})
eq(lis, list_items(l))
- lib.tv_list_item_remove(l, lis[3])
+ lib.tv_list_item_remove(l, lis[2])
alloc_log:check({
- a.freed(table.remove(lis, 3)),
+ a.freed(table.remove(strings, 2)),
+ a.freed(table.remove(lis, 2)),
})
eq(lis, list_items(l))
end)