diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2023-11-30 20:35:25 +0000 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2023-11-30 20:35:25 +0000 |
commit | 1b7b916b7631ddf73c38e3a0070d64e4636cb2f3 (patch) | |
tree | cd08258054db80bb9a11b1061bb091c70b76926a /src/nvim/msgpack_rpc/unpacker.c | |
parent | eaa89c11d0f8aefbb512de769c6c82f61a8baca3 (diff) | |
parent | 4a8bf24ac690004aedf5540fa440e788459e5e34 (diff) | |
download | rneovim-1b7b916b7631ddf73c38e3a0070d64e4636cb2f3.tar.gz rneovim-1b7b916b7631ddf73c38e3a0070d64e4636cb2f3.tar.bz2 rneovim-1b7b916b7631ddf73c38e3a0070d64e4636cb2f3.zip |
Merge remote-tracking branch 'upstream/master' into aucmd_textputpostaucmd_textputpost
Diffstat (limited to 'src/nvim/msgpack_rpc/unpacker.c')
-rw-r--r-- | src/nvim/msgpack_rpc/unpacker.c | 118 |
1 files changed, 59 insertions, 59 deletions
diff --git a/src/nvim/msgpack_rpc/unpacker.c b/src/nvim/msgpack_rpc/unpacker.c index 44a16beb48..38263381bf 100644 --- a/src/nvim/msgpack_rpc/unpacker.c +++ b/src/nvim/msgpack_rpc/unpacker.c @@ -1,6 +1,3 @@ -// 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 <assert.h> #include <stdbool.h> #include <stdlib.h> @@ -8,8 +5,9 @@ #include "klib/kvec.h" #include "mpack/conv.h" #include "nvim/api/private/helpers.h" -#include "nvim/ascii.h" -#include "nvim/macros.h" +#include "nvim/ascii_defs.h" +#include "nvim/grid.h" +#include "nvim/macros_defs.h" #include "nvim/memory.h" #include "nvim/msgpack_rpc/channel_defs.h" #include "nvim/msgpack_rpc/helpers.h" @@ -87,7 +85,7 @@ static void api_parse_enter(mpack_parser_t *parser, mpack_node_t *node) *result = NIL; break; case MPACK_TOKEN_BOOLEAN: - *result = BOOL(mpack_unpack_boolean(node->tok)); + *result = BOOLEAN_OBJ(mpack_unpack_boolean(node->tok)); break; case MPACK_TOKEN_SINT: *result = INTEGER_OBJ(mpack_unpack_sint(node->tok)); @@ -172,14 +170,12 @@ static void api_parse_enter(mpack_parser_t *parser, mpack_node_t *node) node->data[0].p = result; break; } - - default: - abort(); } } static void api_parse_exit(mpack_parser_t *parser, mpack_node_t *node) -{} +{ +} void unpacker_init(Unpacker *p) { @@ -292,13 +288,13 @@ error: // objects. For the moment "redraw/grid_line" uses a hand-rolled decoder, // to avoid a blizzard of small objects for each screen cell. // -// <0>[2, "redraw", <10>[{11}["method", <12>[args], <12>[args], ...], <11>[...], ...]] +// <0>[2, "redraw", <10>[<11>["method", <12>[args], <12>[args], ...], <11>[...], ...]] // // Where [args] gets unpacked as an Array. Note: first {11} is not saved as a state. // // When method is "grid_line", we furthermore decode a cell at a time like: // -// <0>[2, "redraw", <10>[{11}["grid_line", <14>[g, r, c, [<15>[cell], <15>[cell], ...]], ...], <11>[...], ...]] +// <0>[2, "redraw", <10>[<11>["grid_line", <14>[g, r, c, [<15>[cell], <15>[cell], ...], <16>wrap]], <11>[...], ...]] // // where [cell] is [char, repeat, attr], where 'repeat' and 'attr' is optional @@ -323,7 +319,7 @@ bool unpacker_advance(Unpacker *p) return false; } - if (p->state == 15) { + if (p->state == 16) { // grid_line event already unpacked goto done; } else { @@ -358,10 +354,10 @@ done: p->state = 0; return true; case 13: - case 15: + case 16: p->ncalls--; if (p->ncalls > 0) { - p->state = (p->state == 15) ? 14 : 12; + p->state = (p->state == 16) ? 14 : 12; } else if (p->nevents > 0) { p->state = 11; } else { @@ -382,7 +378,6 @@ bool unpacker_parse_redraw(Unpacker *p) size_t size = p->read_size; GridLineEvent *g = p->grid_line_event; -// -V:NEXT_TYPE:501 #define NEXT_TYPE(tok, typ) \ result = mpack_rtoken(&data, &size, &tok); \ if (result == MPACK_EOF) { \ @@ -394,7 +389,6 @@ bool unpacker_parse_redraw(Unpacker *p) return false; \ } -redo: switch (p->state) { case 10: NEXT_TYPE(tok, MPACK_TOKEN_ARRAY); @@ -440,7 +434,7 @@ redo: case 14: NEXT_TYPE(tok, MPACK_TOKEN_ARRAY); int eventarrsize = (int)tok.length; - if (eventarrsize != 4) { + if (eventarrsize != 5) { p->state = -1; return false; } @@ -462,58 +456,64 @@ redo: FALLTHROUGH; case 15: - assert(g->icell < g->ncells); - - NEXT_TYPE(tok, MPACK_TOKEN_ARRAY); - int cellarrsize = (int)tok.length; - if (cellarrsize < 1 || cellarrsize > 3) { - p->state = -1; - return false; - } + for (; g->icell != g->ncells; g->icell++) { + assert(g->icell < g->ncells); + + NEXT_TYPE(tok, MPACK_TOKEN_ARRAY); + int cellarrsize = (int)tok.length; + if (cellarrsize < 1 || cellarrsize > 3) { + p->state = -1; + return false; + } - NEXT_TYPE(tok, MPACK_TOKEN_STR); - if (tok.length > size) { - return false; - } + NEXT_TYPE(tok, MPACK_TOKEN_STR); + if (tok.length > size) { + return false; + } - const char *cellbuf = data; - size_t cellsize = tok.length; - data += cellsize; - size -= cellsize; + const char *cellbuf = data; + size_t cellsize = tok.length; + data += cellsize; + size -= cellsize; - if (cellarrsize >= 2) { - NEXT_TYPE(tok, MPACK_TOKEN_SINT); - g->cur_attr = (int)tok.data.value.lo; - } + if (cellarrsize >= 2) { + NEXT_TYPE(tok, MPACK_TOKEN_SINT); + g->cur_attr = (int)tok.data.value.lo; + } - int repeat = 1; - if (cellarrsize >= 3) { - NEXT_TYPE(tok, MPACK_TOKEN_UINT); - repeat = (int)tok.data.value.lo; - } + int repeat = 1; + if (cellarrsize >= 3) { + NEXT_TYPE(tok, MPACK_TOKEN_UINT); + repeat = (int)tok.data.value.lo; + } - g->clear_width = 0; - if (g->icell == g->ncells - 1 && cellsize == 1 && cellbuf[0] == ' ' && repeat > 1) { - g->clear_width = repeat; - } else { - for (int r = 0; r < repeat; r++) { - if (g->coloff >= (int)grid_line_buf_size) { - p->state = -1; - return false; + g->clear_width = 0; + if (g->icell == g->ncells - 1 && cellsize == 1 && cellbuf[0] == ' ' && repeat > 1) { + g->clear_width = repeat; + } else { + schar_T sc = schar_from_buf(cellbuf, cellsize); + for (int r = 0; r < repeat; r++) { + if (g->coloff >= (int)grid_line_buf_size) { + p->state = -1; + return false; + } + grid_line_buf_char[g->coloff] = sc; + grid_line_buf_attr[g->coloff++] = g->cur_attr; } - memcpy(grid_line_buf_char[g->coloff], cellbuf, cellsize); - grid_line_buf_char[g->coloff][cellsize] = NUL; - grid_line_buf_attr[g->coloff++] = g->cur_attr; } + + p->read_ptr = data; + p->read_size = size; } + p->state = 16; + FALLTHROUGH; - g->icell++; + case 16: + NEXT_TYPE(tok, MPACK_TOKEN_BOOLEAN); + g->wrap = mpack_unpack_boolean(tok); p->read_ptr = data; p->read_size = size; - if (g->icell == g->ncells) { - return true; - } - goto redo; + return true; case 12: return true; |