aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/os
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/os')
-rw-r--r--src/nvim/os/channel.c8
-rw-r--r--src/nvim/os/msgpack_rpc.c4
-rw-r--r--src/nvim/os/msgpack_rpc_helpers.c85
-rw-r--r--src/nvim/os/msgpack_rpc_helpers.h92
-rw-r--r--src/nvim/os/provider.c5
5 files changed, 35 insertions, 159 deletions
diff --git a/src/nvim/os/channel.c b/src/nvim/os/channel.c
index bc1bef3a57..5a42db112e 100644
--- a/src/nvim/os/channel.c
+++ b/src/nvim/os/channel.c
@@ -158,7 +158,7 @@ bool channel_send_event(uint64_t id, char *name, Array args)
if (id > 0) {
if (!(channel = pmap_get(uint64_t)(channels, id)) || !channel->enabled) {
- msgpack_rpc_free_array(args);
+ api_free_array(args);
return false;
}
send_event(channel, name, args);
@@ -186,7 +186,7 @@ bool channel_send_call(uint64_t id,
Channel *channel = NULL;
if (!(channel = pmap_get(uint64_t)(channels, id)) || !channel->enabled) {
- msgpack_rpc_free_array(args);
+ api_free_array(args);
return false;
}
@@ -199,7 +199,7 @@ bool channel_send_call(uint64_t id,
"Channel %" PRIu64 " crossed maximum stack depth",
channel->id);
*result = STRING_OBJ(cstr_to_string(buf));
- msgpack_rpc_free_array(args);
+ api_free_array(args);
return false;
}
@@ -448,7 +448,7 @@ static void broadcast_event(char *name, Array args)
});
if (!kv_size(subscribed)) {
- msgpack_rpc_free_array(args);
+ api_free_array(args);
goto end;
}
diff --git a/src/nvim/os/msgpack_rpc.c b/src/nvim/os/msgpack_rpc.c
index fe4918b7d9..2f347d9b15 100644
--- a/src/nvim/os/msgpack_rpc.c
+++ b/src/nvim/os/msgpack_rpc.c
@@ -120,7 +120,7 @@ WBuffer *serialize_request(uint64_t request_id,
sbuffer->size,
refcount,
free);
- msgpack_rpc_free_array(args);
+ api_free_array(args);
msgpack_sbuffer_clear(sbuffer);
return rv;
}
@@ -156,7 +156,7 @@ WBuffer *serialize_response(uint64_t response_id,
sbuffer->size,
1, // responses only go though 1 channel
free);
- msgpack_rpc_free_object(arg);
+ api_free_object(arg);
msgpack_sbuffer_clear(sbuffer);
return rv;
}
diff --git a/src/nvim/os/msgpack_rpc_helpers.c b/src/nvim/os/msgpack_rpc_helpers.c
index 67c37fa8f4..b14de8245c 100644
--- a/src/nvim/os/msgpack_rpc_helpers.c
+++ b/src/nvim/os/msgpack_rpc_helpers.c
@@ -7,11 +7,16 @@
#include "nvim/vim.h"
#include "nvim/memory.h"
+#ifdef INCLUDE_GENERATED_DECLARATIONS
+# include "os/msgpack_rpc_helpers.c.generated.h"
+#endif
+
static msgpack_zone zone;
static msgpack_sbuffer sbuffer;
#define HANDLE_TYPE_CONVERSION_IMPL(t, lt) \
bool msgpack_rpc_to_##lt(msgpack_object *obj, t *arg) \
+ FUNC_ATTR_NONNULL_ALL \
{ \
if (obj->type != MSGPACK_OBJECT_EXT \
|| obj->via.ext.type != kObjectType##t) { \
@@ -34,6 +39,7 @@ static msgpack_sbuffer sbuffer;
} \
\
void msgpack_rpc_from_##lt(t o, msgpack_packer *res) \
+ FUNC_ATTR_NONNULL_ARG(2) \
{ \
msgpack_packer pac; \
msgpack_packer_init(&pac, &sbuffer, msgpack_sbuffer_write); \
@@ -49,13 +55,19 @@ void msgpack_rpc_helpers_init(void)
msgpack_sbuffer_init(&sbuffer);
}
+HANDLE_TYPE_CONVERSION_IMPL(Buffer, buffer)
+HANDLE_TYPE_CONVERSION_IMPL(Window, window)
+HANDLE_TYPE_CONVERSION_IMPL(Tabpage, tabpage)
+
bool msgpack_rpc_to_boolean(msgpack_object *obj, Boolean *arg)
+ FUNC_ATTR_NONNULL_ALL
{
*arg = obj->via.boolean;
return obj->type == MSGPACK_OBJECT_BOOLEAN;
}
bool msgpack_rpc_to_integer(msgpack_object *obj, Integer *arg)
+ FUNC_ATTR_NONNULL_ALL
{
if (obj->type == MSGPACK_OBJECT_POSITIVE_INTEGER
&& obj->via.u64 <= INT64_MAX) {
@@ -68,12 +80,14 @@ bool msgpack_rpc_to_integer(msgpack_object *obj, Integer *arg)
}
bool msgpack_rpc_to_float(msgpack_object *obj, Float *arg)
+ FUNC_ATTR_NONNULL_ALL
{
*arg = obj->via.dec;
return obj->type == MSGPACK_OBJECT_DOUBLE;
}
bool msgpack_rpc_to_string(msgpack_object *obj, String *arg)
+ FUNC_ATTR_NONNULL_ALL
{
if (obj->type == MSGPACK_OBJECT_BIN || obj->type == MSGPACK_OBJECT_STR) {
arg->data = xmemdupz(obj->via.bin.ptr, obj->via.bin.size);
@@ -86,6 +100,7 @@ bool msgpack_rpc_to_string(msgpack_object *obj, String *arg)
}
bool msgpack_rpc_to_object(msgpack_object *obj, Object *arg)
+ FUNC_ATTR_NONNULL_ALL
{
switch (obj->type) {
case MSGPACK_OBJECT_NIL:
@@ -133,6 +148,7 @@ bool msgpack_rpc_to_object(msgpack_object *obj, Object *arg)
}
bool msgpack_rpc_to_array(msgpack_object *obj, Array *arg)
+ FUNC_ATTR_NONNULL_ALL
{
if (obj->type != MSGPACK_OBJECT_ARRAY) {
return false;
@@ -151,6 +167,7 @@ bool msgpack_rpc_to_array(msgpack_object *obj, Array *arg)
}
bool msgpack_rpc_to_dictionary(msgpack_object *obj, Dictionary *arg)
+ FUNC_ATTR_NONNULL_ALL
{
if (obj->type != MSGPACK_OBJECT_MAP) {
return false;
@@ -176,6 +193,7 @@ bool msgpack_rpc_to_dictionary(msgpack_object *obj, Dictionary *arg)
}
void msgpack_rpc_from_boolean(Boolean result, msgpack_packer *res)
+ FUNC_ATTR_NONNULL_ARG(2)
{
if (result) {
msgpack_pack_true(res);
@@ -185,22 +203,26 @@ void msgpack_rpc_from_boolean(Boolean result, msgpack_packer *res)
}
void msgpack_rpc_from_integer(Integer result, msgpack_packer *res)
+ FUNC_ATTR_NONNULL_ARG(2)
{
msgpack_pack_int64(res, result);
}
void msgpack_rpc_from_float(Float result, msgpack_packer *res)
+ FUNC_ATTR_NONNULL_ARG(2)
{
msgpack_pack_double(res, result);
}
void msgpack_rpc_from_string(String result, msgpack_packer *res)
+ FUNC_ATTR_NONNULL_ARG(2)
{
msgpack_pack_bin(res, result.size);
msgpack_pack_bin_body(res, result.data, result.size);
}
void msgpack_rpc_from_object(Object result, msgpack_packer *res)
+ FUNC_ATTR_NONNULL_ARG(2)
{
switch (result.type) {
case kObjectTypeNil:
@@ -246,6 +268,7 @@ void msgpack_rpc_from_object(Object result, msgpack_packer *res)
}
void msgpack_rpc_from_array(Array result, msgpack_packer *res)
+ FUNC_ATTR_NONNULL_ARG(2)
{
msgpack_pack_array(res, result.size);
@@ -255,6 +278,7 @@ void msgpack_rpc_from_array(Array result, msgpack_packer *res)
}
void msgpack_rpc_from_dictionary(Dictionary result, msgpack_packer *res)
+ FUNC_ATTR_NONNULL_ARG(2)
{
msgpack_pack_map(res, result.size);
@@ -263,64 +287,3 @@ void msgpack_rpc_from_dictionary(Dictionary result, msgpack_packer *res)
msgpack_rpc_from_object(result.items[i].value, res);
}
}
-
-void msgpack_rpc_free_string(String value)
-{
- if (!value.data) {
- return;
- }
-
- free(value.data);
-}
-
-void msgpack_rpc_free_object(Object value)
-{
- switch (value.type) {
- case kObjectTypeNil:
- case kObjectTypeBoolean:
- case kObjectTypeInteger:
- case kObjectTypeFloat:
- case kObjectTypeBuffer:
- case kObjectTypeWindow:
- case kObjectTypeTabpage:
- break;
-
- case kObjectTypeString:
- msgpack_rpc_free_string(value.data.string);
- break;
-
- case kObjectTypeArray:
- msgpack_rpc_free_array(value.data.array);
- break;
-
- case kObjectTypeDictionary:
- msgpack_rpc_free_dictionary(value.data.dictionary);
- break;
-
- default:
- abort();
- }
-}
-
-void msgpack_rpc_free_array(Array value)
-{
- for (uint32_t i = 0; i < value.size; i++) {
- msgpack_rpc_free_object(value.items[i]);
- }
-
- free(value.items);
-}
-
-void msgpack_rpc_free_dictionary(Dictionary value)
-{
- for (uint32_t i = 0; i < value.size; i++) {
- msgpack_rpc_free_string(value.items[i].key);
- msgpack_rpc_free_object(value.items[i].value);
- }
-
- free(value.items);
-}
-
-HANDLE_TYPE_CONVERSION_IMPL(Buffer, buffer)
-HANDLE_TYPE_CONVERSION_IMPL(Window, window)
-HANDLE_TYPE_CONVERSION_IMPL(Tabpage, tabpage)
diff --git a/src/nvim/os/msgpack_rpc_helpers.h b/src/nvim/os/msgpack_rpc_helpers.h
index 0eb2d5c77a..aede6b1587 100644
--- a/src/nvim/os/msgpack_rpc_helpers.h
+++ b/src/nvim/os/msgpack_rpc_helpers.h
@@ -6,97 +6,11 @@
#include <msgpack.h>
-#include "nvim/func_attr.h"
#include "nvim/api/private/defs.h"
-void msgpack_rpc_helpers_init(void);
-
-/// Functions for validating and converting from msgpack types to C types.
-/// These are used by `msgpack_rpc_dispatch` to validate and convert each
-/// argument.
-///
-/// @param obj The object to convert
-/// @param[out] arg A pointer to the avalue
-/// @return true if the conversion succeeded, false otherwise
-bool msgpack_rpc_to_boolean(msgpack_object *obj, Boolean *arg)
- FUNC_ATTR_NONNULL_ALL;
-bool msgpack_rpc_to_integer(msgpack_object *obj, Integer *arg)
- FUNC_ATTR_NONNULL_ALL;
-bool msgpack_rpc_to_float(msgpack_object *obj, Float *arg)
- FUNC_ATTR_NONNULL_ALL;
-bool msgpack_rpc_to_string(msgpack_object *obj, String *arg)
- FUNC_ATTR_NONNULL_ALL;
-bool msgpack_rpc_to_buffer(msgpack_object *obj, Buffer *arg)
- FUNC_ATTR_NONNULL_ALL;
-bool msgpack_rpc_to_window(msgpack_object *obj, Window *arg)
- FUNC_ATTR_NONNULL_ALL;
-bool msgpack_rpc_to_tabpage(msgpack_object *obj, Tabpage *arg)
- FUNC_ATTR_NONNULL_ALL;
-bool msgpack_rpc_to_object(msgpack_object *obj, Object *arg)
- FUNC_ATTR_NONNULL_ALL;
-bool msgpack_rpc_to_array(msgpack_object *obj, Array *arg)
- FUNC_ATTR_NONNULL_ALL;
-bool msgpack_rpc_to_dictionary(msgpack_object *obj, Dictionary *arg)
- FUNC_ATTR_NONNULL_ALL;
-
-/// Functions for converting from C types to msgpack types.
-/// These are used by `msgpack_rpc_dispatch` to convert return values
-/// from the API
-///
-/// @param result A pointer to the result
-/// @param res A packer that contains the response
-void msgpack_rpc_from_boolean(Boolean result, msgpack_packer *res)
- FUNC_ATTR_NONNULL_ARG(2);
-void msgpack_rpc_from_integer(Integer result, msgpack_packer *res)
- FUNC_ATTR_NONNULL_ARG(2);
-void msgpack_rpc_from_float(Float result, msgpack_packer *res)
- FUNC_ATTR_NONNULL_ARG(2);
-void msgpack_rpc_from_string(String result, msgpack_packer *res)
- FUNC_ATTR_NONNULL_ARG(2);
-void msgpack_rpc_from_buffer(Buffer result, msgpack_packer *res)
- FUNC_ATTR_NONNULL_ARG(2);
-void msgpack_rpc_from_window(Window result, msgpack_packer *res)
- FUNC_ATTR_NONNULL_ARG(2);
-void msgpack_rpc_from_tabpage(Tabpage result, msgpack_packer *res)
- FUNC_ATTR_NONNULL_ARG(2);
-void msgpack_rpc_from_object(Object result, msgpack_packer *res)
- FUNC_ATTR_NONNULL_ARG(2);
-void msgpack_rpc_from_array(Array result, msgpack_packer *res)
- FUNC_ATTR_NONNULL_ARG(2);
-void msgpack_rpc_from_dictionary(Dictionary result, msgpack_packer *res)
- FUNC_ATTR_NONNULL_ARG(2);
-
-/// Helpers for initializing types that may be freed later
-#define msgpack_rpc_init_boolean
-#define msgpack_rpc_init_integer
-#define msgpack_rpc_init_float
-#define msgpack_rpc_init_position
-#define msgpack_rpc_init_string = STRING_INIT
-#define msgpack_rpc_init_buffer
-#define msgpack_rpc_init_window
-#define msgpack_rpc_init_tabpage
-#define msgpack_rpc_init_object = {.type = kObjectTypeNil}
-#define msgpack_rpc_init_stringarray = ARRAY_DICT_INIT
-#define msgpack_rpc_init_bufferarray = ARRAY_DICT_INIT
-#define msgpack_rpc_init_windowarray = ARRAY_DICT_INIT
-#define msgpack_rpc_init_tabpagearray = ARRAY_DICT_INIT
-#define msgpack_rpc_init_array = ARRAY_DICT_INIT
-#define msgpack_rpc_init_dictionary = ARRAY_DICT_INIT
-
-/// Helpers for freeing arguments/return value
-///
-/// @param value The value to be freed
-#define msgpack_rpc_free_boolean(value)
-#define msgpack_rpc_free_integer(value)
-#define msgpack_rpc_free_float(value)
-#define msgpack_rpc_free_position(value)
-void msgpack_rpc_free_string(String value);
-#define msgpack_rpc_free_buffer(value)
-#define msgpack_rpc_free_window(value)
-#define msgpack_rpc_free_tabpage(value)
-void msgpack_rpc_free_object(Object value);
-void msgpack_rpc_free_array(Array value);
-void msgpack_rpc_free_dictionary(Dictionary value);
+#ifdef INCLUDE_GENERATED_DECLARATIONS
+# include "os/msgpack_rpc_helpers.h.generated.h"
+#endif
#endif // NVIM_OS_MSGPACK_RPC_HELPERS_H
diff --git a/src/nvim/os/provider.c b/src/nvim/os/provider.c
index 07e757fe0e..57c2e57a3c 100644
--- a/src/nvim/os/provider.c
+++ b/src/nvim/os/provider.c
@@ -14,7 +14,6 @@
#include "nvim/log.h"
#include "nvim/map.h"
#include "nvim/message.h"
-#include "nvim/os/msgpack_rpc_helpers.h"
#define FEATURE_COUNT (sizeof(features) / sizeof(features[0]))
@@ -109,7 +108,7 @@ Object provider_call(char *method, Array args)
"Provider for \"%s\" is not available",
method);
report_error(buf);
- msgpack_rpc_free_array(args);
+ api_free_array(args);
return NIL;
}
@@ -119,7 +118,7 @@ Object provider_call(char *method, Array args)
if (error) {
report_error(result.data.string.data);
- msgpack_rpc_free_object(result);
+ api_free_object(result);
return NIL;
}