aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Zhao <zhaozg@gmail.com>2018-01-17 19:40:31 +0800
committerGeorge Zhao <zhaozg@gmail.com>2018-01-18 21:30:04 +0800
commit12acf0f7a76160e33bb84876121d3a63dde3c252 (patch)
tree17534b03eddec52f6117dd0d707495c78566c2ad
parentbac86a194117008656d02951de6d303ab8687eec (diff)
downloadrneovim-12acf0f7a76160e33bb84876121d3a63dde3c252.tar.gz
rneovim-12acf0f7a76160e33bb84876121d3a63dde3c252.tar.bz2
rneovim-12acf0f7a76160e33bb84876121d3a63dde3c252.zip
Fix warning when assing size_t type value to uv_buf_t.len, convert type to ULONG on Windows.
-rw-r--r--src/nvim/event/rstream.c4
-rw-r--r--src/nvim/event/wstream.c2
-rw-r--r--src/nvim/macros.h7
-rw-r--r--src/nvim/tui/tui.c6
-rw-r--r--test/functional/fixtures/tty-test.c9
5 files changed, 21 insertions, 7 deletions
diff --git a/src/nvim/event/rstream.c b/src/nvim/event/rstream.c
index e0500ba828..2fbe7f6773 100644
--- a/src/nvim/event/rstream.c
+++ b/src/nvim/event/rstream.c
@@ -95,7 +95,7 @@ static void alloc_cb(uv_handle_t *handle, size_t suggested, uv_buf_t *buf)
// `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;
+ buf->len = UV_BUF_LEN(write_count);
}
// Callback invoked by libuv after it copies the data into the buffer provided
@@ -146,7 +146,7 @@ static void fread_idle_cb(uv_idle_t *handle)
// `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;
+ stream->uvbuf.len = UV_BUF_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/event/wstream.c b/src/nvim/event/wstream.c
index 320006890d..d2fb52243c 100644
--- a/src/nvim/event/wstream.c
+++ b/src/nvim/event/wstream.c
@@ -90,7 +90,7 @@ bool wstream_write(Stream *stream, WBuffer *buffer)
uv_buf_t uvbuf;
uvbuf.base = buffer->data;
- uvbuf.len = buffer->size;
+ uvbuf.len = UV_BUF_LEN(buffer->size);
if (uv_write(&data->uv_req, stream->uvstream, &uvbuf, 1, write_cb)) {
xfree(data);
diff --git a/src/nvim/macros.h b/src/nvim/macros.h
index 0bec9af733..351fa55929 100644
--- a/src/nvim/macros.h
+++ b/src/nvim/macros.h
@@ -188,4 +188,11 @@
/// @return ((Type *)obj).
#define STRUCT_CAST(Type, obj) ((Type *)(obj))
+// Type of uv_buf_t.len on Windows is ULONG, but others is size_t.
+#if defined(WIN32)
+# define UV_BUF_LEN(x) (ULONG)(x)
+#else
+# define UV_BUF_LEN(x) (x)
+#endif
+
#endif // NVIM_MACROS_H
diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c
index 2349bd2ae9..f3383eb006 100644
--- a/src/nvim/tui/tui.c
+++ b/src/nvim/tui/tui.c
@@ -1744,14 +1744,14 @@ static void flush_buf(UI *ui)
// cursor is visible. Write a "cursor invisible" command before writing the
// buffer.
bufp->base = data->invis;
- bufp->len = data->invislen;
+ bufp->len = UV_BUF_LEN(data->invislen);
bufp++;
data->is_invisible = true;
}
if (data->bufpos > 0) {
bufp->base = data->buf;
- bufp->len = data->bufpos;
+ bufp->len = UV_BUF_LEN(data->bufpos);
bufp++;
}
@@ -1759,7 +1759,7 @@ static void flush_buf(UI *ui)
// not busy and the cursor is invisible. Write a "cursor normal" command
// after writing the buffer.
bufp->base = data->norm;
- bufp->len = data->normlen;
+ bufp->len = UV_BUF_LEN(data->normlen);
bufp++;
data->is_invisible = data->busy;
}
diff --git a/test/functional/fixtures/tty-test.c b/test/functional/fixtures/tty-test.c
index edcbe23f86..9c42ca28d0 100644
--- a/test/functional/fixtures/tty-test.c
+++ b/test/functional/fixtures/tty-test.c
@@ -94,7 +94,14 @@ static void read_cb(uv_stream_t *stream, ssize_t cnt, const uv_buf_t *buf)
uv_tty_init(&write_loop, &out, fileno(stdout), 0);
uv_write_t req;
- uv_buf_t b = {.base = buf->base, .len = (size_t)cnt};
+ uv_buf_t b = {
+ .base = buf->base,
+#ifdef WIN32
+ .len = (ULONG)cnt
+#else
+ .len = (size_t)cnt
+#endif
+ };
uv_write(&req, STRUCT_CAST(uv_stream_t, &out), &b, 1, NULL);
uv_run(&write_loop, UV_RUN_DEFAULT);