*: Fix some Windows-specific warnings

Also fixed an error in path_fnamecmp().
This commit is contained in:
ZyX 2016-11-05 01:03:44 +03:00
parent 9ed9af7e11
commit 4bcee96347
10 changed files with 122 additions and 65 deletions

View File

@ -395,10 +395,10 @@ void nvim_buf_set_lines(uint64_t channel_id,
mark_adjust((linenr_T)start, (linenr_T)(end - 1), MAXLNUM, extra); 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) { 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: end:

View File

@ -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) static void alloc_cb(uv_handle_t *handle, size_t suggested, uv_buf_t *buf)
{ {
Stream *stream = handle->data; 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 // 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; uv_fs_t req;
Stream *stream = handle->data; 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 // the offset argument to uv_fs_read is int64_t, could someone really try
// to read more than 9 quintillion (9e18) bytes? // to read more than 9 quintillion (9e18) bytes?

View File

@ -579,7 +579,7 @@ static int command_line_execute(VimState *state, int key)
} }
if (vim_ispathsep(ccline.cmdbuff[s->j]) if (vim_ispathsep(ccline.cmdbuff[s->j])
#ifdef BACKSLASH_IN_FILENAME #ifdef BACKSLASH_IN_FILENAME
&& vim_strchr(" *?[{`$%#", ccline.cmdbuff[s->j + 1]) && strchr(" *?[{`$%#", ccline.cmdbuff[s->j + 1])
== NULL == NULL
#endif #endif
) { ) {

View File

@ -322,8 +322,11 @@ vim_findfile_init (
drive[0] = path[0]; drive[0] = path[0];
drive[1] = ':'; drive[1] = ':';
drive[2] = NUL; 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; goto error_return;
}
path += 2; path += 2;
} else } else
#endif #endif

View File

