Skip to content

Commit

Permalink
Merge a8cb510 into 9ddeb6e
Browse files Browse the repository at this point in the history
  • Loading branch information
ZyX-I committed Jan 13, 2018
2 parents 9ddeb6e + a8cb510 commit 51a60c0
Show file tree
Hide file tree
Showing 24 changed files with 426 additions and 204 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ else()
set(DEBUG 0)
endif()

option(LOG_LIST_ACTIONS "Add list actions logging" OFF)

add_definitions(-DINCLUDE_GENERATED_DECLARATIONS)

if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_SYSTEM_NAME STREQUAL "Linux")
Expand Down
1 change: 1 addition & 0 deletions config/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@

#ifndef UNIT_TESTING
#cmakedefine HAVE_JEMALLOC
#cmakedefine LOG_LIST_ACTIONS
#endif

#cmakedefine HAVE_BE64TOH
Expand Down
2 changes: 1 addition & 1 deletion src/nvim/api/private/helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ bool object_to_vim(Object obj, typval_T *tv, Error *err)
break;

case kObjectTypeArray: {
list_T *const list = tv_list_alloc();
list_T *const list = tv_list_alloc((ptrdiff_t)obj.data.array.size);

for (uint32_t i = 0; i < obj.data.array.size; i++) {
Object item = obj.data.array.items[i];
Expand Down
42 changes: 16 additions & 26 deletions src/nvim/channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "nvim/api/ui.h"
#include "nvim/channel.h"
#include "nvim/eval.h"
#include "nvim/eval/encode.h"
#include "nvim/event/socket.h"
#include "nvim/msgpack_rpc/channel.h"
#include "nvim/msgpack_rpc/server.h"
Expand Down Expand Up @@ -522,32 +523,21 @@ size_t channel_send(uint64_t id, char *data, size_t len, const char **error)
return 0;
}

/// NB: mutates buf in place!
static list_T *buffer_to_tv_list(char *buf, size_t count)
{
list_T *ret = tv_list_alloc();
char *ptr = buf;
size_t remaining = count;
size_t off = 0;

while (off < remaining) {
// append the line
if (ptr[off] == NL) {
tv_list_append_string(ret, ptr, (ssize_t)off);
size_t skip = off + 1;
ptr += skip;
remaining -= skip;
off = 0;
continue;
}
if (ptr[off] == NUL) {
// Translate NUL to NL
ptr[off] = NL;
}
off++;
}
tv_list_append_string(ret, ptr, (ssize_t)off);
return ret;
/// Convert binary byte array to a readfile()-style list
///
/// @param[in] buf Array to convert.
/// @param[in] len Array length.
///
/// @return [allocated] Converted list.
static inline list_T *buffer_to_tv_list(const char *const buf, const size_t len)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_ALWAYS_INLINE
{
list_T *const l = tv_list_alloc(kListLenMayKnow);
// Empty buffer should be represented by [''], encode_list_write() thinks
// empty list is fine for the case.
tv_list_append_string(l, "", 0);
encode_list_write(l, buf, len);
return l;
}

// vimscript job callbacks must be executed on Nvim main loop
Expand Down

0 comments on commit 51a60c0

Please sign in to comment.