diff options
author | Thiago de Arruda <tpadilha84@gmail.com> | 2014-10-22 11:40:38 -0300 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-10-22 11:40:38 -0300 |
commit | 2f31c3d6ce665ea9aceea700b29858e6e2bc7e62 (patch) | |
tree | 059e5ccf4d4173cc8bc335cd553941ed23e43147 /src | |
parent | 5cd9b6474287650790e97187058c81b176fbc7c9 (diff) | |
parent | b31a74ad11c8943b795d132c7d3e3c961d048118 (diff) | |
download | rneovim-2f31c3d6ce665ea9aceea700b29858e6e2bc7e62.tar.gz rneovim-2f31c3d6ce665ea9aceea700b29858e6e2bc7e62.tar.bz2 rneovim-2f31c3d6ce665ea9aceea700b29858e6e2bc7e62.zip |
Merge PR #1326 'Add verification of log macros'
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/api/private/helpers.c | 98 | ||||
-rw-r--r-- | src/nvim/msgpack_rpc/channel.c | 5 | ||||
-rw-r--r-- | src/nvim/os/input.c | 4 | ||||
-rw-r--r-- | src/nvim/os/rstream.c | 5 |
4 files changed, 103 insertions, 9 deletions
diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 093cb0e55f..784915cd16 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -1,4 +1,5 @@ #include <assert.h> +#include <inttypes.h> #include <stdbool.h> #include <stdlib.h> #include <string.h> @@ -553,6 +554,103 @@ Dictionary api_metadata(void) return copy_object(DICTIONARY_OBJ(metadata)).data.dictionary; } +char *api_stringify(Object obj) +{ + Array array = ARRAY_DICT_INIT; + print_to_array(obj, &array); + size_t size = 0; + for (size_t i = 0; i < array.size; i++) { + size += array.items[i].data.string.size; + } + + char *rv = xmalloc(size + 1); + size_t pos = 0; + for (size_t i = 0; i < array.size; i++) { + String str = array.items[i].data.string; + memcpy(rv + pos, str.data, str.size); + pos += str.size; + free(str.data); + } + rv[pos] = NUL; + free(array.items); + return rv; +} + +static void print_to_array(Object obj, Array *array) +{ + char buf[32]; + + switch (obj.type) { + case kObjectTypeNil: + ADD(*array, STRING_OBJ(cstr_to_string("nil"))); + break; + + case kObjectTypeBoolean: + ADD(*array, + STRING_OBJ(cstr_to_string(obj.data.boolean ? "true" : "false"))); + break; + + case kObjectTypeInteger: + snprintf(buf, sizeof(buf), "%" PRId64, obj.data.integer); + ADD(*array, STRING_OBJ(cstr_to_string(buf))); + break; + + case kObjectTypeFloat: + snprintf(buf, sizeof(buf), "%f", obj.data.floating); + ADD(*array, STRING_OBJ(cstr_to_string(buf))); + break; + + case kObjectTypeBuffer: + snprintf(buf, sizeof(buf), "Buffer(%" PRIu64 ")", obj.data.buffer); + ADD(*array, STRING_OBJ(cstr_to_string(buf))); + break; + + case kObjectTypeWindow: + snprintf(buf, sizeof(buf), "Window(%" PRIu64 ")", obj.data.window); + ADD(*array, STRING_OBJ(cstr_to_string(buf))); + break; + + case kObjectTypeTabpage: + snprintf(buf, sizeof(buf), "Tabpage(%" PRIu64 ")", obj.data.tabpage); + ADD(*array, STRING_OBJ(cstr_to_string(buf))); + break; + + case kObjectTypeString: + ADD(*array, STRING_OBJ(cstr_to_string("\""))); + ADD(*array, STRING_OBJ(cstr_to_string(obj.data.string.data))); + ADD(*array, STRING_OBJ(cstr_to_string("\""))); + break; + + case kObjectTypeArray: + ADD(*array, STRING_OBJ(cstr_to_string("["))); + for (size_t i = 0; i < obj.data.array.size; i++) { + print_to_array(obj.data.array.items[i], array); + if (i < obj.data.array.size - 1) { + ADD(*array, STRING_OBJ(cstr_to_string(", "))); + } + } + ADD(*array, STRING_OBJ(cstr_to_string("]"))); + break; + + case kObjectTypeDictionary: + ADD(*array, STRING_OBJ(cstr_to_string("{"))); + for (size_t i = 0; i < obj.data.dictionary.size; i++) { + ADD(*array, + STRING_OBJ(cstr_to_string(obj.data.dictionary.items[i].key.data))); + ADD(*array, STRING_OBJ(cstr_to_string(": "))); + print_to_array(obj.data.dictionary.items[i].value, array); + if (i < obj.data.array.size - 1) { + ADD(*array, STRING_OBJ(cstr_to_string(", "))); + } + } + ADD(*array, STRING_OBJ(cstr_to_string("}"))); + break; + + default: + ADD(*array, STRING_OBJ(cstr_to_string("INVALID"))); + } +} + static void init_error_type_metadata(Dictionary *metadata) { Dictionary types = ARRAY_DICT_INIT; diff --git a/src/nvim/msgpack_rpc/channel.c b/src/nvim/msgpack_rpc/channel.c index a1ab12f7c3..94605c37e9 100644 --- a/src/nvim/msgpack_rpc/channel.c +++ b/src/nvim/msgpack_rpc/channel.c @@ -461,15 +461,10 @@ static void call_request_handler(Channel *channel, msgpack_packer_init(&response, &out_buffer, msgpack_sbuffer_write); if (error.set) { - ELOG("Error dispatching msgpack-rpc call: %s(request: id %" PRIu64 ")", - error.msg, - request_id); channel_write(channel, serialize_response(request_id, &error, NIL, &out_buffer)); } - DLOG("Successfully completed mspgack-rpc call(request id: %" PRIu64 ")", - request_id); channel_write(channel, serialize_response(request_id, &error, result, &out_buffer)); } diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index b7eba47d5e..2c8026d099 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -264,15 +264,15 @@ static void convert_input(void) for (int i = (int)count - 1; i >= 0; i--) { if (inbuf[i] == 3) { + got_int = true; consume_count = (size_t)i; break; } } - if (consume_count) { + if (got_int) { // Remove everything typed before the CTRL-C rbuffer_consumed(input_buffer, consume_count); - got_int = true; } } diff --git a/src/nvim/os/rstream.c b/src/nvim/os/rstream.c index 8cfd9d1b75..d96b3d931c 100644 --- a/src/nvim/os/rstream.c +++ b/src/nvim/os/rstream.c @@ -73,13 +73,14 @@ void rbuffer_consumed(RBuffer *rbuffer, size_t count) void rbuffer_produced(RBuffer *rbuffer, size_t count) { rbuffer->wpos += count; - DLOG("Received %u bytes from RStream(%p)", (size_t)cnt, rbuffer->rstream); + DLOG("Received %u bytes from RStream(%p)", (size_t)count, rbuffer->rstream); rbuffer_relocate(rbuffer); if (rbuffer->rstream && rbuffer->wpos == rbuffer->capacity) { // The last read filled the buffer, stop reading for now + // rstream_stop(rbuffer->rstream); - DLOG("Buffer for RStream(%p) is full, stopping it", rstream); + DLOG("Buffer for RStream(%p) is full, stopping it", rbuffer->rstream); } } |