aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2021-06-22 08:50:18 -0400
committerJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2021-06-23 23:16:20 -0400
commitd5329c0331a4e899ea88277b745df8d1bf3a99fa (patch)
tree200c2403379bf041d27b7cf2634b8304ed8a1976
parent24e0c16fd6cb33a399772330cb80dfa4c1306284 (diff)
downloadrneovim-d5329c0331a4e899ea88277b745df8d1bf3a99fa.tar.gz
rneovim-d5329c0331a4e899ea88277b745df8d1bf3a99fa.tar.bz2
rneovim-d5329c0331a4e899ea88277b745df8d1bf3a99fa.zip
vim-patch:8.1.1437: code to handle callbacks is duplicated
Problem: Code to handle callbacks is duplicated. Solution: Add callback_T and functions to deal with it. https://github.com/vim/vim/commit/3a97bb3f0f8bd118ae23f1c97e55d84ff42eef20 Port Vim's put_callback() as callback_put() because Neovim's naming convention is {type}_{action}, not {action}_{type}. Renaming put_callback type as PutCallback. https://neovim.io/develop/style-guide.xml#Type_Names
-rw-r--r--src/nvim/eval.c9
-rw-r--r--src/nvim/eval/typval.c15
-rw-r--r--src/nvim/event/multiqueue.c6
-rw-r--r--src/nvim/event/multiqueue.h2
4 files changed, 20 insertions, 12 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index a3fa9c986f..7e462e568b 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -7324,14 +7324,7 @@ void add_timer_info(typval_T *rettv, timer_T *timer)
return;
}
- if (timer->callback.type == kCallbackPartial) {
- di->di_tv.v_type = VAR_PARTIAL;
- di->di_tv.vval.v_partial = timer->callback.data.partial;
- timer->callback.data.partial->pt_refcount++;
- } else if (timer->callback.type == kCallbackFuncref) {
- di->di_tv.v_type = VAR_FUNC;
- di->di_tv.vval.v_string = vim_strsave(timer->callback.data.funcref);
- }
+ callback_put(&timer->callback, &di->di_tv);
}
void add_timer_info_all(typval_T *rettv)
diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c
index 61de83fc21..4118ec407c 100644
--- a/src/nvim/eval/typval.c
+++ b/src/nvim/eval/typval.c
@@ -1164,6 +1164,21 @@ void callback_free(Callback *callback)
callback->type = kCallbackNone;
}
+/// Copy a callback into a typval_T.
+void callback_put(Callback *cb, typval_T *tv)
+ FUNC_ATTR_NONNULL_ALL
+{
+ if (cb->type == kCallbackPartial) {
+ tv->v_type = VAR_PARTIAL;
+ tv->vval.v_partial = cb->data.partial;
+ cb->data.partial->pt_refcount++;
+ } else if (cb->type == kCallbackFuncref) {
+ tv->v_type = VAR_FUNC;
+ tv->vval.v_string = vim_strsave(cb->data.funcref);
+ func_ref(cb->data.funcref);
+ }
+}
+
/// Remove watcher from a dictionary
///
/// @param dict Dictionary to remove watcher from.
diff --git a/src/nvim/event/multiqueue.c b/src/nvim/event/multiqueue.c
index 1e6d62135c..f534fc483f 100644
--- a/src/nvim/event/multiqueue.c
+++ b/src/nvim/event/multiqueue.c
@@ -73,7 +73,7 @@ struct multiqueue_item {
struct multiqueue {
MultiQueue *parent;
QUEUE headtail; // circularly-linked
- put_callback put_cb;
+ PutCallback put_cb;
void *data;
size_t size;
};
@@ -91,7 +91,7 @@ typedef struct {
static Event NILEVENT = { .handler = NULL, .argv = {NULL} };
-MultiQueue *multiqueue_new_parent(put_callback put_cb, void *data)
+MultiQueue *multiqueue_new_parent(PutCallback put_cb, void *data)
{
return multiqueue_new(NULL, put_cb, data);
}
@@ -104,7 +104,7 @@ MultiQueue *multiqueue_new_child(MultiQueue *parent)
return multiqueue_new(parent, NULL, NULL);
}
-static MultiQueue *multiqueue_new(MultiQueue *parent, put_callback put_cb,
+static MultiQueue *multiqueue_new(MultiQueue *parent, PutCallback put_cb,
void *data)
{
MultiQueue *rv = xmalloc(sizeof(MultiQueue));
diff --git a/src/nvim/event/multiqueue.h b/src/nvim/event/multiqueue.h
index a688107665..dc60fbb4c7 100644
--- a/src/nvim/event/multiqueue.h
+++ b/src/nvim/event/multiqueue.h
@@ -7,7 +7,7 @@
#include "nvim/lib/queue.h"
typedef struct multiqueue MultiQueue;
-typedef void (*put_callback)(MultiQueue *multiq, void *data);
+typedef void (*PutCallback)(MultiQueue *multiq, void *data);
#define multiqueue_put(q, h, ...) \
multiqueue_put_event(q, event_create(h, __VA_ARGS__));