mirror of
https://github.com/neovim/neovim.git
synced 2025-10-08 19:06:31 +00:00
API: Refactor: Duplicate/free string arguments coming from msgpack
When receiving strings *from* msgpack, we don't need to duplicate/free since the data only lives in the msgpack parse buffer until the end of the call. But in order to reuse `msgpack_rpc_free_object` when sending event data(which is sent *to* msgpack), Strings must be freed, which means they must also be allocated separately.
This commit is contained in:
@@ -307,7 +307,7 @@ Integer buffer_get_number(Buffer buffer, Error *err)
|
||||
|
||||
String buffer_get_name(Buffer buffer, Error *err)
|
||||
{
|
||||
String rv = {.size = 0, .data = ""};
|
||||
String rv = STRING_INIT;
|
||||
buf_T *buf = find_buffer(buffer, err);
|
||||
|
||||
if (!buf || buf->b_ffname == NULL) {
|
||||
|
@@ -6,6 +6,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#define ARRAY_DICT_INIT {.size = 0, .items = NULL}
|
||||
#define STRING_INIT {.data = NULL, .size = 0}
|
||||
#define REMOTE_TYPE(type) typedef uint64_t type
|
||||
|
||||
#define TYPED_ARRAY_OF(type) \
|
||||
|
@@ -319,7 +319,7 @@ tabpage_T * find_tab(Tabpage tabpage, Error *err)
|
||||
|
||||
String cstr_to_string(const char *str) {
|
||||
if (str == NULL) {
|
||||
return (String) { .data = NULL, .size = 0 };
|
||||
return (String) STRING_INIT;
|
||||
}
|
||||
|
||||
size_t len = strlen(str);
|
||||
|
Reference in New Issue
Block a user