From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: Cyrill Gorcunov <gorcunov@gmail.com>,
tml <tarantool-patches@dev.tarantool.org>
Subject: Re: [Tarantool-patches] [PATCH v8 1/4] box/func: factor out c function entry structure
Date: Thu, 29 Oct 2020 23:15:51 +0100 [thread overview]
Message-ID: <8706dd6e-0b8d-f3f1-2344-f1b24906eecd@tarantool.org> (raw)
In-Reply-To: <20201014133535.224573-2-gorcunov@gmail.com>
Hi! Thanks for the patch!
See 3 comments below.
On 14.10.2020 15:35, Cyrill Gorcunov wrote:
> Currently func_c structure is a wrapper over struct func
> which in turn handles function definition, credentials
> and etc, mostly to handle internal "_func" space.
>
> Such tight bound doesn't allow to reuse func_c in any
> other context. But we're going to support C function
> execution in read-only instances and for this we better
> reuse already existing structures as much as possible
> instead of breeding new ones.
>
> Thus lets extract module symbols into module_sym structure,
> this allows us to reuse module path cache in other code.
>
> While extracting the structure rename "func" member to
> "addr" since this exactly what the member represents:
> an address of symbol in memory.
>
> Same time to be completely independent of "_func" specific lets
> carry symbolic name inplace (ie member "name" is kind of redundant
> when module_sym is used for "_func" handling where we can retrieve
> the name via function definition but such definition won't be
> available for non-persistent C functions which we will support
> in next patches).
>
> The new structure allows us to load/unload general symbols via
> module_sym_load() and module_sym_unload() helpers.
>
> Part-of #4642
>
> Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
> ---
> src/box/func.c | 156 +++++++++++++++++++++++--------------------------
> src/box/func.h | 43 ++++++++++++++
> 2 files changed, 116 insertions(+), 83 deletions(-)
>
> diff --git a/src/box/func.c b/src/box/func.c
> index 8087c953f..75d2abb5f 100644
> --- a/src/box/func.c
> +++ b/src/box/func.c
> @@ -371,6 +361,53 @@ module_sym(struct module *module, const char *name)
> return f;
> }
>
> +int
> +module_sym_load(struct module_sym *mod_sym)
> +{
> + assert(mod_sym->addr == NULL);
> +
> + struct func_name name;
> + func_split_name(mod_sym->name, &name);
> +
> + struct module *module = module_cache_find(name.package,
> + name.package_end);
> + if (module == NULL) {
> + /* Try to find loaded module in the cache */
> + module = module_load(name.package, name.package_end);
> + if (module == NULL)
> + return -1;
> + if (module_cache_put(module)) {
1. Please, use explicit != 0.
https://github.com/tarantool/tarantool/wiki/Code-review-procedure#code-style
> + module_delete(module);
> + return -1;
> + }
> + }
> +
> + mod_sym->addr = module_sym(module, name.sym);
> + if (mod_sym->addr == NULL)
> + return -1;
2. If the module was loaded first time here, it is not unloaded in case of
an error in this place.
> + mod_sym->module = module;
> + rlist_add(&module->funcs, &mod_sym->item);
> + return 0;
> +}
> diff --git a/src/box/func.h b/src/box/func.h
> index 581e468cb..acf2df9a9 100644
> --- a/src/box/func.h
> +++ b/src/box/func.h
> @@ -58,6 +58,29 @@ struct module {
> char package[0];
> };
>
> +/**
> + * Callable symbol bound to a module.
> + */
> +struct module_sym {
> + /**
> + * Anchor for module membership.
> + */
> + struct rlist item;
> + /**
> + * For C functions, address of the function.
> + */
> + box_function_f addr;
> + /**
> + * Each stored function keeps a handle to the
> + * dynamic library for the C callback.
> + */
3. Can't parse the comment. What is the 'C callback'?
And why is this function stored? After you extracted it
from struct func_c, it is not related to _func space, and
is not stored.
> + struct module *module;
> + /**
> + * Function name definition.
> + */
> + char *name;
> +};
next prev parent reply other threads:[~2020-10-29 22:15 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-14 13:35 [Tarantool-patches] [PATCH v8 0/4] box/cbox: implement cfunc Lua module Cyrill Gorcunov
2020-10-14 13:35 ` [Tarantool-patches] [PATCH v8 1/4] box/func: factor out c function entry structure Cyrill Gorcunov
2020-10-29 22:15 ` Vladislav Shpilevoy [this message]
2020-10-30 9:51 ` Cyrill Gorcunov
2020-10-31 0:13 ` Vladislav Shpilevoy
2020-10-31 15:27 ` Cyrill Gorcunov
2020-10-14 13:35 ` [Tarantool-patches] [PATCH v8 2/4] module_cache: move module handling into own subsystem Cyrill Gorcunov
2020-10-29 22:15 ` Vladislav Shpilevoy
2020-10-30 10:15 ` Cyrill Gorcunov
2020-10-31 0:15 ` Vladislav Shpilevoy
2020-10-31 15:29 ` Cyrill Gorcunov
2020-10-14 13:35 ` [Tarantool-patches] [PATCH v8 3/4] box/cbox: implement cbox Lua module Cyrill Gorcunov
2020-10-29 22:15 ` Vladislav Shpilevoy
2020-10-30 12:51 ` Cyrill Gorcunov
2020-10-31 0:21 ` Vladislav Shpilevoy
2020-10-31 21:59 ` Cyrill Gorcunov
2020-11-01 8:26 ` Cyrill Gorcunov
2020-11-02 22:25 ` Vladislav Shpilevoy
2020-11-03 7:26 ` Cyrill Gorcunov
2020-11-12 22:54 ` Vladislav Shpilevoy
2020-11-13 18:30 ` Cyrill Gorcunov
2020-10-14 13:35 ` [Tarantool-patches] [PATCH v8 4/4] test: box/cfunc -- add simple module test Cyrill Gorcunov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8706dd6e-0b8d-f3f1-2344-f1b24906eecd@tarantool.org \
--to=v.shpilevoy@tarantool.org \
--cc=gorcunov@gmail.com \
--cc=tarantool-patches@dev.tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH v8 1/4] box/func: factor out c function entry structure' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox