mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
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.
This commit is contained in:
parent
d932693d51
commit
5c1b9a0d2a
@ -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'
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user