diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/nvim/api/deprecated.c | 20 | ||||
| -rw-r--r-- | src/nvim/api/vim.c | 30 | ||||
| -rw-r--r-- | src/nvim/eval/funcs.c | 4 | ||||
| -rw-r--r-- | src/nvim/generators/gen_api_dispatch.lua | 6 | ||||
| -rw-r--r-- | src/nvim/generators/nvim_version.lua.in | 2 | ||||
| -rw-r--r-- | src/nvim/msgpack_rpc/channel.c | 74 | ||||
| -rw-r--r-- | src/nvim/msgpack_rpc/channel_defs.h | 1 | ||||
| -rw-r--r-- | src/nvim/os/env.c | 14 | ||||
| -rw-r--r-- | src/nvim/os/fs.c | 14 | ||||
| -rw-r--r-- | src/nvim/path.c | 43 |
10 files changed, 61 insertions, 147 deletions
diff --git a/src/nvim/api/deprecated.c b/src/nvim/api/deprecated.c index d63b8411e8..af3bfe2c03 100644 --- a/src/nvim/api/deprecated.c +++ b/src/nvim/api/deprecated.c @@ -786,3 +786,23 @@ theend: api_clear_error(&nested_error); return rv; } + +/// @deprecated +/// +/// @param channel_id Channel id (passed automatically by the dispatcher) +/// @param event Event type string +void nvim_subscribe(uint64_t channel_id, String event) + FUNC_API_SINCE(1) FUNC_API_REMOTE_ONLY +{ + // Does nothing. `rpcnotify(0,…)` broadcasts to all channels, there are no "subscriptions". +} + +/// @deprecated +/// +/// @param channel_id Channel id (passed automatically by the dispatcher) +/// @param event Event type string +void nvim_unsubscribe(uint64_t channel_id, String event) + FUNC_API_SINCE(1) FUNC_API_REMOTE_ONLY +{ + // Does nothing. `rpcnotify(0,…)` broadcasts to all channels, there are no "subscriptions". +} diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index f5b7c8abdd..fc780e1248 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1334,36 +1334,6 @@ void nvim_put(ArrayOf(String) lines, String type, Boolean after, Boolean follow, }); } -/// Subscribes to event broadcasts. -/// -/// @param channel_id Channel id (passed automatically by the dispatcher) -/// @param event Event type string -void nvim_subscribe(uint64_t channel_id, String event) - FUNC_API_SINCE(1) FUNC_API_REMOTE_ONLY -{ - size_t length = (event.size < METHOD_MAXLEN ? event.size : METHOD_MAXLEN); - char e[METHOD_MAXLEN + 1]; - memcpy(e, event.data, length); - e[length] = NUL; - rpc_subscribe(channel_id, e); -} - -/// Unsubscribes to event broadcasts. -/// -/// @param channel_id Channel id (passed automatically by the dispatcher) -/// @param event Event type string -void nvim_unsubscribe(uint64_t channel_id, String event) - FUNC_API_SINCE(1) FUNC_API_REMOTE_ONLY -{ - size_t length = (event.size < METHOD_MAXLEN - ? event.size - : METHOD_MAXLEN); - char e[METHOD_MAXLEN + 1]; - memcpy(e, event.data, length); - e[length] = NUL; - rpc_unsubscribe(channel_id, e); -} - /// Returns the 24-bit RGB value of a |nvim_get_color_map()| color name or /// "#rrggbb" hexadecimal string. /// diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index b1ee33929c..1fc80e88c4 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -6479,7 +6479,7 @@ static void f_resolve(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) char *v = os_resolve_shortcut(fname); if (v == NULL) { if (os_is_reparse_point_include(fname)) { - v = os_realpath(fname, v); + v = os_realpath(fname, NULL, MAXPATHL + 1); } } rettv->vval.v_string = (v == NULL ? xstrdup(fname) : v); @@ -6631,7 +6631,7 @@ static void f_resolve(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) xfree(buf); } # else - char *v = os_realpath(fname, NULL); + char *v = os_realpath(fname, NULL, MAXPATHL + 1); rettv->vval.v_string = v == NULL ? xstrdup(fname) : v; # endif #endif diff --git a/src/nvim/generators/gen_api_dispatch.lua b/src/nvim/generators/gen_api_dispatch.lua index 8ad5858c12..62c99ce082 100644 --- a/src/nvim/generators/gen_api_dispatch.lua +++ b/src/nvim/generators/gen_api_dispatch.lua @@ -260,7 +260,11 @@ fixdict(1 + #version) for _, item in ipairs(version) do -- NB: all items are mandatory. But any error will be less confusing -- with placeholder vim.NIL (than invalid mpack data) - put(item[1], item[2] or vim.NIL) + local val = item[2] + if val == nil then + val = vim.NIL + end + put(item[1], val) end put('build', version_build) diff --git a/src/nvim/generators/nvim_version.lua.in b/src/nvim/generators/nvim_version.lua.in index d0dbf77922..c29141fc68 100644 --- a/src/nvim/generators/nvim_version.lua.in +++ b/src/nvim/generators/nvim_version.lua.in @@ -2,7 +2,7 @@ return { {"major", ${NVIM_VERSION_MAJOR}}, {"minor", ${NVIM_VERSION_MINOR}}, {"patch", ${NVIM_VERSION_PATCH}}, - {"prerelease", "$NVIM_VERSION_PRERELEASE" ~= ""}, + {"prerelease", "${NVIM_VERSION_PRERELEASE}" ~= ""}, {"api_level", ${NVIM_API_LEVEL}}, {"api_compatible", ${NVIM_API_LEVEL_COMPAT}}, {"api_prerelease", ${NVIM_API_PRERELEASE}}, diff --git a/src/nvim/msgpack_rpc/channel.c b/src/nvim/msgpack_rpc/channel.c index 268d6fe6e4..5737a0440f 100644 --- a/src/nvim/msgpack_rpc/channel.c +++ b/src/nvim/msgpack_rpc/channel.c @@ -67,8 +67,6 @@ static void log_notify(char *dir, uint64_t channel_id, const char *name) # define log_notify(...) #endif -static Set(cstr_t) event_strings = SET_INIT; - #ifdef INCLUDE_GENERATED_DECLARATIONS # include "msgpack_rpc/channel.c.generated.h" #endif @@ -111,9 +109,9 @@ static Channel *find_rpc_channel(uint64_t id) return chan; } -/// Publishes an event to a channel. +/// Publishes an event to a channel (emits a notification to method `name`). /// -/// @param id Channel id. 0 means "broadcast to all subscribed channels" +/// @param id Channel id, or 0 to broadcast to all RPC channels. /// @param name Event name (application-defined) /// @param args Array of event arguments /// @return True if the event was sent successfully, false otherwise. @@ -204,41 +202,6 @@ Object rpc_send_call(uint64_t id, const char *method_name, Array args, ArenaMem return frame.errored ? NIL : frame.result; } -/// Subscribes to event broadcasts -/// -/// @param id The channel id -/// @param event The event type string -void rpc_subscribe(uint64_t id, char *event) -{ - Channel *channel; - - if (!(channel = find_rpc_channel(id))) { - abort(); - } - - const char **key_alloc = NULL; - if (set_put_ref(cstr_t, &event_strings, event, &key_alloc)) { - *key_alloc = xstrdup(event); - } - - set_put(cstr_t, channel->rpc.subscribed_events, *key_alloc); -} - -/// Unsubscribes to event broadcasts -/// -/// @param id The channel id -/// @param event The event type string -void rpc_unsubscribe(uint64_t id, char *event) -{ - Channel *channel; - - if (!(channel = find_rpc_channel(id))) { - abort(); - } - - unsubscribe(channel, event); -} - static void receive_msgpack(Stream *stream, RBuffer *rbuf, size_t c, void *data, bool eof) { Channel *channel = data; @@ -494,34 +457,24 @@ static void send_error(Channel *chan, MsgpackRpcRequestHandler handler, MessageT api_clear_error(&e); } +/// Broadcasts a notification to all RPC channels. static void broadcast_event(const char *name, Array args) { - kvec_withinit_t(Channel *, 4) subscribed = KV_INITIAL_VALUE; - kvi_init(subscribed); + kvec_withinit_t(Channel *, 4) chans = KV_INITIAL_VALUE; + kvi_init(chans); Channel *channel; map_foreach_value(&channels, channel, { - if (channel->is_rpc - && set_has(cstr_t, channel->rpc.subscribed_events, name)) { - kv_push(subscribed, channel); + if (channel->is_rpc) { + kv_push(chans, channel); } }); - if (kv_size(subscribed)) { - serialize_request(subscribed.items, kv_size(subscribed), 0, name, args); + if (kv_size(chans)) { + serialize_request(chans.items, kv_size(chans), 0, name, args); } - kvi_destroy(subscribed); -} - -static void unsubscribe(Channel *channel, char *event) -{ - if (!set_has(cstr_t, &event_strings, event)) { - WLOG("RPC: ch %" PRIu64 ": tried to unsubscribe unknown event '%s'", - channel->id, event); - return; - } - set_del(cstr_t, channel->rpc.subscribed_events, event); + kvi_destroy(chans); } /// Mark rpc state as closed, and release its reference to the channel. @@ -551,7 +504,6 @@ void rpc_free(Channel *channel) unpacker_teardown(channel->rpc.unpacker); xfree(channel->rpc.unpacker); - set_destroy(cstr_t, channel->rpc.subscribed_events); kv_destroy(channel->rpc.call_stack); api_free_dictionary(channel->rpc.info); } @@ -719,12 +671,6 @@ const char *get_client_info(Channel *chan, const char *key) #ifdef EXITFREE void rpc_free_all_mem(void) { - cstr_t key; - set_foreach(&event_strings, key, { - xfree((void *)key); - }); - set_destroy(cstr_t, &event_strings); - multiqueue_free(ch_before_blocking_events); } #endif diff --git a/src/nvim/msgpack_rpc/channel_defs.h b/src/nvim/msgpack_rpc/channel_defs.h index 56dbb332e0..7dc1374964 100644 --- a/src/nvim/msgpack_rpc/channel_defs.h +++ b/src/nvim/msgpack_rpc/channel_defs.h @@ -37,7 +37,6 @@ typedef struct { } RequestEvent; typedef struct { - Set(cstr_t) subscribed_events[1]; bool closed; Unpacker *unpacker; uint32_t next_request_id; diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index fbc3a243a6..5a79004c41 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -474,17 +474,9 @@ void init_homedir(void) var = os_homedir(); } - if (var != NULL) { - // Change to the directory and get the actual path. This resolves - // links. Don't do it when we can't return. - if (os_dirname(os_buf, MAXPATHL) == OK && os_chdir(os_buf) == 0) { - if (!os_chdir(var) && os_dirname(IObuff, IOSIZE) == OK) { - var = IObuff; - } - if (os_chdir(os_buf) != 0) { - emsg(_(e_prev_dir)); - } - } + // Get the actual path. This resolves links. + if (var != NULL && os_realpath(var, IObuff, IOSIZE) != NULL) { + var = IObuff; } // Fall back to current working directory if home is not found diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 2eca906d4e..19bdf30311 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -1320,22 +1320,22 @@ bool os_fileid_equal_fileinfo(const FileID *file_id, const FileInfo *file_info) /// Return the canonicalized absolute pathname. /// /// @param[in] name Filename to be canonicalized. -/// @param[out] buf Buffer to store the canonicalized values. A minimum length -// of MAXPATHL+1 is required. If it is NULL, memory is -// allocated. In that case, the caller should deallocate this -// buffer. +/// @param[out] buf Buffer to store the canonicalized values. +/// If it is NULL, memory is allocated. In that case, the caller +/// should deallocate this buffer. +/// @param[in] len The length of the buffer. /// /// @return pointer to the buf on success, or NULL. -char *os_realpath(const char *name, char *buf) +char *os_realpath(const char *name, char *buf, size_t len) FUNC_ATTR_NONNULL_ARG(1) { uv_fs_t request; int result = uv_fs_realpath(NULL, &request, name, NULL); if (result == kLibuvSuccess) { if (buf == NULL) { - buf = xmallocz(MAXPATHL); + buf = xmalloc(len); } - xstrlcpy(buf, request.ptr, MAXPATHL + 1); + xstrlcpy(buf, request.ptr, len); } uv_fs_req_cleanup(&request); return result == kLibuvSuccess ? buf : NULL; diff --git a/src/nvim/path.c b/src/nvim/path.c index f7e8b2b65c..96330e000b 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -2273,13 +2273,20 @@ bool match_suffix(char *fname) /// @return `FAIL` for failure, `OK` for success. int path_full_dir_name(char *directory, char *buffer, size_t len) { - int SUCCESS = 0; - int retval = OK; - if (strlen(directory) == 0) { return os_dirname(buffer, len); } + if (os_realpath(directory, buffer, len) != NULL) { + return OK; + } + + // Path does not exist (yet). For a full path fail, will use the path as-is. + if (path_is_absolute(directory)) { + return FAIL; + } + // For a relative path use the current directory and append the file name. + char old_dir[MAXPATHL]; // Get current directory name. @@ -2287,36 +2294,12 @@ int path_full_dir_name(char *directory, char *buffer, size_t len) return FAIL; } - // We have to get back to the current dir at the end, check if that works. - if (os_chdir(old_dir) != SUCCESS) { + xstrlcpy(buffer, old_dir, len); + if (append_path(buffer, directory, len) == FAIL) { return FAIL; } - if (os_chdir(directory) != SUCCESS) { - // Path does not exist (yet). For a full path fail, - // will use the path as-is. For a relative path use - // the current directory and append the file name. - if (path_is_absolute(directory)) { - // Do not return immediately since we may be in the wrong directory. - retval = FAIL; - } else { - xstrlcpy(buffer, old_dir, len); - if (append_path(buffer, directory, len) == FAIL) { - retval = FAIL; - } - } - } else if (os_dirname(buffer, len) == FAIL) { - // Do not return immediately since we are in the wrong directory. - retval = FAIL; - } - - if (os_chdir(old_dir) != SUCCESS) { - // That shouldn't happen, since we've tested if it works. - retval = FAIL; - emsg(_(e_prev_dir)); - } - - return retval; + return OK; } // Append to_append to path with a slash in between. |