mirror of
https://github.com/neovim/neovim.git
synced 2025-09-20 18:28:19 +00:00
Refactor: Use size_t for {w,r}streams.c
This commit is contained in:
@@ -33,7 +33,7 @@ static void close_cb(uv_handle_t *handle);
|
|||||||
static void emit_read_event(RStream *rstream, bool eof);
|
static void emit_read_event(RStream *rstream, bool eof);
|
||||||
|
|
||||||
RStream * rstream_new(rstream_cb cb,
|
RStream * rstream_new(rstream_cb cb,
|
||||||
uint32_t buffer_size,
|
size_t buffer_size,
|
||||||
void *data,
|
void *data,
|
||||||
bool async)
|
bool async)
|
||||||
{
|
{
|
||||||
@@ -133,7 +133,7 @@ void rstream_stop(RStream *rstream)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t rstream_read(RStream *rstream, char *buf, uint32_t count)
|
size_t rstream_read(RStream *rstream, char *buf, size_t count)
|
||||||
{
|
{
|
||||||
size_t read_count = rstream->wpos - rstream->rpos;
|
size_t read_count = rstream->wpos - rstream->rpos;
|
||||||
|
|
||||||
|
@@ -21,7 +21,7 @@
|
|||||||
/// this to false
|
/// this to false
|
||||||
/// @return The newly-allocated `RStream` instance
|
/// @return The newly-allocated `RStream` instance
|
||||||
RStream * rstream_new(rstream_cb cb,
|
RStream * rstream_new(rstream_cb cb,
|
||||||
uint32_t buffer_size,
|
size_t buffer_size,
|
||||||
void *data,
|
void *data,
|
||||||
bool async);
|
bool async);
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ void rstream_stop(RStream *rstream);
|
|||||||
/// @param buffer The buffer which will receive the data
|
/// @param buffer The buffer which will receive the data
|
||||||
/// @param count Number of bytes that `buffer` can accept
|
/// @param count Number of bytes that `buffer` can accept
|
||||||
/// @return The number of bytes copied into `buffer`
|
/// @return The number of bytes copied into `buffer`
|
||||||
size_t rstream_read(RStream *rstream, char *buffer, uint32_t count);
|
size_t rstream_read(RStream *rstream, char *buffer, size_t count);
|
||||||
|
|
||||||
/// Returns the number of bytes available for reading from `rstream`
|
/// Returns the number of bytes available for reading from `rstream`
|
||||||
///
|
///
|
||||||
|
@@ -12,11 +12,11 @@
|
|||||||
struct wstream {
|
struct wstream {
|
||||||
uv_stream_t *stream;
|
uv_stream_t *stream;
|
||||||
// Memory currently used by pending buffers
|
// Memory currently used by pending buffers
|
||||||
uint32_t curmem;
|
size_t curmem;
|
||||||
// Maximum memory used by this instance
|
// Maximum memory used by this instance
|
||||||
uint32_t maxmem;
|
size_t maxmem;
|
||||||
// Number of pending requests
|
// Number of pending requests
|
||||||
uint32_t pending_reqs;
|
size_t pending_reqs;
|
||||||
bool freed;
|
bool freed;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -25,14 +25,14 @@ typedef struct {
|
|||||||
// Buffer containing data to be written
|
// Buffer containing data to be written
|
||||||
char *buffer;
|
char *buffer;
|
||||||
// Size of the buffer
|
// Size of the buffer
|
||||||
uint32_t length;
|
size_t length;
|
||||||
// If it's our responsibility to free the buffer
|
// If it's our responsibility to free the buffer
|
||||||
bool free;
|
bool free;
|
||||||
} WriteData;
|
} WriteData;
|
||||||
|
|
||||||
static void write_cb(uv_write_t *req, int status);
|
static void write_cb(uv_write_t *req, int status);
|
||||||
|
|
||||||
WStream * wstream_new(uint32_t maxmem)
|
WStream * wstream_new(size_t maxmem)
|
||||||
{
|
{
|
||||||
WStream *rv = xmalloc(sizeof(WStream));
|
WStream *rv = xmalloc(sizeof(WStream));
|
||||||
rv->maxmem = maxmem;
|
rv->maxmem = maxmem;
|
||||||
@@ -59,7 +59,7 @@ void wstream_set_stream(WStream *wstream, uv_stream_t *stream)
|
|||||||
wstream->stream = stream;
|
wstream->stream = stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wstream_write(WStream *wstream, char *buffer, uint32_t length, bool free)
|
bool wstream_write(WStream *wstream, char *buffer, size_t length, bool free)
|
||||||
{
|
{
|
||||||
WriteData *data;
|
WriteData *data;
|
||||||
uv_buf_t uvbuf;
|
uv_buf_t uvbuf;
|
||||||
|
@@ -12,7 +12,7 @@
|
|||||||
///
|
///
|
||||||
/// @param maxmem Maximum amount memory used by this `WStream` instance.
|
/// @param maxmem Maximum amount memory used by this `WStream` instance.
|
||||||
/// @return The newly-allocated `WStream` instance
|
/// @return The newly-allocated `WStream` instance
|
||||||
WStream * wstream_new(uint32_t maxmem);
|
WStream * wstream_new(size_t maxmem);
|
||||||
|
|
||||||
/// Frees all memory allocated for a WStream instance
|
/// Frees all memory allocated for a WStream instance
|
||||||
///
|
///
|
||||||
@@ -34,7 +34,7 @@ void wstream_set_stream(WStream *wstream, uv_stream_t *stream);
|
|||||||
/// @param length Number of bytes that should be written from `buffer`
|
/// @param length Number of bytes that should be written from `buffer`
|
||||||
/// @param free If true, `buffer` will be freed after the write is complete
|
/// @param free If true, `buffer` will be freed after the write is complete
|
||||||
/// @return true if the data was successfully queued, false otherwise.
|
/// @return true if the data was successfully queued, false otherwise.
|
||||||
bool wstream_write(WStream *wstream, char *buffer, uint32_t length, bool free);
|
bool wstream_write(WStream *wstream, char *buffer, size_t length, bool free);
|
||||||
|
|
||||||
#endif // NVIM_OS_WSTREAM_H
|
#endif // NVIM_OS_WSTREAM_H
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user