From 543e0256c19f397921a332e06b423215fd9aecb5 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 30 Nov 2023 15:51:05 +0800 Subject: build: don't define FUNC_ATTR_* as empty in headers (#26317) FUNC_ATTR_* should only be used in .c files with generated headers. Defining FUNC_ATTR_* as empty in headers causes misuses of them to be silently ignored. Instead don't define them by default, and only define them as empty after a .c file has included its generated header. --- src/nvim/api/private/converter.c | 1 - src/nvim/api/private/helpers.c | 1 - 2 files changed, 2 deletions(-) (limited to 'src/nvim/api/private') diff --git a/src/nvim/api/private/converter.c b/src/nvim/api/private/converter.c index 90023171e5..ef57bde32d 100644 --- a/src/nvim/api/private/converter.c +++ b/src/nvim/api/private/converter.c @@ -11,7 +11,6 @@ #include "nvim/eval/typval.h" #include "nvim/eval/typval_defs.h" #include "nvim/eval/userfunc.h" -#include "nvim/func_attr.h" #include "nvim/lua/executor.h" #include "nvim/memory.h" #include "nvim/types_defs.h" diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index be39836a5b..b23684aee9 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -20,7 +20,6 @@ #include "nvim/eval/typval_defs.h" #include "nvim/eval/vars.h" #include "nvim/ex_eval.h" -#include "nvim/func_attr.h" #include "nvim/garray.h" #include "nvim/globals.h" #include "nvim/highlight_group.h" -- cgit From ce56e0a845d68862118f44cb66c5f080e3c1bbed Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 30 Nov 2023 17:16:57 +0800 Subject: refactor(IWYU): move UI and LineFlags to ui_defs.h (#26318) --- src/nvim/api/private/dispatch.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/nvim/api/private') diff --git a/src/nvim/api/private/dispatch.h b/src/nvim/api/private/dispatch.h index 6a2c9eaf54..88f846f813 100644 --- a/src/nvim/api/private/dispatch.h +++ b/src/nvim/api/private/dispatch.h @@ -14,12 +14,12 @@ typedef Object (*ApiDispatchWrapper)(uint64_t channel_id, Array args, Arena *are struct MsgpackRpcRequestHandler { const char *name; ApiDispatchWrapper fn; - bool fast; // Function is safe to be executed immediately while running the - // uv loop (the loop is run very frequently due to breakcheck). - // If "fast" is false, the function is deferred, i e the call will - // be put in the event queue, for safe handling later. - bool arena_return; // return value is allocated in the arena (or statically) - // and should not be freed as such. + bool fast; ///< Function is safe to be executed immediately while running the + ///< uv loop (the loop is run very frequently due to breakcheck). + ///< If "fast" is false, the function is deferred, i e the call will + ///< be put in the event queue, for safe handling later. + bool arena_return; ///< return value is allocated in the arena (or statically) + ///< and should not be freed as such. }; extern const MsgpackRpcRequestHandler method_handlers[]; -- cgit From cca6c4c6986abc67cd213ad1d32d329384a57790 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 6 Dec 2023 17:02:13 +0100 Subject: feat(rpc): allow empty string key in msgpack => Vim conversion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Since e057b38e7037 #20757 we support empty key in JSON encode/decode, but we don't allow it in RPC object => Vim dict conversion. But empty string is a valid key in Vim dicts and the msgpack spec. Empty string key was disallowed in 7c01d5ff9286 (2014) but that commit/PR doesn't explicitly discuss it, so presumably it was a "seems reasonable" decision (or Vimscript didn't allow empty keys until later). Solution: Remove the check in `object_to_vim()`. Note that `tv_dict_item_alloc_len` will invoke `memcpy(…, 0)` but that's allowed by the C spec: https://stackoverflow.com/a/3751937/152142 --- src/nvim/api/private/converter.c | 9 --------- 1 file changed, 9 deletions(-) (limited to 'src/nvim/api/private') diff --git a/src/nvim/api/private/converter.c b/src/nvim/api/private/converter.c index ef57bde32d..1e11683c38 100644 --- a/src/nvim/api/private/converter.c +++ b/src/nvim/api/private/converter.c @@ -328,15 +328,6 @@ bool object_to_vim(Object obj, typval_T *tv, Error *err) for (uint32_t i = 0; i < obj.data.dictionary.size; i++) { KeyValuePair item = obj.data.dictionary.items[i]; String key = item.key; - - if (key.size == 0) { - api_set_error(err, kErrorTypeValidation, - "Empty dictionary keys aren't allowed"); - // cleanup - tv_dict_free(dict); - return false; - } - dictitem_T *const di = tv_dict_item_alloc(key.data); if (!object_to_vim(item.value, &di->di_tv, err)) { -- cgit From a16218d4c6773c474011149661470af6e8c90892 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 7 Dec 2023 13:01:42 +0100 Subject: refactor: object_to_vim() cannot fail Since the parent commit, object_to_vim() can't fail, so callers don't need to check its result. --- src/nvim/api/private/converter.c | 22 +++------------------- src/nvim/api/private/helpers.c | 4 +--- 2 files changed, 4 insertions(+), 22 deletions(-) (limited to 'src/nvim/api/private') diff --git a/src/nvim/api/private/converter.c b/src/nvim/api/private/converter.c index 1e11683c38..e7b8934c97 100644 --- a/src/nvim/api/private/converter.c +++ b/src/nvim/api/private/converter.c @@ -258,9 +258,7 @@ Object vim_to_object(typval_T *obj) /// @param tv Conversion result is placed here. On failure member v_type is /// set to VAR_UNKNOWN (no allocation was made for this variable). /// @param err Error object. -/// -/// @returns true if conversion is successful, otherwise false. -bool object_to_vim(Object obj, typval_T *tv, Error *err) +void object_to_vim(Object obj, typval_T *tv, Error *err) { tv->v_type = VAR_UNKNOWN; tv->v_lock = VAR_UNLOCKED; @@ -307,12 +305,7 @@ bool object_to_vim(Object obj, typval_T *tv, Error *err) for (uint32_t i = 0; i < obj.data.array.size; i++) { Object item = obj.data.array.items[i]; typval_T li_tv; - - if (!object_to_vim(item, &li_tv, err)) { - tv_list_free(list); - return false; - } - + object_to_vim(item, &li_tv, err); tv_list_append_owned_tv(list, li_tv); } tv_list_ref(list); @@ -329,14 +322,7 @@ bool object_to_vim(Object obj, typval_T *tv, Error *err) KeyValuePair item = obj.data.dictionary.items[i]; String key = item.key; dictitem_T *const di = tv_dict_item_alloc(key.data); - - if (!object_to_vim(item.value, &di->di_tv, err)) { - // cleanup - tv_dict_item_free(di); - tv_dict_free(dict); - return false; - } - + object_to_vim(item.value, &di->di_tv, err); tv_dict_add(dict, di); } dict->dv_refcount++; @@ -353,6 +339,4 @@ bool object_to_vim(Object obj, typval_T *tv, Error *err) break; } } - - return true; } diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index b23684aee9..2772fa8b59 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -253,9 +253,7 @@ Object dict_set_var(dict_T *dict, String key, Object value, bool del, bool retva typval_T tv; // Convert the object to a vimscript type in the temporary variable - if (!object_to_vim(value, &tv, err)) { - return rv; - } + object_to_vim(value, &tv, err); typval_T oldtv = TV_INITIAL_VALUE; -- cgit From 69bc519b53ebf78fd95c8256468e7d538ebcb948 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Tue, 12 Dec 2023 15:40:21 +0100 Subject: refactor: move non-symbols to defs.h headers --- src/nvim/api/private/dispatch.h | 2 +- src/nvim/api/private/helpers.c | 1 - src/nvim/api/private/helpers.h | 8 +------- 3 files changed, 2 insertions(+), 9 deletions(-) (limited to 'src/nvim/api/private') diff --git a/src/nvim/api/private/dispatch.h b/src/nvim/api/private/dispatch.h index 88f846f813..b627db6b00 100644 --- a/src/nvim/api/private/dispatch.h +++ b/src/nvim/api/private/dispatch.h @@ -27,5 +27,5 @@ extern const MsgpackRpcRequestHandler method_handlers[]; #ifdef INCLUDE_GENERATED_DECLARATIONS # include "api/private/dispatch.h.generated.h" # include "api/private/dispatch_wrappers.h.generated.h" // IWYU pragma: export -# include "keysets_defs.generated.h" +# include "keysets_defs.generated.h" // IWYU pragma: export #endif diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 2772fa8b59..70e63d0ad5 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -17,7 +17,6 @@ #include "nvim/ascii_defs.h" #include "nvim/buffer_defs.h" #include "nvim/eval/typval.h" -#include "nvim/eval/typval_defs.h" #include "nvim/eval/vars.h" #include "nvim/ex_eval.h" #include "nvim/garray.h" diff --git a/src/nvim/api/private/helpers.h b/src/nvim/api/private/helpers.h index e61dd5f992..64558f0410 100644 --- a/src/nvim/api/private/helpers.h +++ b/src/nvim/api/private/helpers.h @@ -2,21 +2,15 @@ #include #include -#include #include "klib/kvec.h" #include "nvim/api/private/defs.h" -#include "nvim/api/private/dispatch.h" -#include "nvim/decoration.h" -#include "nvim/eval/typval_defs.h" #include "nvim/ex_eval_defs.h" -#include "nvim/getchar.h" #include "nvim/gettext.h" #include "nvim/globals.h" #include "nvim/macros_defs.h" #include "nvim/map_defs.h" -#include "nvim/memory.h" -#include "nvim/message.h" +#include "nvim/message_defs.h" // IWYU pragma: keep #define OBJECT_OBJ(o) o -- cgit From d82a586a9e39f1d346c1aea78167a85c586ed3f4 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 18 Dec 2023 06:18:11 +0800 Subject: refactor: move some anonymous enums back to non-defs headers (#26622) It isn't really useful to put anonymous enums only used as arguments to functions calls in _defs.h headers, as they will only be used by a file that calls those functions, which requires including a non-defs header. Also move os_msg() and os_errmsg() back to message.h, as on Windows they are actual functions instead of macros. Also remove gettext.h and globals.h from private/helpers.h. --- src/nvim/api/private/helpers.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/api/private') diff --git a/src/nvim/api/private/helpers.h b/src/nvim/api/private/helpers.h index 64558f0410..701ce91257 100644 --- a/src/nvim/api/private/helpers.h +++ b/src/nvim/api/private/helpers.h @@ -5,9 +5,9 @@ #include "klib/kvec.h" #include "nvim/api/private/defs.h" +#include "nvim/buffer_defs.h" // IWYU pragma: keep +#include "nvim/eval/typval_defs.h" // IWYU pragma: keep #include "nvim/ex_eval_defs.h" -#include "nvim/gettext.h" -#include "nvim/globals.h" #include "nvim/macros_defs.h" #include "nvim/map_defs.h" #include "nvim/message_defs.h" // IWYU pragma: keep -- cgit From 1cf51a07a6bfb827efc36911cd018da3a3cb863b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 19 Dec 2023 08:01:05 +0800 Subject: fix(api): don't set coladd of mark (#26648) --- src/nvim/api/private/helpers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/private') diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 70e63d0ad5..23ec815346 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -1044,7 +1044,7 @@ bool set_mark(buf_T *buf, String name, Integer line, Integer col, Error *err) } } assert(INT32_MIN <= line && line <= INT32_MAX); - pos_T pos = { (linenr_T)line, (int)col, (int)col }; + pos_T pos = { (linenr_T)line, (int)col, 0 }; res = setmark_pos(*name.data, &pos, buf->handle, NULL); if (!res) { if (deleting) { -- cgit From af93a74a0f4afa9a3a4f55ffdf28141eaf776d22 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 18 Dec 2023 10:55:23 +0100 Subject: refactor: run IWYU on entire repo Reference: https://github.com/neovim/neovim/issues/6371. --- src/nvim/api/private/converter.h | 2 +- src/nvim/api/private/dispatch.h | 2 +- src/nvim/api/private/helpers.h | 2 +- src/nvim/api/private/validate.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/api/private') diff --git a/src/nvim/api/private/converter.h b/src/nvim/api/private/converter.h index fc82abf332..a5acc56c7c 100644 --- a/src/nvim/api/private/converter.h +++ b/src/nvim/api/private/converter.h @@ -1,6 +1,6 @@ #pragma once -#include "nvim/api/private/defs.h" // IWYU pragma: keep +#include "nvim/api/private/defs.h" // IWYU pragma: export #include "nvim/eval/typval_defs.h" // IWYU pragma: keep #ifdef INCLUDE_GENERATED_DECLARATIONS diff --git a/src/nvim/api/private/dispatch.h b/src/nvim/api/private/dispatch.h index b627db6b00..d322c1ceca 100644 --- a/src/nvim/api/private/dispatch.h +++ b/src/nvim/api/private/dispatch.h @@ -3,7 +3,7 @@ #include #include -#include "nvim/api/private/defs.h" +#include "nvim/api/private/defs.h" // IWYU pragma: export #include "nvim/memory_defs.h" #include "nvim/types_defs.h" diff --git a/src/nvim/api/private/helpers.h b/src/nvim/api/private/helpers.h index 701ce91257..1ee66f906b 100644 --- a/src/nvim/api/private/helpers.h +++ b/src/nvim/api/private/helpers.h @@ -4,7 +4,7 @@ #include #include "klib/kvec.h" -#include "nvim/api/private/defs.h" +#include "nvim/api/private/defs.h" // IWYU pragma: export #include "nvim/buffer_defs.h" // IWYU pragma: keep #include "nvim/eval/typval_defs.h" // IWYU pragma: keep #include "nvim/ex_eval_defs.h" diff --git a/src/nvim/api/private/validate.h b/src/nvim/api/private/validate.h index d1c977cd6e..692ea46176 100644 --- a/src/nvim/api/private/validate.h +++ b/src/nvim/api/private/validate.h @@ -3,7 +3,7 @@ #include #include -#include "nvim/api/private/defs.h" +#include "nvim/api/private/defs.h" // IWYU pragma: export #include "nvim/api/private/helpers.h" #include "nvim/assert_defs.h" #include "nvim/macros_defs.h" -- cgit From ba0fa4fa197330687b06c74a50b2ccd4800f5881 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 22 Dec 2023 13:32:46 +0800 Subject: refactor(IWYU): add "private" pragma to more generated headers (#26706) "export" only prevents IWYU from adding these headers if the headers that export them are included, while "private" ensures that IWYU never adds these headers. --- src/nvim/api/private/dispatch.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/api/private') diff --git a/src/nvim/api/private/dispatch.h b/src/nvim/api/private/dispatch.h index d322c1ceca..9b167a7b9e 100644 --- a/src/nvim/api/private/dispatch.h +++ b/src/nvim/api/private/dispatch.h @@ -26,6 +26,6 @@ extern const MsgpackRpcRequestHandler method_handlers[]; #ifdef INCLUDE_GENERATED_DECLARATIONS # include "api/private/dispatch.h.generated.h" -# include "api/private/dispatch_wrappers.h.generated.h" // IWYU pragma: export -# include "keysets_defs.generated.h" // IWYU pragma: export +# include "api/private/dispatch_wrappers.h.generated.h" +# include "keysets_defs.generated.h" #endif -- cgit From c89292fcb7f2ebf06efb7c1d00c28f34c6f68fec Mon Sep 17 00:00:00 2001 From: dundargoc Date: Thu, 28 Dec 2023 13:42:24 +0100 Subject: refactor: follow style guide --- src/nvim/api/private/helpers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/private') diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 23ec815346..06addbecb7 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -138,7 +138,7 @@ bool try_end(Error *err) api_set_error(err, kErrorTypeException, "Keyboard interrupt"); got_int = false; } else if (msg_list != NULL && *msg_list != NULL) { - int should_free; + bool should_free; char *msg = get_exception_string(*msg_list, ET_ERROR, NULL, -- cgit From 1813661a6197c76ea6621284570aca1d56597099 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Thu, 4 Jan 2024 15:38:16 +0100 Subject: refactor(IWYU): fix headers Remove `export` pramgas from defs headers as it causes IWYU to believe that the definitions from the defs headers comes from main header, which is not what we really want. --- src/nvim/api/private/converter.h | 2 +- src/nvim/api/private/dispatch.h | 2 +- src/nvim/api/private/helpers.c | 4 +++- src/nvim/api/private/helpers.h | 2 +- src/nvim/api/private/validate.h | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) (limited to 'src/nvim/api/private') diff --git a/src/nvim/api/private/converter.h b/src/nvim/api/private/converter.h index a5acc56c7c..fc82abf332 100644 --- a/src/nvim/api/private/converter.h +++ b/src/nvim/api/private/converter.h @@ -1,6 +1,6 @@ #pragma once -#include "nvim/api/private/defs.h" // IWYU pragma: export +#include "nvim/api/private/defs.h" // IWYU pragma: keep #include "nvim/eval/typval_defs.h" // IWYU pragma: keep #ifdef INCLUDE_GENERATED_DECLARATIONS diff --git a/src/nvim/api/private/dispatch.h b/src/nvim/api/private/dispatch.h index 9b167a7b9e..6d051176ac 100644 --- a/src/nvim/api/private/dispatch.h +++ b/src/nvim/api/private/dispatch.h @@ -3,7 +3,7 @@ #include #include -#include "nvim/api/private/defs.h" // IWYU pragma: export +#include "nvim/api/private/defs.h" // IWYU pragma: keep #include "nvim/memory_defs.h" #include "nvim/types_defs.h" diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 06addbecb7..677e1ce9fd 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -19,7 +19,7 @@ #include "nvim/eval/typval.h" #include "nvim/eval/vars.h" #include "nvim/ex_eval.h" -#include "nvim/garray.h" +#include "nvim/garray_defs.h" #include "nvim/globals.h" #include "nvim/highlight_group.h" #include "nvim/lua/executor.h" @@ -27,11 +27,13 @@ #include "nvim/mark.h" #include "nvim/memline.h" #include "nvim/memory.h" +#include "nvim/memory_defs.h" #include "nvim/message.h" #include "nvim/msgpack_rpc/helpers.h" #include "nvim/pos_defs.h" #include "nvim/types_defs.h" #include "nvim/ui.h" +#include "nvim/ui_defs.h" #include "nvim/version.h" #ifdef INCLUDE_GENERATED_DECLARATIONS diff --git a/src/nvim/api/private/helpers.h b/src/nvim/api/private/helpers.h index 1ee66f906b..8a56d1704f 100644 --- a/src/nvim/api/private/helpers.h +++ b/src/nvim/api/private/helpers.h @@ -4,7 +4,7 @@ #include #include "klib/kvec.h" -#include "nvim/api/private/defs.h" // IWYU pragma: export +#include "nvim/api/private/defs.h" // IWYU pragma: keep #include "nvim/buffer_defs.h" // IWYU pragma: keep #include "nvim/eval/typval_defs.h" // IWYU pragma: keep #include "nvim/ex_eval_defs.h" diff --git a/src/nvim/api/private/validate.h b/src/nvim/api/private/validate.h index 692ea46176..2c1d1a241d 100644 --- a/src/nvim/api/private/validate.h +++ b/src/nvim/api/private/validate.h @@ -3,7 +3,7 @@ #include #include -#include "nvim/api/private/defs.h" // IWYU pragma: export +#include "nvim/api/private/defs.h" // IWYU pragma: keep #include "nvim/api/private/helpers.h" #include "nvim/assert_defs.h" #include "nvim/macros_defs.h" -- cgit From 646fdf1073433e2bdeec3433f6cbdf8f4be37098 Mon Sep 17 00:00:00 2001 From: glepnir Date: Wed, 17 Jan 2024 20:14:26 +0800 Subject: refactor(api): use hl id directly in nvim_buf_set_extmark --- src/nvim/api/private/defs.h | 1 + src/nvim/api/private/helpers.c | 21 +++++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) (limited to 'src/nvim/api/private') diff --git a/src/nvim/api/private/defs.h b/src/nvim/api/private/defs.h index 25c8377518..84ded1e647 100644 --- a/src/nvim/api/private/defs.h +++ b/src/nvim/api/private/defs.h @@ -135,6 +135,7 @@ typedef struct { size_t ptr_off; ObjectType type; // kObjectTypeNil == untyped int opt_index; + bool is_hlgroup; } KeySetLink; typedef KeySetLink *(*FieldHashfn)(const char *str, size_t len); diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 677e1ce9fd..8f30ac7c8f 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -936,13 +936,26 @@ bool api_dict_to_keydict(void *retval, FieldHashfn hashy, Dictionary dict, Error char *mem = ((char *)retval + field->ptr_off); Object *value = &dict.items[i].value; + if (field->type == kObjectTypeNil) { *(Object *)mem = *value; } else if (field->type == kObjectTypeInteger) { - VALIDATE_T(field->str, kObjectTypeInteger, value->type, { - return false; - }); - *(Integer *)mem = value->data.integer; + if (field->is_hlgroup) { + int hl_id = 0; + if (value->type != kObjectTypeNil) { + hl_id = object_to_hl_id(*value, k.data, err); + if (ERROR_SET(err)) { + return false; + } + } + *(Integer *)mem = hl_id; + } else { + VALIDATE_T(field->str, kObjectTypeInteger, value->type, { + return false; + }); + + *(Integer *)mem = value->data.integer; + } } else if (field->type == kObjectTypeFloat) { Float *val = (Float *)mem; if (value->type == kObjectTypeInteger) { -- cgit From d66ed4ea468d411668713c3777ad3658f18badf3 Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 22 Jan 2024 08:49:45 +0100 Subject: refactor(api): give "hl_group" more accurate _meta type These can either be number or string in lua, so we can specify this directly as "number|string". --- src/nvim/api/private/defs.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/api/private') diff --git a/src/nvim/api/private/defs.h b/src/nvim/api/private/defs.h index 84ded1e647..0cdc90e50f 100644 --- a/src/nvim/api/private/defs.h +++ b/src/nvim/api/private/defs.h @@ -124,6 +124,7 @@ struct key_value_pair { }; typedef uint64_t OptionalKeys; +typedef Integer HLGroupID; // this is the prefix of all keysets with optional keys typedef struct { -- cgit From 7367838359bfb5fadf72ea2aeea2f84efb34590e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 27 Jan 2024 14:03:44 +0800 Subject: fix(api): limit depth of nvim_cmd (#27225) --- src/nvim/api/private/helpers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/private') diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 8f30ac7c8f..9ce1786fa0 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -151,7 +151,7 @@ bool try_end(Error *err) if (should_free) { xfree(msg); } - } else if (did_throw) { + } else if (did_throw || need_rethrow) { if (*current_exception->throw_name != NUL) { if (current_exception->throw_lnum != 0) { api_set_error(err, kErrorTypeException, "%s, line %" PRIdLINENR ": %s", -- cgit From f9d81c43d2296d212c9cebcbdce401cd76cf0f1f Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 31 Jan 2024 22:02:06 +0100 Subject: refactor(api): use keydict and arena for more api return values Implement api_keydict_to_dict as the complement to api_dict_to_keydict Fix a conversion error when nvim_get_win_config gets called from lua, where Float values "x" and "y" didn't get converted to lua numbers. --- src/nvim/api/private/helpers.c | 48 ++++++++++++++++++++++++++++++++++++++++++ src/nvim/api/private/helpers.h | 4 ++++ 2 files changed, 52 insertions(+) (limited to 'src/nvim/api/private') diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 9ce1786fa0..cc95f46baf 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -1014,6 +1014,54 @@ bool api_dict_to_keydict(void *retval, FieldHashfn hashy, Dictionary dict, Error return true; } +Dictionary api_keydict_to_dict(void *value, KeySetLink *table, size_t max_size, Arena *arena) +{ + Dictionary rv = arena_dict(arena, max_size); + for (size_t i = 0; table[i].str; i++) { + KeySetLink *field = &table[i]; + bool is_set = true; + if (field->opt_index >= 0) { + OptKeySet *ks = (OptKeySet *)value; + is_set = ks->is_set_ & (1ULL << field->opt_index); + } + + if (!is_set) { + continue; + } + + char *mem = ((char *)value + field->ptr_off); + Object val = NIL; + + if (field->type == kObjectTypeNil) { + val = *(Object *)mem; + } else if (field->type == kObjectTypeInteger) { + val = INTEGER_OBJ(*(Integer *)mem); + } else if (field->type == kObjectTypeFloat) { + val = FLOAT_OBJ(*(Float *)mem); + } else if (field->type == kObjectTypeBoolean) { + val = BOOLEAN_OBJ(*(Boolean *)mem); + } else if (field->type == kObjectTypeString) { + val = STRING_OBJ(*(String *)mem); + } else if (field->type == kObjectTypeArray) { + val = ARRAY_OBJ(*(Array *)mem); + } else if (field->type == kObjectTypeDictionary) { + val = DICTIONARY_OBJ(*(Dictionary *)mem); + } else if (field->type == kObjectTypeBuffer || field->type == kObjectTypeWindow + || field->type == kObjectTypeTabpage) { + val.data.integer = *(Integer *)mem; + val.type = field->type; + } else if (field->type == kObjectTypeLuaRef) { + // do nothing + } else { + abort(); + } + + PUT_C(rv, field->str, val); + } + + return rv; +} + void api_free_keydict(void *dict, KeySetLink *table) { for (size_t i = 0; table[i].str; i++) { diff --git a/src/nvim/api/private/helpers.h b/src/nvim/api/private/helpers.h index 8a56d1704f..0dbe3d2fb6 100644 --- a/src/nvim/api/private/helpers.h +++ b/src/nvim/api/private/helpers.h @@ -32,6 +32,7 @@ #define CSTR_AS_OBJ(s) STRING_OBJ(cstr_as_string(s)) #define CSTR_TO_OBJ(s) STRING_OBJ(cstr_to_string(s)) +#define CSTR_TO_ARENA_OBJ(arena, s) STRING_OBJ(arena_string(arena, cstr_as_string(s))) #define BUFFER_OBJ(s) ((Object) { \ .type = kObjectTypeBuffer, \ @@ -70,6 +71,9 @@ #define PUT_C(dict, k, v) \ kv_push_c(dict, ((KeyValuePair) { .key = cstr_as_string(k), .value = v })) +#define PUT_KEY(d, typ, key, v) \ + do { (d).is_set__##typ##_ |= (1 << KEYSET_OPTIDX_##typ##__##key); (d).key = v; } while (0) + #define ADD(array, item) \ kv_push(array, item) -- cgit From e0e5b7f0ba1b0440bdc2b557e2b2cfae24706cbd Mon Sep 17 00:00:00 2001 From: bfredl Date: Fri, 9 Feb 2024 11:42:40 +0100 Subject: refactor(api): make cstr_as_string accept "const char*" In the context a String inside an Object/Dictionary etc is consumed, it is considered to be read-only. --- src/nvim/api/private/helpers.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/api/private') diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index cc95f46baf..8b45af7c71 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -425,12 +425,12 @@ String cstrn_as_string(char *str, size_t maxsize) /// @param str the C string to use /// @return The resulting String, or an empty String if /// str was NULL -String cstr_as_string(char *str) FUNC_ATTR_PURE +String cstr_as_string(const char *str) FUNC_ATTR_PURE { if (str == NULL) { return (String)STRING_INIT; } - return (String){ .data = str, .size = strlen(str) }; + return (String){ .data = (char *)str, .size = strlen(str) }; } /// Return the owned memory of a ga as a String -- cgit From 2d8d35f838e0f9737a8b0231e94d35315e54ca8f Mon Sep 17 00:00:00 2001 From: bfredl Date: Fri, 9 Feb 2024 10:06:50 +0100 Subject: refactor(api): use arena for nvim_parse_cmd() --- src/nvim/api/private/helpers.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/nvim/api/private') diff --git a/src/nvim/api/private/helpers.h b/src/nvim/api/private/helpers.h index 0dbe3d2fb6..9ee812f45c 100644 --- a/src/nvim/api/private/helpers.h +++ b/src/nvim/api/private/helpers.h @@ -32,7 +32,8 @@ #define CSTR_AS_OBJ(s) STRING_OBJ(cstr_as_string(s)) #define CSTR_TO_OBJ(s) STRING_OBJ(cstr_to_string(s)) -#define CSTR_TO_ARENA_OBJ(arena, s) STRING_OBJ(arena_string(arena, cstr_as_string(s))) +#define CSTR_TO_ARENA_STR(arena, s) arena_string(arena, cstr_as_string(s)) +#define CSTR_TO_ARENA_OBJ(arena, s) STRING_OBJ(CSTR_TO_ARENA_STR(arena, s)) #define BUFFER_OBJ(s) ((Object) { \ .type = kObjectTypeBuffer, \ -- cgit From 0353dd3029f9ce31c3894530385443a90f6677ee Mon Sep 17 00:00:00 2001 From: bfredl Date: Sun, 11 Feb 2024 15:46:14 +0100 Subject: refactor(lua): use Arena when converting from lua stack to API args and for return value of nlua_exec/nlua_call_ref, as this uses the same family of functions. NB: the handling of luaref:s is a bit of a mess. add api_luarefs_free_XX functions as a stop-gap as refactoring luarefs is a can of worms for another PR:s. as a minor feature/bug-fix, nvim_buf_call and nvim_win_call now preserves arbitrary return values. --- src/nvim/api/private/helpers.c | 50 ++++++++++++++++++++++++++++++++++-------- src/nvim/api/private/helpers.h | 3 +++ 2 files changed, 44 insertions(+), 9 deletions(-) (limited to 'src/nvim/api/private') diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 8b45af7c71..7bf0d87603 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -576,7 +576,7 @@ String arena_string(Arena *arena, String str) if (str.size) { return cbuf_as_string(arena_memdupz(arena, str.data, str.size), str.size); } else { - return (String)STRING_INIT; + return (String){ .data = arena ? "" : xstrdup(""), .size = 0 }; } } @@ -1062,24 +1062,56 @@ Dictionary api_keydict_to_dict(void *value, KeySetLink *table, size_t max_size, return rv; } -void api_free_keydict(void *dict, KeySetLink *table) +void api_luarefs_free_object(Object value) +{ + // TODO(bfredl): this is more complicated than it needs to be. + // we should be able to lock down more specifically where luarefs can be + switch (value.type) { + case kObjectTypeLuaRef: + api_free_luaref(value.data.luaref); + break; + + case kObjectTypeArray: + api_luarefs_free_array(value.data.array); + break; + + case kObjectTypeDictionary: + api_luarefs_free_dict(value.data.dictionary); + break; + + default: + break; + } +} + +void api_luarefs_free_keydict(void *dict, KeySetLink *table) { for (size_t i = 0; table[i].str; i++) { char *mem = ((char *)dict + table[i].ptr_off); if (table[i].type == kObjectTypeNil) { - api_free_object(*(Object *)mem); - } else if (table[i].type == kObjectTypeString) { - api_free_string(*(String *)mem); - } else if (table[i].type == kObjectTypeArray) { - api_free_array(*(Array *)mem); - } else if (table[i].type == kObjectTypeDictionary) { - api_free_dictionary(*(Dictionary *)mem); + api_luarefs_free_object(*(Object *)mem); } else if (table[i].type == kObjectTypeLuaRef) { api_free_luaref(*(LuaRef *)mem); + } else if (table[i].type == kObjectTypeDictionary) { + api_luarefs_free_dict(*(Dictionary *)mem); } } } +void api_luarefs_free_array(Array value) +{ + for (size_t i = 0; i < value.size; i++) { + api_luarefs_free_object(value.items[i]); + } +} + +void api_luarefs_free_dict(Dictionary value) +{ + for (size_t i = 0; i < value.size; i++) { + api_luarefs_free_object(value.items[i].value); + } +} + /// Set a named mark /// buffer and mark name must be validated already /// @param buffer Buffer to set the mark on diff --git a/src/nvim/api/private/helpers.h b/src/nvim/api/private/helpers.h index 9ee812f45c..11abb8f801 100644 --- a/src/nvim/api/private/helpers.h +++ b/src/nvim/api/private/helpers.h @@ -34,6 +34,7 @@ #define CSTR_TO_OBJ(s) STRING_OBJ(cstr_to_string(s)) #define CSTR_TO_ARENA_STR(arena, s) arena_string(arena, cstr_as_string(s)) #define CSTR_TO_ARENA_OBJ(arena, s) STRING_OBJ(CSTR_TO_ARENA_STR(arena, s)) +#define CBUF_TO_ARENA_STR(arena, s, len) arena_string(arena, cbuf_as_string((char *)(s), len)) #define BUFFER_OBJ(s) ((Object) { \ .type = kObjectTypeBuffer, \ @@ -119,6 +120,8 @@ #define api_init_array = ARRAY_DICT_INIT #define api_init_dictionary = ARRAY_DICT_INIT +#define KEYDICT_INIT { 0 } + #define api_free_boolean(value) #define api_free_integer(value) #define api_free_float(value) -- cgit From d60412b18e4e21f301baa2ac3f3fb7be89655e4b Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 12 Feb 2024 20:40:27 +0100 Subject: refactor(eval): use arena when converting typvals to Object Note: this contains two _temporary_ changes which can be reverted once the Arena vs no-Arena distinction in API wrappers has been removed. Both nlua_push_Object and object_to_vim_take_luaref() has been changed to take the object argument as a pointer. This is not going to be necessary once these are only used with arena (or not at all) allocated Objects. The object_to_vim() variant which leaves luaref untouched might need to stay for a little longer. --- src/nvim/api/private/converter.c | 95 +++++++++++++++++++++++----------------- src/nvim/api/private/helpers.c | 11 ++--- src/nvim/api/private/helpers.h | 1 + 3 files changed, 63 insertions(+), 44 deletions(-) (limited to 'src/nvim/api/private') diff --git a/src/nvim/api/private/converter.c b/src/nvim/api/private/converter.c index e7b8934c97..a70ef1e50b 100644 --- a/src/nvim/api/private/converter.c +++ b/src/nvim/api/private/converter.c @@ -19,6 +19,8 @@ /// Helper structure for vim_to_object typedef struct { kvec_withinit_t(Object, 2) stack; ///< Object stack. + Arena *arena; ///< arena where objects will be allocated + bool reuse_strdata; } EncodedData; #ifdef INCLUDE_GENERATED_DECLARATIONS @@ -41,12 +43,21 @@ typedef struct { #define TYPVAL_ENCODE_CONV_FLOAT(tv, flt) \ kvi_push(edata->stack, FLOAT_OBJ((Float)(flt))) +static Object typval_cbuf_to_obj(EncodedData *edata, const char *data, size_t len) +{ + if (edata->reuse_strdata) { + return STRING_OBJ(cbuf_as_string((char *)(len ? data : ""), len)); + } else { + return CBUF_TO_ARENA_OBJ(edata->arena, data, len); + } +} + #define TYPVAL_ENCODE_CONV_STRING(tv, str, len) \ do { \ const size_t len_ = (size_t)(len); \ const char *const str_ = (str); \ assert(len_ == 0 || str_ != NULL); \ - kvi_push(edata->stack, STRING_OBJ(cbuf_to_string((len_ ? str_ : ""), len_))); \ + kvi_push(edata->stack, typval_cbuf_to_obj(edata, str_, len_)); \ } while (0) #define TYPVAL_ENCODE_CONV_STR_STRING TYPVAL_ENCODE_CONV_STRING @@ -58,10 +69,7 @@ typedef struct { do { \ const size_t len_ = (size_t)(len); \ const blob_T *const blob_ = (blob); \ - kvi_push(edata->stack, STRING_OBJ(((String) { \ - .data = len_ != 0 ? xmemdupz(blob_->bv_ga.ga_data, len_) : xstrdup(""), \ - .size = len_ \ - }))); \ + kvi_push(edata->stack, typval_cbuf_to_obj(edata, len_ ? blob_->bv_ga.ga_data : "", len_)); \ } while (0) #define TYPVAL_ENCODE_CONV_FUNC_START(tv, fun) \ @@ -90,11 +98,7 @@ typedef struct { static inline void typval_encode_list_start(EncodedData *const edata, const size_t len) FUNC_ATTR_ALWAYS_INLINE FUNC_ATTR_NONNULL_ALL { - kvi_push(edata->stack, ARRAY_OBJ(((Array) { - .capacity = len, - .size = 0, - .items = xmalloc(len * sizeof(*((Object)OBJECT_INIT).data.array.items)), - }))); + kvi_push(edata->stack, ARRAY_OBJ(arena_array(edata->arena, len))); } #define TYPVAL_ENCODE_CONV_LIST_START(tv, len) \ @@ -109,7 +113,7 @@ static inline void typval_encode_between_list_items(EncodedData *const edata) Object *const list = &kv_last(edata->stack); assert(list->type == kObjectTypeArray); assert(list->data.array.size < list->data.array.capacity); - list->data.array.items[list->data.array.size++] = item; + ADD_C(list->data.array, item); } #define TYPVAL_ENCODE_CONV_LIST_BETWEEN_ITEMS(tv) \ @@ -131,11 +135,7 @@ static inline void typval_encode_list_end(EncodedData *const edata) static inline void typval_encode_dict_start(EncodedData *const edata, const size_t len) FUNC_ATTR_ALWAYS_INLINE FUNC_ATTR_NONNULL_ALL { - kvi_push(edata->stack, DICTIONARY_OBJ(((Dictionary) { - .capacity = len, - .size = 0, - .items = xmalloc(len * sizeof(*((Object)OBJECT_INIT).data.dictionary.items)), - }))); + kvi_push(edata->stack, DICTIONARY_OBJ(arena_dict(edata->arena, len))); } #define TYPVAL_ENCODE_CONV_DICT_START(tv, dict, len) \ @@ -156,9 +156,8 @@ static inline void typval_encode_after_key(EncodedData *const edata) dict->data.dictionary.items[dict->data.dictionary.size].key = key.data.string; } else { - api_free_object(key); dict->data.dictionary.items[dict->data.dictionary.size].key - = STATIC_CSTR_TO_STRING("__INVALID_KEY__"); + = STATIC_CSTR_AS_STRING("__INVALID_KEY__"); } } @@ -233,17 +232,22 @@ static inline void typval_encode_dict_end(EncodedData *const edata) #undef TYPVAL_ENCODE_CONV_RECURSE #undef TYPVAL_ENCODE_ALLOW_SPECIALS -/// Convert a vim object to an `Object` instance, recursively expanding +/// Convert a vim object to an `Object` instance, recursively converting /// Arrays/Dictionaries. /// /// @param obj The source object +/// @param arena if NULL, use direct allocation +/// @param reuse_strdata when true, don't copy string data to Arena but reference +/// typval strings directly. takes no effect when arena is +/// NULL /// @return The converted value -Object vim_to_object(typval_T *obj) +Object vim_to_object(typval_T *obj, Arena *arena, bool reuse_strdata) { EncodedData edata; kvi_init(edata.stack); - const int evo_ret = encode_vim_to_object(&edata, obj, - "vim_to_object argument"); + edata.arena = arena; + edata.reuse_strdata = reuse_strdata; + const int evo_ret = encode_vim_to_object(&edata, obj, "vim_to_object argument"); (void)evo_ret; assert(evo_ret == OK); Object ret = kv_A(edata.stack, 0); @@ -259,11 +263,19 @@ Object vim_to_object(typval_T *obj) /// set to VAR_UNKNOWN (no allocation was made for this variable). /// @param err Error object. void object_to_vim(Object obj, typval_T *tv, Error *err) +{ + object_to_vim_take_luaref(&obj, tv, false, err); +} + +/// same as object_to_vim but consumes all luarefs (nested) in `obj` +/// +/// useful when `obj` is allocated on an arena +void object_to_vim_take_luaref(Object *obj, typval_T *tv, bool take_luaref, Error *err) { tv->v_type = VAR_UNKNOWN; tv->v_lock = VAR_UNLOCKED; - switch (obj.type) { + switch (obj->type) { case kObjectTypeNil: tv->v_type = VAR_SPECIAL; tv->vval.v_special = kSpecialVarNull; @@ -271,41 +283,40 @@ void object_to_vim(Object obj, typval_T *tv, Error *err) case kObjectTypeBoolean: tv->v_type = VAR_BOOL; - tv->vval.v_bool = obj.data.boolean ? kBoolVarTrue : kBoolVarFalse; + tv->vval.v_bool = obj->data.boolean ? kBoolVarTrue : kBoolVarFalse; break; case kObjectTypeBuffer: case kObjectTypeWindow: case kObjectTypeTabpage: case kObjectTypeInteger: - STATIC_ASSERT(sizeof(obj.data.integer) <= sizeof(varnumber_T), + STATIC_ASSERT(sizeof(obj->data.integer) <= sizeof(varnumber_T), "Integer size must be <= Vimscript number size"); tv->v_type = VAR_NUMBER; - tv->vval.v_number = (varnumber_T)obj.data.integer; + tv->vval.v_number = (varnumber_T)obj->data.integer; break; case kObjectTypeFloat: tv->v_type = VAR_FLOAT; - tv->vval.v_float = obj.data.floating; + tv->vval.v_float = obj->data.floating; break; case kObjectTypeString: tv->v_type = VAR_STRING; - if (obj.data.string.data == NULL) { + if (obj->data.string.data == NULL) { tv->vval.v_string = NULL; } else { - tv->vval.v_string = xmemdupz(obj.data.string.data, - obj.data.string.size); + tv->vval.v_string = xmemdupz(obj->data.string.data, + obj->data.string.size); } break; case kObjectTypeArray: { - list_T *const list = tv_list_alloc((ptrdiff_t)obj.data.array.size); + list_T *const list = tv_list_alloc((ptrdiff_t)obj->data.array.size); - for (uint32_t i = 0; i < obj.data.array.size; i++) { - Object item = obj.data.array.items[i]; + for (uint32_t i = 0; i < obj->data.array.size; i++) { typval_T li_tv; - object_to_vim(item, &li_tv, err); + object_to_vim_take_luaref(&obj->data.array.items[i], &li_tv, take_luaref, err); tv_list_append_owned_tv(list, li_tv); } tv_list_ref(list); @@ -318,11 +329,11 @@ void object_to_vim(Object obj, typval_T *tv, Error *err) case kObjectTypeDictionary: { dict_T *const dict = tv_dict_alloc(); - for (uint32_t i = 0; i < obj.data.dictionary.size; i++) { - KeyValuePair item = obj.data.dictionary.items[i]; - String key = item.key; + for (uint32_t i = 0; i < obj->data.dictionary.size; i++) { + KeyValuePair *item = &obj->data.dictionary.items[i]; + String key = item->key; dictitem_T *const di = tv_dict_item_alloc(key.data); - object_to_vim(item.value, &di->di_tv, err); + object_to_vim_take_luaref(&item->value, &di->di_tv, take_luaref, err); tv_dict_add(dict, di); } dict->dv_refcount++; @@ -333,7 +344,13 @@ void object_to_vim(Object obj, typval_T *tv, Error *err) } case kObjectTypeLuaRef: { - char *name = register_luafunc(api_new_luaref(obj.data.luaref)); + LuaRef ref = obj->data.luaref; + if (take_luaref) { + obj->data.luaref = LUA_NOREF; + } else { + ref = api_new_luaref(ref); + } + char *name = register_luafunc(ref); tv->v_type = VAR_FUNC; tv->vval.v_string = xstrdup(name); break; diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 7bf0d87603..1446683b0c 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -175,7 +175,7 @@ bool try_end(Error *err) /// @param dict The vimscript dict /// @param key The key /// @param[out] err Details of an error that may have occurred -Object dict_get_value(dict_T *dict, String key, Error *err) +Object dict_get_value(dict_T *dict, String key, Arena *arena, Error *err) { dictitem_T *const di = tv_dict_find(dict, key.data, (ptrdiff_t)key.size); @@ -184,7 +184,7 @@ Object dict_get_value(dict_T *dict, String key, Error *err) return (Object)OBJECT_INIT; } - return vim_to_object(&di->di_tv); + return vim_to_object(&di->di_tv, arena, true); } dictitem_T *dict_check_writable(dict_T *dict, String key, bool del, Error *err) @@ -221,7 +221,8 @@ dictitem_T *dict_check_writable(dict_T *dict, String key, bool del, Error *err) /// @param retval If true the old value will be converted and returned. /// @param[out] err Details of an error that may have occurred /// @return The old value if `retval` is true and the key was present, else NIL -Object dict_set_var(dict_T *dict, String key, Object value, bool del, bool retval, Error *err) +Object dict_set_var(dict_T *dict, String key, Object value, bool del, bool retval, Arena *arena, + Error *err) { Object rv = OBJECT_INIT; dictitem_T *di = dict_check_writable(dict, key, del, err); @@ -244,7 +245,7 @@ Object dict_set_var(dict_T *dict, String key, Object value, bool del, bool retva } // Return the old value if (retval) { - rv = vim_to_object(&di->di_tv); + rv = vim_to_object(&di->di_tv, arena, false); } // Delete the entry tv_dict_item_remove(dict, di); @@ -265,7 +266,7 @@ Object dict_set_var(dict_T *dict, String key, Object value, bool del, bool retva } else { // Return the old value if (retval) { - rv = vim_to_object(&di->di_tv); + rv = vim_to_object(&di->di_tv, arena, false); } bool type_error = false; if (dict == &vimvardict diff --git a/src/nvim/api/private/helpers.h b/src/nvim/api/private/helpers.h index 11abb8f801..395c5a9d1f 100644 --- a/src/nvim/api/private/helpers.h +++ b/src/nvim/api/private/helpers.h @@ -35,6 +35,7 @@ #define CSTR_TO_ARENA_STR(arena, s) arena_string(arena, cstr_as_string(s)) #define CSTR_TO_ARENA_OBJ(arena, s) STRING_OBJ(CSTR_TO_ARENA_STR(arena, s)) #define CBUF_TO_ARENA_STR(arena, s, len) arena_string(arena, cbuf_as_string((char *)(s), len)) +#define CBUF_TO_ARENA_OBJ(arena, s, len) STRING_OBJ(CBUF_TO_ARENA_STR(arena, s, len)) #define BUFFER_OBJ(s) ((Object) { \ .type = kObjectTypeBuffer, \ -- cgit From f25fcc68a34c2d51b0715fadc62cb50509de338b Mon Sep 17 00:00:00 2001 From: bfredl Date: Sat, 17 Feb 2024 20:31:21 +0100 Subject: refactor(api): use an arena for mappings --- src/nvim/api/private/helpers.c | 9 +++++++++ src/nvim/api/private/helpers.h | 2 ++ 2 files changed, 11 insertions(+) (limited to 'src/nvim/api/private') diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 1446683b0c..3cbf16fa72 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -581,6 +581,15 @@ String arena_string(Arena *arena, String str) } } +Array arena_take_arraybuilder(Arena *arena, ArrayBuilder *arr) +{ + Array ret = arena_array(arena, kv_size(*arr)); + ret.size = kv_size(*arr); + memcpy((ret).items, (*arr).items, sizeof((ret).items[0]) * (ret).size); + kvi_destroy(*arr); + return ret; +} + void api_free_object(Object value) { switch (value.type) { diff --git a/src/nvim/api/private/helpers.h b/src/nvim/api/private/helpers.h index 395c5a9d1f..20bc889a0a 100644 --- a/src/nvim/api/private/helpers.h +++ b/src/nvim/api/private/helpers.h @@ -95,6 +95,8 @@ name.capacity = maxsize; \ name.items = name##__items; \ +typedef kvec_withinit_t(Object, 16) ArrayBuilder; + #define cbuf_as_string(d, s) ((String) { .data = d, .size = s }) #define STATIC_CSTR_AS_STRING(s) ((String) { .data = s, .size = sizeof("" s) - 1 }) -- cgit From 97531be1f766e6cad79e6360ae9cb827434cff3c Mon Sep 17 00:00:00 2001 From: bfredl Date: Sat, 17 Feb 2024 20:33:58 +0100 Subject: refactor(api): use arena for autocmds --- src/nvim/api/private/helpers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/private') diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 3cbf16fa72..983f1a4fed 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -585,7 +585,7 @@ Array arena_take_arraybuilder(Arena *arena, ArrayBuilder *arr) { Array ret = arena_array(arena, kv_size(*arr)); ret.size = kv_size(*arr); - memcpy((ret).items, (*arr).items, sizeof((ret).items[0]) * (ret).size); + memcpy(ret.items, arr->items, sizeof(ret.items[0]) * ret.size); kvi_destroy(*arr); return ret; } -- cgit From bbf6d4a4bc44c8e61f807d23cc4ff2c2683e1ef4 Mon Sep 17 00:00:00 2001 From: bfredl Date: Sun, 18 Feb 2024 12:51:27 +0100 Subject: refactor(api): use arena for metadata; msgpack_rpc_to_object delenda est Note: kSDItemHeader is something is _written_ by nvim in the shada file to identify it for debugging purposes outside of nvim. But this data wasn't ever used by neovim after reading the file back, So I removed the parsing of it for now. --- src/nvim/api/private/helpers.c | 116 ++++++++++++++++++----------------------- 1 file changed, 51 insertions(+), 65 deletions(-) (limited to 'src/nvim/api/private') diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 983f1a4fed..63c5689109 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -30,6 +30,7 @@ #include "nvim/memory_defs.h" #include "nvim/message.h" #include "nvim/msgpack_rpc/helpers.h" +#include "nvim/msgpack_rpc/unpacker.h" #include "nvim/pos_defs.h" #include "nvim/types_defs.h" #include "nvim/ui.h" @@ -650,102 +651,87 @@ void api_clear_error(Error *value) value->type = kErrorTypeNone; } +// initialized once, never freed +static ArenaMem mem_for_metadata = NULL; + /// @returns a shared value. caller must not modify it! Dictionary api_metadata(void) { static Dictionary metadata = ARRAY_DICT_INIT; if (!metadata.size) { - PUT(metadata, "version", DICTIONARY_OBJ(version_dict())); - init_function_metadata(&metadata); - init_ui_event_metadata(&metadata); - init_error_type_metadata(&metadata); - init_type_metadata(&metadata); + Arena arena = ARENA_EMPTY; + Error err = ERROR_INIT; + metadata = arena_dict(&arena, 6); + PUT_C(metadata, "version", DICTIONARY_OBJ(version_dict(&arena))); + PUT_C(metadata, "functions", + unpack((char *)funcs_metadata, sizeof(funcs_metadata), &arena, &err)); + if (ERROR_SET(&err)) { + abort(); + } + PUT_C(metadata, "ui_events", + unpack((char *)ui_events_metadata, sizeof(ui_events_metadata), &arena, &err)); + if (ERROR_SET(&err)) { + abort(); + } + PUT_C(metadata, "ui_options", ARRAY_OBJ(ui_options_metadata(&arena))); + PUT_C(metadata, "error_types", DICTIONARY_OBJ(error_type_metadata(&arena))); + PUT_C(metadata, "types", DICTIONARY_OBJ(type_metadata(&arena))); + mem_for_metadata = arena_finish(&arena); } return metadata; } -static void init_function_metadata(Dictionary *metadata) +static Array ui_options_metadata(Arena *arena) { - msgpack_unpacked unpacked; - msgpack_unpacked_init(&unpacked); - if (msgpack_unpack_next(&unpacked, - (const char *)funcs_metadata, - sizeof(funcs_metadata), - NULL) != MSGPACK_UNPACK_SUCCESS) { - abort(); - } - Object functions; - msgpack_rpc_to_object(&unpacked.data, &functions); - msgpack_unpacked_destroy(&unpacked); - PUT(*metadata, "functions", functions); -} - -static void init_ui_event_metadata(Dictionary *metadata) -{ - msgpack_unpacked unpacked; - msgpack_unpacked_init(&unpacked); - if (msgpack_unpack_next(&unpacked, - (const char *)ui_events_metadata, - sizeof(ui_events_metadata), - NULL) != MSGPACK_UNPACK_SUCCESS) { - abort(); - } - Object ui_events; - msgpack_rpc_to_object(&unpacked.data, &ui_events); - msgpack_unpacked_destroy(&unpacked); - PUT(*metadata, "ui_events", ui_events); - Array ui_options = ARRAY_DICT_INIT; - ADD(ui_options, CSTR_TO_OBJ("rgb")); + Array ui_options = arena_array(arena, kUIExtCount + 1); + ADD_C(ui_options, CSTR_AS_OBJ("rgb")); for (UIExtension i = 0; i < kUIExtCount; i++) { if (ui_ext_names[i][0] != '_') { - ADD(ui_options, CSTR_TO_OBJ(ui_ext_names[i])); + ADD_C(ui_options, CSTR_AS_OBJ(ui_ext_names[i])); } } - PUT(*metadata, "ui_options", ARRAY_OBJ(ui_options)); + return ui_options; } -static void init_error_type_metadata(Dictionary *metadata) +static Dictionary error_type_metadata(Arena *arena) { - Dictionary types = ARRAY_DICT_INIT; + Dictionary types = arena_dict(arena, 2); - Dictionary exception_metadata = ARRAY_DICT_INIT; - PUT(exception_metadata, "id", INTEGER_OBJ(kErrorTypeException)); + Dictionary exception_metadata = arena_dict(arena, 1); + PUT_C(exception_metadata, "id", INTEGER_OBJ(kErrorTypeException)); - Dictionary validation_metadata = ARRAY_DICT_INIT; - PUT(validation_metadata, "id", INTEGER_OBJ(kErrorTypeValidation)); + Dictionary validation_metadata = arena_dict(arena, 1); + PUT_C(validation_metadata, "id", INTEGER_OBJ(kErrorTypeValidation)); - PUT(types, "Exception", DICTIONARY_OBJ(exception_metadata)); - PUT(types, "Validation", DICTIONARY_OBJ(validation_metadata)); + PUT_C(types, "Exception", DICTIONARY_OBJ(exception_metadata)); + PUT_C(types, "Validation", DICTIONARY_OBJ(validation_metadata)); - PUT(*metadata, "error_types", DICTIONARY_OBJ(types)); + return types; } -static void init_type_metadata(Dictionary *metadata) +static Dictionary type_metadata(Arena *arena) { - Dictionary types = ARRAY_DICT_INIT; + Dictionary types = arena_dict(arena, 3); - Dictionary buffer_metadata = ARRAY_DICT_INIT; - PUT(buffer_metadata, "id", - INTEGER_OBJ(kObjectTypeBuffer - EXT_OBJECT_TYPE_SHIFT)); - PUT(buffer_metadata, "prefix", CSTR_TO_OBJ("nvim_buf_")); + Dictionary buffer_metadata = arena_dict(arena, 2); + PUT_C(buffer_metadata, "id", INTEGER_OBJ(kObjectTypeBuffer - EXT_OBJECT_TYPE_SHIFT)); + PUT_C(buffer_metadata, "prefix", CSTR_AS_OBJ("nvim_buf_")); - Dictionary window_metadata = ARRAY_DICT_INIT; - PUT(window_metadata, "id", - INTEGER_OBJ(kObjectTypeWindow - EXT_OBJECT_TYPE_SHIFT)); - PUT(window_metadata, "prefix", CSTR_TO_OBJ("nvim_win_")); + Dictionary window_metadata = arena_dict(arena, 2); + PUT_C(window_metadata, "id", INTEGER_OBJ(kObjectTypeWindow - EXT_OBJECT_TYPE_SHIFT)); + PUT_C(window_metadata, "prefix", CSTR_AS_OBJ("nvim_win_")); - Dictionary tabpage_metadata = ARRAY_DICT_INIT; - PUT(tabpage_metadata, "id", - INTEGER_OBJ(kObjectTypeTabpage - EXT_OBJECT_TYPE_SHIFT)); - PUT(tabpage_metadata, "prefix", CSTR_TO_OBJ("nvim_tabpage_")); + Dictionary tabpage_metadata = arena_dict(arena, 2); + PUT_C(tabpage_metadata, "id", INTEGER_OBJ(kObjectTypeTabpage - EXT_OBJECT_TYPE_SHIFT)); + PUT_C(tabpage_metadata, "prefix", CSTR_AS_OBJ("nvim_tabpage_")); - PUT(types, "Buffer", DICTIONARY_OBJ(buffer_metadata)); - PUT(types, "Window", DICTIONARY_OBJ(window_metadata)); - PUT(types, "Tabpage", DICTIONARY_OBJ(tabpage_metadata)); + PUT_C(types, "Buffer", DICTIONARY_OBJ(buffer_metadata)); + PUT_C(types, "Window", DICTIONARY_OBJ(window_metadata)); + PUT_C(types, "Tabpage", DICTIONARY_OBJ(tabpage_metadata)); - PUT(*metadata, "types", DICTIONARY_OBJ(types)); + return types; } // all the copy_[object] functions allow arena=NULL, -- cgit From 404707c7606389ccb6c6062bfe9e2ff30a2552af Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 19 Feb 2024 12:07:16 +0100 Subject: refactor(api): use arena for nvim_put and nvim_paste --- src/nvim/api/private/helpers.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'src/nvim/api/private') diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 63c5689109..14f4046a56 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -456,9 +456,10 @@ String ga_take_string(garray_T *ga) /// @param input Binary string /// @param crlf Also break lines at CR and CRLF. /// @return [allocated] String array -Array string_to_array(const String input, bool crlf) +Array string_to_array(const String input, bool crlf, Arena *arena) { - Array ret = ARRAY_DICT_INIT; + ArrayBuilder ret = ARRAY_DICT_INIT; + kvi_init(ret); for (size_t i = 0; i < input.size; i++) { const char *start = input.data + i; const char *end = start; @@ -473,20 +474,17 @@ Array string_to_array(const String input, bool crlf) if (crlf && *end == CAR && i + 1 < input.size && *(end + 1) == NL) { i += 1; // Advance past CRLF. } - String s = { - .size = line_len, - .data = xmemdupz(start, line_len), - }; + String s = CBUF_TO_ARENA_STR(arena, start, line_len); memchrsub(s.data, NUL, NL, line_len); - ADD(ret, STRING_OBJ(s)); + kvi_push(ret, STRING_OBJ(s)); // If line ends at end-of-buffer, add empty final item. // This is "readfile()-style", see also ":help channel-lines". if (i + 1 == input.size && (*end == NL || (crlf && *end == CAR))) { - ADD(ret, STRING_OBJ(STRING_INIT)); + kvi_push(ret, STRING_OBJ(STRING_INIT)); } } - return ret; + return arena_take_arraybuilder(arena, &ret); } /// Normalizes 0-based indexes to buffer line numbers. -- cgit From 3cc54586be7760652e8bad88cae82ce74ef9432e Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 20 Feb 2024 13:44:50 +0100 Subject: 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). --- src/nvim/api/private/dispatch.h | 4 ++-- src/nvim/api/private/helpers.h | 7 ------- 2 files changed, 2 insertions(+), 9 deletions(-) (limited to 'src/nvim/api/private') diff --git a/src/nvim/api/private/dispatch.h b/src/nvim/api/private/dispatch.h index 6d051176ac..288f368fba 100644 --- a/src/nvim/api/private/dispatch.h +++ b/src/nvim/api/private/dispatch.h @@ -18,8 +18,8 @@ struct MsgpackRpcRequestHandler { ///< uv loop (the loop is run very frequently due to breakcheck). ///< If "fast" is false, the function is deferred, i e the call will ///< be put in the event queue, for safe handling later. - bool arena_return; ///< return value is allocated in the arena (or statically) - ///< and should not be freed as such. + bool ret_alloc; ///< return value is allocated and should be freed using api_free_object + ///< otherwise it uses arena and/or static memory }; extern const MsgpackRpcRequestHandler method_handlers[]; diff --git a/src/nvim/api/private/helpers.h b/src/nvim/api/private/helpers.h index 20bc889a0a..7eda8ffaf6 100644 --- a/src/nvim/api/private/helpers.h +++ b/src/nvim/api/private/helpers.h @@ -125,13 +125,6 @@ typedef kvec_withinit_t(Object, 16) ArrayBuilder; #define KEYDICT_INIT { 0 } -#define api_free_boolean(value) -#define api_free_integer(value) -#define api_free_float(value) -#define api_free_buffer(value) -#define api_free_window(value) -#define api_free_tabpage(value) - EXTERN PMap(int) buffer_handles INIT( = MAP_INIT); EXTERN PMap(int) window_handles INIT( = MAP_INIT); EXTERN PMap(int) tabpage_handles INIT( = MAP_INIT); -- cgit From de5cf09cf98e20d8d3296ad6933ff2741acf83f7 Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 26 Feb 2024 18:00:46 +0100 Subject: refactor(metadata): generate all metadata in lua Then we can just load metadata in C as a single msgpack blob. Which also can be used directly as binarly data, instead of first unpacking all the functions and ui_events metadata to immediately pack it again, which was a bit of a silly walk (and one extra usecase of `msgpack_rpc_from_object` which will get yak shaved in the next PR) --- src/nvim/api/private/helpers.c | 74 +++++------------------------------------- 1 file changed, 8 insertions(+), 66 deletions(-) (limited to 'src/nvim/api/private') diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 14f4046a56..97ba15e871 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -38,9 +38,8 @@ #include "nvim/version.h" #ifdef INCLUDE_GENERATED_DECLARATIONS -# include "api/private/funcs_metadata.generated.h" +# include "api/private/api_metadata.generated.h" # include "api/private/helpers.c.generated.h" -# include "api/private/ui_events_metadata.generated.h" #endif /// Start block that may cause Vimscript exceptions while evaluating another code @@ -653,83 +652,26 @@ void api_clear_error(Error *value) static ArenaMem mem_for_metadata = NULL; /// @returns a shared value. caller must not modify it! -Dictionary api_metadata(void) +Object api_metadata(void) { - static Dictionary metadata = ARRAY_DICT_INIT; + static Object metadata = OBJECT_INIT; - if (!metadata.size) { + if (metadata.type == kObjectTypeNil) { Arena arena = ARENA_EMPTY; Error err = ERROR_INIT; - metadata = arena_dict(&arena, 6); - PUT_C(metadata, "version", DICTIONARY_OBJ(version_dict(&arena))); - PUT_C(metadata, "functions", - unpack((char *)funcs_metadata, sizeof(funcs_metadata), &arena, &err)); - if (ERROR_SET(&err)) { + metadata = unpack((char *)packed_api_metadata, sizeof(packed_api_metadata), &arena, &err); + if (ERROR_SET(&err) || metadata.type != kObjectTypeDictionary) { abort(); } - PUT_C(metadata, "ui_events", - unpack((char *)ui_events_metadata, sizeof(ui_events_metadata), &arena, &err)); - if (ERROR_SET(&err)) { - abort(); - } - PUT_C(metadata, "ui_options", ARRAY_OBJ(ui_options_metadata(&arena))); - PUT_C(metadata, "error_types", DICTIONARY_OBJ(error_type_metadata(&arena))); - PUT_C(metadata, "types", DICTIONARY_OBJ(type_metadata(&arena))); mem_for_metadata = arena_finish(&arena); } return metadata; } -static Array ui_options_metadata(Arena *arena) -{ - Array ui_options = arena_array(arena, kUIExtCount + 1); - ADD_C(ui_options, CSTR_AS_OBJ("rgb")); - for (UIExtension i = 0; i < kUIExtCount; i++) { - if (ui_ext_names[i][0] != '_') { - ADD_C(ui_options, CSTR_AS_OBJ(ui_ext_names[i])); - } - } - return ui_options; -} - -static Dictionary error_type_metadata(Arena *arena) +String api_metadata_raw(void) { - Dictionary types = arena_dict(arena, 2); - - Dictionary exception_metadata = arena_dict(arena, 1); - PUT_C(exception_metadata, "id", INTEGER_OBJ(kErrorTypeException)); - - Dictionary validation_metadata = arena_dict(arena, 1); - PUT_C(validation_metadata, "id", INTEGER_OBJ(kErrorTypeValidation)); - - PUT_C(types, "Exception", DICTIONARY_OBJ(exception_metadata)); - PUT_C(types, "Validation", DICTIONARY_OBJ(validation_metadata)); - - return types; -} - -static Dictionary type_metadata(Arena *arena) -{ - Dictionary types = arena_dict(arena, 3); - - Dictionary buffer_metadata = arena_dict(arena, 2); - PUT_C(buffer_metadata, "id", INTEGER_OBJ(kObjectTypeBuffer - EXT_OBJECT_TYPE_SHIFT)); - PUT_C(buffer_metadata, "prefix", CSTR_AS_OBJ("nvim_buf_")); - - Dictionary window_metadata = arena_dict(arena, 2); - PUT_C(window_metadata, "id", INTEGER_OBJ(kObjectTypeWindow - EXT_OBJECT_TYPE_SHIFT)); - PUT_C(window_metadata, "prefix", CSTR_AS_OBJ("nvim_win_")); - - Dictionary tabpage_metadata = arena_dict(arena, 2); - PUT_C(tabpage_metadata, "id", INTEGER_OBJ(kObjectTypeTabpage - EXT_OBJECT_TYPE_SHIFT)); - PUT_C(tabpage_metadata, "prefix", CSTR_AS_OBJ("nvim_tabpage_")); - - PUT_C(types, "Buffer", DICTIONARY_OBJ(buffer_metadata)); - PUT_C(types, "Window", DICTIONARY_OBJ(window_metadata)); - PUT_C(types, "Tabpage", DICTIONARY_OBJ(tabpage_metadata)); - - return types; + return cbuf_as_string((char *)packed_api_metadata, sizeof(packed_api_metadata)); } // all the copy_[object] functions allow arena=NULL, -- cgit From dc37c1550bed46fffbb677d343cdc5bc94056219 Mon Sep 17 00:00:00 2001 From: bfredl Date: Sun, 25 Feb 2024 15:02:48 +0100 Subject: refactor(msgpack): allow flushing buffer while packing msgpack Before, we needed to always pack an entire msgpack_rpc Object to a continous memory buffer before sending it out to a channel. But this is generally wasteful. it is better to just flush whatever is in the buffer and then continue packing to a new buffer. This is also done for the UI event packer where there are some extra logic to "finish" of an existing batch of nevents/ncalls. This doesn't really stop us from flushing the buffer, just that we need to update the state machine accordingly so the next call to prepare_call() always will start with a new event (even though the buffer might contain overflow data from a large event). --- src/nvim/api/private/defs.h | 8 ++++++++ src/nvim/api/private/helpers.c | 3 +-- 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'src/nvim/api/private') diff --git a/src/nvim/api/private/defs.h b/src/nvim/api/private/defs.h index 0cdc90e50f..ca088d7a55 100644 --- a/src/nvim/api/private/defs.h +++ b/src/nvim/api/private/defs.h @@ -105,6 +105,14 @@ typedef enum { kObjectTypeTabpage, } ObjectType; +/// Value by which objects represented as EXT type are shifted +/// +/// Subtracted when packing, added when unpacking. Used to allow moving +/// buffer/window/tabpage block inside ObjectType enum. This block yet cannot be +/// split or reordered. +#define EXT_OBJECT_TYPE_SHIFT kObjectTypeBuffer +#define EXT_OBJECT_TYPE_MAX (kObjectTypeTabpage - EXT_OBJECT_TYPE_SHIFT) + struct object { ObjectType type; union { diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 97ba15e871..1cd98aa0c4 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -29,7 +29,6 @@ #include "nvim/memory.h" #include "nvim/memory_defs.h" #include "nvim/message.h" -#include "nvim/msgpack_rpc/helpers.h" #include "nvim/msgpack_rpc/unpacker.h" #include "nvim/pos_defs.h" #include "nvim/types_defs.h" @@ -984,7 +983,7 @@ Dictionary api_keydict_to_dict(void *value, KeySetLink *table, size_t max_size, val = DICTIONARY_OBJ(*(Dictionary *)mem); } else if (field->type == kObjectTypeBuffer || field->type == kObjectTypeWindow || field->type == kObjectTypeTabpage) { - val.data.integer = *(Integer *)mem; + val.data.integer = *(handle_T *)mem; val.type = field->type; } else if (field->type == kObjectTypeLuaRef) { // do nothing -- cgit