diff options
-rw-r--r-- | src/os/job.c | 18 | ||||
-rw-r--r-- | src/os/rstream.c | 16 | ||||
-rw-r--r-- | src/os/rstream_defs.h | 2 | ||||
-rw-r--r-- | src/os/wstream.c | 4 |
4 files changed, 28 insertions, 12 deletions
diff --git a/src/os/job.c b/src/os/job.c index bb8e79124f..f0c64a27a8 100644 --- a/src/os/job.c +++ b/src/os/job.c @@ -3,6 +3,7 @@ #include <uv.h> +#include "os/uv_helpers.h" #include "os/job.h" #include "os/job_defs.h" #include "os/rstream.h" @@ -160,10 +161,13 @@ int job_start(char **argv, job->proc_opts.exit_cb = exit_cb; job->proc_opts.cwd = NULL; job->proc_opts.env = NULL; + job->proc.data = NULL; + job->proc_stdin.data = NULL; + job->proc_stdout.data = NULL; + job->proc_stderr.data = NULL; // Initialize the job std{in,out,err} uv_pipe_init(uv_default_loop(), &job->proc_stdin, 0); - job->proc_stdin.data = job; job->stdio[0].flags = UV_CREATE_PIPE | UV_READABLE_PIPE; job->stdio[0].data.stream = (uv_stream_t *)&job->proc_stdin; @@ -181,6 +185,12 @@ int job_start(char **argv, return -1; } + // Give all handles a reference to the job + handle_set_job((uv_handle_t *)&job->proc, job); + handle_set_job((uv_handle_t *)&job->proc_stdin, job); + handle_set_job((uv_handle_t *)&job->proc_stdout, job); + handle_set_job((uv_handle_t *)&job->proc_stderr, job); + job->in = wstream_new(JOB_WRITE_MAXMEM); wstream_set_stream(job->in, (uv_stream_t *)&job->proc_stdin); // Start the readable streams @@ -190,8 +200,6 @@ int job_start(char **argv, rstream_set_stream(job->err, (uv_stream_t *)&job->proc_stderr); rstream_start(job->out); rstream_start(job->err); - // Give the callback a reference to the job - job->proc.data = job; // Save the job to the table table[i] = job; @@ -328,7 +336,7 @@ static void read_cb(RStream *rstream, void *data, bool eof) // Emits a JobExit event if both rstreams are closed static void exit_cb(uv_process_t *proc, int64_t status, int term_signal) { - Job *job = proc->data; + Job *job = handle_get_job((uv_handle_t *)proc); if (--job->pending_refs == 0) { emit_exit_event(job); @@ -345,7 +353,7 @@ static void emit_exit_event(Job *job) static void close_cb(uv_handle_t *handle) { - Job *job = handle->data; + Job *job = handle_get_job(handle); if (--job->pending_closes == 0) { // Only free the job memory after all the associated handles are properly diff --git a/src/os/rstream.c b/src/os/rstream.c index c15dda4eb2..90ead839c5 100644 --- a/src/os/rstream.c +++ b/src/os/rstream.c @@ -4,6 +4,7 @@ #include <uv.h> +#include "os/uv_helpers.h" #include "os/rstream_defs.h" #include "os/rstream.h" #include "os/event_defs.h" @@ -66,7 +67,7 @@ void rstream_free(RStream *rstream) void rstream_set_stream(RStream *rstream, uv_stream_t *stream) { - stream->data = rstream; + handle_set_rstream((uv_handle_t *)stream, rstream); rstream->stream = stream; } @@ -90,7 +91,8 @@ void rstream_set_file(RStream *rstream, uv_file file) // be processed between reads. rstream->fread_idle = xmalloc(sizeof(uv_idle_t)); uv_idle_init(uv_default_loop(), rstream->fread_idle); - rstream->fread_idle->data = rstream; + rstream->fread_idle->data = NULL; + handle_set_rstream((uv_handle_t *)rstream->fread_idle, rstream); } else { // Only pipes are supported for now assert(rstream->file_type == UV_NAMED_PIPE @@ -98,7 +100,8 @@ void rstream_set_file(RStream *rstream, uv_file file) rstream->stream = xmalloc(sizeof(uv_pipe_t)); uv_pipe_init(uv_default_loop(), (uv_pipe_t *)rstream->stream, 0); uv_pipe_open((uv_pipe_t *)rstream->stream, file); - rstream->stream->data = rstream; + rstream->stream->data = NULL; + handle_set_rstream((uv_handle_t *)rstream->stream, rstream); } rstream->fd = file; @@ -176,7 +179,7 @@ void rstream_read_event(Event event) // Called by libuv to allocate memory for reading. static void alloc_cb(uv_handle_t *handle, size_t suggested, uv_buf_t *buf) { - RStream *rstream = handle->data; + RStream *rstream = handle_get_rstream(handle); if (rstream->reading) { buf->len = 0; @@ -195,7 +198,7 @@ static void alloc_cb(uv_handle_t *handle, size_t suggested, uv_buf_t *buf) // 0-length buffer. static void read_cb(uv_stream_t *stream, ssize_t cnt, const uv_buf_t *buf) { - RStream *rstream = stream->data; + RStream *rstream = handle_get_rstream((uv_handle_t *)stream); if (cnt <= 0) { if (cnt != UV_ENOBUFS) { @@ -227,7 +230,7 @@ static void read_cb(uv_stream_t *stream, ssize_t cnt, const uv_buf_t *buf) static void fread_idle_cb(uv_idle_t *handle) { uv_fs_t req; - RStream *rstream = handle->data; + RStream *rstream = handle_get_rstream((uv_handle_t *)handle); rstream->uvbuf.base = rstream->buffer + rstream->wpos; rstream->uvbuf.len = rstream->buffer_size - rstream->wpos; @@ -272,6 +275,7 @@ static void fread_idle_cb(uv_idle_t *handle) static void close_cb(uv_handle_t *handle) { + free(handle->data); free(handle); } diff --git a/src/os/rstream_defs.h b/src/os/rstream_defs.h index ca3035adbf..3d1dbec34f 100644 --- a/src/os/rstream_defs.h +++ b/src/os/rstream_defs.h @@ -1,6 +1,8 @@ #ifndef NEOVIM_OS_RSTREAM_DEFS_H #define NEOVIM_OS_RSTREAM_DEFS_H +#include <stdbool.h> + typedef struct rstream RStream; /// Type of function called when the RStream receives data diff --git a/src/os/wstream.c b/src/os/wstream.c index c7984d8266..6bbd09dcd1 100644 --- a/src/os/wstream.c +++ b/src/os/wstream.c @@ -3,6 +3,7 @@ #include <uv.h> +#include "os/uv_helpers.h" #include "os/wstream.h" #include "os/wstream_defs.h" #include "vim.h" @@ -54,7 +55,7 @@ void wstream_free(WStream *wstream) void wstream_set_stream(WStream *wstream, uv_stream_t *stream) { - stream->data = wstream; + handle_set_wstream((uv_handle_t *)stream, wstream); wstream->stream = stream; } @@ -112,3 +113,4 @@ static void write_cb(uv_write_t *req, int status) free(data); } + |