refactor(style): switch-case formatting, "uncrustify:indent-off" #15669

* refactor: disable formatting for attribute in macro
* fixup: disable/enable uncrustify with uncrustify:indent-off/on
* fixup: stop indenting contents inside braces in case
* fixup: remove case brace if no variable declaration
This commit is contained in:
dundargoc
2021-09-17 16:38:16 +02:00
committed by GitHub
parent 1ec3d37192
commit 867e888599
9 changed files with 726 additions and 778 deletions

View File

@@ -1,37 +1,36 @@
// This is an open source non-commercial project. Dear PVS-Studio, please check
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include <inttypes.h>
#include <msgpack.h>
#include <stdbool.h>
#include <string.h>
#include <inttypes.h>
#include <uv.h>
#include <msgpack.h>
#include "nvim/api/private/helpers.h"
#include "nvim/api/vim.h"
#include "nvim/api/ui.h"
#include "nvim/channel.h"
#include "nvim/msgpack_rpc/channel.h"
#include "nvim/event/loop.h"
#include "nvim/event/libuv_process.h"
#include "nvim/event/rstream.h"
#include "nvim/event/wstream.h"
#include "nvim/event/socket.h"
#include "nvim/msgpack_rpc/helpers.h"
#include "nvim/vim.h"
#include "nvim/main.h"
#include "nvim/api/vim.h"
#include "nvim/ascii.h"
#include "nvim/memory.h"
#include "nvim/channel.h"
#include "nvim/eval.h"
#include "nvim/os_unix.h"
#include "nvim/message.h"
#include "nvim/map.h"
#include "nvim/log.h"
#include "nvim/misc1.h"
#include "nvim/event/libuv_process.h"
#include "nvim/event/loop.h"
#include "nvim/event/rstream.h"
#include "nvim/event/socket.h"
#include "nvim/event/wstream.h"
#include "nvim/lib/kvec.h"
#include "nvim/log.h"
#include "nvim/main.h"
#include "nvim/map.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
#include "nvim/msgpack_rpc/channel.h"
#include "nvim/msgpack_rpc/helpers.h"
#include "nvim/os/input.h"
#include "nvim/os_unix.h"
#include "nvim/ui.h"
#include "nvim/vim.h"
#if MIN_LOG_LEVEL > DEBUG_LOG_LEVEL
#define log_client_msg(...)
@@ -102,7 +101,7 @@ bool rpc_send_event(uint64_t id, const char *name, Array args)
if (channel) {
send_event(channel, name, args);
} else {
} else {
broadcast_event(name, args);
}
@@ -116,10 +115,7 @@ bool rpc_send_event(uint64_t id, const char *name, Array args)
/// @param args Array with method arguments
/// @param[out] error True if the return value is an error
/// @return Whatever the remote method returned
Object rpc_send_call(uint64_t id,
const char *method_name,
Array args,
Error *err)
Object rpc_send_call(uint64_t id, const char *method_name, Array args, Error *err)
{
Channel *channel = NULL;
@@ -206,8 +202,7 @@ void rpc_unsubscribe(uint64_t id, char *event)
unsubscribe(channel, event);
}
static void receive_msgpack(Stream *stream, RBuffer *rbuf, size_t c,
void *data, bool eof)
static void receive_msgpack(Stream *stream, RBuffer *rbuf, size_t c, void *data, bool eof)
{
Channel *channel = data;
channel_incref(channel);
@@ -463,10 +458,7 @@ static void send_error(Channel *chan, MessageType type, uint32_t id, char *err)
api_clear_error(&e);
}
static void send_request(Channel *channel,
uint32_t id,
const char *name,
Array args)
static void send_request(Channel *channel, uint32_t id, const char *name, Array args)
{
const String method = cstr_as_string((char *)name);
channel_write(channel, serialize_request(channel->id,
@@ -477,9 +469,7 @@ static void send_request(Channel *channel,
1));
}
static void send_event(Channel *channel,
const char *name,
Array args)
static void send_event(Channel *channel, const char *name, Array args)
{
const String method = cstr_as_string((char *)name);
channel_write(channel, serialize_request(channel->id,
@@ -528,9 +518,9 @@ static void unsubscribe(Channel *channel, char *event)
{
char *event_string = pmap_get(cstr_t)(&event_strings, event);
if (!event_string) {
WLOG("RPC: ch %" PRIu64 ": tried to unsubscribe unknown event '%s'",
channel->id, event);
return;
WLOG("RPC: ch %" PRIu64 ": tried to unsubscribe unknown event '%s'",
channel->id, event);
return;
}
pmap_del(cstr_t)(channel->rpc.subscribed_events, event_string);
@@ -589,10 +579,10 @@ void rpc_free(Channel *channel)
static bool is_rpc_response(msgpack_object *obj)
{
return obj->type == MSGPACK_OBJECT_ARRAY
&& obj->via.array.size == 4
&& obj->via.array.ptr[0].type == MSGPACK_OBJECT_POSITIVE_INTEGER
&& obj->via.array.ptr[0].via.u64 == 1
&& obj->via.array.ptr[1].type == MSGPACK_OBJECT_POSITIVE_INTEGER;
&& obj->via.array.size == 4
&& obj->via.array.ptr[0].type == MSGPACK_OBJECT_POSITIVE_INTEGER
&& obj->via.array.ptr[0].via.u64 == 1
&& obj->via.array.ptr[1].type == MSGPACK_OBJECT_POSITIVE_INTEGER;
}
static bool is_valid_rpc_response(msgpack_object *obj, Channel *channel)
@@ -634,12 +624,8 @@ static void call_set_error(Channel *channel, char *msg, int loglevel)
channel_close(channel->id, kChannelPartRpc, NULL);
}
static WBuffer *serialize_request(uint64_t channel_id,
uint32_t request_id,
const String method,
Array args,
msgpack_sbuffer *sbuffer,
size_t refcount)
static WBuffer *serialize_request(uint64_t channel_id, uint32_t request_id, const String method,
Array args, msgpack_sbuffer *sbuffer, size_t refcount)
{
msgpack_packer pac;
msgpack_packer_init(&pac, sbuffer, msgpack_sbuffer_write);
@@ -654,12 +640,8 @@ static WBuffer *serialize_request(uint64_t channel_id,
return rv;
}
static WBuffer *serialize_response(uint64_t channel_id,
MessageType type,
uint32_t response_id,
Error *err,
Object arg,
msgpack_sbuffer *sbuffer)
static WBuffer *serialize_response(uint64_t channel_id, MessageType type, uint32_t response_id,
Error *err, Object arg, msgpack_sbuffer *sbuffer)
{
msgpack_packer pac;
msgpack_packer_init(&pac, sbuffer, msgpack_sbuffer_write);
@@ -733,47 +715,43 @@ static const char *const msgpack_error_messages[] = {
[MSGPACK_UNPACK_NOMEM_ERROR + MUR_OFF] = "not enough memory",
};
static void log_server_msg(uint64_t channel_id,
msgpack_sbuffer *packed)
static void log_server_msg(uint64_t channel_id, msgpack_sbuffer *packed)
{
msgpack_unpacked unpacked;
msgpack_unpacked_init(&unpacked);
DLOGN("RPC ->ch %" PRIu64 ": ", channel_id);
const msgpack_unpack_return result =
msgpack_unpack_next(&unpacked, packed->data, packed->size, NULL);
msgpack_unpack_next(&unpacked, packed->data, packed->size, NULL);
switch (result) {
case MSGPACK_UNPACK_SUCCESS: {
uint64_t type = unpacked.data.via.array.ptr[0].via.u64;
log_lock();
FILE *f = open_log_file();
fprintf(f, type ? (type == 1 ? RES : NOT) : REQ);
log_msg_close(f, unpacked.data);
msgpack_unpacked_destroy(&unpacked);
break;
}
case MSGPACK_UNPACK_EXTRA_BYTES:
case MSGPACK_UNPACK_CONTINUE:
case MSGPACK_UNPACK_PARSE_ERROR:
case MSGPACK_UNPACK_NOMEM_ERROR: {
log_lock();
FILE *f = open_log_file();
fprintf(f, ERR);
log_msg_close(f, (msgpack_object) {
.type = MSGPACK_OBJECT_STR,
.via.str = {
.ptr = (char *)msgpack_error_messages[result + MUR_OFF],
.size = (uint32_t)strlen(
msgpack_error_messages[result + MUR_OFF]),
},
case MSGPACK_UNPACK_SUCCESS: {
uint64_t type = unpacked.data.via.array.ptr[0].via.u64;
log_lock();
FILE *f = open_log_file();
fprintf(f, type ? (type == 1 ? RES : NOT) : REQ);
log_msg_close(f, unpacked.data);
msgpack_unpacked_destroy(&unpacked);
break;
}
case MSGPACK_UNPACK_EXTRA_BYTES:
case MSGPACK_UNPACK_CONTINUE:
case MSGPACK_UNPACK_PARSE_ERROR:
case MSGPACK_UNPACK_NOMEM_ERROR: {
log_lock();
FILE *f = open_log_file();
fprintf(f, ERR);
log_msg_close(f, (msgpack_object) {
.type = MSGPACK_OBJECT_STR,
.via.str = {
.ptr = (char *)msgpack_error_messages[result + MUR_OFF],
.size = (uint32_t)strlen(msgpack_error_messages[result + MUR_OFF]),
},
});
break;
}
break;
}
}
}
static void log_client_msg(uint64_t channel_id,
bool is_request,
msgpack_object msg)
static void log_client_msg(uint64_t channel_id, bool is_request, msgpack_object msg)
{
DLOGN("RPC <-ch %" PRIu64 ": ", channel_id);
log_lock();

View File

@@ -1,19 +1,18 @@
// This is an open source non-commercial project. Dear PVS-Studio, please check
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include <stdbool.h>
#include <inttypes.h>
#include <msgpack.h>
#include <stdbool.h>
#include "nvim/api/private/dispatch.h"
#include "nvim/api/private/helpers.h"
#include "nvim/msgpack_rpc/helpers.h"
#include "nvim/assert.h"
#include "nvim/lib/kvec.h"
#include "nvim/vim.h"
#include "nvim/log.h"
#include "nvim/memory.h"
#include "nvim/assert.h"
#include "nvim/msgpack_rpc/helpers.h"
#include "nvim/vim.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "msgpack_rpc/helpers.c.generated.h"
@@ -48,15 +47,17 @@ static msgpack_sbuffer sbuffer;
} \
\
static void msgpack_rpc_from_##lt(Integer o, msgpack_packer *res) \
/* uncrustify:indent-off */ \
FUNC_ATTR_NONNULL_ARG(2) \
/* uncrustify:indent-on */ \
{ \
msgpack_packer pac; \
msgpack_packer_init(&pac, &sbuffer, msgpack_sbuffer_write); \
msgpack_pack_int64(&pac, (handle_T)o); \
msgpack_pack_ext(res, sbuffer.size, \
kObjectType##t - EXT_OBJECT_TYPE_SHIFT); \
msgpack_pack_ext_body(res, sbuffer.data, sbuffer.size); \
msgpack_sbuffer_clear(&sbuffer); \
msgpack_packer pac; \
msgpack_packer_init(&pac, &sbuffer, msgpack_sbuffer_write); \
msgpack_pack_int64(&pac, (handle_T)o); \
msgpack_pack_ext(res, sbuffer.size, \
kObjectType##t - EXT_OBJECT_TYPE_SHIFT); \
msgpack_pack_ext_body(res, sbuffer.data, sbuffer.size); \
msgpack_sbuffer_clear(&sbuffer); \
}
void msgpack_rpc_helpers_init(void)
@@ -89,177 +90,167 @@ bool msgpack_rpc_to_object(const msgpack_object *const obj, Object *const arg)
kvec_withinit_t(MPToAPIObjectStackItem, 2) stack = KV_INITIAL_VALUE;
kvi_init(stack);
kvi_push(stack, ((MPToAPIObjectStackItem) {
.mobj = obj,
.aobj = arg,
.container = false,
.idx = 0,
}));
.mobj = obj,
.aobj = arg,
.container = false,
.idx = 0,
}));
while (ret && kv_size(stack)) {
MPToAPIObjectStackItem cur = kv_last(stack);
if (!cur.container) {
*cur.aobj = NIL;
}
switch (cur.mobj->type) {
case MSGPACK_OBJECT_NIL: {
break;
}
case MSGPACK_OBJECT_BOOLEAN: {
*cur.aobj = BOOLEAN_OBJ(cur.mobj->via.boolean);
break;
}
case MSGPACK_OBJECT_NEGATIVE_INTEGER: {
STATIC_ASSERT(sizeof(Integer) == sizeof(cur.mobj->via.i64),
"Msgpack integer size does not match API integer");
*cur.aobj = INTEGER_OBJ(cur.mobj->via.i64);
break;
}
case MSGPACK_OBJECT_POSITIVE_INTEGER: {
STATIC_ASSERT(sizeof(Integer) == sizeof(cur.mobj->via.u64),
"Msgpack integer size does not match API integer");
if (cur.mobj->via.u64 > API_INTEGER_MAX) {
ret = false;
} else {
*cur.aobj = INTEGER_OBJ((Integer)cur.mobj->via.u64);
}
break;
case MSGPACK_OBJECT_NIL:
break;
case MSGPACK_OBJECT_BOOLEAN:
*cur.aobj = BOOLEAN_OBJ(cur.mobj->via.boolean);
break;
case MSGPACK_OBJECT_NEGATIVE_INTEGER:
STATIC_ASSERT(sizeof(Integer) == sizeof(cur.mobj->via.i64),
"Msgpack integer size does not match API integer");
*cur.aobj = INTEGER_OBJ(cur.mobj->via.i64);
break;
case MSGPACK_OBJECT_POSITIVE_INTEGER:
STATIC_ASSERT(sizeof(Integer) == sizeof(cur.mobj->via.u64),
"Msgpack integer size does not match API integer");
if (cur.mobj->via.u64 > API_INTEGER_MAX) {
ret = false;
} else {
*cur.aobj = INTEGER_OBJ((Integer)cur.mobj->via.u64);
}
break;
#ifdef NVIM_MSGPACK_HAS_FLOAT32
case MSGPACK_OBJECT_FLOAT32:
case MSGPACK_OBJECT_FLOAT64:
case MSGPACK_OBJECT_FLOAT32:
case MSGPACK_OBJECT_FLOAT64:
#else
case MSGPACK_OBJECT_FLOAT:
case MSGPACK_OBJECT_FLOAT:
#endif
{
STATIC_ASSERT(sizeof(Float) == sizeof(cur.mobj->via.f64),
"Msgpack floating-point size does not match API integer");
*cur.aobj = FLOAT_OBJ(cur.mobj->via.f64);
break;
}
{
STATIC_ASSERT(sizeof(Float) == sizeof(cur.mobj->via.f64),
"Msgpack floating-point size does not match API integer");
*cur.aobj = FLOAT_OBJ(cur.mobj->via.f64);
break;
}
#define STR_CASE(type, attr, obj, dest, conv) \
case type: { \
dest = conv(((String) { \
.size = obj->via.attr.size, \
.data = (obj->via.attr.ptr == NULL || obj->via.attr.size == 0 \
case type: { \
dest = conv(((String) { \
.size = obj->via.attr.size, \
.data = (obj->via.attr.ptr == NULL || obj->via.attr.size == 0 \
? xmemdupz("", 0) \
: xmemdupz(obj->via.attr.ptr, obj->via.attr.size)), \
})); \
break; \
}
})); \
break; \
}
STR_CASE(MSGPACK_OBJECT_STR, str, cur.mobj, *cur.aobj, STRING_OBJ)
STR_CASE(MSGPACK_OBJECT_BIN, bin, cur.mobj, *cur.aobj, STRING_OBJ)
case MSGPACK_OBJECT_ARRAY: {
const size_t size = cur.mobj->via.array.size;
if (cur.container) {
if (cur.idx >= size) {
(void)kv_pop(stack);
} else {
const size_t idx = cur.idx;
cur.idx++;
kv_last(stack) = cur;
kvi_push(stack, ((MPToAPIObjectStackItem) {
.mobj = &cur.mobj->via.array.ptr[idx],
.aobj = &cur.aobj->data.array.items[idx],
.container = false,
}));
}
case MSGPACK_OBJECT_ARRAY: {
const size_t size = cur.mobj->via.array.size;
if (cur.container) {
if (cur.idx >= size) {
(void)kv_pop(stack);
} else {
*cur.aobj = ARRAY_OBJ(((Array) {
.size = size,
.capacity = size,
.items = (size > 0
? xcalloc(size, sizeof(*cur.aobj->data.array.items))
: NULL),
}));
cur.container = true;
const size_t idx = cur.idx;
cur.idx++;
kv_last(stack) = cur;
}
break;
}
case MSGPACK_OBJECT_MAP: {
const size_t size = cur.mobj->via.map.size;
if (cur.container) {
if (cur.idx >= size) {
(void)kv_pop(stack);
} else {
const size_t idx = cur.idx;
cur.idx++;
kv_last(stack) = cur;
const msgpack_object *const key = &cur.mobj->via.map.ptr[idx].key;
switch (key->type) {
#define ID(x) x
STR_CASE(MSGPACK_OBJECT_STR, str, key,
cur.aobj->data.dictionary.items[idx].key, ID)
STR_CASE(MSGPACK_OBJECT_BIN, bin, key,
cur.aobj->data.dictionary.items[idx].key, ID)
#undef ID
case MSGPACK_OBJECT_NIL:
case MSGPACK_OBJECT_BOOLEAN:
case MSGPACK_OBJECT_POSITIVE_INTEGER:
case MSGPACK_OBJECT_NEGATIVE_INTEGER:
#ifdef NVIM_MSGPACK_HAS_FLOAT32
case MSGPACK_OBJECT_FLOAT32:
case MSGPACK_OBJECT_FLOAT64:
#else
case MSGPACK_OBJECT_FLOAT:
#endif
case MSGPACK_OBJECT_EXT:
case MSGPACK_OBJECT_MAP:
case MSGPACK_OBJECT_ARRAY: {
ret = false;
break;
}
}
if (ret) {
kvi_push(stack, ((MPToAPIObjectStackItem) {
.mobj = &cur.mobj->via.map.ptr[idx].val,
.aobj = &cur.aobj->data.dictionary.items[idx].value,
kvi_push(stack, ((MPToAPIObjectStackItem) {
.mobj = &cur.mobj->via.array.ptr[idx],
.aobj = &cur.aobj->data.array.items[idx],
.container = false,
}));
}
}
}
} else {
*cur.aobj = ARRAY_OBJ(((Array) {
.size = size,
.capacity = size,
.items = (size > 0
? xcalloc(size, sizeof(*cur.aobj->data.array.items))
: NULL),
}));
cur.container = true;
kv_last(stack) = cur;
}
break;
}
case MSGPACK_OBJECT_MAP: {
const size_t size = cur.mobj->via.map.size;
if (cur.container) {
if (cur.idx >= size) {
(void)kv_pop(stack);
} else {
*cur.aobj = DICTIONARY_OBJ(((Dictionary) {
.size = size,
.capacity = size,
.items = (size > 0
const size_t idx = cur.idx;
cur.idx++;
kv_last(stack) = cur;
const msgpack_object *const key = &cur.mobj->via.map.ptr[idx].key;
switch (key->type) {
#define ID(x) x
STR_CASE(MSGPACK_OBJECT_STR, str, key,
cur.aobj->data.dictionary.items[idx].key, ID)
STR_CASE(MSGPACK_OBJECT_BIN, bin, key,
cur.aobj->data.dictionary.items[idx].key, ID)
#undef ID
case MSGPACK_OBJECT_NIL:
case MSGPACK_OBJECT_BOOLEAN:
case MSGPACK_OBJECT_POSITIVE_INTEGER:
case MSGPACK_OBJECT_NEGATIVE_INTEGER:
#ifdef NVIM_MSGPACK_HAS_FLOAT32
case MSGPACK_OBJECT_FLOAT32:
case MSGPACK_OBJECT_FLOAT64:
#else
case MSGPACK_OBJECT_FLOAT:
#endif
case MSGPACK_OBJECT_EXT:
case MSGPACK_OBJECT_MAP:
case MSGPACK_OBJECT_ARRAY:
ret = false;
break;
}
if (ret) {
kvi_push(stack, ((MPToAPIObjectStackItem) {
.mobj = &cur.mobj->via.map.ptr[idx].val,
.aobj = &cur.aobj->data.dictionary.items[idx].value,
.container = false,
}));
}
}
} else {
*cur.aobj = DICTIONARY_OBJ(((Dictionary) {
.size = size,
.capacity = size,
.items = (size > 0
? xcalloc(size, sizeof(*cur.aobj->data.dictionary.items))
: NULL),
}));
cur.container = true;
kv_last(stack) = cur;
}
break;
}
case MSGPACK_OBJECT_EXT: {
switch ((ObjectType)(cur.mobj->via.ext.type + EXT_OBJECT_TYPE_SHIFT)) {
case kObjectTypeBuffer: {
cur.aobj->type = kObjectTypeBuffer;
ret = msgpack_rpc_to_buffer(cur.mobj, &cur.aobj->data.integer);
break;
}
case kObjectTypeWindow: {
cur.aobj->type = kObjectTypeWindow;
ret = msgpack_rpc_to_window(cur.mobj, &cur.aobj->data.integer);
break;
}
case kObjectTypeTabpage: {
cur.aobj->type = kObjectTypeTabpage;
ret = msgpack_rpc_to_tabpage(cur.mobj, &cur.aobj->data.integer);
break;
}
case kObjectTypeNil:
case kObjectTypeBoolean:
case kObjectTypeInteger:
case kObjectTypeFloat:
case kObjectTypeString:
case kObjectTypeArray:
case kObjectTypeDictionary:
case kObjectTypeLuaRef: {
break;
}
}
}));
cur.container = true;
kv_last(stack) = cur;
}
break;
}
case MSGPACK_OBJECT_EXT:
switch ((ObjectType)(cur.mobj->via.ext.type + EXT_OBJECT_TYPE_SHIFT)) {
case kObjectTypeBuffer:
cur.aobj->type = kObjectTypeBuffer;
ret = msgpack_rpc_to_buffer(cur.mobj, &cur.aobj->data.integer);
break;
case kObjectTypeWindow:
cur.aobj->type = kObjectTypeWindow;
ret = msgpack_rpc_to_window(cur.mobj, &cur.aobj->data.integer);
break;
case kObjectTypeTabpage:
cur.aobj->type = kObjectTypeTabpage;
ret = msgpack_rpc_to_tabpage(cur.mobj, &cur.aobj->data.integer);
break;
case kObjectTypeNil:
case kObjectTypeBoolean:
case kObjectTypeInteger:
case kObjectTypeFloat:
case kObjectTypeString:
case kObjectTypeArray:
case kObjectTypeDictionary:
case kObjectTypeLuaRef:
break;
}
break;
#undef STR_CASE
}
if (!cur.container) {
@@ -270,8 +261,7 @@ bool msgpack_rpc_to_object(const msgpack_object *const obj, Object *const arg)
return ret;
}
static bool msgpack_rpc_to_string(const msgpack_object *const obj,
String *const arg)
static bool msgpack_rpc_to_string(const msgpack_object *const obj, String *const arg)
FUNC_ATTR_NONNULL_ALL
{
if (obj->type == MSGPACK_OBJECT_BIN || obj->type == MSGPACK_OBJECT_STR) {
@@ -303,8 +293,7 @@ bool msgpack_rpc_to_array(const msgpack_object *const obj, Array *const arg)
return true;
}
bool msgpack_rpc_to_dictionary(const msgpack_object *const obj,
Dictionary *const arg)
bool msgpack_rpc_to_dictionary(const msgpack_object *const obj, Dictionary *const arg)
FUNC_ATTR_NONNULL_ALL
{
if (obj->type != MSGPACK_OBJECT_MAP) {
@@ -317,12 +306,12 @@ bool msgpack_rpc_to_dictionary(const msgpack_object *const obj,
for (uint32_t i = 0; i < obj->via.map.size; i++) {
if (!msgpack_rpc_to_string(&obj->via.map.ptr[i].key,
&arg->items[i].key)) {
&arg->items[i].key)) {
return false;
}
if (!msgpack_rpc_to_object(&obj->via.map.ptr[i].val,
&arg->items[i].value)) {
&arg->items[i].value)) {
return false;
}
}
@@ -385,86 +374,78 @@ void msgpack_rpc_from_object(const Object result, msgpack_packer *const res)
&& kObjectTypeTabpage == kObjectTypeWindow + 1,
"Buffer, window and tabpage enum items are in order");
switch (cur.aobj->type) {
case kObjectTypeNil:
case kObjectTypeLuaRef: {
// TODO(bfredl): could also be an error. Though kObjectTypeLuaRef
// should only appear when the caller has opted in to handle references,
// see nlua_pop_Object.
msgpack_pack_nil(res);
break;
}
case kObjectTypeBoolean: {
msgpack_rpc_from_boolean(cur.aobj->data.boolean, res);
break;
}
case kObjectTypeInteger: {
msgpack_rpc_from_integer(cur.aobj->data.integer, res);
break;
}
case kObjectTypeFloat: {
msgpack_rpc_from_float(cur.aobj->data.floating, res);
break;
}
case kObjectTypeString: {
msgpack_rpc_from_string(cur.aobj->data.string, res);
break;
}
case kObjectTypeBuffer: {
msgpack_rpc_from_buffer(cur.aobj->data.integer, res);
break;
}
case kObjectTypeWindow: {
msgpack_rpc_from_window(cur.aobj->data.integer, res);
break;
}
case kObjectTypeTabpage: {
msgpack_rpc_from_tabpage(cur.aobj->data.integer, res);
break;
}
case kObjectTypeArray: {
const size_t size = cur.aobj->data.array.size;
if (cur.container) {
if (cur.idx >= size) {
(void)kv_pop(stack);
} else {
const size_t idx = cur.idx;
cur.idx++;
kv_last(stack) = cur;
kvi_push(stack, ((APIToMPObjectStackItem) {
.aobj = &cur.aobj->data.array.items[idx],
.container = false,
}));
}
case kObjectTypeNil:
case kObjectTypeLuaRef:
// TODO(bfredl): could also be an error. Though kObjectTypeLuaRef
// should only appear when the caller has opted in to handle references,
// see nlua_pop_Object.
msgpack_pack_nil(res);
break;
case kObjectTypeBoolean:
msgpack_rpc_from_boolean(cur.aobj->data.boolean, res);
break;
case kObjectTypeInteger:
msgpack_rpc_from_integer(cur.aobj->data.integer, res);
break;
case kObjectTypeFloat:
msgpack_rpc_from_float(cur.aobj->data.floating, res);
break;
case kObjectTypeString:
msgpack_rpc_from_string(cur.aobj->data.string, res);
break;
case kObjectTypeBuffer:
msgpack_rpc_from_buffer(cur.aobj->data.integer, res);
break;
case kObjectTypeWindow:
msgpack_rpc_from_window(cur.aobj->data.integer, res);
break;
case kObjectTypeTabpage:
msgpack_rpc_from_tabpage(cur.aobj->data.integer, res);
break;
case kObjectTypeArray: {
const size_t size = cur.aobj->data.array.size;
if (cur.container) {
if (cur.idx >= size) {
(void)kv_pop(stack);
} else {
msgpack_pack_array(res, size);
cur.container = true;
const size_t idx = cur.idx;
cur.idx++;
kv_last(stack) = cur;
kvi_push(stack, ((APIToMPObjectStackItem) {
.aobj = &cur.aobj->data.array.items[idx],
.container = false,
}));
}
break;
} else {
msgpack_pack_array(res, size);
cur.container = true;
kv_last(stack) = cur;
}
case kObjectTypeDictionary: {
const size_t size = cur.aobj->data.dictionary.size;
if (cur.container) {
if (cur.idx >= size) {
(void)kv_pop(stack);
} else {
const size_t idx = cur.idx;
cur.idx++;
kv_last(stack) = cur;
msgpack_rpc_from_string(cur.aobj->data.dictionary.items[idx].key,
res);
kvi_push(stack, ((APIToMPObjectStackItem) {
.aobj = &cur.aobj->data.dictionary.items[idx].value,
.container = false,
}));
}
break;
}
case kObjectTypeDictionary: {
const size_t size = cur.aobj->data.dictionary.size;
if (cur.container) {
if (cur.idx >= size) {
(void)kv_pop(stack);
} else {
msgpack_pack_map(res, size);
cur.container = true;
const size_t idx = cur.idx;
cur.idx++;
kv_last(stack) = cur;
msgpack_rpc_from_string(cur.aobj->data.dictionary.items[idx].key,
res);
kvi_push(stack, ((APIToMPObjectStackItem) {
.aobj = &cur.aobj->data.dictionary.items[idx].value,
.container = false,
}));
}
break;
} else {
msgpack_pack_map(res, size);
cur.container = true;
kv_last(stack) = cur;
}
break;
}
}
if (!cur.container) {
(void)kv_pop(stack);
@@ -495,9 +476,7 @@ void msgpack_rpc_from_dictionary(Dictionary result, msgpack_packer *res)
}
/// Serializes a msgpack-rpc request or notification(id == 0)
void msgpack_rpc_serialize_request(uint32_t request_id,
const String method,
Array args,
void msgpack_rpc_serialize_request(uint32_t request_id, const String method, Array args,
msgpack_packer *pac)
FUNC_ATTR_NONNULL_ARG(4)
{
@@ -513,9 +492,7 @@ void msgpack_rpc_serialize_request(uint32_t request_id,
}
/// Serializes a msgpack-rpc response
void msgpack_rpc_serialize_response(uint32_t response_id,
Error *err,
Object arg,
void msgpack_rpc_serialize_response(uint32_t response_id, Error *err, Object arg,
msgpack_packer *pac)
FUNC_ATTR_NONNULL_ARG(2, 4)
{
@@ -546,15 +523,15 @@ static bool msgpack_rpc_is_notification(msgpack_object *req)
msgpack_object *msgpack_rpc_method(msgpack_object *req)
{
msgpack_object *obj = req->via.array.ptr
+ (msgpack_rpc_is_notification(req) ? 1 : 2);
+ (msgpack_rpc_is_notification(req) ? 1 : 2);
return obj->type == MSGPACK_OBJECT_STR || obj->type == MSGPACK_OBJECT_BIN ?
obj : NULL;
obj : NULL;
}
msgpack_object *msgpack_rpc_args(msgpack_object *req)
{
msgpack_object *obj = req->via.array.ptr
+ (msgpack_rpc_is_notification(req) ? 2 : 3);
+ (msgpack_rpc_is_notification(req) ? 2 : 3);
return obj->type == MSGPACK_OBJECT_ARRAY ? obj : NULL;
}
@@ -567,8 +544,7 @@ static msgpack_object *msgpack_rpc_msg_id(msgpack_object *req)
return obj->type == MSGPACK_OBJECT_POSITIVE_INTEGER ? obj : NULL;
}
MessageType msgpack_rpc_validate(uint32_t *response_id, msgpack_object *req,
Error *err)
MessageType msgpack_rpc_validate(uint32_t *response_id, msgpack_object *req, Error *err)
{
*response_id = 0;
// Validate the basic structure of the msgpack-rpc payload

View File

@@ -2,24 +2,24 @@
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include <assert.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include "nvim/ascii.h"
#include "nvim/eval.h"
#include "nvim/event/socket.h"
#include "nvim/fileio.h"
#include "nvim/garray.h"
#include "nvim/log.h"
#include "nvim/main.h"
#include "nvim/memory.h"
#include "nvim/msgpack_rpc/channel.h"
#include "nvim/msgpack_rpc/server.h"
#include "nvim/os/os.h"
#include "nvim/event/socket.h"
#include "nvim/ascii.h"
#include "nvim/eval.h"
#include "nvim/garray.h"
#include "nvim/vim.h"
#include "nvim/main.h"
#include "nvim/memory.h"
#include "nvim/log.h"
#include "nvim/fileio.h"
#include "nvim/path.h"
#include "nvim/strings.h"
#include "nvim/vim.h"
#define MAX_CONNECTIONS 32
#define LISTEN_ADDRESS_ENV_VAR "NVIM_LISTEN_ADDRESS"
@@ -90,7 +90,7 @@ char *server_address_new(void)
static uint32_t count = 0;
char template[ADDRESS_MAX_SIZE];
snprintf(template, ADDRESS_MAX_SIZE,
"\\\\.\\pipe\\nvim-%" PRIu64 "-%" PRIu32, os_get_pid(), count++);
"\\\\.\\pipe\\nvim-%" PRIu64 "-%" PRIu32, os_get_pid(), count++);
return xstrdup(template);
#else
return (char *)vim_tempname();