diff options
-rw-r--r-- | src/nvim/api/private/handle.c | 31 | ||||
-rw-r--r-- | src/nvim/api/private/handle.h | 14 | ||||
-rw-r--r-- | src/nvim/map.c | 1 | ||||
-rw-r--r-- | src/nvim/map.h | 1 | ||||
-rw-r--r-- | src/nvim/os_unix.c | 2 |
5 files changed, 49 insertions, 0 deletions
diff --git a/src/nvim/api/private/handle.c b/src/nvim/api/private/handle.c new file mode 100644 index 0000000000..3bf519bc58 --- /dev/null +++ b/src/nvim/api/private/handle.c @@ -0,0 +1,31 @@ +#include <stdint.h> + +#include "nvim/vim.h" +#include "nvim/map.h" +#include "nvim/api/private/handle.h" + +#define HANDLE_INIT(name) name##_handles = map_new(uint64_t)() + +#define HANDLE_IMPL(type, name) \ + static Map(uint64_t) *name##_handles = NULL; \ + \ + type *handle_get_##name(uint64_t handle) \ + { \ + return map_get(uint64_t)(name##_handles, handle); \ + } \ + \ + void handle_register_##name(type *name) \ + { \ + assert(!name->handle); \ + name->handle = next_handle++; \ + map_put(uint64_t)(name##_handles, name->handle, name); \ + } \ + \ + void handle_unregister_##name(type *name) \ + { \ + map_del(uint64_t)(name##_handles, name->handle); \ + } + +void handle_init() +{ +} diff --git a/src/nvim/api/private/handle.h b/src/nvim/api/private/handle.h new file mode 100644 index 0000000000..b9ed507ce9 --- /dev/null +++ b/src/nvim/api/private/handle.h @@ -0,0 +1,14 @@ +#ifndef NVIM_API_HANDLE_H +#define NVIM_API_HANDLE_H + +#include "nvim/vim.h" + +#define HANDLE_DECLS(type, name) \ + type *handle_get_##name(uint64_t handle); \ + void handle_register_##name(type *name); \ + void handle_unregister_##name(type *name); + +void handle_init(void); + +#endif // NVIM_API_HANDLE_H + diff --git a/src/nvim/map.c b/src/nvim/map.c index 28fd0af61c..559a5f261a 100644 --- a/src/nvim/map.c +++ b/src/nvim/map.c @@ -85,3 +85,4 @@ MAP_IMPL(cstr_t) MAP_IMPL(ptr_t) +MAP_IMPL(uint64_t) diff --git a/src/nvim/map.h b/src/nvim/map.h index ae47561deb..dba56dc5aa 100644 --- a/src/nvim/map.h +++ b/src/nvim/map.h @@ -21,6 +21,7 @@ MAP_DECLS(cstr_t) MAP_DECLS(ptr_t) +MAP_DECLS(uint64_t) #define map_new(T) map_##T##_new #define map_free(T) map_##T##_free diff --git a/src/nvim/os_unix.c b/src/nvim/os_unix.c index 52627b6a8b..e0b838ed26 100644 --- a/src/nvim/os_unix.c +++ b/src/nvim/os_unix.c @@ -27,6 +27,7 @@ #include <string.h> +#include "nvim/api/private/handle.h" #include "nvim/vim.h" #include "nvim/os_unix.h" #include "nvim/buffer.h" @@ -542,6 +543,7 @@ int mch_nodetype(char_u *name) void mch_early_init() { + handle_init(); time_init(); } |