aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2016-11-05 01:03:44 +0300
committerZyX <kp-pav@yandex.ru>2017-03-29 10:08:42 +0300
commit4bcee963471abd939bb9edd1709418e30be7290f (patch)
treeed4d8ef5d4526b538a2f6113c3f0fce28c94c2fe
parent9ed9af7e11e3a707f65abfeb1d02b029e39241ea (diff)
downloadrneovim-4bcee963471abd939bb9edd1709418e30be7290f.tar.gz
rneovim-4bcee963471abd939bb9edd1709418e30be7290f.tar.bz2
rneovim-4bcee963471abd939bb9edd1709418e30be7290f.zip
*: Fix some Windows-specific warnings
Also fixed an error in path_fnamecmp().
-rw-r--r--src/nvim/api/buffer.c4
-rw-r--r--src/nvim/event/rstream.c10
-rw-r--r--src/nvim/ex_getln.c2
-rw-r--r--src/nvim/file_search.c5
-rw-r--r--src/nvim/fileio.c2
-rw-r--r--src/nvim/indent_c.c2
-rw-r--r--src/nvim/os/env.c1
-rw-r--r--src/nvim/os/pty_process_win.h5
-rw-r--r--src/nvim/path.c26
-rw-r--r--test/unit/eval/typval_spec.lua130
10 files changed, 122 insertions, 65 deletions
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index b75a2c7211..037a6ee1da 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -395,10 +395,10 @@ void nvim_buf_set_lines(uint64_t channel_id,
mark_adjust((linenr_T)start, (linenr_T)(end - 1), MAXLNUM, extra);
}
- changed_lines((linenr_T)start, 0, (linenr_T)end, extra);
+ changed_lines((linenr_T)start, 0, (linenr_T)end, (long)extra);
if (save_curbuf.br_buf == NULL) {
- fix_cursor((linenr_T)start, (linenr_T)end, extra);
+ fix_cursor((linenr_T)start, (linenr_T)end, (linenr_T)extra);
}
end:
diff --git a/src/nvim/event/rstream.c b/src/nvim/event/rstream.c
index 92efc9fa2e..2737dad305 100644
--- a/src/nvim/event/rstream.c
+++ b/src/nvim/event/rstream.c
@@ -89,7 +89,10 @@ static void on_rbuffer_nonfull(RBuffer *buf, void *data)
static void alloc_cb(uv_handle_t *handle, size_t suggested, uv_buf_t *buf)
{
Stream *stream = handle->data;
- buf->base = rbuffer_write_ptr(stream->buffer, &buf->len);
+ // `uv_buf_t.len` happens to have different size on Windows.
+ size_t write_count;
+ buf->base = rbuffer_write_ptr(stream->buffer, &write_count);
+ buf->len = write_count;
}
// Callback invoked by libuv after it copies the data into the buffer provided
@@ -136,7 +139,10 @@ static void fread_idle_cb(uv_idle_t *handle)
uv_fs_t req;
Stream *stream = handle->data;
- stream->uvbuf.base = rbuffer_write_ptr(stream->buffer, &stream->uvbuf.len);
+ // `uv_buf_t.len` happens to have different size on Windows.
+ size_t write_count;
+ stream->uvbuf.base = rbuffer_write_ptr(stream->buffer, &write_count);
+ stream->uvbuf.len = write_count;
// the offset argument to uv_fs_read is int64_t, could someone really try
// to read more than 9 quintillion (9e18) bytes?
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index a0981a42ce..e140dfa886 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -579,7 +579,7 @@ static int command_line_execute(VimState *state, int key)
}
if (vim_ispathsep(ccline.cmdbuff[s->j])
#ifdef BACKSLASH_IN_FILENAME
- && vim_strchr(" *?[{`$%#", ccline.cmdbuff[s->j + 1])
+ && strchr(" *?[{`$%#", ccline.cmdbuff[s->j + 1])
== NULL
#endif
) {
diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c
index f7932bc296..9592235905 100644
--- a/src/nvim/file_search.c
+++ b/src/nvim/file_search.c
@@ -322,8 +322,11 @@ vim_findfile_init (
drive[0] = path[0];
drive[1] = ':';
drive[2] = NUL;
- if (vim_FullName(drive, ff_expand_buffer, MAXPATHL, TRUE) == FAIL)
+ if (vim_FullName((const char *)drive, (char *)ff_expand_buffer, MAXPATHL,
+ true)
+ == FAIL) {
goto error_return;
+ }
path += 2;
} else
#endif
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index 127efda65c..bd632b2755 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -5207,7 +5207,7 @@ void forward_slash(char_u *fname)
{
char_u *p;
- if (path_with_url(fname)) {
+ if (path_with_url((const char *)fname)) {
return;
}
for (p = fname; *p != NUL; p++) {
diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c
index 7b758b4dac..4a73fbaf61 100644
--- a/src/nvim/indent_c.c
+++ b/src/nvim/indent_c.c
@@ -174,7 +174,7 @@ static char_u *skip_string(char_u *p)
char_u *paren = vim_strchr(delim, '(');
if (paren != NULL) {
- ptrdiff_t delim_len = paren - delim;
+ const ptrdiff_t delim_len = paren - delim;
for (p += 3; *p; ++p)
if (p[0] == ')' && STRNCMP(p + 1, delim, delim_len) == 0
diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c
index a73d753e46..ae69462055 100644
--- a/src/nvim/os/env.c
+++ b/src/nvim/os/env.c
@@ -18,6 +18,7 @@
#include "nvim/eval.h"
#include "nvim/ex_getln.h"
#include "nvim/version.h"
+#include "nvim/fileio.h"
#ifdef WIN32
#include "nvim/mbyte.h" // for utf8_to_utf16, utf16_to_utf8
diff --git a/src/nvim/os/pty_process_win.h b/src/nvim/os/pty_process_win.h
index 20cc589925..8e2b37a1c1 100644
--- a/src/nvim/os/pty_process_win.h
+++ b/src/nvim/os/pty_process_win.h
@@ -12,8 +12,9 @@ typedef struct pty_process {
#define pty_process_spawn(job) libuv_process_spawn((LibuvProcess *)job)
#define pty_process_close(job) libuv_process_close((LibuvProcess *)job)
#define pty_process_close_master(job) libuv_process_close((LibuvProcess *)job)
-#define pty_process_resize(job, width, height)
-#define pty_process_teardown(loop)
+#define pty_process_resize(job, width, height) ( \
+ (void)job, (void)width, (void)height, 0)
+#define pty_process_teardown(loop) ((void)loop, 0)
static inline PtyProcess pty_process_init(Loop *loop, void *data)
{
diff --git a/src/nvim/path.c b/src/nvim/path.c
index e92261f4fd..d0248690d9 100644
--- a/src/nvim/path.c
+++ b/src/nvim/path.c
@@ -312,7 +312,7 @@ int path_fnamecmp(const char *fname1, const char *fname2)
///
/// @return 0 if they are equal, non-zero otherwise.
int path_fnamencmp(const char *const fname1, const char *const fname2,
- const size_t len)
+ size_t len)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
{
#ifdef BACKSLASH_IN_FILENAME
@@ -322,16 +322,16 @@ int path_fnamencmp(const char *const fname1, const char *const fname2,
const char *p1 = fname1;
const char *p2 = fname2;
while (len > 0) {
- c1 = PTR2CHAR(p1);
- c2 = PTR2CHAR(p2);
- if (c1 == NUL || c2 == NUL
- || (!((c1 == '/' || c1 == '\\') && (c2 == '\\' || c2 == '/')))
- || (p_fic ? (c1 != c2 && CH_FOLD(c1) != CH_FOLD(c2)) : c1 != c2)) {
+ c1 = PTR2CHAR((const char_u *)p1);
+ c2 = PTR2CHAR((const char_u *)p2);
+ if ((c1 == NUL || c2 == NUL
+ || (!((c1 == '/' || c1 == '\\') && (c2 == '\\' || c2 == '/'))))
+ && (p_fic ? (c1 != c2 && CH_FOLD(c1) != CH_FOLD(c2)) : c1 != c2)) {
break;
}
- len -= MB_PTR2LEN(p1);
- p1 += MB_PTR2LEN(p1);
- p2 += MB_PTR2LEN(p2);
+ len -= MB_PTR2LEN((const char_u *)p1);
+ p1 += MB_PTR2LEN((const char_u *)p1);
+ p2 += MB_PTR2LEN((const char_u *)p2);
}
return c1 - c2;
#else
@@ -819,7 +819,7 @@ static void expand_path_option(char_u *curdir, garray_T *gap)
}
STRMOVE(buf + len + 1, buf);
STRCPY(buf, curdir);
- buf[len] = PATHSEP;
+ buf[len] = (char_u)PATHSEP;
simplify_filename(buf);
}
@@ -1333,12 +1333,12 @@ static int expand_backtick(
/// When the path looks like a URL leave it unmodified.
void slash_adjust(char_u *p)
{
- if (path_with_url(p)) {
+ if (path_with_url((const char *)p)) {
return;
}
while (*p) {
- if (*p == psepcN) {
- *p = psepc;
+ if (*p == (char_u)psepcN) {
+ *p = (char_u)psepc;
}
mb_ptr_adv(p);
}
diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua
index d308ee5794..a785350c15 100644
--- a/test/unit/eval/typval_spec.lua
+++ b/test/unit/eval/typval_spec.lua
@@ -294,8 +294,8 @@ describe('typval.c', function()
end)
end)
-- add() and fix() were tested when testing tv_list_item_remove()
- describe('alloc()/free()', function()
- itp('recursively frees list with', function()
+ describe('free()', function()
+ itp('recursively frees list', function()
local l1 = ffi.gc(list(1, 'abc'), nil)
local l2 = ffi.gc(list({}), nil)
local l3 = ffi.gc(list(empty_list), nil)
@@ -332,27 +332,73 @@ describe('typval.c', function()
alloc_rets:freed(8),
})
end)
- itp('does not free container items with recurse=false', function()
- local l1 = ffi.gc(list('abc', {}, empty_list), nil)
+ end)
+ describe('free_list()', function()
+ itp('does not free list contents', function()
+ local l1 = ffi.gc(list(1, 'abc'), nil)
+ local l2 = ffi.gc(list({}), nil)
+ local l3 = ffi.gc(list(empty_list), nil)
local alloc_rets = {}
alloc_log:check(get_alloc_rets({
a.list(l1),
- a.str(l1.lv_first.li_tv.vval.v_string, #('abc')),
a.li(l1.lv_first),
- a.dict(l1.lv_first.li_next.li_tv.vval.v_dict),
- a.li(l1.lv_first.li_next),
- a.list(l1.lv_last.li_tv.vval.v_list),
+ a.str(l1.lv_last.li_tv.vval.v_string, #('abc')),
a.li(l1.lv_last),
+ a.list(l2),
+ a.dict(l2.lv_first.li_tv.vval.v_dict),
+ a.li(l2.lv_first),
+ a.list(l3),
+ a.list(l3.lv_first.li_tv.vval.v_list),
+ a.li(l3.lv_first),
}, alloc_rets))
- lib.tv_list_free(l1)
+ lib.tv_list_free_list(l1)
+ alloc_log:check({
+ alloc_rets:freed(1),
+ })
+ lib.tv_list_free_list(l2)
+ alloc_log:check({
+ alloc_rets:freed(5),
+ })
+ lib.tv_list_free_list(l3)
+ alloc_log:check({
+ alloc_rets:freed(8),
+ })
+ end)
+ end)
+ describe('free_contents()', function()
+ itp('recursively frees list, except for the list structure itself',
+ function()
+ local l1 = ffi.gc(list(1, 'abc'), nil)
+ local l2 = ffi.gc(list({}), nil)
+ local l3 = ffi.gc(list(empty_list), nil)
+ local alloc_rets = {}
+ alloc_log:check(get_alloc_rets({
+ a.list(l1),
+ a.li(l1.lv_first),
+ a.str(l1.lv_last.li_tv.vval.v_string, #('abc')),
+ a.li(l1.lv_last),
+ a.list(l2),
+ a.dict(l2.lv_first.li_tv.vval.v_dict),
+ a.li(l2.lv_first),
+ a.list(l3),
+ a.list(l3.lv_first.li_tv.vval.v_list),
+ a.li(l3.lv_first),
+ }, alloc_rets))
+ lib.tv_list_free_contents(l1)
alloc_log:check({
alloc_rets:freed(2),
alloc_rets:freed(3),
alloc_rets:freed(4),
- alloc_rets:freed(5),
+ })
+ lib.tv_list_free_contents(l2)
+ alloc_log:check({
alloc_rets:freed(6),
alloc_rets:freed(7),
- alloc_rets:freed(1),
+ })
+ lib.tv_list_free_contents(l3)
+ alloc_log:check({
+ alloc_rets:freed(9),
+ alloc_rets:freed(10),
})
end)
end)
@@ -1063,8 +1109,8 @@ describe('typval.c', function()
local recursive_l = l.lv_first.li_tv.vval.v_list
local recursive_li = recursive_l.lv_first
lib.tv_list_item_remove(recursive_l, recursive_li)
- lib.tv_list_free(l, true)
- end)
+ lib.tv_list_free(l)
+ end, true)
end)
describe('equal()', function()
itp('compares empty and NULL lists correctly', function()
@@ -1140,7 +1186,7 @@ describe('typval.c', function()
itp('correctly indexes list', function()
local l = list(1, 2, 3, 4, 5)
local lis = list_items(l)
- clear_alloc_log()
+ alloc_log:clear()
eq(nil, lib.tv_list_find(nil, -1))
eq(nil, lib.tv_list_find(nil, 0))
@@ -1185,7 +1231,7 @@ describe('typval.c', function()
eq(lis[3], lib.tv_list_find(l, 2))
eq(lis[3], lib.tv_list_find(l, -3))
- check_alloc_log({})
+ alloc_log:check({})
end)
end)
local function check_emsg(f, msg)
@@ -1207,54 +1253,54 @@ describe('typval.c', function()
return (err[0] == true), ret
end, msg)
end
- it('returns correct number', function()
+ itp('returns correct number', function()
local l = list(int(1), int(2), int(3), int(4), int(5))
- clear_alloc_log()
+ alloc_log:clear()
eq({false, 1}, {tv_list_find_nr(l, -5)})
eq({false, 5}, {tv_list_find_nr(l, 4)})
eq({false, 3}, {tv_list_find_nr(l, 2)})
eq({false, 3}, {tv_list_find_nr(l, -3)})
- check_alloc_log({})
+ alloc_log:check({})
end)
- it('returns correct number when given a string', function()
+ itp('returns correct number when given a string', function()
local l = list('1', '2', '3', '4', '5')
- clear_alloc_log()
+ alloc_log:clear()
eq({false, 1}, {tv_list_find_nr(l, -5)})
eq({false, 5}, {tv_list_find_nr(l, 4)})
eq({false, 3}, {tv_list_find_nr(l, 2)})
eq({false, 3}, {tv_list_find_nr(l, -3)})
- check_alloc_log({})
+ alloc_log:check({})
end)
- it('returns zero when given a NULL string', function()
+ itp('returns zero when given a NULL string', function()
local l = list(null_string)
- clear_alloc_log()
+ alloc_log:clear()
eq({false, 0}, {tv_list_find_nr(l, 0)})
- check_alloc_log({})
+ alloc_log:check({})
end)
- it('errors out on NULL lists', function()
+ itp('errors out on NULL lists', function()
eq({true, -1}, {tv_list_find_nr(nil, -5)})
eq({true, -1}, {tv_list_find_nr(nil, 4)})
eq({true, -1}, {tv_list_find_nr(nil, 2)})
eq({true, -1}, {tv_list_find_nr(nil, -3)})
- check_alloc_log({})
+ alloc_log:check({})
end)
- it('errors out on out-of-range indexes', function()
+ itp('errors out on out-of-range indexes', function()
local l = list(int(1), int(2), int(3), int(4), int(5))
- clear_alloc_log()
+ alloc_log:clear()
eq({true, -1}, {tv_list_find_nr(l, -6)})
eq({true, -1}, {tv_list_find_nr(l, 5)})
- check_alloc_log({})
+ alloc_log:check({})
end)
- it('errors out on invalid types', function()
+ itp('errors out on invalid types', function()
local l = list(1, empty_list, {})
eq({true, 0}, {tv_list_find_nr(l, 0, 'E805: Using a Float as a Number')})
@@ -1276,43 +1322,43 @@ describe('typval.c', function()
end, msg)
end
describe('str()', function()
- it('returns correct string', function()
+ itp('returns correct string', function()
local l = list(int(1), int(2), int(3), int(4), int(5))
- clear_alloc_log()
+ alloc_log:clear()
eq('1', tv_list_find_str(l, -5))
eq('5', tv_list_find_str(l, 4))
eq('3', tv_list_find_str(l, 2))
eq('3', tv_list_find_str(l, -3))
- check_alloc_log({})
+ alloc_log:check({})
end)
- it('returns string when used with VAR_STRING items', function()
+ itp('returns string when used with VAR_STRING items', function()
local l = list('1', '2', '3', '4', '5')
- clear_alloc_log()
+ alloc_log:clear()
eq('1', tv_list_find_str(l, -5))
eq('5', tv_list_find_str(l, 4))
eq('3', tv_list_find_str(l, 2))
eq('3', tv_list_find_str(l, -3))
- check_alloc_log({})
+ alloc_log:check({})
end)
- it('returns empty when used with NULL string', function()
+ itp('returns empty when used with NULL string', function()
local l = list(null_string)
- clear_alloc_log()
+ alloc_log:clear()
eq('', tv_list_find_str(l, 0))
- check_alloc_log({})
+ alloc_log:check({})
end)
- it('fails with error message when index is out of range', function()
+ itp('fails with error message when index is out of range', function()
local l = list(int(1), int(2), int(3), int(4), int(5))
eq(nil, tv_list_find_str(l, -6, 'E684: list index out of range: -6'))
eq(nil, tv_list_find_str(l, 5, 'E684: list index out of range: 5'))
end)
- it('fails with error message on invalid types', function()
+ itp('fails with error message on invalid types', function()
local l = list(1, empty_list, {})
eq('', tv_list_find_str(l, 0, 'E806: using Float as a String'))
@@ -1325,7 +1371,7 @@ describe('typval.c', function()
end)
end)
describe('idx_of_item()', function()
- it('works', function()
+ itp('works', function()
local l = list(1, 2, 3, 4, 5)
local l2 = list(42, empty_list)
local lis = list_items(l)