mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
API: Refactor: Implement api/handle module
This module will be used to implement remote management of objects through the API. Object types to be registered must have a `uint64_t` field named 'handle'.
This commit is contained in:
parent
72e3125f45
commit
7dfc7bc2e1
31
src/nvim/api/private/handle.c
Normal file
31
src/nvim/api/private/handle.c
Normal file
@ -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()
|
||||||
|
{
|
||||||
|
}
|
14
src/nvim/api/private/handle.h
Normal file
14
src/nvim/api/private/handle.h
Normal file
@ -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
|
||||||
|
|
@ -85,3 +85,4 @@
|
|||||||
|
|
||||||
MAP_IMPL(cstr_t)
|
MAP_IMPL(cstr_t)
|
||||||
MAP_IMPL(ptr_t)
|
MAP_IMPL(ptr_t)
|
||||||
|
MAP_IMPL(uint64_t)
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
MAP_DECLS(cstr_t)
|
MAP_DECLS(cstr_t)
|
||||||
MAP_DECLS(ptr_t)
|
MAP_DECLS(ptr_t)
|
||||||
|
MAP_DECLS(uint64_t)
|
||||||
|
|
||||||
#define map_new(T) map_##T##_new
|
#define map_new(T) map_##T##_new
|
||||||
#define map_free(T) map_##T##_free
|
#define map_free(T) map_##T##_free
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "nvim/api/private/handle.h"
|
||||||
#include "nvim/vim.h"
|
#include "nvim/vim.h"
|
||||||
#include "nvim/os_unix.h"
|
#include "nvim/os_unix.h"
|
||||||
#include "nvim/buffer.h"
|
#include "nvim/buffer.h"
|
||||||
@ -542,6 +543,7 @@ int mch_nodetype(char_u *name)
|
|||||||
|
|
||||||
void mch_early_init()
|
void mch_early_init()
|
||||||
{
|
{
|
||||||
|
handle_init();
|
||||||
time_init();
|
time_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user