@ -5207,7 +5207,7 @@ void forward_slash(char_u *fname)
{ {
char_u *p; char_u *p;
if (path_with_url(fname)) { if (path_with_url((const char *)fname)) {
return; return;
} }
for (p = fname; *p != NUL; p++) { for (p = fname; *p != NUL; p++) {

View File

@ -174,7 +174,7 @@ static char_u *skip_string(char_u *p)
char_u *paren = vim_strchr(delim, '('); char_u *paren = vim_strchr(delim, '(');
if (paren != NULL) { if (paren != NULL) {
ptrdiff_t delim_len = paren - delim; const ptrdiff_t delim_len = paren - delim;
for (p += 3; *p; ++p) for (p += 3; *p; ++p)
if (p[0] == ')' && STRNCMP(p + 1, delim, delim_len) == 0 if (p[0] == ')' && STRNCMP(p + 1, delim, delim_len) == 0

View File

@ -18,6 +18,7 @@
#include "nvim/eval.h" #include "nvim/eval.h"
#include "nvim/ex_getln.h" #include "nvim/ex_getln.h"
#include "nvim/version.h" #include "nvim/version.h"
#include "nvim/fileio.h"
#ifdef WIN32 #ifdef WIN32
#include "nvim/mbyte.h" // for utf8_to_utf16, utf16_to_utf8 #include "nvim/mbyte.h" // for utf8_to_utf16, utf16_to_utf8

View File

@ -12,8 +12,9 @@ typedef struct pty_process {
#define pty_process_spawn(job) libuv_process_spawn((LibuvProcess *)job) #define pty_process_spawn(job) libuv_process_spawn((LibuvProcess *)job)
#define pty_process_close(job) libuv_process_close((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_close_master(job) libuv_process_close((LibuvProcess *)job)
#define pty_process_resize(job, width, height) #define pty_process_resize(job, width, height) ( \
#define pty_process_teardown(loop) (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) static inline PtyProcess pty_process_init(Loop *loop, void *data)
{ {

View File

@ -312,7 +312,7 @@ int path_fnamecmp(const char *fname1, const char *fname2)
/// ///
/// @return 0 if they are equal, non-zero otherwise. /// @return 0 if they are equal, non-zero otherwise.
int path_fnamencmp(const char *const fname1, const char *const fname2, 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 FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
{ {
#ifdef BACKSLASH_IN_FILENAME #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 *p1 = fname1;
const char *p2 = fname2; const char *p2 = fname2;
while (len > 0) { while (len > 0) {
c1 = PTR2CHAR(p1); c1 = PTR2CHAR((const char_u *)p1);
c2 = PTR2CHAR(p2); c2 = PTR2CHAR((const char_u *)p2);
if (c1 == NUL || c2 == NUL if ((c1 == NUL || c2 == NUL
|| (!((c1 == '/' || c1 == '\\') && (c2 == '\\' || c2 == '/'))) || (!((c1 == '/' || c1 == '\\') && (c2 == '\\' || c2 == '/'))))
|| (p_fic ? (c1 != c2 && CH_FOLD(c1) != CH_FOLD(c2)) : c1 != c2)) { && (p_fic ? (c1 != c2 && CH_FOLD(c1) != CH_FOLD(c2)) : c1 != c2)) {
break; break;
} }
len -= MB_PTR2LEN(p1); len -= MB_PTR2LEN((const char_u *)p1);
p1 += MB_PTR2LEN(p1); p1 += MB_PTR2LEN((const char_u *)p1);
p2 += MB_PTR2LEN(p2); p2 += MB_PTR2LEN((const char_u *)p2);
} }
return c1 - c2; return c1 - c2;
#else #else
@ -819,7 +819,7 @@ static void expand_path_option(char_u *curdir, garray_T *gap)
} }
STRMOVE(buf + len + 1, buf); STRMOVE(buf + len + 1, buf);
STRCPY(buf, curdir); STRCPY(buf, curdir);
buf[len] = PATHSEP; buf[len] = (char_u)PATHSEP;
simplify_filename(buf); simplify_filename(buf);
} }
@ -1333,12 +1333,12 @@ static int expand_backtick(
/// When the path looks like a URL leave it unmodified. /// When the path looks like a URL leave it unmodified.
void slash_adjust(char_u *p) void slash_adjust(char_u *p)
{ {
if (path_with_url(p)) { if (path_with_url((const char *)p)) {
return; return;
} }
while (*p) { while (*p) {
if (*p == psepcN) { if (*p == (char_u)psepcN) {
*p = psepc; *p = (char_u)psepc;
} }
mb_ptr_adv(p); mb_ptr_adv(p);
} }

View File

@ -294,8 +294,8 @@ describe('typval.c', function()
end) end)
end) end)
-- add() and fix() were tested when testing tv_list_item_remove() -- add() and fix() were tested when testing tv_list_item_remove()
describe('alloc()/free()', function() describe('free()', function()
itp('recursively frees list with', function() itp('recursively frees list', function()
local l1 = ffi.gc(list(1, 'abc'), nil) local l1 = ffi.gc(list(1, 'abc'), nil)
local l2 = ffi.gc(list({}), nil) local l2 = ffi.gc(list({}), nil)
local l3 = ffi.gc(list(empty_list), nil) local l3 = ffi.gc(list(empty_list), nil)
@ -332,27 +332,73 @@ describe('typval.c', function()
alloc_rets:freed(8), alloc_rets:freed(8),
}) })
end) end)
itp('does not free container items with recurse=false', function() end)
local l1 = ffi.gc(list('abc', {}, empty_list), nil) 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 = {} local alloc_rets = {}
alloc_log:check(get_alloc_rets({ alloc_log:check(get_alloc_rets({
a.list(l1), a.list(l1),
a.str(l1.lv_first.li_tv.vval.v_string, #('abc')),
a.li(l1.lv_first), a.li(l1.lv_first),
a.dict(l1.lv_first.li_next.li_tv.vval.v_dict), a.str(l1.lv_last.li_tv.vval.v_string, #('abc')),
a.li(l1.lv_first.li_next),
a.list(l1.lv_last.li_tv.vval.v_list),
a.li(l1.lv_last), 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)) }, 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_log:check({
alloc_rets:freed(2), alloc_rets:freed(2),
alloc_rets:freed(3), alloc_rets:freed(3),
alloc_rets:freed(4), alloc_rets:freed(4),
alloc_rets:freed(5), })
lib.tv_list_free_contents(l2)
alloc_log:check({
alloc_rets:freed(6), alloc_rets:freed(6),
alloc_rets:freed(7), 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)
end) end)
@ -1063,8 +1109,8 @@ describe('typval.c', function()
local recursive_l = l.lv_first.li_tv.vval.v_list local recursive_l = l.lv_first.li_tv.vval.v_list
local recursive_li = recursive_l.lv_first local recursive_li = recursive_l.lv_first
lib.tv_list_item_remove(recursive_l, recursive_li) lib.tv_list_item_remove(recursive_l, recursive_li)
lib.tv_list_free(l, true) lib.tv_list_free(l)
end) end, true)
end) end)
describe('equal()', function() describe('equal()', function()
itp('compares empty and NULL lists correctly', function() itp('compares empty and NULL lists correctly', function()
@ -1140,7 +1186,7 @@ describe('typval.c', function()
itp('correctly indexes list', function() itp('correctly indexes list', function()
local l = list(1, 2, 3, 4, 5) local l = list(1, 2, 3, 4, 5)
local lis = list_items(l) 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, -1))
eq(nil, lib.tv_list_find(nil, 0)) 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, 2))
eq(lis[3], lib.tv_list_find(l, -3)) eq(lis[3], lib.tv_list_find(l, -3))
check_alloc_log({}) alloc_log:check({})
end) end)
end) end)
local function check_emsg(f, msg) local function check_emsg(f, msg)
@ -1207,54 +1253,54 @@ describe('typval.c', function()
return (err[0] == true), ret return (err[0] == true), ret
end, msg) end, msg)
end end
it('returns correct number', function() itp('returns correct number', function()
local l = list(int(1), int(2), int(3), int(4), int(5)) 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, 1}, {tv_list_find_nr(l, -5)})
eq({false, 5}, {tv_list_find_nr(l, 4)}) 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, 2)})
eq({false, 3}, {tv_list_find_nr(l, -3)}) eq({false, 3}, {tv_list_find_nr(l, -3)})
check_alloc_log({}) alloc_log:check({})
end) 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') 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, 1}, {tv_list_find_nr(l, -5)})
eq({false, 5}, {tv_list_find_nr(l, 4)}) 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, 2)})
eq({false, 3}, {tv_list_find_nr(l, -3)}) eq({false, 3}, {tv_list_find_nr(l, -3)})
check_alloc_log({}) alloc_log:check({})
end) end)
it('returns zero when given a NULL string', function() itp('returns zero when given a NULL string', function()
local l = list(null_string) local l = list(null_string)
clear_alloc_log() alloc_log:clear()
eq({false, 0}, {tv_list_find_nr(l, 0)}) eq({false, 0}, {tv_list_find_nr(l, 0)})
check_alloc_log({}) alloc_log:check({})
end) 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, -5)})
eq({true, -1}, {tv_list_find_nr(nil, 4)}) 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, 2)})
eq({true, -1}, {tv_list_find_nr(nil, -3)}) eq({true, -1}, {tv_list_find_nr(nil, -3)})
check_alloc_log({}) alloc_log:check({})
end) 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)) 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, -6)})
eq({true, -1}, {tv_list_find_nr(l, 5)}) eq({true, -1}, {tv_list_find_nr(l, 5)})
check_alloc_log({}) alloc_log:check({})
end) end)
it('errors out on invalid types', function() itp('errors out on invalid types', function()
local l = list(1, empty_list, {}) local l = list(1, empty_list, {})
eq({true, 0}, {tv_list_find_nr(l, 0, 'E805: Using a Float as a Number')}) 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, msg)
end end
describe('str()', function() 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)) 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('1', tv_list_find_str(l, -5))
eq('5', tv_list_find_str(l, 4)) eq('5', tv_list_find_str(l, 4))
eq('3', tv_list_find_str(l, 2)) eq('3', tv_list_find_str(l, 2))
eq('3', tv_list_find_str(l, -3)) eq('3', tv_list_find_str(l, -3))
check_alloc_log({}) alloc_log:check({})
end) 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') local l = list('1', '2', '3', '4', '5')
clear_alloc_log() alloc_log:clear()
eq('1', tv_list_find_str(l, -5)) eq('1', tv_list_find_str(l, -5))
eq('5', tv_list_find_str(l, 4)) eq('5', tv_list_find_str(l, 4))
eq('3', tv_list_find_str(l, 2)) eq('3', tv_list_find_str(l, 2))
eq('3', tv_list_find_str(l, -3)) eq('3', tv_list_find_str(l, -3))
check_alloc_log({}) alloc_log:check({})
end) end)
it('returns empty when used with NULL string', function() itp('returns empty when used with NULL string', function()
local l = list(null_string) local l = list(null_string)
clear_alloc_log() alloc_log:clear()
eq('', tv_list_find_str(l, 0)) eq('', tv_list_find_str(l, 0))
check_alloc_log({}) alloc_log:check({})
end) 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)) 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, -6, 'E684: list index out of range: -6'))
eq(nil, tv_list_find_str(l, 5, 'E684: list index out of range: 5')) eq(nil, tv_list_find_str(l, 5, 'E684: list index out of range: 5'))
end) 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, {}) local l = list(1, empty_list, {})
eq('', tv_list_find_str(l, 0, 'E806: using Float as a String')) eq('', tv_list_find_str(l, 0, 'E806: using Float as a String'))
@ -1325,7 +1371,7 @@ describe('typval.c', function()
end) end)
end) end)
describe('idx_of_item()', function() describe('idx_of_item()', function()
it('works', function() itp('works', function()
local l = list(1, 2, 3, 4, 5) local l = list(1, 2, 3, 4, 5)
local l2 = list(42, empty_list) local l2 = list(42, empty_list)
local lis = list_items(l) local lis = list_items(l)