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:
Thiago de Arruda
2014-05-26 13:39:05 -03:00
parent 339d106f7c
commit 4bac5e9ce1
5 changed files with 20 additions and 8 deletions

View File

@@ -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) {

View File

@@ -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) \

View File

@@ -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);