From da15b5c1f3230b127ebdbe52d449d1ee8104b2ae Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 18 Apr 2016 15:55:51 +0300 Subject: api/helpers: Use typval_encode.h for vim_to_object This ought to prevent stack overflow, but I do not see this actually working: *lua* code crashes with stack overflow when trying to deserialize msgpack from Neovim, Neovim is fine even if nesting level is increased 100x (though test becomes very slow); not sure how recursive function may survive this. So it looks like there are currently only two positive effects: 1. NULL lists are returned as empty (#4596). 2. Functional tests are slightly more fast. Very slightly. Checked for Release build for test/functional/eval tests because benchmarking of debug mode is not very useful. --- src/nvim/api/private/helpers.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/nvim/api/private/helpers.h') diff --git a/src/nvim/api/private/helpers.h b/src/nvim/api/private/helpers.h index 731f186ecc..a946e35149 100644 --- a/src/nvim/api/private/helpers.h +++ b/src/nvim/api/private/helpers.h @@ -27,6 +27,10 @@ .type = kObjectTypeInteger, \ .data.integer = i }) +#define FLOATING_OBJ(f) ((Object) { \ + .type = kObjectTypeFloat, \ + .data.floating = f }) + #define STRING_OBJ(s) ((Object) { \ .type = kObjectTypeString, \ .data.string = s }) @@ -61,6 +65,13 @@ #define STATIC_CSTR_AS_STRING(s) ((String) {.data = s, .size = sizeof(s) - 1}) +/// Create a new String instance, putting data in allocated memory +/// +/// @param[in] s String to work with. Must be a string literal. +#define STATIC_CSTR_TO_STRING(s) ((String){ \ + .data = xmemdupz(s, sizeof(s) - 1), \ + .size = sizeof(s) - 1 }) + // Helpers used by the generated msgpack-rpc api wrappers #define api_init_boolean #define api_init_integer -- cgit