diff options
author | Thiago de Arruda <tpadilha84@gmail.com> | 2014-09-03 18:43:58 -0300 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-09-12 13:25:28 -0300 |
commit | 505985b870b4b9d7cae07354518b28dd12ee5b6f (patch) | |
tree | c50b06d479a4d0caa505a527050ec3a42a2eb4ad /src | |
parent | 41a48a3fc7d6f170d0c5ed852f1bf98ea3a89f27 (diff) | |
download | rneovim-505985b870b4b9d7cae07354518b28dd12ee5b6f.tar.gz rneovim-505985b870b4b9d7cae07354518b28dd12ee5b6f.tar.bz2 rneovim-505985b870b4b9d7cae07354518b28dd12ee5b6f.zip |
msgpack-rpc: Remove the `msgpack_rpc_unpack` function
The `msgpack_rpc_unpack` function was created to work around a deficiency in the
msgpack unpack API, which did not let the caller know if parsing failed due to
needing more data or to invalid input. The deficiency does not exist in the
latest version of `msgpack_unpacker_next`, so it can safely be removed.
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/os/channel.c | 15 | ||||
-rw-r--r-- | src/nvim/os/msgpack_rpc.c | 36 |
2 files changed, 11 insertions, 40 deletions
diff --git a/src/nvim/os/channel.c b/src/nvim/os/channel.c index bad82bc272..bc1bef3a57 100644 --- a/src/nvim/os/channel.c +++ b/src/nvim/os/channel.c @@ -22,8 +22,10 @@ #include "nvim/memory.h" #include "nvim/os_unix.h" #include "nvim/message.h" +#include "nvim/term.h" #include "nvim/map.h" #include "nvim/log.h" +#include "nvim/misc1.h" #include "nvim/lib/kvec.h" #define CHANNEL_BUFFER_SIZE 0xffff @@ -331,11 +333,10 @@ static void parse_msgpack(RStream *rstream, void *data, bool eof) msgpack_unpacked unpacked; msgpack_unpacked_init(&unpacked); - UnpackResult result; + msgpack_unpack_return result; // Deserialize everything we can. - while ((result = msgpack_rpc_unpack(channel->unpacker, &unpacked)) - == kUnpackResultOk) { + while ((result = msgpack_unpacker_next(channel->unpacker, &unpacked))) { if (kv_size(channel->call_stack) && is_rpc_response(&unpacked.data)) { if (is_valid_rpc_response(&unpacked.data, channel)) { call_stack_pop(&unpacked.data, channel); @@ -362,7 +363,13 @@ static void parse_msgpack(RStream *rstream, void *data, bool eof) } } - if (result == kUnpackResultFail) { + if (result == MSGPACK_UNPACK_NOMEM_ERROR) { + OUT_STR(e_outofmem); + out_char('\n'); + preserve_exit(); + } + + if (result == MSGPACK_UNPACK_PARSE_ERROR) { // See src/msgpack/unpack_template.h in msgpack source tree for // causes for this error(search for 'goto _failed') // diff --git a/src/nvim/os/msgpack_rpc.c b/src/nvim/os/msgpack_rpc.c index 485ef0d04b..fe4918b7d9 100644 --- a/src/nvim/os/msgpack_rpc.c +++ b/src/nvim/os/msgpack_rpc.c @@ -57,42 +57,6 @@ WBuffer *msgpack_rpc_call(uint64_t channel_id, return serialize_response(response_id, NULL, rv, sbuffer); } -/// Try to unpack a msgpack document from the data in the unpacker buffer. This -/// function is a replacement to msgpack.h `msgpack_unpack_next` that lets -/// the called know if the unpacking failed due to bad input or due to missing -/// data. -/// -/// @param unpacker The unpacker containing the parse buffer -/// @param result The result which will contain the parsed object -/// @return kUnpackResultOk : An object was parsed -/// kUnpackResultFail : Got bad input -/// kUnpackResultNeedMore: Need more data -UnpackResult msgpack_rpc_unpack(msgpack_unpacker* unpacker, - msgpack_unpacked* result) - FUNC_ATTR_NONNULL_ALL -{ - if (result->zone != NULL) { - msgpack_zone_free(result->zone); - } - - int res = msgpack_unpacker_execute(unpacker); - - if (res > 0) { - result->zone = msgpack_unpacker_release_zone(unpacker); - result->data = msgpack_unpacker_data(unpacker); - msgpack_unpacker_reset(unpacker); - return kUnpackResultOk; - } - - if (res < 0) { - // Since we couldn't parse it, destroy the data consumed so far - msgpack_unpacker_reset(unpacker); - return kUnpackResultFail; - } - - return kUnpackResultNeedMore; -} - /// Finishes the msgpack-rpc call with an error message. /// /// @param msg The error message |