diff options
Diffstat (limited to 'src/os')
-rw-r--r-- | src/os/env.c | 9 | ||||
-rw-r--r-- | src/os/event.c | 13 | ||||
-rw-r--r-- | src/os/event_defs.h | 2 | ||||
-rw-r--r-- | src/os/input.c | 4 | ||||
-rw-r--r-- | src/os/job.c | 22 | ||||
-rw-r--r-- | src/os/job.h | 2 | ||||
-rw-r--r-- | src/os/job_defs.h | 2 | ||||
-rw-r--r-- | src/os/os.h | 2 | ||||
-rw-r--r-- | src/os/shell.c | 32 | ||||
-rw-r--r-- | src/os/signal.c | 6 | ||||
-rw-r--r-- | src/os/signal.h | 2 |
11 files changed, 49 insertions, 47 deletions
diff --git a/src/os/env.c b/src/os/env.c index a3053e3350..6d3e8bd683 100644 --- a/src/os/env.c +++ b/src/os/env.c @@ -55,12 +55,12 @@ char *os_getenvname_at_index(size_t index) } -long os_get_pid() +int64_t os_get_pid() { #ifdef _WIN32 - return (long)GetCurrentProcessId(); + return (int64_t)GetCurrentProcessId(); #else - return (long)getpid(); + return (int64_t)getpid(); #endif } @@ -76,7 +76,8 @@ void os_get_hostname(char *hostname, size_t len) hostname[len - 1] = '\0'; } #else - // TODO: Implement this for windows. See the implementation used in vim: + // TODO(unknown): Implement this for windows. + // See the implementation used in vim: // https://code.google.com/p/vim/source/browse/src/os_win32.c?r=6b69d8dde19e32909f4ee3a6337e6a2ecfbb6f72#2899 *hostname = '\0'; #endif diff --git a/src/os/event.c b/src/os/event.c index 9e95159dbc..fb3fffc35a 100644 --- a/src/os/event.c +++ b/src/os/event.c @@ -60,7 +60,7 @@ bool event_poll(int32_t ms) if (ms > 0) { // Calculate remaining time in milliseconds - remaining = (end - uv_hrtime()) / 1e6; + remaining = (end - uv_hrtime()) / 1e6; } if (input_ready() || got_int) { @@ -69,7 +69,7 @@ bool event_poll(int32_t ms) } if (!result || (ms >= 0 && remaining <= 0)) { - // Or if we timed out + // Or if we timed out return false; } } @@ -133,11 +133,10 @@ static bool poll_uv_loop(int32_t ms) uv_run(uv_default_loop(), run_mode); } while ( // Continue running if ... - !input_ready() && // we have no input - kl_empty(event_queue) && // no events are waiting to be processed - run_mode != UV_RUN_NOWAIT && // ms != 0 - !timed_out // we didn't get a timeout - ); + !input_ready() && // we have no input + kl_empty(event_queue) && // no events are waiting to be processed + run_mode != UV_RUN_NOWAIT && // ms != 0 + !timed_out); // we didn't get a timeout input_stop(); diff --git a/src/os/event_defs.h b/src/os/event_defs.h index 5764534382..a72462b18a 100644 --- a/src/os/event_defs.h +++ b/src/os/event_defs.h @@ -16,4 +16,4 @@ typedef struct { } data; } Event; -#endif // NEOVIM_OS_EVENT_H +#endif // NEOVIM_OS_EVENT_DEFS_H diff --git a/src/os/input.c b/src/os/input.c index 14a7088024..122600630d 100644 --- a/src/os/input.c +++ b/src/os/input.c @@ -154,7 +154,7 @@ int os_inchar(char_u *buf, int maxlen, int32_t ms, int tb_change_cnt) return 0; } - return read_from_input_buf(buf, (long)maxlen); + return read_from_input_buf(buf, (int64_t)maxlen); } // Check if a character is available for reading @@ -168,7 +168,7 @@ bool os_char_avail() void os_breakcheck() { if (curr_tmode == TMODE_RAW && event_poll(0)) - fill_input_buf(FALSE); + fill_input_buf(false); } // This is a replacement for the old `WaitForChar` function in os_unix.c diff --git a/src/os/job.c b/src/os/job.c index f8d9d6d576..8a02de35b7 100644 --- a/src/os/job.c +++ b/src/os/job.c @@ -3,8 +3,8 @@ #include <uv.h> -#include "os/job_defs.h" #include "os/job.h" +#include "os/job_defs.h" #include "os/time.h" #include "os/shell.h" #include "vim.h" @@ -17,13 +17,13 @@ /// Possible lock states of the job buffer typedef enum { - kBufferLockNone = 0, ///< No data was read - kBufferLockStdout, ///< Data read from stdout - kBufferLockStderr ///< Data read from stderr + kBufferLockNone = 0, ///< No data was read + kBufferLockStdout, ///< Data read from stdout + kBufferLockStderr ///< Data read from stderr } BufferLock; -struct _Job { - // Job id the index in the job table plus one. +struct job { + // Job id the index in the job table plus one. int id; // Number of polls after a SIGTERM that will trigger a SIGKILL int exit_timeout; @@ -83,7 +83,7 @@ void job_teardown() uv_process_kill(&job->proc, SIGTERM); } } - + if (all_dead) { return; } @@ -120,7 +120,7 @@ int job_start(char **argv, void *data, job_read_cb cb) { int i; Job *job; - + // Search for a free slot in the table for (i = 0; i < MAX_RUNNING_JOBS; i++) { if (table[i] == NULL) { @@ -133,7 +133,7 @@ int job_start(char **argv, void *data, job_read_cb cb) return 0; } - job = xmalloc(sizeof(Job)); + job = xmalloc(sizeof(Job)); // Initialize job->id = i + 1; job->data = data; @@ -245,7 +245,7 @@ static Job * find_job(int id) if (id <= 0 || id > MAX_RUNNING_JOBS) { return NULL; } - + return table[id - 1]; } @@ -269,7 +269,7 @@ static void job_prepare_cb(uv_prepare_t *handle, int status) if ((job = table[i]) == NULL || !job->stopped) { continue; } - + if ((job->exit_timeout--) == EXIT_TIMEOUT) { // Job was just stopped, close all stdio handles and send SIGTERM uv_process_kill(&job->proc, SIGTERM); diff --git a/src/os/job.h b/src/os/job.h index 0350f44d58..b0f9c99bb8 100644 --- a/src/os/job.h +++ b/src/os/job.h @@ -47,7 +47,7 @@ int job_start(char **argv, void *data, job_read_cb cb); /// Terminates a job. This is a non-blocking operation, but if the job exists /// it's guaranteed to succeed(SIGKILL will eventually be sent) -/// +/// /// @param id The job id /// @return true if the stop request was successfully sent, false if the job /// id is invalid(probably because it has already stopped) diff --git a/src/os/job_defs.h b/src/os/job_defs.h index f1cb74d08d..27a1133c2c 100644 --- a/src/os/job_defs.h +++ b/src/os/job_defs.h @@ -1,6 +1,6 @@ #ifndef NEOVIM_OS_JOB_DEFS_H #define NEOVIM_OS_JOB_DEFS_H -typedef struct _Job Job; +typedef struct job Job; #endif // NEOVIM_OS_JOB_DEFS_H diff --git a/src/os/os.h b/src/os/os.h index fc66307d34..eac6e730c5 100644 --- a/src/os/os.h +++ b/src/os/os.h @@ -86,7 +86,7 @@ char *os_getenvname_at_index(size_t index); /// Get the process ID of the Neovim process. /// /// @return the process ID. -long os_get_pid(void); +int64_t os_get_pid(void); /// Get the hostname of the machine runing Neovim. /// diff --git a/src/os/shell.c b/src/os/shell.c index bc562474df..d14e355d19 100644 --- a/src/os/shell.c +++ b/src/os/shell.c @@ -103,7 +103,7 @@ void shell_free_argv(char **argv) } while (*p != NULL) { - // Free each argument + // Free each argument free(*p); p++; } @@ -138,9 +138,9 @@ int os_call_shell(char_u *cmd, ShellOpts opts, char_u *extra_shell_arg) signal_reject_deadly(); // Create argv for `uv_spawn` - // TODO we can use a static buffer for small argument vectors. 1024 bytes - // should be enough for most of the commands and if more is necessary we can - // allocate a another buffer + // TODO(tarruda): we can use a static buffer for small argument vectors. 1024 + // bytes should be enough for most of the commands and if more is necessary + // we can allocate a another buffer proc_opts.args = shell_build_argv(cmd, extra_shell_arg); proc_opts.file = proc_opts.args[0]; proc_opts.exit_cb = exit_cb; @@ -219,8 +219,9 @@ int os_call_shell(char_u *cmd, ShellOpts opts, char_u *extra_shell_arg) if (got_int) { // Forward SIGINT to the shell - // TODO for now this is only needed if the terminal is in raw mode, but - // when the UI is externalized we'll also need it, so leave it here + // TODO(tarruda): for now this is only needed if the terminal is in raw + // mode, but when the UI is externalized we'll also need it, so leave it + // here uv_process_kill(&proc, SIGINT); got_int = false; } @@ -232,8 +233,9 @@ int os_call_shell(char_u *cmd, ShellOpts opts, char_u *extra_shell_arg) append_ga_line(&pdata.ga); // remember that the NL was missing curbuf->b_no_eol_lnum = curwin->w_cursor.lnum; - } else + } else { curbuf->b_no_eol_lnum = 0; + } ga_clear(&pdata.ga); } @@ -296,9 +298,9 @@ static int word_length(char_u *str) static void write_selection(uv_write_t *req) { ProcessData *pdata = (ProcessData *)req->data; - // TODO use a static buffer for up to a limit(BUFFER_LENGTH) and only after - // filled we should start allocating memory(skip unnecessary allocations for - // small writes) + // TODO(tarruda): use a static buffer for up to a limit(BUFFER_LENGTH) and + // only after filled we should start allocating memory(skip unnecessary + // allocations for small writes) int buflen = BUFFER_LENGTH; pdata->wbuffer = (char *)xmalloc(buflen); uv_buf_t uvbuf; @@ -356,8 +358,9 @@ static void write_selection(uv_write_t *req) } lp = ml_get(lnum); written = 0; - } else if (len > 0) + } else if (len > 0) { written += len; + } } uvbuf.base = pdata->wbuffer; @@ -384,8 +387,8 @@ static void alloc_cb(uv_handle_t *handle, size_t suggested, uv_buf_t *buf) static void read_cb(uv_stream_t *stream, ssize_t cnt, const uv_buf_t *buf) { - // TODO avoid using a growable array for this, refactor the algorithm - // to call `ml_append` directly(skip unecessary copies/resizes) + // TODO(tarruda): avoid using a growable array for this, refactor the + // algorithm to call `ml_append` directly(skip unecessary copies/resizes) int i; ProcessData *pdata = (ProcessData *)stream->data; @@ -429,12 +432,11 @@ static int proc_cleanup_exit(ProcessData *proc_data, uv_process_options_t *proc_opts, int shellopts) { - if (proc_data->exited) { if (!emsg_silent && proc_data->exit_status != 0 && !(shellopts & kShellOptSilent)) { MSG_PUTS(_("\nshell returned ")); - msg_outnum((long)proc_data->exit_status); + msg_outnum((int64_t)proc_data->exit_status); msg_putchar('\n'); } } diff --git a/src/os/signal.c b/src/os/signal.c index 58c959db6b..87eb379014 100644 --- a/src/os/signal.c +++ b/src/os/signal.c @@ -80,7 +80,7 @@ void signal_handle(Event event) case SIGPWR: // Signal of a power failure(eg batteries low), flush the swap files to // be safe - ml_sync_all(FALSE, FALSE); + ml_sync_all(false, false); break; #endif case SIGPIPE: @@ -136,7 +136,7 @@ static void deadly_signal(int signum) // Set the v:dying variable. set_vim_var_nr(VV_DYING, 1); - sprintf((char *)IObuff, "Vim: Caught deadly signal '%s'\n", + snprintf((char *)IObuff, sizeof(IObuff), "Vim: Caught deadly signal '%s'\n", signal_name(signum)); // Preserve files and exit. This sets the really_exiting flag to prevent @@ -152,7 +152,7 @@ static void signal_cb(uv_signal_t *handle, int signum) } return; - } + } Event event = { .type = kEventSignal, diff --git a/src/os/signal.h b/src/os/signal.h index 13231a0998..79fdc8d79c 100644 --- a/src/os/signal.h +++ b/src/os/signal.h @@ -9,5 +9,5 @@ void signal_accept_deadly(void); void signal_reject_deadly(void); void signal_handle(Event event); -#endif +#endif // NEOVIM_OS_SIGNAL_H |