aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2017-01-20 23:06:22 +0300
committerZyX <kp-pav@yandex.ru>2017-03-27 00:11:28 +0300
commit5c1b9a0d2af86461f56f0d27ed275456921f6187 (patch)
treef1516db36a75c88d6c2a2c87a586ed42c6b01563 /src/nvim/api
parentd932693d5147ac12d181e0810a20bdcbffab2818 (diff)
downloadrneovim-5c1b9a0d2af86461f56f0d27ed275456921f6187.tar.gz
rneovim-5c1b9a0d2af86461f56f0d27ed275456921f6187.tar.bz2
rneovim-5c1b9a0d2af86461f56f0d27ed275456921f6187.zip
api: Reserve more numbers for internal calls
Reasoning; currently INTERNAL_CALL is mostly used to determine whether it is needed to deal with NL-used-as-NUL problem. This code is useful for nvim_… API calls done from VimL, but not for API calls done from lua, yet lua needs to supply something as channel_id.
Diffstat (limited to 'src/nvim/api')
-rw-r--r--src/nvim/api/buffer.c4
-rw-r--r--src/nvim/api/private/defs.h27
2 files changed, 27 insertions, 4 deletions
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index b75a2c7211..5eda88025f 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -192,7 +192,7 @@ ArrayOf(String) nvim_buf_get_lines(uint64_t channel_id,
Object str = STRING_OBJ(cstr_to_string(bufstr));
// Vim represents NULs as NLs, but this may confuse clients.
- if (channel_id != INTERNAL_CALL) {
+ if (channel_id != VIML_INTERNAL_CALL) {
strchrsub(str.data.string.data, '\n', '\0');
}
@@ -313,7 +313,7 @@ void nvim_buf_set_lines(uint64_t channel_id,
// line and convert NULs to newlines to avoid truncation.
lines[i] = xmallocz(l.size);
for (size_t j = 0; j < l.size; j++) {
- if (l.data[j] == '\n' && channel_id != INTERNAL_CALL) {
+ if (l.data[j] == '\n' && channel_id != VIML_INTERNAL_CALL) {
api_set_error(err, Exception, _("string cannot contain newlines"));
new_len = i + 1;
goto end;
diff --git a/src/nvim/api/private/defs.h b/src/nvim/api/private/defs.h
index 86b549cb44..cb7ee8eb4c 100644
--- a/src/nvim/api/private/defs.h
+++ b/src/nvim/api/private/defs.h
@@ -5,6 +5,8 @@
#include <stdbool.h>
#include <string.h>
+#include "nvim/func_attr.h"
+
#define ARRAY_DICT_INIT {.size = 0, .capacity = 0, .items = NULL}
#define STRING_INIT {.data = NULL, .size = 0}
#define OBJECT_INIT { .type = kObjectTypeNil }
@@ -33,8 +35,29 @@ typedef enum {
/// Used as the message ID of notifications.
#define NO_RESPONSE UINT64_MAX
-/// Used as channel_id when the call is local.
-#define INTERNAL_CALL UINT64_MAX
+/// Mask for all internal calls
+#define INTERNAL_CALL_MASK (UINT64_MAX ^ (UINT64_MAX >> 1))
+// (1 << 63) in all forms produces “warning: shift count >= width of type
+// [-Wshift-count-overflow]”
+
+/// Internal call from VimL code
+#define VIML_INTERNAL_CALL INTERNAL_CALL_MASK
+
+/// Internal call from lua code
+#define LUA_INTERNAL_CALL (VIML_INTERNAL_CALL + 1)
+
+static inline bool is_internal_call(uint64_t channel_id)
+ REAL_FATTR_ALWAYS_INLINE REAL_FATTR_CONST;
+
+/// Check whether call is internal
+///
+/// @param[in] channel_id Channel id.
+///
+/// @return true if channel_id refers to internal channel.
+static inline bool is_internal_call(const uint64_t channel_id)
+{
+ return !!(channel_id & INTERNAL_CALL_MASK);
+}
typedef struct {
ErrorType type;