mirror of
https://github.com/neovim/neovim.git
synced 2025-09-13 23:08:16 +00:00
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.
3a97bb3f0f
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
This commit is contained in:
@@ -7324,14 +7324,7 @@ void add_timer_info(typval_T *rettv, timer_T *timer)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (timer->callback.type == kCallbackPartial) {
|
callback_put(&timer->callback, &di->di_tv);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_timer_info_all(typval_T *rettv)
|
void add_timer_info_all(typval_T *rettv)
|
||||||
|
@@ -1164,6 +1164,21 @@ void callback_free(Callback *callback)
|
|||||||
callback->type = kCallbackNone;
|
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
|
/// Remove watcher from a dictionary
|
||||||
///
|
///
|
||||||
/// @param dict Dictionary to remove watcher from.
|
/// @param dict Dictionary to remove watcher from.
|
||||||
|
@@ -73,7 +73,7 @@ struct multiqueue_item {
|
|||||||
struct multiqueue {
|
struct multiqueue {
|
||||||
MultiQueue *parent;
|
MultiQueue *parent;
|
||||||
QUEUE headtail; // circularly-linked
|
QUEUE headtail; // circularly-linked
|
||||||
put_callback put_cb;
|
PutCallback put_cb;
|
||||||
void *data;
|
void *data;
|
||||||
size_t size;
|
size_t size;
|
||||||
};
|
};
|
||||||
@@ -91,7 +91,7 @@ typedef struct {
|
|||||||
|
|
||||||
static Event NILEVENT = { .handler = NULL, .argv = {NULL} };
|
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);
|
return multiqueue_new(NULL, put_cb, data);
|
||||||
}
|
}
|
||||||
@@ -104,7 +104,7 @@ MultiQueue *multiqueue_new_child(MultiQueue *parent)
|
|||||||
return multiqueue_new(parent, NULL, NULL);
|
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)
|
void *data)
|
||||||
{
|
{
|
||||||
MultiQueue *rv = xmalloc(sizeof(MultiQueue));
|
MultiQueue *rv = xmalloc(sizeof(MultiQueue));
|
||||||
|
@@ -7,7 +7,7 @@
|
|||||||
#include "nvim/lib/queue.h"
|
#include "nvim/lib/queue.h"
|
||||||
|
|
||||||
typedef struct multiqueue MultiQueue;
|
typedef struct multiqueue MultiQueue;
|
||||||
typedef void (*put_callback)(MultiQueue *multiq, void *data);
|
typedef void (*PutCallback)(MultiQueue *multiq, void *data);
|
||||||
|
|
||||||
#define multiqueue_put(q, h, ...) \
|
#define multiqueue_put(q, h, ...) \
|
||||||
multiqueue_put_event(q, event_create(h, __VA_ARGS__));
|
multiqueue_put_event(q, event_create(h, __VA_ARGS__));
|
||||||
|
Reference in New Issue
Block a user