aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/event
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/event')
-rw-r--r--src/nvim/event/defs.h5
-rw-r--r--src/nvim/event/libuv_process.c22
-rw-r--r--src/nvim/event/libuv_process.h4
-rw-r--r--src/nvim/event/loop.c11
-rw-r--r--src/nvim/event/loop.h9
-rw-r--r--src/nvim/event/multiqueue.c86
-rw-r--r--src/nvim/event/multiqueue.h4
-rw-r--r--src/nvim/event/process.c33
-rw-r--r--src/nvim/event/process.h13
-rw-r--r--src/nvim/event/rstream.c9
-rw-r--r--src/nvim/event/rstream.h4
-rw-r--r--src/nvim/event/signal.c4
-rw-r--r--src/nvim/event/signal.h4
-rw-r--r--src/nvim/event/socket.c29
-rw-r--r--src/nvim/event/socket.h4
-rw-r--r--src/nvim/event/stream.c14
-rw-r--r--src/nvim/event/stream.h4
-rw-r--r--src/nvim/event/time.c4
-rw-r--r--src/nvim/event/time.h4
-rw-r--r--src/nvim/event/wstream.c6
-rw-r--r--src/nvim/event/wstream.h4
21 files changed, 115 insertions, 162 deletions
diff --git a/src/nvim/event/defs.h b/src/nvim/event/defs.h
index cf079681d0..571f61dfdb 100644
--- a/src/nvim/event/defs.h
+++ b/src/nvim/event/defs.h
@@ -1,5 +1,4 @@
-#ifndef NVIM_EVENT_DEFS_H
-#define NVIM_EVENT_DEFS_H
+#pragma once
#include <assert.h>
#include <stdarg.h>
@@ -34,5 +33,3 @@ static inline Event event_create(argv_callback cb, int argc, ...)
VA_EVENT_INIT(&event, cb, argc);
return event;
}
-
-#endif // NVIM_EVENT_DEFS_H
diff --git a/src/nvim/event/libuv_process.c b/src/nvim/event/libuv_process.c
index e528d21a71..be48b39af1 100644
--- a/src/nvim/event/libuv_process.c
+++ b/src/nvim/event/libuv_process.c
@@ -1,17 +1,14 @@
-// This is an open source non-commercial project. Dear PVS-Studio, please check
-// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
-
#include <assert.h>
+#include <locale.h>
#include <stdint.h>
#include <uv.h>
#include "nvim/eval/typval.h"
#include "nvim/event/libuv_process.h"
-#include "nvim/event/loop.h"
#include "nvim/event/process.h"
#include "nvim/event/stream.h"
+#include "nvim/func_attr.h"
#include "nvim/log.h"
-#include "nvim/macros.h"
#include "nvim/os/os.h"
#include "nvim/ui_client.h"
@@ -24,7 +21,7 @@ int libuv_process_spawn(LibuvProcess *uvproc)
FUNC_ATTR_NONNULL_ALL
{
Process *proc = (Process *)uvproc;
- uvproc->uvopts.file = proc->argv[0];
+ uvproc->uvopts.file = process_get_exepath(proc);
uvproc->uvopts.args = proc->argv;
uvproc->uvopts.flags = UV_PROCESS_WINDOWS_HIDE;
#ifdef MSWIN
@@ -68,25 +65,22 @@ int libuv_process_spawn(LibuvProcess *uvproc)
#ifdef MSWIN
uvproc->uvstdio[0].flags |= proc->overlapped ? UV_OVERLAPPED_PIPE : 0;
#endif
- uvproc->uvstdio[0].data.stream = STRUCT_CAST(uv_stream_t,
- &proc->in.uv.pipe);
+ uvproc->uvstdio[0].data.stream = (uv_stream_t *)(&proc->in.uv.pipe);
}
if (!proc->out.closed) {
uvproc->uvstdio[1].flags = UV_CREATE_PIPE | UV_WRITABLE_PIPE;
#ifdef MSWIN
// pipe must be readable for IOCP to work on Windows.
- uvproc->uvstdio[1].flags |= proc->overlapped ?
- (UV_READABLE_PIPE | UV_OVERLAPPED_PIPE) : 0;
+ uvproc->uvstdio[1].flags |= proc->overlapped
+ ? (UV_READABLE_PIPE | UV_OVERLAPPED_PIPE) : 0;
#endif
- uvproc->uvstdio[1].data.stream = STRUCT_CAST(uv_stream_t,
- &proc->out.uv.pipe);
+ uvproc->uvstdio[1].data.stream = (uv_stream_t *)(&proc->out.uv.pipe);
}
if (!proc->err.closed) {
uvproc->uvstdio[2].flags = UV_CREATE_PIPE | UV_WRITABLE_PIPE;
- uvproc->uvstdio[2].data.stream = STRUCT_CAST(uv_stream_t,
- &proc->err.uv.pipe);
+ uvproc->uvstdio[2].data.stream = (uv_stream_t *)(&proc->err.uv.pipe);
} else if (proc->fwd_err) {
uvproc->uvstdio[2].flags = UV_INHERIT_FD;
uvproc->uvstdio[2].data.fd = STDERR_FILENO;
diff --git a/src/nvim/event/libuv_process.h b/src/nvim/event/libuv_process.h
index 4472839944..e3e2bfeb76 100644
--- a/src/nvim/event/libuv_process.h
+++ b/src/nvim/event/libuv_process.h
@@ -1,5 +1,4 @@
-#ifndef NVIM_EVENT_LIBUV_PROCESS_H
-#define NVIM_EVENT_LIBUV_PROCESS_H
+#pragma once
#include <uv.h>
@@ -24,4 +23,3 @@ static inline LibuvProcess libuv_process_init(Loop *loop, void *data)
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "event/libuv_process.h.generated.h"
#endif
-#endif // NVIM_EVENT_LIBUV_PROCESS_H
diff --git a/src/nvim/event/loop.c b/src/nvim/event/loop.c
index ab2524c1a9..d61666e6d4 100644
--- a/src/nvim/event/loop.c
+++ b/src/nvim/event/loop.c
@@ -1,6 +1,3 @@
-// This is an open source non-commercial project. Dear PVS-Studio, please check
-// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
-
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
@@ -20,6 +17,7 @@ void loop_init(Loop *loop, void *data)
{
uv_loop_init(&loop->uv);
loop->recursive = 0;
+ loop->closing = false;
loop->uv.data = loop;
loop->children = kl_init(WatcherPtr);
loop->events = multiqueue_new_parent(loop_on_put, loop);
@@ -61,9 +59,9 @@ bool loop_uv_run(Loop *loop, int64_t ms, bool once)
mode = UV_RUN_NOWAIT;
}
- do { // -V1044
+ do {
uv_run(&loop->uv, mode);
- } while (ms > 0 && !once && !*timeout_expired); // -V560
+ } while (ms > 0 && !once && !*timeout_expired);
if (ms > 0) {
uv_timer_stop(&loop->poll_timer);
@@ -152,6 +150,7 @@ static void loop_walk_cb(uv_handle_t *handle, void *arg)
bool loop_close(Loop *loop, bool wait)
{
bool rv = true;
+ loop->closing = true;
uv_mutex_destroy(&loop->mutex);
uv_close((uv_handle_t *)&loop->children_watcher, NULL);
uv_close((uv_handle_t *)&loop->children_kill_timer, NULL);
@@ -163,7 +162,7 @@ bool loop_close(Loop *loop, bool wait)
while (true) {
// Run the loop to tickle close-callbacks (which should then free memory).
// Use UV_RUN_NOWAIT to avoid a hang. #11820
- uv_run(&loop->uv, didstop ? UV_RUN_DEFAULT : UV_RUN_NOWAIT); // -V547
+ uv_run(&loop->uv, didstop ? UV_RUN_DEFAULT : UV_RUN_NOWAIT);
if ((uv_loop_close(&loop->uv) != UV_EBUSY) || !wait) {
break;
}
diff --git a/src/nvim/event/loop.h b/src/nvim/event/loop.h
index b2265a726d..5665332e95 100644
--- a/src/nvim/event/loop.h
+++ b/src/nvim/event/loop.h
@@ -1,6 +1,6 @@
-#ifndef NVIM_EVENT_LOOP_H
-#define NVIM_EVENT_LOOP_H
+#pragma once
+#include <stdbool.h>
#include <stdint.h>
#include <uv.h>
@@ -41,6 +41,7 @@ typedef struct loop {
uv_async_t async;
uv_mutex_t mutex;
int recursive;
+ bool closing; ///< Set to true if loop_close() has been called
} Loop;
#define CREATE_EVENT(multiqueue, handler, argc, ...) \
@@ -53,8 +54,6 @@ typedef struct loop {
} \
} while (0)
-// -V:LOOP_PROCESS_EVENTS_UNTIL:547
-
// Poll for events until a condition or timeout
#define LOOP_PROCESS_EVENTS_UNTIL(loop, multiqueue, timeout, condition) \
do { \
@@ -87,5 +86,3 @@ typedef struct loop {
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "event/loop.h.generated.h"
#endif
-
-#endif // NVIM_EVENT_LOOP_H
diff --git a/src/nvim/event/multiqueue.c b/src/nvim/event/multiqueue.c
index e05084b656..3ab41bd299 100644
--- a/src/nvim/event/multiqueue.c
+++ b/src/nvim/event/multiqueue.c
@@ -1,6 +1,3 @@
-// This is an open source non-commercial project. Dear PVS-Studio, please check
-// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
-
// Multi-level queue for selective async event processing.
// Not threadsafe; access must be synchronized externally.
//
@@ -40,7 +37,7 @@
//
// The main reason for this queue hierarchy is to allow focusing on a single
// event emitter while blocking the main loop. For example, if the `jobwait`
-// VimL function is called on job1, the main loop will temporarily stop polling
+// Vimscript function is called on job1, the main loop will temporarily stop polling
// the event loop queue and poll job1 queue instead. Same with channels, when
// calling `rpcrequest` we want to temporarily stop processing events from
// other sources and focus on a specific channel.
@@ -48,10 +45,10 @@
#include <assert.h>
#include <stdbool.h>
#include <stddef.h>
-#include <uv.h>
#include "nvim/event/defs.h"
#include "nvim/event/multiqueue.h"
+#include "nvim/func_attr.h"
#include "nvim/lib/queue.h"
#include "nvim/memory.h"
@@ -112,13 +109,13 @@ static MultiQueue *multiqueue_new(MultiQueue *parent, PutCallback put_cb, void *
return rv;
}
-void multiqueue_free(MultiQueue *this)
+void multiqueue_free(MultiQueue *self)
{
- assert(this);
+ assert(self);
QUEUE *q;
- QUEUE_FOREACH(q, &this->headtail, {
+ QUEUE_FOREACH(q, &self->headtail, {
MultiQueueItem *item = multiqueue_node_data(q);
- if (this->parent) {
+ if (self->parent) {
QUEUE_REMOVE(&item->data.item.parent_item->node);
xfree(item->data.item.parent_item);
}
@@ -126,29 +123,29 @@ void multiqueue_free(MultiQueue *this)
xfree(item);
})
- xfree(this);
+ xfree(self);
}
/// Removes the next item and returns its Event.
-Event multiqueue_get(MultiQueue *this)
+Event multiqueue_get(MultiQueue *self)
{
- return multiqueue_empty(this) ? NILEVENT : multiqueue_remove(this);
+ return multiqueue_empty(self) ? NILEVENT : multiqueue_remove(self);
}
-void multiqueue_put_event(MultiQueue *this, Event event)
+void multiqueue_put_event(MultiQueue *self, Event event)
{
- assert(this);
- multiqueue_push(this, event);
- if (this->parent && this->parent->put_cb) {
- this->parent->put_cb(this->parent, this->parent->data);
+ assert(self);
+ multiqueue_push(self, event);
+ if (self->parent && self->parent->put_cb) {
+ self->parent->put_cb(self->parent, self->parent->data);
}
}
-void multiqueue_process_events(MultiQueue *this)
+void multiqueue_process_events(MultiQueue *self)
{
- assert(this);
- while (!multiqueue_empty(this)) {
- Event event = multiqueue_remove(this);
+ assert(self);
+ while (!multiqueue_empty(self)) {
+ Event event = multiqueue_remove(self);
if (event.handler) {
event.handler(event.argv);
}
@@ -156,30 +153,30 @@ void multiqueue_process_events(MultiQueue *this)
}
/// Removes all events without processing them.
-void multiqueue_purge_events(MultiQueue *this)
+void multiqueue_purge_events(MultiQueue *self)
{
- assert(this);
- while (!multiqueue_empty(this)) {
- (void)multiqueue_remove(this);
+ assert(self);
+ while (!multiqueue_empty(self)) {
+ (void)multiqueue_remove(self);
}
}
-bool multiqueue_empty(MultiQueue *this)
+bool multiqueue_empty(MultiQueue *self)
{
- assert(this);
- return QUEUE_EMPTY(&this->headtail);
+ assert(self);
+ return QUEUE_EMPTY(&self->headtail);
}
-void multiqueue_replace_parent(MultiQueue *this, MultiQueue *new_parent)
+void multiqueue_replace_parent(MultiQueue *self, MultiQueue *new_parent)
{
- assert(multiqueue_empty(this));
- this->parent = new_parent;
+ assert(multiqueue_empty(self));
+ self->parent = new_parent;
}
/// Gets the count of all events currently in the queue.
-size_t multiqueue_size(MultiQueue *this)
+size_t multiqueue_size(MultiQueue *self)
{
- return this->size;
+ return self->size;
}
/// Gets an Event from an item.
@@ -213,38 +210,39 @@ static Event multiqueueitem_get_event(MultiQueueItem *item, bool remove)
return ev;
}
-static Event multiqueue_remove(MultiQueue *this)
+static Event multiqueue_remove(MultiQueue *self)
{
- assert(!multiqueue_empty(this));
- QUEUE *h = QUEUE_HEAD(&this->headtail);
+ assert(!multiqueue_empty(self));
+ QUEUE *h = QUEUE_HEAD(&self->headtail);
QUEUE_REMOVE(h);
MultiQueueItem *item = multiqueue_node_data(h);
- assert(!item->link || !this->parent); // Only a parent queue has link-nodes
+ assert(!item->link || !self->parent); // Only a parent queue has link-nodes
Event ev = multiqueueitem_get_event(item, true);
- this->size--;
+ self->size--;
xfree(item);
return ev;
}
-static void multiqueue_push(MultiQueue *this, Event event)
+static void multiqueue_push(MultiQueue *self, Event event)
{
MultiQueueItem *item = xmalloc(sizeof(MultiQueueItem));
item->link = false;
item->data.item.event = event;
item->data.item.parent_item = NULL;
- QUEUE_INSERT_TAIL(&this->headtail, &item->node);
- if (this->parent) {
+ QUEUE_INSERT_TAIL(&self->headtail, &item->node);
+ if (self->parent) {
// push link node to the parent queue
item->data.item.parent_item = xmalloc(sizeof(MultiQueueItem));
item->data.item.parent_item->link = true;
- item->data.item.parent_item->data.queue = this;
- QUEUE_INSERT_TAIL(&this->parent->headtail,
+ item->data.item.parent_item->data.queue = self;
+ QUEUE_INSERT_TAIL(&self->parent->headtail,
&item->data.item.parent_item->node);
}
- this->size++;
+ self->size++;
}
static MultiQueueItem *multiqueue_node_data(QUEUE *q)
+ FUNC_ATTR_NO_SANITIZE_ADDRESS
{
return QUEUE_DATA(q, MultiQueueItem, node);
}
diff --git a/src/nvim/event/multiqueue.h b/src/nvim/event/multiqueue.h
index 2c5ba9d436..e01ee1e710 100644
--- a/src/nvim/event/multiqueue.h
+++ b/src/nvim/event/multiqueue.h
@@ -1,5 +1,4 @@
-#ifndef NVIM_EVENT_MULTIQUEUE_H
-#define NVIM_EVENT_MULTIQUEUE_H
+#pragma once
#include <uv.h>
@@ -15,4 +14,3 @@ typedef void (*PutCallback)(MultiQueue *multiq, void *data);
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "event/multiqueue.h.generated.h"
#endif
-#endif // NVIM_EVENT_MULTIQUEUE_H
diff --git a/src/nvim/event/process.c b/src/nvim/event/process.c
index 1a524a56ca..864fc2c1d8 100644
--- a/src/nvim/event/process.c
+++ b/src/nvim/event/process.c
@@ -1,19 +1,15 @@
-// This is an open source non-commercial project. Dear PVS-Studio, please check
-// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
-
#include <assert.h>
#include <inttypes.h>
#include <signal.h>
-#include <stdlib.h>
#include <uv.h>
#include "klib/klist.h"
#include "nvim/event/libuv_process.h"
#include "nvim/event/loop.h"
#include "nvim/event/process.h"
+#include "nvim/func_attr.h"
#include "nvim/globals.h"
#include "nvim/log.h"
-#include "nvim/macros.h"
#include "nvim/main.h"
#include "nvim/os/process.h"
#include "nvim/os/pty_process.h"
@@ -78,8 +74,6 @@ int process_spawn(Process *proc, bool in, bool out, bool err)
case kProcessTypePty:
status = pty_process_spawn((PtyProcess *)proc);
break;
- default:
- abort();
}
if (status) {
@@ -104,24 +98,21 @@ int process_spawn(Process *proc, bool in, bool out, bool err)
}
if (in) {
- stream_init(NULL, &proc->in, -1,
- STRUCT_CAST(uv_stream_t, &proc->in.uv.pipe));
+ stream_init(NULL, &proc->in, -1, (uv_stream_t *)&proc->in.uv.pipe);
proc->in.internal_data = proc;
proc->in.internal_close_cb = on_process_stream_close;
proc->refcount++;
}
if (out) {
- stream_init(NULL, &proc->out, -1,
- STRUCT_CAST(uv_stream_t, &proc->out.uv.pipe));
+ stream_init(NULL, &proc->out, -1, (uv_stream_t *)&proc->out.uv.pipe);
proc->out.internal_data = proc;
proc->out.internal_close_cb = on_process_stream_close;
proc->refcount++;
}
if (err) {
- stream_init(NULL, &proc->err, -1,
- STRUCT_CAST(uv_stream_t, &proc->err.uv.pipe));
+ stream_init(NULL, &proc->err, -1, (uv_stream_t *)&proc->err.uv.pipe);
proc->err.internal_data = proc;
proc->err.internal_close_cb = on_process_stream_close;
proc->refcount++;
@@ -131,7 +122,7 @@ int process_spawn(Process *proc, bool in, bool out, bool err)
proc->internal_close_cb = decref;
proc->refcount++;
kl_push(WatcherPtr, proc->loop->children, proc);
- DLOG("new: pid=%d argv=[%s]", proc->pid, proc->argv[0]);
+ DLOG("new: pid=%d exepath=[%s]", proc->pid, process_get_exepath(proc));
return 0;
}
@@ -239,8 +230,6 @@ void process_stop(Process *proc) FUNC_ATTR_NONNULL_ALL
process_close_streams(proc);
pty_process_close_master((PtyProcess *)proc);
break;
- default:
- abort();
}
// (Re)start timer to verify that stopped process(es) died.
@@ -340,8 +329,6 @@ static void process_close(Process *proc)
case kProcessTypePty:
pty_process_close((PtyProcess *)proc);
break;
- default:
- abort();
}
}
@@ -382,7 +369,7 @@ static void flush_stream(Process *proc, Stream *stream)
}
// Stream can be closed if it is empty.
- if (num_bytes == stream->num_bytes) { // -V547
+ if (num_bytes == stream->num_bytes) {
if (stream->read_cb && !stream->did_eof) {
// Stream callback could miss EOF handling if a child keeps the stream
// open. But only send EOF if we haven't already.
@@ -422,7 +409,13 @@ static void exit_event(void **argv)
}
if (!exiting) {
- os_exit(status);
+ if (ui_client_channel_id) {
+ ui_client_exit_status = status;
+ os_exit(status);
+ } else {
+ assert(status == 0); // Called from rpc_close(), which passes 0 as status.
+ preserve_exit(NULL);
+ }
}
}
diff --git a/src/nvim/event/process.h b/src/nvim/event/process.h
index e0057faffb..234fc815af 100644
--- a/src/nvim/event/process.h
+++ b/src/nvim/event/process.h
@@ -1,11 +1,9 @@
-#ifndef NVIM_EVENT_PROCESS_H
-#define NVIM_EVENT_PROCESS_H
+#pragma once
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
-#include "nvim/eval/typval.h"
#include "nvim/eval/typval_defs.h"
#include "nvim/event/loop.h"
#include "nvim/event/multiqueue.h"
@@ -33,6 +31,7 @@ struct process {
uint64_t stopped_time; // process_stop() timestamp
const char *cwd;
char **argv;
+ const char *exepath;
dict_T *env;
Stream in, out, err;
/// Exit handler. If set, user must call process_free().
@@ -55,6 +54,7 @@ static inline Process process_init(Loop *loop, ProcessType type, void *data)
.stopped_time = 0,
.cwd = NULL,
.argv = NULL,
+ .exepath = NULL,
.in = { .closed = false },
.out = { .closed = false },
.err = { .closed = false },
@@ -67,6 +67,12 @@ static inline Process process_init(Loop *loop, ProcessType type, void *data)
};
}
+/// Get the path to the executable of the process.
+static inline const char *process_get_exepath(Process *proc)
+{
+ return proc->exepath != NULL ? proc->exepath : proc->argv[0];
+}
+
static inline bool process_is_stopped(Process *proc)
{
bool exited = (proc->status >= 0);
@@ -76,4 +82,3 @@ static inline bool process_is_stopped(Process *proc)
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "event/process.h.generated.h"
#endif
-#endif // NVIM_EVENT_PROCESS_H
diff --git a/src/nvim/event/rstream.c b/src/nvim/event/rstream.c
index a88d62fd6b..73828a2271 100644
--- a/src/nvim/event/rstream.c
+++ b/src/nvim/event/rstream.c
@@ -1,17 +1,16 @@
-// This is an open source non-commercial project. Dear PVS-Studio, please check
-// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
-
#include <assert.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
+#include <sys/types.h>
#include <uv.h>
#include "nvim/event/loop.h"
#include "nvim/event/rstream.h"
#include "nvim/event/stream.h"
+#include "nvim/func_attr.h"
#include "nvim/log.h"
-#include "nvim/macros.h"
+#include "nvim/macros_defs.h"
#include "nvim/main.h"
#include "nvim/os/os_defs.h"
#include "nvim/rbuffer.h"
@@ -155,7 +154,7 @@ static void fread_idle_cb(uv_idle_t *handle)
uintmax_t fpos_intmax = stream->fpos;
if (fpos_intmax > INT64_MAX) {
ELOG("stream offset overflow");
- preserve_exit();
+ preserve_exit("stream offset overflow");
}
// Synchronous read
diff --git a/src/nvim/event/rstream.h b/src/nvim/event/rstream.h
index 23ed00bfea..b2a62acf83 100644
--- a/src/nvim/event/rstream.h
+++ b/src/nvim/event/rstream.h
@@ -1,5 +1,4 @@
-#ifndef NVIM_EVENT_RSTREAM_H
-#define NVIM_EVENT_RSTREAM_H
+#pragma once
#include <stdbool.h>
#include <stddef.h>
@@ -11,4 +10,3 @@
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "event/rstream.h.generated.h"
#endif
-#endif // NVIM_EVENT_RSTREAM_H
diff --git a/src/nvim/event/signal.c b/src/nvim/event/signal.c
index 8256ca2091..e64d526856 100644
--- a/src/nvim/event/signal.c
+++ b/src/nvim/event/signal.c
@@ -1,11 +1,9 @@
-// This is an open source non-commercial project. Dear PVS-Studio, please check
-// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
-
#include <stddef.h>
#include <uv.h>
#include "nvim/event/loop.h"
#include "nvim/event/signal.h"
+#include "nvim/func_attr.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "event/signal.c.generated.h"
diff --git a/src/nvim/event/signal.h b/src/nvim/event/signal.h
index f9adf62c20..946de1b4f0 100644
--- a/src/nvim/event/signal.h
+++ b/src/nvim/event/signal.h
@@ -1,5 +1,4 @@
-#ifndef NVIM_EVENT_SIGNAL_H
-#define NVIM_EVENT_SIGNAL_H
+#pragma once
#include <uv.h>
@@ -23,4 +22,3 @@ struct signal_watcher {
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "event/signal.h.generated.h"
#endif
-#endif // NVIM_EVENT_SIGNAL_H
diff --git a/src/nvim/event/socket.c b/src/nvim/event/socket.c
index 10756015ad..e787e023f0 100644
--- a/src/nvim/event/socket.c
+++ b/src/nvim/event/socket.c
@@ -1,6 +1,3 @@
-// This is an open source non-commercial project. Dear PVS-Studio, please check
-// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
-
#include <assert.h>
#include <inttypes.h>
#include <stdbool.h>
@@ -8,16 +5,17 @@
#include <string.h>
#include <uv.h>
-#include "nvim/ascii.h"
+#include "nvim/ascii_defs.h"
#include "nvim/charset.h"
#include "nvim/event/loop.h"
#include "nvim/event/socket.h"
#include "nvim/event/stream.h"
+#include "nvim/func_attr.h"
#include "nvim/gettext.h"
#include "nvim/log.h"
-#include "nvim/macros.h"
#include "nvim/main.h"
#include "nvim/memory.h"
+#include "nvim/os/fs.h"
#include "nvim/os/os.h"
#include "nvim/path.h"
@@ -64,10 +62,10 @@ int socket_watcher_init(Loop *loop, SocketWatcher *watcher, const char *endpoint
uv_tcp_init(&loop->uv, &watcher->uv.tcp.handle);
uv_tcp_nodelay(&watcher->uv.tcp.handle, true);
- watcher->stream = STRUCT_CAST(uv_stream_t, &watcher->uv.tcp.handle);
+ watcher->stream = (uv_stream_t *)(&watcher->uv.tcp.handle);
} else {
uv_pipe_init(&loop->uv, &watcher->uv.pipe.handle, 0);
- watcher->stream = STRUCT_CAST(uv_stream_t, &watcher->uv.pipe.handle);
+ watcher->stream = (uv_stream_t *)(&watcher->uv.pipe.handle);
}
watcher->stream->data = watcher;
@@ -102,9 +100,8 @@ int socket_watcher_start(SocketWatcher *watcher, int backlog, socket_cb cb)
// contain 0 in this case, unless uv_tcp_getsockname() is used first.
uv_tcp_getsockname(&watcher->uv.tcp.handle, (struct sockaddr *)&sas,
&(int){ sizeof(sas) });
- uint16_t port = (uint16_t)((sas.ss_family == AF_INET)
- ? (STRUCT_CAST(struct sockaddr_in, &sas))->sin_port
- : (STRUCT_CAST(struct sockaddr_in6, &sas))->sin6_port);
+ uint16_t port = (sas.ss_family == AF_INET) ? ((struct sockaddr_in *)(&sas))->sin_port
+ : ((struct sockaddr_in6 *)(&sas))->sin6_port;
// v:servername uses the string from watcher->addr
size_t len = strlen(watcher->addr);
snprintf(watcher->addr + len, sizeof(watcher->addr) - len, ":%" PRIu16,
@@ -142,11 +139,11 @@ int socket_watcher_accept(SocketWatcher *watcher, Stream *stream)
uv_stream_t *client;
if (watcher->stream->type == UV_TCP) {
- client = STRUCT_CAST(uv_stream_t, &stream->uv.tcp);
+ client = (uv_stream_t *)(&stream->uv.tcp);
uv_tcp_init(watcher->uv.tcp.handle.loop, (uv_tcp_t *)client);
uv_tcp_nodelay((uv_tcp_t *)client, true);
} else {
- client = STRUCT_CAST(uv_stream_t, &stream->uv.pipe);
+ client = (uv_stream_t *)&stream->uv.pipe;
uv_pipe_init(watcher->uv.pipe.handle.loop, (uv_pipe_t *)client, 0);
}
@@ -165,7 +162,7 @@ void socket_watcher_close(SocketWatcher *watcher, socket_close_cb cb)
FUNC_ATTR_NONNULL_ARG(1)
{
watcher->close_cb = cb;
- uv_close(STRUCT_CAST(uv_handle_t, watcher->stream), close_cb);
+ uv_close((uv_handle_t *)watcher->stream, close_cb);
}
static void connection_event(void **argv)
@@ -224,7 +221,7 @@ bool socket_connect(Loop *loop, Stream *stream, bool is_tcp, const char *address
const struct addrinfo hints = { .ai_family = AF_UNSPEC,
.ai_socktype = SOCK_STREAM,
- .ai_flags = AI_NUMERICSERV };
+ .ai_flags = AI_NUMERICSERV };
int retval = uv_getaddrinfo(&loop->uv, &addr_req, NULL,
addr, host_end + 1, &hints);
if (retval != 0) {
@@ -242,11 +239,11 @@ tcp_retry:
uv_pipe_t *pipe = &stream->uv.pipe;
uv_pipe_init(&loop->uv, pipe, 0);
uv_pipe_connect(&req, pipe, address, connect_cb);
- uv_stream = STRUCT_CAST(uv_stream_t, pipe);
+ uv_stream = (uv_stream_t *)pipe;
}
status = 1;
LOOP_PROCESS_EVENTS_UNTIL(&main_loop, NULL, timeout, status != 1);
- if (status == 0) { // -V547
+ if (status == 0) {
stream_init(NULL, stream, -1, uv_stream);
success = true;
} else if (is_tcp && addrinfo->ai_next) {
diff --git a/src/nvim/event/socket.h b/src/nvim/event/socket.h
index c6fcdec4bb..504af3c7a8 100644
--- a/src/nvim/event/socket.h
+++ b/src/nvim/event/socket.h
@@ -1,5 +1,4 @@
-#ifndef NVIM_EVENT_SOCKET_H
-#define NVIM_EVENT_SOCKET_H
+#pragma once
#include <uv.h>
@@ -39,4 +38,3 @@ struct socket_watcher {
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "event/socket.h.generated.h"
#endif
-#endif // NVIM_EVENT_SOCKET_H
diff --git a/src/nvim/event/stream.c b/src/nvim/event/stream.c
index 0a4918636a..aff116bad9 100644
--- a/src/nvim/event/stream.c
+++ b/src/nvim/event/stream.c
@@ -1,6 +1,3 @@
-// This is an open source non-commercial project. Dear PVS-Studio, please check
-// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
-
#include <assert.h>
#include <stdbool.h>
#include <stddef.h>
@@ -9,8 +6,8 @@
#include "nvim/event/loop.h"
#include "nvim/event/stream.h"
+#include "nvim/func_attr.h"
#include "nvim/log.h"
-#include "nvim/macros.h"
#include "nvim/rbuffer.h"
#ifdef MSWIN
# include "nvim/os/os_win_console.h"
@@ -37,9 +34,8 @@ int stream_set_blocking(int fd, bool blocking)
uv_loop_init(&loop);
uv_pipe_init(&loop, &stream, 0);
uv_pipe_open(&stream, fd);
- int retval = uv_stream_set_blocking(STRUCT_CAST(uv_stream_t, &stream),
- blocking);
- uv_close(STRUCT_CAST(uv_handle_t, &stream), NULL);
+ int retval = uv_stream_set_blocking((uv_stream_t *)&stream, blocking);
+ uv_close((uv_handle_t *)&stream, NULL);
uv_run(&loop, UV_RUN_NOWAIT); // not necessary, but couldn't hurt.
uv_loop_close(&loop);
return retval;
@@ -71,12 +67,12 @@ void stream_init(Loop *loop, Stream *stream, int fd, uv_stream_t *uvstream)
dwMode |= ENABLE_VIRTUAL_TERMINAL_INPUT;
SetConsoleMode(stream->uv.tty.handle, dwMode);
}
- stream->uvstream = STRUCT_CAST(uv_stream_t, &stream->uv.tty);
+ stream->uvstream = (uv_stream_t *)&stream->uv.tty;
} else {
#endif
uv_pipe_init(&loop->uv, &stream->uv.pipe, 0);
uv_pipe_open(&stream->uv.pipe, fd);
- stream->uvstream = STRUCT_CAST(uv_stream_t, &stream->uv.pipe);
+ stream->uvstream = (uv_stream_t *)&stream->uv.pipe;
#ifdef MSWIN
}
#endif
diff --git a/src/nvim/event/stream.h b/src/nvim/event/stream.h
index 33d2d6e775..d02707dc45 100644
--- a/src/nvim/event/stream.h
+++ b/src/nvim/event/stream.h
@@ -1,5 +1,4 @@
-#ifndef NVIM_EVENT_STREAM_H
-#define NVIM_EVENT_STREAM_H
+#pragma once
#include <stdbool.h>
#include <stddef.h>
@@ -61,4 +60,3 @@ struct stream {
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "event/stream.h.generated.h"
#endif
-#endif // NVIM_EVENT_STREAM_H
diff --git a/src/nvim/event/time.c b/src/nvim/event/time.c
index c997e3c558..f678f25f3f 100644
--- a/src/nvim/event/time.c
+++ b/src/nvim/event/time.c
@@ -1,11 +1,9 @@
-// This is an open source non-commercial project. Dear PVS-Studio, please check
-// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
-
#include <stdint.h>
#include <uv.h>
#include "nvim/event/loop.h"
#include "nvim/event/time.h"
+#include "nvim/func_attr.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "event/time.c.generated.h"
diff --git a/src/nvim/event/time.h b/src/nvim/event/time.h
index e84488fdd6..3514566901 100644
--- a/src/nvim/event/time.h
+++ b/src/nvim/event/time.h
@@ -1,5 +1,4 @@
-#ifndef NVIM_EVENT_TIME_H
-#define NVIM_EVENT_TIME_H
+#pragma once
#include <stdbool.h>
#include <uv.h>
@@ -23,4 +22,3 @@ struct time_watcher {
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "event/time.h.generated.h"
#endif
-#endif // NVIM_EVENT_TIME_H
diff --git a/src/nvim/event/wstream.c b/src/nvim/event/wstream.c
index 65391ba5cf..e8f757874b 100644
--- a/src/nvim/event/wstream.c
+++ b/src/nvim/event/wstream.c
@@ -1,6 +1,3 @@
-// This is an open source non-commercial project. Dear PVS-Studio, please check
-// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
-
#include <assert.h>
#include <stdbool.h>
#include <uv.h>
@@ -8,7 +5,8 @@
#include "nvim/event/loop.h"
#include "nvim/event/stream.h"
#include "nvim/event/wstream.h"
-#include "nvim/macros.h"
+#include "nvim/func_attr.h"
+#include "nvim/macros_defs.h"
#include "nvim/memory.h"
#define DEFAULT_MAXMEM 1024 * 1024 * 2000
diff --git a/src/nvim/event/wstream.h b/src/nvim/event/wstream.h
index ef1311c619..4cba7bde8f 100644
--- a/src/nvim/event/wstream.h
+++ b/src/nvim/event/wstream.h
@@ -1,5 +1,4 @@
-#ifndef NVIM_EVENT_WSTREAM_H
-#define NVIM_EVENT_WSTREAM_H
+#pragma once
#include <stdbool.h>
#include <stddef.h>
@@ -23,4 +22,3 @@ struct wbuffer {
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "event/wstream.h.generated.h"
#endif
-#endif // NVIM_EVENT_WSTREAM_H