diff options
author | bfredl <bjorn.linse@gmail.com> | 2024-02-20 13:44:50 +0100 |
---|---|---|
committer | bfredl <bjorn.linse@gmail.com> | 2024-02-21 11:58:28 +0100 |
commit | 3cc54586be7760652e8bad88cae82ce74ef9432e (patch) | |
tree | d39cab2ecf5fb8f8bfc44ecf40c6fb2efb13a241 /src/nvim/api/vim.c | |
parent | 9bb046d1be5aa9ba0482b2cad050b286d4b78978 (diff) | |
download | rneovim-3cc54586be7760652e8bad88cae82ce74ef9432e.tar.gz rneovim-3cc54586be7760652e8bad88cae82ce74ef9432e.tar.bz2 rneovim-3cc54586be7760652e8bad88cae82ce74ef9432e.zip |
refactor(api): make freeing of return-value opt-in instead of opt out
As only a few API functions make use of explicit freeing of the return
value, make it opt-in instead. The arena is always present under the
hood, so `Arena *arena` arg now doesn't mean anything other than getting
access to this arena. Also it is in principle possible to return an
allocated value while still using the arena as scratch space for other
stuff (unlikely, but there no reason to not allow it).
Diffstat (limited to 'src/nvim/api/vim.c')
-rw-r--r-- | src/nvim/api/vim.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index c6043a2871..2888656a7a 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -461,7 +461,7 @@ error: /// @see replace_termcodes /// @see cpoptions String nvim_replace_termcodes(String str, Boolean from_part, Boolean do_lt, Boolean special) - FUNC_API_SINCE(1) + FUNC_API_SINCE(1) FUNC_API_RET_ALLOC { if (str.size == 0) { // Empty string @@ -601,6 +601,7 @@ static bool find_runtime_cb(int num_fnames, char **fnames, bool all, void *c) } String nvim__get_lib_dir(void) + FUNC_API_RET_ALLOC { return cstr_as_string(get_lib_dir()); } @@ -1726,7 +1727,7 @@ Array nvim_call_atomic(uint64_t channel_id, Array calls, Arena *arena, Error *er // directly here. But `result` might become invalid when next api function // is called in the loop. ADD_C(results, copy_object(result, arena)); - if (!handler.arena_return) { + if (handler.ret_alloc) { api_free_object(result); } } @@ -1806,9 +1807,9 @@ static void write_msg(String message, bool to_err, bool writeln) /// @param[in] obj Object to return. /// /// @return its argument. -Object nvim__id(Object obj) +Object nvim__id(Object obj, Arena *arena) { - return copy_object(obj, NULL); + return copy_object(obj, arena); } /// Returns array given as argument. @@ -1819,9 +1820,9 @@ Object nvim__id(Object obj) /// @param[in] arr Array to return. /// /// @return its argument. -Array nvim__id_array(Array arr) +Array nvim__id_array(Array arr, Arena *arena) { - return copy_array(arr, NULL); + return copy_array(arr, arena); } /// Returns dictionary given as argument. @@ -1832,9 +1833,9 @@ Array nvim__id_array(Array arr) /// @param[in] dct Dictionary to return. /// /// @return its argument. -Dictionary nvim__id_dictionary(Dictionary dct) +Dictionary nvim__id_dictionary(Dictionary dct, Arena *arena) { - return copy_dictionary(dct, NULL); + return copy_dictionary(dct, arena); } /// Returns floating-point value given as argument. |