mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
process: Pass loop reference during initialization
Change the API so that it is passed to {uv,pty}_process_init instead of `process_spawn`.
This commit is contained in:
parent
3f5af6c1c4
commit
696f9c2759
@ -21054,9 +21054,9 @@ static inline TerminalJobData *common_job_init(char **argv, ufunc_T *on_stdout,
|
|||||||
data->on_exit = on_exit;
|
data->on_exit = on_exit;
|
||||||
data->self = self;
|
data->self = self;
|
||||||
if (pty) {
|
if (pty) {
|
||||||
data->proc.pty = pty_process_init(data);
|
data->proc.pty = pty_process_init(&loop, data);
|
||||||
} else {
|
} else {
|
||||||
data->proc.uv = uv_process_init(data);
|
data->proc.uv = uv_process_init(&loop, data);
|
||||||
}
|
}
|
||||||
Process *proc = (Process *)&data->proc;
|
Process *proc = (Process *)&data->proc;
|
||||||
proc->argv = argv;
|
proc->argv = argv;
|
||||||
@ -21094,7 +21094,7 @@ static inline bool common_job_start(TerminalJobData *data, typval_T *rettv)
|
|||||||
{
|
{
|
||||||
data->refcount++;
|
data->refcount++;
|
||||||
Process *proc = (Process *)&data->proc;
|
Process *proc = (Process *)&data->proc;
|
||||||
if (!process_spawn(&loop, proc)) {
|
if (!process_spawn(proc)) {
|
||||||
EMSG(_(e_jobexe));
|
EMSG(_(e_jobexe));
|
||||||
if (proc->type == kProcessTypePty) {
|
if (proc->type == kProcessTypePty) {
|
||||||
xfree(data->proc.pty.term_name);
|
xfree(data->proc.pty.term_name);
|
||||||
|
@ -30,19 +30,18 @@
|
|||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
bool process_spawn(Loop *loop, Process *proc) FUNC_ATTR_NONNULL_ALL
|
bool process_spawn(Process *proc) FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
proc->loop = loop;
|
|
||||||
if (proc->in) {
|
if (proc->in) {
|
||||||
uv_pipe_init(&loop->uv, &proc->in->uv.pipe, 0);
|
uv_pipe_init(&proc->loop->uv, &proc->in->uv.pipe, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (proc->out) {
|
if (proc->out) {
|
||||||
uv_pipe_init(&loop->uv, &proc->out->uv.pipe, 0);
|
uv_pipe_init(&proc->loop->uv, &proc->out->uv.pipe, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (proc->err) {
|
if (proc->err) {
|
||||||
uv_pipe_init(&loop->uv, &proc->err->uv.pipe, 0);
|
uv_pipe_init(&proc->loop->uv, &proc->err->uv.pipe, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool success;
|
bool success;
|
||||||
@ -99,7 +98,7 @@ bool process_spawn(Loop *loop, Process *proc) FUNC_ATTR_NONNULL_ALL
|
|||||||
proc->internal_exit_cb = on_process_exit;
|
proc->internal_exit_cb = on_process_exit;
|
||||||
proc->internal_close_cb = decref;
|
proc->internal_close_cb = decref;
|
||||||
proc->refcount++;
|
proc->refcount++;
|
||||||
kl_push(WatcherPtr, loop->children, proc);
|
kl_push(WatcherPtr, proc->loop->children, proc);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,12 +28,12 @@ struct process {
|
|||||||
bool closed, term_sent;
|
bool closed, term_sent;
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline Process process_init(ProcessType type, void *data)
|
static inline Process process_init(Loop *loop, ProcessType type, void *data)
|
||||||
{
|
{
|
||||||
return (Process) {
|
return (Process) {
|
||||||
.type = type,
|
.type = type,
|
||||||
.data = data,
|
.data = data,
|
||||||
.loop = NULL,
|
.loop = loop,
|
||||||
.pid = 0,
|
.pid = 0,
|
||||||
.status = 0,
|
.status = 0,
|
||||||
.refcount = 0,
|
.refcount = 0,
|
||||||
|
@ -13,10 +13,10 @@ typedef struct pty_process {
|
|||||||
int tty_fd;
|
int tty_fd;
|
||||||
} PtyProcess;
|
} PtyProcess;
|
||||||
|
|
||||||
static inline PtyProcess pty_process_init(void *data)
|
static inline PtyProcess pty_process_init(Loop *loop, void *data)
|
||||||
{
|
{
|
||||||
PtyProcess rv;
|
PtyProcess rv;
|
||||||
rv.process = process_init(kProcessTypePty, data);
|
rv.process = process_init(loop, kProcessTypePty, data);
|
||||||
rv.term_name = NULL;
|
rv.term_name = NULL;
|
||||||
rv.width = 80;
|
rv.width = 80;
|
||||||
rv.height = 24;
|
rv.height = 24;
|
||||||
|
@ -12,10 +12,10 @@ typedef struct uv_process {
|
|||||||
uv_stdio_container_t uvstdio[3];
|
uv_stdio_container_t uvstdio[3];
|
||||||
} UvProcess;
|
} UvProcess;
|
||||||
|
|
||||||
static inline UvProcess uv_process_init(void *data)
|
static inline UvProcess uv_process_init(Loop *loop, void *data)
|
||||||
{
|
{
|
||||||
UvProcess rv;
|
UvProcess rv;
|
||||||
rv.process = process_init(kProcessTypeUv, data);
|
rv.process = process_init(loop, kProcessTypeUv, data);
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,14 +123,14 @@ void channel_teardown(void)
|
|||||||
uint64_t channel_from_process(char **argv)
|
uint64_t channel_from_process(char **argv)
|
||||||
{
|
{
|
||||||
Channel *channel = register_channel(kChannelTypeProc);
|
Channel *channel = register_channel(kChannelTypeProc);
|
||||||
channel->data.process.uvproc = uv_process_init(channel);
|
channel->data.process.uvproc = uv_process_init(&loop, channel);
|
||||||
Process *proc = &channel->data.process.uvproc.process;
|
Process *proc = &channel->data.process.uvproc.process;
|
||||||
proc->argv = argv;
|
proc->argv = argv;
|
||||||
proc->in = &channel->data.process.in;
|
proc->in = &channel->data.process.in;
|
||||||
proc->out = &channel->data.process.out;
|
proc->out = &channel->data.process.out;
|
||||||
proc->err = &channel->data.process.err;
|
proc->err = &channel->data.process.err;
|
||||||
proc->cb = process_exit;
|
proc->cb = process_exit;
|
||||||
if (!process_spawn(&loop, proc)) {
|
if (!process_spawn(proc)) {
|
||||||
loop_poll_events(&loop, 0);
|
loop_poll_events(&loop, 0);
|
||||||
decref(channel);
|
decref(channel);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -205,13 +205,13 @@ static int do_os_system(char **argv,
|
|||||||
xstrlcpy(prog, argv[0], MAXPATHL);
|
xstrlcpy(prog, argv[0], MAXPATHL);
|
||||||
|
|
||||||
Stream in, out, err;
|
Stream in, out, err;
|
||||||
UvProcess uvproc = uv_process_init(&buf);
|
UvProcess uvproc = uv_process_init(&loop, &buf);
|
||||||
Process *proc = &uvproc.process;
|
Process *proc = &uvproc.process;
|
||||||
proc->argv = argv;
|
proc->argv = argv;
|
||||||
proc->in = input != NULL ? &in : NULL;
|
proc->in = input != NULL ? &in : NULL;
|
||||||
proc->out = &out;
|
proc->out = &out;
|
||||||
proc->err = &err;
|
proc->err = &err;
|
||||||
if (!process_spawn(&loop, proc)) {
|
if (!process_spawn(proc)) {
|
||||||
loop_poll_events(&loop, 0);
|
loop_poll_events(&loop, 0);
|
||||||
// Failed, probably due to `sh` not being executable
|
// Failed, probably due to `sh` not being executable
|
||||||
if (!silent) {
|
if (!silent) {
|
||||||
|
Loading…
Reference in New Issue
Block a user