Fix warning when assing size_t type value to uv_buf_t.len, convert type to ULONG on Windows.

This commit is contained in:
George Zhao
2018-01-17 19:40:31 +08:00
parent bac86a1941
commit 12acf0f7a7
5 changed files with 21 additions and 7 deletions

View File

@@ -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?

View File

@@ -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);

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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);