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:
Thiago de Arruda 2015-07-24 11:56:44 -03:00
parent 3f5af6c1c4
commit 696f9c2759
7 changed files with 18 additions and 19 deletions

View File

@ -21054,9 +21054,9 @@ static inline TerminalJobData *common_job_init(char **argv, ufunc_T *on_stdout,
data->on_exit = on_exit;
data->self = self;
if (pty) {
data->proc.pty = pty_process_init(data);
data->proc.pty = pty_process_init(&loop, data);
} else {
data->proc.uv = uv_process_init(data);
data->proc.uv = uv_process_init(&loop, data);
}
Process *proc = (Process *)&data->proc;
proc->argv = argv;
@ -21094,7 +21094,7 @@ static inline bool common_job_start(TerminalJobData *data, typval_T *rettv)
{
data->refcount++;
Process *proc = (Process *)&data->proc;
if (!process_spawn(&loop, proc)) {
if (!process_spawn(proc)) {
EMSG(_(e_jobexe));
if (proc->type == kProcessTypePty) {
xfree(data->proc.pty.term_name);

View File

@ -30,19 +30,18 @@
} 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) {
uv_pipe_init(&loop->uv, &proc->in->uv.pipe, 0);
uv_pipe_init(&proc->loop->uv, &proc->in->uv.pipe, 0);
}
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) {
uv_pipe_init(&loop->uv, &proc->err->uv.pipe, 0);
uv_pipe_init(&proc->loop->uv, &proc->err->uv.pipe, 0);
}
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_close_cb = decref;
proc->refcount++;
kl_push(WatcherPtr, loop->children, proc);
kl_push(WatcherPtr, proc->loop->children, proc);
return true;
}

View File

@ -28,12 +28,12 @@ struct process {
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) {
.type = type,
.data = data,
.loop = NULL,
.loop = loop,
.pid = 0,
.status = 0,
.refcount = 0,

View File

@ -13,10 +13,10 @@ typedef struct pty_process {
int tty_fd;
} PtyProcess;
static inline PtyProcess pty_process_init(void *data)
static inline PtyProcess pty_process_init(Loop *loop, void *data)
{
PtyProcess rv;
rv.process = process_init(kProcessTypePty, data);
rv.process = process_init(loop, kProcessTypePty, data);
rv.term_name = NULL;
rv.width = 80;
rv.height = 24;

View File

@ -12,10 +12,10 @@ typedef struct uv_process {
uv_stdio_container_t uvstdio[3];
} UvProcess;
static inline UvProcess uv_process_init(void *data)
static inline UvProcess uv_process_init(Loop *loop, void *data)
{
UvProcess rv;
rv.process = process_init(kProcessTypeUv, data);
rv.process = process_init(loop, kProcessTypeUv, data);
return rv;
}

View File

@ -123,14 +123,14 @@ void channel_teardown(void)
uint64_t channel_from_process(char **argv)
{
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;
proc->argv = argv;
proc->in = &channel->data.process.in;
proc->out = &channel->data.process.out;
proc->err = &channel->data.process.err;
proc->cb = process_exit;
if (!process_spawn(&loop, proc)) {
if (!process_spawn(proc)) {
loop_poll_events(&loop, 0);
decref(channel);
return 0;

View File

@ -205,13 +205,13 @@ static int do_os_system(char **argv,
xstrlcpy(prog, argv[0], MAXPATHL);
Stream in, out, err;
UvProcess uvproc = uv_process_init(&buf);
UvProcess uvproc = uv_process_init(&loop, &buf);
Process *proc = &uvproc.process;
proc->argv = argv;
proc->in = input != NULL ? &in : NULL;
proc->out = &out;
proc->err = &err;
if (!process_spawn(&loop, proc)) {
if (!process_spawn(proc)) {
loop_poll_events(&loop, 0);
// Failed, probably due to `sh` not being executable
if (!silent) {