aboutsummaryrefslogtreecommitdiff
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
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.
-rw-r--r--scripts/genmsgpack.lua2
-rw-r--r--src/nvim/api/buffer.c4
-rw-r--r--src/nvim/api/private/defs.h27
-rw-r--r--src/nvim/eval.c2
4 files changed, 29 insertions, 6 deletions
diff --git a/scripts/genmsgpack.lua b/scripts/genmsgpack.lua
index d47d637548..aed56b29eb 100644
--- a/scripts/genmsgpack.lua
+++ b/scripts/genmsgpack.lua
@@ -422,7 +422,7 @@ local function process_function(fn)
cparams = cparam .. ', ' .. cparams
end
if fn.receives_channel_id then
- cparams = 'INTERNAL_CALL, ' .. cparams
+ cparams = 'LUA_INTERNAL_CALL, ' .. cparams
end
if fn.can_fail then
cparams = cparams .. '&err'
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;
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index de82f8a145..8b6638f1d7 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -7796,7 +7796,7 @@ static void api_wrapper(typval_T *argvars, typval_T *rettv, FunPtr fptr)
}
Error err = ERROR_INIT;
- Object result = fn(INTERNAL_CALL, args, &err);
+ Object result = fn(VIML_INTERNAL_CALL, args, &err);
if (err.set) {
nvim_err_writeln(cstr_as_string(err.msg));