From 3fb66122339f1d844af3e1e76ef24fad5ea4a3f6 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sat, 31 Aug 2013 15:48:23 +0200 Subject: [PATCH] include: uv_alloc_cb now takes uv_buf_t* Passing or returning structs as values makes life hard for people that work with libuv through a foreign function interface. Switch to a pointer-based approach. Fixes #684. --- include/uv.h | 6 +++-- src/unix/stream.c | 2 +- src/unix/udp.c | 2 +- src/win/pipe.c | 2 +- src/win/tcp.c | 4 ++-- src/win/tty.c | 4 ++-- src/win/udp.c | 4 ++-- test/benchmark-multi-accept.c | 24 +++++++++++++------ test/benchmark-ping-pongs.c | 16 ++++++------- test/benchmark-pound.c | 12 +++++----- test/benchmark-pump.c | 23 +++++++++--------- test/benchmark-spawn.c | 10 ++++---- test/benchmark-udp-pummel.c | 9 ++++--- test/blackhole-server.c | 11 +++++---- test/dns-server.c | 10 ++++---- test/echo-server.c | 7 ++++-- test/test-callback-stack.c | 10 ++++---- test/test-delayed-accept.c | 8 +++---- test/test-getsockname.c | 8 +++---- test/test-ipc-send-recv.c | 9 ++++--- test/test-ipc.c | 17 +++++++------ test/test-osx-select.c | 8 +++---- test/test-ping-pong.c | 5 ++-- test/test-shutdown-eof.c | 8 +++---- test/test-spawn.c | 10 ++++---- test/test-stdio-over-pipes.c | 14 +++++++---- test/test-tcp-open.c | 9 ++++--- test/test-tcp-shutdown-after-write.c | 7 ++++-- test/test-tcp-unexpected-read.c | 6 ++--- test/test-tcp-write-to-half-open-connection.c | 9 ++++--- test/test-tcp-writealot.c | 5 ++-- test/test-udp-ipv6.c | 7 ++++-- test/test-udp-multicast-join.c | 11 +++++---- test/test-udp-open.c | 9 ++++--- test/test-udp-send-and-recv.c | 11 +++++---- 35 files changed, 179 insertions(+), 138 deletions(-) diff --git a/include/uv.h b/include/uv.h index 5700f941..cde05cb9 100644 --- a/include/uv.h +++ b/include/uv.h @@ -338,7 +338,7 @@ UV_EXTERN int uv_backend_timeout(const uv_loop_t*); /* - * Should return a buffer that libuv can use to read data into. + * Should prepare a buffer that libuv can use to read data into. * * `suggested_size` is a hint. Returning a buffer that is smaller is perfectly * okay as long as `buf.len > 0`. @@ -349,7 +349,9 @@ UV_EXTERN int uv_backend_timeout(const uv_loop_t*); * Note that returning a zero-length buffer does not stop the handle, call * uv_read_stop() or uv_udp_recv_stop() for that. */ -typedef uv_buf_t (*uv_alloc_cb)(uv_handle_t* handle, size_t suggested_size); +typedef void (*uv_alloc_cb)(uv_handle_t* handle, + size_t suggested_size, + uv_buf_t* buf); /* * `nread` is > 0 if there is data available, 0 if libuv is done reading for diff --git a/src/unix/stream.c b/src/unix/stream.c index 5f42c344..ab030a79 100644 --- a/src/unix/stream.c +++ b/src/unix/stream.c @@ -979,7 +979,7 @@ static void uv__read(uv_stream_t* stream) { && (count-- > 0)) { assert(stream->alloc_cb != NULL); - buf = stream->alloc_cb((uv_handle_t*)stream, 64 * 1024); + stream->alloc_cb((uv_handle_t*)stream, 64 * 1024, &buf); if (buf.len == 0) { /* User indicates it can't or won't handle the read. */ uv__stream_read_cb(stream, UV_ENOBUFS, buf, UV_UNKNOWN_HANDLE); diff --git a/src/unix/udp.c b/src/unix/udp.c index 1413985b..2356794b 100644 --- a/src/unix/udp.c +++ b/src/unix/udp.c @@ -205,7 +205,7 @@ static void uv__udp_recvmsg(uv_loop_t* loop, h.msg_name = &peer; do { - buf = handle->alloc_cb((uv_handle_t*) handle, 64 * 1024); + handle->alloc_cb((uv_handle_t*) handle, 64 * 1024, &buf); if (buf.len == 0) { handle->recv_cb(handle, UV_ENOBUFS, buf, NULL, 0); return; diff --git a/src/win/pipe.c b/src/win/pipe.c index 586adbfe..5e73cb9e 100644 --- a/src/win/pipe.c +++ b/src/win/pipe.c @@ -1429,7 +1429,7 @@ void uv_process_pipe_read_req(uv_loop_t* loop, uv_pipe_t* handle, } } - buf = handle->alloc_cb((uv_handle_t*) handle, avail); + handle->alloc_cb((uv_handle_t*) handle, avail, &buf); if (buf.len == 0) { if (handle->read2_cb) { handle->read2_cb(handle, UV_ENOBUFS, buf, UV_UNKNOWN_HANDLE); diff --git a/src/win/tcp.c b/src/win/tcp.c index 5ed7976c..7b653175 100644 --- a/src/win/tcp.c +++ b/src/win/tcp.c @@ -434,7 +434,7 @@ static void uv_tcp_queue_read(uv_loop_t* loop, uv_tcp_t* handle) { */ if (loop->active_tcp_streams < uv_active_tcp_streams_threshold) { handle->flags &= ~UV_HANDLE_ZERO_READ; - handle->read_buffer = handle->alloc_cb((uv_handle_t*) handle, 65536); + handle->alloc_cb((uv_handle_t*) handle, 65536, &handle->read_buffer); if (handle->read_buffer.len == 0) { handle->read_cb((uv_stream_t*) handle, UV_ENOBUFS, handle->read_buffer); return; @@ -947,7 +947,7 @@ void uv_process_tcp_read_req(uv_loop_t* loop, uv_tcp_t* handle, /* Do nonblocking reads until the buffer is empty */ while (handle->flags & UV_HANDLE_READING) { - buf = handle->alloc_cb((uv_handle_t*) handle, 65536); + handle->alloc_cb((uv_handle_t*) handle, 65536, &buf); if (buf.len == 0) { handle->read_cb(handle, UV_ENOBUFS, buf); break; diff --git a/src/win/tty.c b/src/win/tty.c index e6077a99..b3eea839 100644 --- a/src/win/tty.c +++ b/src/win/tty.c @@ -347,7 +347,7 @@ static void uv_tty_queue_read_line(uv_loop_t* loop, uv_tty_t* handle) { req = &handle->read_req; memset(&req->overlapped, 0, sizeof(req->overlapped)); - handle->read_line_buffer = handle->alloc_cb((uv_handle_t*) handle, 8192); + handle->alloc_cb((uv_handle_t*) handle, 8192, &handle->read_line_buffer); if (handle->read_line_buffer.len == 0) { handle->read_cb(handle, UV_ENOBUFS, handle->read_line_buffer); return; @@ -684,7 +684,7 @@ void uv_process_tty_read_raw_req(uv_loop_t* loop, uv_tty_t* handle, if (handle->last_key_offset < handle->last_key_len) { /* Allocate a buffer if needed */ if (buf_used == 0) { - buf = handle->alloc_cb((uv_handle_t*) handle, 1024); + handle->alloc_cb((uv_handle_t*) handle, 1024, &buf); if (buf.len == 0) { handle->read_cb((uv_stream_t*) handle, UV_ENOBUFS, buf); goto out; diff --git a/src/win/udp.c b/src/win/udp.c index ba21b545..51b31664 100644 --- a/src/win/udp.c +++ b/src/win/udp.c @@ -271,7 +271,7 @@ static void uv_udp_queue_recv(uv_loop_t* loop, uv_udp_t* handle) { if (loop->active_udp_streams < uv_active_udp_streams_threshold) { handle->flags &= ~UV_HANDLE_ZERO_READ; - handle->recv_buffer = handle->alloc_cb((uv_handle_t*) handle, 65536); + handle->alloc_cb((uv_handle_t*) handle, 65536, &handle->recv_buffer); if (handle->recv_buffer.len == 0) { handle->recv_cb(handle, UV_ENOBUFS, handle->recv_buffer, NULL, 0); return; @@ -518,7 +518,7 @@ void uv_process_udp_recv_req(uv_loop_t* loop, uv_udp_t* handle, /* Do a nonblocking receive */ /* TODO: try to read multiple datagrams at once. FIONREAD maybe? */ - buf = handle->alloc_cb((uv_handle_t*) handle, 65536); + handle->alloc_cb((uv_handle_t*) handle, 65536, &buf); if (buf.len == 0) { handle->recv_cb(handle, UV_ENOBUFS, buf, NULL, 0); goto done; diff --git a/test/benchmark-multi-accept.c b/test/benchmark-multi-accept.c index eb574648..72ca1fa3 100644 --- a/test/benchmark-multi-accept.c +++ b/test/benchmark-multi-accept.c @@ -87,12 +87,16 @@ static void ipc_read2_cb(uv_pipe_t* ipc_pipe, ssize_t nread, uv_buf_t buf, uv_handle_type type); -static uv_buf_t ipc_alloc_cb(uv_handle_t* handle, size_t suggested_size); +static void ipc_alloc_cb(uv_handle_t* handle, + size_t suggested_size, + uv_buf_t* buf); static void sv_async_cb(uv_async_t* handle, int status); static void sv_connection_cb(uv_stream_t* server_handle, int status); static void sv_read_cb(uv_stream_t* handle, ssize_t nread, uv_buf_t buf); -static uv_buf_t sv_alloc_cb(uv_handle_t* handle, size_t suggested_size); +static void sv_alloc_cb(uv_handle_t* handle, + size_t suggested_size, + uv_buf_t* buf); static void cl_connect_cb(uv_connect_t* req, int status); static void cl_idle_cb(uv_idle_t* handle, int status); @@ -157,10 +161,13 @@ static void ipc_connect_cb(uv_connect_t* req, int status) { } -static uv_buf_t ipc_alloc_cb(uv_handle_t* handle, size_t suggested_size) { +static void ipc_alloc_cb(uv_handle_t* handle, + size_t suggested_size, + uv_buf_t* buf) { struct ipc_client_ctx* ctx; ctx = container_of(handle, struct ipc_client_ctx, ipc_pipe); - return uv_buf_init(ctx->scratch, sizeof(ctx->scratch)); + buf->base = ctx->scratch; + buf->len = sizeof(ctx->scratch); } @@ -295,9 +302,12 @@ static void sv_connection_cb(uv_stream_t* server_handle, int status) { } -static uv_buf_t sv_alloc_cb(uv_handle_t* handle, size_t suggested_size) { - static char buf[32]; - return uv_buf_init(buf, sizeof(buf)); +static void sv_alloc_cb(uv_handle_t* handle, + size_t suggested_size, + uv_buf_t* buf) { + static char slab[32]; + buf->base = slab; + buf->len = sizeof(slab); } diff --git a/test/benchmark-ping-pongs.c b/test/benchmark-ping-pongs.c index 0012cfd5..daa14538 100644 --- a/test/benchmark-ping-pongs.c +++ b/test/benchmark-ping-pongs.c @@ -53,21 +53,19 @@ static int completed_pingers = 0; static int64_t start_time; -static uv_buf_t buf_alloc(uv_handle_t* tcp, size_t size) { +static void buf_alloc(uv_handle_t* tcp, size_t size, uv_buf_t* buf) { buf_t* ab; ab = buf_freelist; - - if (ab != NULL) { + if (ab != NULL) buf_freelist = ab->next; - return ab->uv_buf_t; + else { + ab = malloc(size + sizeof(*ab)); + ab->uv_buf_t.len = size; + ab->uv_buf_t.base = (char*) (ab + 1); } - ab = (buf_t*) malloc(size + sizeof *ab); - ab->uv_buf_t.len = size; - ab->uv_buf_t.base = ((char*) ab) + sizeof *ab; - - return ab->uv_buf_t; + *buf = ab->uv_buf_t; } diff --git a/test/benchmark-pound.c b/test/benchmark-pound.c index df19c980..555a5283 100644 --- a/test/benchmark-pound.c +++ b/test/benchmark-pound.c @@ -75,18 +75,18 @@ static uint64_t start; /* in ms */ static int closed_streams; static int conns_failed; -static uv_buf_t alloc_cb(uv_handle_t* handle, size_t suggested_size); +static void alloc_cb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf); static void connect_cb(uv_connect_t* conn_req, int status); static void read_cb(uv_stream_t* stream, ssize_t nread, uv_buf_t buf); static void close_cb(uv_handle_t* handle); -static uv_buf_t alloc_cb(uv_handle_t* handle, size_t suggested_size) { +static void alloc_cb(uv_handle_t* handle, + size_t suggested_size, + uv_buf_t* buf) { static char slab[65536]; - uv_buf_t buf; - buf.base = slab; - buf.len = sizeof(slab); - return buf; + buf->base = slab; + buf->len = sizeof(slab); } diff --git a/test/benchmark-pump.c b/test/benchmark-pump.c index 5b4db3c0..1d0a058a 100644 --- a/test/benchmark-pump.c +++ b/test/benchmark-pump.c @@ -41,7 +41,7 @@ static void maybe_connect_some(); static uv_req_t* req_alloc(); static void req_free(uv_req_t* uv_req); -static uv_buf_t buf_alloc(uv_handle_t*, size_t size); +static void buf_alloc(uv_handle_t* handle, size_t size, uv_buf_t* buf); static void buf_free(uv_buf_t uv_buf_t); static uv_loop_t* loop; @@ -331,20 +331,19 @@ typedef struct buf_list_s { static buf_list_t* buf_freelist = NULL; -static uv_buf_t buf_alloc(uv_handle_t* handle, size_t size) { - buf_list_t* buf; +static void buf_alloc(uv_handle_t* handle, size_t size, uv_buf_t* buf) { + buf_list_t* ab; - buf = buf_freelist; - if (buf != NULL) { - buf_freelist = buf->next; - return buf->uv_buf_t; + ab = buf_freelist; + if (ab != NULL) + buf_freelist = ab->next; + else { + ab = malloc(size + sizeof(*ab)); + ab->uv_buf_t.len = size; + ab->uv_buf_t.base = (char*) (ab + 1); } - buf = (buf_list_t*) malloc(size + sizeof *buf); - buf->uv_buf_t.len = (unsigned int)size; - buf->uv_buf_t.base = ((char*) buf) + sizeof *buf; - - return buf->uv_buf_t; + *buf = ab->uv_buf_t; } diff --git a/test/benchmark-spawn.c b/test/benchmark-spawn.c index 140bfa76..683e9b11 100644 --- a/test/benchmark-spawn.c +++ b/test/benchmark-spawn.c @@ -73,11 +73,11 @@ static void exit_cb(uv_process_t* process, } -static uv_buf_t on_alloc(uv_handle_t* handle, size_t suggested_size) { - uv_buf_t buf; - buf.base = output + output_used; - buf.len = OUTPUT_SIZE - output_used; - return buf; +static void on_alloc(uv_handle_t* handle, + size_t suggested_size, + uv_buf_t* buf) { + buf->base = output + output_used; + buf->len = OUTPUT_SIZE - output_used; } diff --git a/test/benchmark-udp-pummel.c b/test/benchmark-udp-pummel.c index 2590f579..f84ac8d6 100644 --- a/test/benchmark-udp-pummel.c +++ b/test/benchmark-udp-pummel.c @@ -59,10 +59,13 @@ static int timed; static int exiting; -static uv_buf_t alloc_cb(uv_handle_t* handle, size_t suggested_size) { +static void alloc_cb(uv_handle_t* handle, + size_t suggested_size, + uv_buf_t* buf) { static char slab[65536]; - ASSERT(suggested_size <= sizeof slab); - return uv_buf_init(slab, sizeof slab); + ASSERT(suggested_size <= sizeof(slab)); + buf->base = slab; + buf->len = sizeof(slab); } diff --git a/test/blackhole-server.c b/test/blackhole-server.c index ade49b48..2ff50b6c 100644 --- a/test/blackhole-server.c +++ b/test/blackhole-server.c @@ -33,7 +33,7 @@ typedef struct { static uv_tcp_t tcp_server; static void connection_cb(uv_stream_t* stream, int status); -static uv_buf_t alloc_cb(uv_handle_t* handle, size_t suggested_size); +static void alloc_cb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf); static void read_cb(uv_stream_t* stream, ssize_t nread, uv_buf_t buf); static void shutdown_cb(uv_shutdown_t* req, int status); static void close_cb(uv_handle_t* handle); @@ -60,9 +60,12 @@ static void connection_cb(uv_stream_t* stream, int status) { } -static uv_buf_t alloc_cb(uv_handle_t* handle, size_t suggested_size) { - static char buf[65536]; - return uv_buf_init(buf, sizeof buf); +static void alloc_cb(uv_handle_t* handle, + size_t suggested_size, + uv_buf_t* buf) { + static char slab[65536]; + buf->base = slab; + buf->len = sizeof(slab); } diff --git a/test/dns-server.c b/test/dns-server.c index 17e7ecf2..ebeb933d 100644 --- a/test/dns-server.c +++ b/test/dns-server.c @@ -255,11 +255,11 @@ static void on_close(uv_handle_t* peer) { } -static uv_buf_t buf_alloc(uv_handle_t* handle, size_t suggested_size) { - uv_buf_t buf; - buf.base = (char*) malloc(suggested_size); - buf.len = suggested_size; - return buf; +static void buf_alloc(uv_handle_t* handle, + size_t suggested_size, + uv_buf_t* buf) { + buf->base = malloc(suggested_size); + buf->len = suggested_size; } diff --git a/test/echo-server.c b/test/echo-server.c index a9891d25..71c11622 100644 --- a/test/echo-server.c +++ b/test/echo-server.c @@ -130,8 +130,11 @@ static void on_close(uv_handle_t* peer) { } -static uv_buf_t echo_alloc(uv_handle_t* handle, size_t suggested_size) { - return uv_buf_init(malloc(suggested_size), suggested_size); +static void echo_alloc(uv_handle_t* handle, + size_t suggested_size, + uv_buf_t* buf) { + buf->base = malloc(suggested_size); + buf->len = suggested_size; } diff --git a/test/test-callback-stack.c b/test/test-callback-stack.c index 1774fdf4..7e848e80 100644 --- a/test/test-callback-stack.c +++ b/test/test-callback-stack.c @@ -45,12 +45,10 @@ static int bytes_received = 0; static int shutdown_cb_called = 0; -static uv_buf_t alloc_cb(uv_handle_t* handle, size_t size) { - uv_buf_t buf; - buf.len = size; - buf.base = (char*) malloc(size); - ASSERT(buf.base); - return buf; +static void alloc_cb(uv_handle_t* handle, size_t size, uv_buf_t* buf) { + buf->len = size; + buf->base = malloc(size); + ASSERT(buf->base != NULL); } diff --git a/test/test-delayed-accept.c b/test/test-delayed-accept.c index cd0b0269..937b47c2 100644 --- a/test/test-delayed-accept.c +++ b/test/test-delayed-accept.c @@ -30,11 +30,9 @@ static int close_cb_called = 0; static int connect_cb_called = 0; -static uv_buf_t alloc_cb(uv_handle_t* handle, size_t size) { - uv_buf_t buf; - buf.base = (char*)malloc(size); - buf.len = size; - return buf; +static void alloc_cb(uv_handle_t* handle, size_t size, uv_buf_t* buf) { + buf->base = malloc(size); + buf->len = size; } diff --git a/test/test-getsockname.c b/test/test-getsockname.c index e3f09ec4..0c9b6a60 100644 --- a/test/test-getsockname.c +++ b/test/test-getsockname.c @@ -42,11 +42,9 @@ static uv_udp_t udpServer; static uv_udp_send_t send_req; -static uv_buf_t alloc(uv_handle_t* handle, size_t suggested_size) { - uv_buf_t buf; - buf.base = (char*) malloc(suggested_size); - buf.len = suggested_size; - return buf; +static void alloc(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) { + buf->base = malloc(suggested_size); + buf->len = suggested_size; } diff --git a/test/test-ipc-send-recv.c b/test/test-ipc-send-recv.c index 90ac69f3..36895573 100644 --- a/test/test-ipc-send-recv.c +++ b/test/test-ipc-send-recv.c @@ -50,10 +50,13 @@ static struct echo_ctx ctx; static int num_recv_handles; -static uv_buf_t alloc_cb(uv_handle_t* handle, size_t suggested_size) { +static void alloc_cb(uv_handle_t* handle, + size_t suggested_size, + uv_buf_t* buf) { /* we're not actually reading anything so a small buffer is okay */ - static char buf[8]; - return uv_buf_init(buf, sizeof(buf)); + static char slab[8]; + buf->base = slab; + buf->len = sizeof(slab); } diff --git a/test/test-ipc.c b/test/test-ipc.c index 0918a927..95e8e769 100644 --- a/test/test-ipc.c +++ b/test/test-ipc.c @@ -94,8 +94,11 @@ static void exit_cb(uv_process_t* process, } -static uv_buf_t on_alloc(uv_handle_t* handle, size_t suggested_size) { - return uv_buf_init(malloc(suggested_size), suggested_size); +static void on_alloc(uv_handle_t* handle, + size_t suggested_size, + uv_buf_t* buf) { + buf->base = malloc(suggested_size); + buf->len = suggested_size; } @@ -238,11 +241,11 @@ static void on_tcp_write(uv_write_t* req, int status) { } -static uv_buf_t on_read_alloc(uv_handle_t* handle, size_t suggested_size) { - uv_buf_t buf; - buf.base = (char*)malloc(suggested_size); - buf.len = suggested_size; - return buf; +static void on_read_alloc(uv_handle_t* handle, + size_t suggested_size, + uv_buf_t* buf) { + buf->base = malloc(suggested_size); + buf->len = suggested_size; } diff --git a/test/test-osx-select.c b/test/test-osx-select.c index bf4c3952..26a86751 100644 --- a/test/test-osx-select.c +++ b/test/test-osx-select.c @@ -30,10 +30,10 @@ static int read_count; -static uv_buf_t alloc_cb(uv_handle_t* handle, size_t size) { - static char buf[1024]; - - return uv_buf_init(buf, ARRAY_SIZE(buf)); +static void alloc_cb(uv_handle_t* handle, size_t size, uv_buf_t* buf) { + static char slab[1024]; + buf->base = slab; + buf->len = sizeof(slab); } diff --git a/test/test-ping-pong.c b/test/test-ping-pong.c index 719f2d19..ee605e5f 100644 --- a/test/test-ping-pong.c +++ b/test/test-ping-pong.c @@ -48,8 +48,9 @@ typedef struct { } pinger_t; -static uv_buf_t alloc_cb(uv_handle_t* handle, size_t size) { - return uv_buf_init(malloc(size), size); +static void alloc_cb(uv_handle_t* handle, size_t size, uv_buf_t* buf) { + buf->base = malloc(size); + buf->len = size; } diff --git a/test/test-shutdown-eof.c b/test/test-shutdown-eof.c index 9c848916..6b9da372 100644 --- a/test/test-shutdown-eof.c +++ b/test/test-shutdown-eof.c @@ -39,11 +39,9 @@ static int called_timer_close_cb; static int called_timer_cb; -static uv_buf_t alloc_cb(uv_handle_t* handle, size_t size) { - uv_buf_t buf; - buf.base = (char*)malloc(size); - buf.len = size; - return buf; +static void alloc_cb(uv_handle_t* handle, size_t size, uv_buf_t* buf) { + buf->base = malloc(size); + buf->len = size; } diff --git a/test/test-spawn.c b/test/test-spawn.c index 96cc307a..16a9ece6 100644 --- a/test/test-spawn.c +++ b/test/test-spawn.c @@ -118,11 +118,11 @@ static void detach_failure_cb(uv_process_t* process, int64_t exit_status, int te exit_cb_called++; } -static uv_buf_t on_alloc(uv_handle_t* handle, size_t suggested_size) { - uv_buf_t buf; - buf.base = output + output_used; - buf.len = OUTPUT_SIZE - output_used; - return buf; +static void on_alloc(uv_handle_t* handle, + size_t suggested_size, + uv_buf_t* buf) { + buf->base = output + output_used; + buf->len = OUTPUT_SIZE - output_used; } diff --git a/test/test-stdio-over-pipes.c b/test/test-stdio-over-pipes.c index 1d6191e7..38c816c0 100644 --- a/test/test-stdio-over-pipes.c +++ b/test/test-stdio-over-pipes.c @@ -74,8 +74,11 @@ static void init_process_options(char* test, uv_exit_cb exit_cb) { } -static uv_buf_t on_alloc(uv_handle_t* handle, size_t suggested_size) { - return uv_buf_init(output + output_used, OUTPUT_SIZE - output_used); +static void on_alloc(uv_handle_t* handle, + size_t suggested_size, + uv_buf_t* buf) { + buf->base = output + output_used; + buf->len = OUTPUT_SIZE - output_used; } @@ -179,8 +182,11 @@ static void after_pipe_write(uv_write_t* req, int status) { } -static uv_buf_t on_read_alloc(uv_handle_t* handle, size_t suggested_size) { - return uv_buf_init(malloc(suggested_size), suggested_size); +static void on_read_alloc(uv_handle_t* handle, + size_t suggested_size, + uv_buf_t* buf) { + buf->base = malloc(suggested_size); + buf->len = suggested_size; } diff --git a/test/test-tcp-open.c b/test/test-tcp-open.c index cd69035b..7e106134 100644 --- a/test/test-tcp-open.c +++ b/test/test-tcp-open.c @@ -71,10 +71,13 @@ static uv_os_sock_t create_tcp_socket(void) { } -static uv_buf_t alloc_cb(uv_handle_t* handle, size_t suggested_size) { +static void alloc_cb(uv_handle_t* handle, + size_t suggested_size, + uv_buf_t* buf) { static char slab[65536]; - ASSERT(suggested_size <= sizeof slab); - return uv_buf_init(slab, sizeof slab); + ASSERT(suggested_size <= sizeof(slab)); + buf->base = slab; + buf->len = sizeof(slab); } diff --git a/test/test-tcp-shutdown-after-write.c b/test/test-tcp-shutdown-after-write.c index a2e9e0f5..1c4f29bc 100644 --- a/test/test-tcp-shutdown-after-write.c +++ b/test/test-tcp-shutdown-after-write.c @@ -49,9 +49,12 @@ static void close_cb(uv_handle_t* handle) { } -static uv_buf_t alloc_cb(uv_handle_t* handle, size_t suggested_size) { +static void alloc_cb(uv_handle_t* handle, + size_t suggested_size, + uv_buf_t* buf) { static char slab[64]; - return uv_buf_init(slab, sizeof(slab)); + buf->base = slab; + buf->len = sizeof(slab); } diff --git a/test/test-tcp-unexpected-read.c b/test/test-tcp-unexpected-read.c index e8fc53c3..6197f786 100644 --- a/test/test-tcp-unexpected-read.c +++ b/test/test-tcp-unexpected-read.c @@ -47,10 +47,10 @@ static void timer_cb(uv_timer_t* handle, int status) { } -static uv_buf_t alloc_cb(uv_handle_t* handle, size_t suggested_size) { +static void alloc_cb(uv_handle_t* handle, + size_t suggested_size, + uv_buf_t* buf) { ASSERT(0 && "alloc_cb should not have been called"); - /* Satisfy the compiler. */ - return uv_buf_init(NULL, 0); } diff --git a/test/test-tcp-write-to-half-open-connection.c b/test/test-tcp-write-to-half-open-connection.c index e3557bc8..5546d86e 100644 --- a/test/test-tcp-write-to-half-open-connection.c +++ b/test/test-tcp-write-to-half-open-connection.c @@ -30,7 +30,7 @@ static void connection_cb(uv_stream_t* server, int status); static void connect_cb(uv_connect_t* req, int status); static void write_cb(uv_write_t* req, int status); static void read_cb(uv_stream_t* stream, ssize_t nread, uv_buf_t buf); -static uv_buf_t alloc_cb(uv_handle_t* handle, size_t suggested_size); +static void alloc_cb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf); static uv_tcp_t tcp_server; static uv_tcp_t tcp_client; @@ -65,9 +65,12 @@ static void connection_cb(uv_stream_t* server, int status) { } -static uv_buf_t alloc_cb(uv_handle_t* handle, size_t suggested_size) { +static void alloc_cb(uv_handle_t* handle, + size_t suggested_size, + uv_buf_t* buf) { static char slab[1024]; - return uv_buf_init(slab, sizeof slab); + buf->base = slab; + buf->len = sizeof(slab); } diff --git a/test/test-tcp-writealot.c b/test/test-tcp-writealot.c index e83aeb9b..8005de91 100644 --- a/test/test-tcp-writealot.c +++ b/test/test-tcp-writealot.c @@ -46,8 +46,9 @@ static uv_shutdown_t shutdown_req; static uv_write_t write_reqs[WRITES]; -static uv_buf_t alloc_cb(uv_handle_t* handle, size_t size) { - return uv_buf_init(malloc(size), size); +static void alloc_cb(uv_handle_t* handle, size_t size, uv_buf_t* buf) { + buf->base = malloc(size); + buf->len = size; } diff --git a/test/test-udp-ipv6.c b/test/test-udp-ipv6.c index 247fe8bf..114f752c 100644 --- a/test/test-udp-ipv6.c +++ b/test/test-udp-ipv6.c @@ -44,10 +44,13 @@ static int recv_cb_called; static int close_cb_called; -static uv_buf_t alloc_cb(uv_handle_t* handle, size_t suggested_size) { +static void alloc_cb(uv_handle_t* handle, + size_t suggested_size, + uv_buf_t* buf) { static char slab[65536]; CHECK_HANDLE(handle); - return uv_buf_init(slab, sizeof slab); + buf->base = slab; + buf->len = sizeof(slab); } diff --git a/test/test-udp-multicast-join.c b/test/test-udp-multicast-join.c index 83ec46b8..2d8426c2 100644 --- a/test/test-udp-multicast-join.c +++ b/test/test-udp-multicast-join.c @@ -38,13 +38,14 @@ static int sv_send_cb_called; static int close_cb_called; -static uv_buf_t alloc_cb(uv_handle_t* handle, size_t suggested_size) { +static void alloc_cb(uv_handle_t* handle, + size_t suggested_size, + uv_buf_t* buf) { static char slab[65536]; - CHECK_HANDLE(handle); - ASSERT(suggested_size <= sizeof slab); - - return uv_buf_init(slab, sizeof slab); + ASSERT(suggested_size <= sizeof(slab)); + buf->base = slab; + buf->len = sizeof(slab); } diff --git a/test/test-udp-open.c b/test/test-udp-open.c index 5d27bdc0..a8be58b0 100644 --- a/test/test-udp-open.c +++ b/test/test-udp-open.c @@ -67,10 +67,13 @@ static uv_os_sock_t create_udp_socket(void) { } -static uv_buf_t alloc_cb(uv_handle_t* handle, size_t suggested_size) { +static void alloc_cb(uv_handle_t* handle, + size_t suggested_size, + uv_buf_t* buf) { static char slab[65536]; - ASSERT(suggested_size <= sizeof slab); - return uv_buf_init(slab, sizeof slab); + ASSERT(suggested_size <= sizeof(slab)); + buf->base = slab; + buf->len = sizeof(slab); } diff --git a/test/test-udp-send-and-recv.c b/test/test-udp-send-and-recv.c index 1ffa6aa8..88640fc5 100644 --- a/test/test-udp-send-and-recv.c +++ b/test/test-udp-send-and-recv.c @@ -41,13 +41,14 @@ static int sv_recv_cb_called; static int close_cb_called; -static uv_buf_t alloc_cb(uv_handle_t* handle, size_t suggested_size) { +static void alloc_cb(uv_handle_t* handle, + size_t suggested_size, + uv_buf_t* buf) { static char slab[65536]; - CHECK_HANDLE(handle); - ASSERT(suggested_size <= sizeof slab); - - return uv_buf_init(slab, sizeof slab); + ASSERT(suggested_size <= sizeof(slab)); + buf->base = slab; + buf->len = sizeof(slab); }