Files
neovim/src/nvim/api/private/handle.c
Pavel Platto 47084ea765 Use strict function prototypes #945
`-Wstrict-prototypes` warn if a function is declared or defined without
specifying the argument types.

This warning disallow function prototypes with empty parameter list.
In C, a function declared with an empty parameter list accepts an
arbitrary number of arguments when being called. This is for historic
reasons; originally, C functions didn't have prototypes, as C evolved
from B, a typeless language. When prototypes were added, the original
typeless declarations were left in the language for backwards
compatibility.
Instead we should provide `void` in argument list to state
that function doesn't have arguments.

Also this warning disallow declaring type of the parameters after the
parentheses because Neovim header generator produce no declarations for
old-stlyle prototypes: it expects to find `{` after prototype.
2014-07-14 20:28:40 +02:00

42 lines
1.8 KiB
C

#include <assert.h>
#include <stdint.h>
#include "nvim/vim.h"
#include "nvim/map.h"
#include "nvim/api/private/handle.h"
#define HANDLE_INIT(name) name##_handles = pmap_new(uint64_t)()
#define HANDLE_IMPL(type, name) \
static PMap(uint64_t) *name##_handles = NULL; \
\
type *handle_get_##name(uint64_t handle) \
{ \
return pmap_get(uint64_t)(name##_handles, handle); \
} \
\
void handle_register_##name(type *name) \
{ \
assert(!name->handle); \
name->handle = next_handle++; \
pmap_put(uint64_t)(name##_handles, name->handle, name); \
} \
\
void handle_unregister_##name(type *name) \
{ \
pmap_del(uint64_t)(name##_handles, name->handle); \
}
static uint64_t next_handle = 1;
HANDLE_IMPL(buf_T, buffer)
HANDLE_IMPL(win_T, window)
HANDLE_IMPL(tabpage_T, tabpage)
void handle_init(void)
{
HANDLE_INIT(buffer);
HANDLE_INIT(window);
HANDLE_INIT(tabpage);
}