From: Cyrill Gorcunov via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: tml <tarantool-patches@dev.tarantool.org>
Cc: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Subject: [Tarantool-patches] [PATCH 3/4] cmod: export cmod_call helper
Date: Wed, 17 Feb 2021 23:15:20 +0300 [thread overview]
Message-ID: <20210217201521.436951-4-gorcunov@gmail.com> (raw)
In-Reply-To: <20210217201521.436951-1-gorcunov@gmail.com>
This will allow us to reuse this code
in when function is executed from
box.schema.func.
Part-of #4642
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
---
src/box/lua/cmod.c | 24 +++++++++---------------
src/box/lua/cmod.h | 15 +++++++++++++++
2 files changed, 24 insertions(+), 15 deletions(-)
diff --git a/src/box/lua/cmod.c b/src/box/lua/cmod.c
index 6b383d8fe..d7d395b7d 100644
--- a/src/box/lua/cmod.c
+++ b/src/box/lua/cmod.c
@@ -12,7 +12,6 @@
#include "box/error.h"
#include "box/port.h"
-#include "box/func_def.h"
#include "tt_static.h"
@@ -805,9 +804,9 @@ lfunc_gc(struct lua_State *L)
return 0;
}
-/** Execute a function. */
int
-do_lfunc_call(struct cmod_func *cf, struct port *args, struct port *ret)
+cmod_call(struct cmod *m, box_function_f func_addr,
+ struct port *args, struct port *ret)
{
struct region *region = &fiber()->gc;
size_t region_svp = region_used(region);
@@ -823,17 +822,12 @@ do_lfunc_call(struct cmod_func *cf, struct port *args, struct port *ret)
};
/*
- * Unlike box.schema.func cmod doesn't support
- * module run-time reloading and while a function
- * is alive a module can't disappear. Still it is
- * unclear if there some existing users are running
- * code which already tries to unload a function inside
- * this call execution, thus make sure the module won't
- * disapper inbetween.
+ * The function may get rescheduled inside,
+ * thus make sure the module won't disappear.
*/
- cmod_ref(cf->cmod);
- int rc = cf->addr(&ctx, data, data + data_sz);
- cmod_unref(cf->cmod);
+ cmod_ref(m);
+ int rc = func_addr(&ctx, data, data + data_sz);
+ cmod_unref(m);
region_truncate(region, region_svp);
if (rc != 0) {
@@ -843,7 +837,7 @@ do_lfunc_call(struct cmod_func *cf, struct port *args, struct port *ret)
return -1;
}
- return rc;
+ return 0;
}
/** Call a function by its name from the Lua code. */
@@ -869,7 +863,7 @@ lfunc_call(struct lua_State *L)
struct port ret;
- if (do_lfunc_call(cf, &args, &ret) != 0) {
+ if (cmod_call(cf->cmod, cf->addr, &args, &ret) != 0) {
port_destroy(&args);
return luaT_error(L);
}
diff --git a/src/box/lua/cmod.h b/src/box/lua/cmod.h
index 224779a04..c34cc156a 100644
--- a/src/box/lua/cmod.h
+++ b/src/box/lua/cmod.h
@@ -9,6 +9,7 @@
#include <sys/types.h>
#include <sys/stat.h>
+#include "box/func_def.h"
#include "trivia/config.h"
#if defined(__cplusplus)
@@ -110,6 +111,20 @@ int
cmod_find_package(const char *package, size_t package_len,
char *path, size_t path_len);
+/**
+ * Execute a function.
+ *
+ * @param m the module function sits in.
+ * @param func_addr function address to call.
+ * @args args incoming arguments.
+ * @ret rets execution results.
+ *
+ * @return 0 on success, -1 otherwise(diag is set).
+ */
+int
+cmod_call(struct cmod *m, box_function_f func_addr,
+ struct port *args, struct port *ret);
+
/**
* Initialize cmod Lua module.
*
--
2.29.2
next prev parent reply other threads:[~2021-02-17 20:17 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-17 12:39 [Tarantool-patches] [PATCH v18 0/2] box: implement cmod Lua module Cyrill Gorcunov via Tarantool-patches
2021-02-17 12:39 ` [Tarantool-patches] [PATCH v18 1/2] box/cmod: " Cyrill Gorcunov via Tarantool-patches
2021-02-17 12:39 ` [Tarantool-patches] [PATCH v18 2/2] test: box/cfunc -- add cmod test Cyrill Gorcunov via Tarantool-patches
2021-02-17 20:15 ` [Tarantool-patches] [PATCH 0/4] cmod: refactor box/func Cyrill Gorcunov via Tarantool-patches
2021-02-17 20:15 ` [Tarantool-patches] [PATCH 1/4] box/func: drop redundant module argument Cyrill Gorcunov via Tarantool-patches
2021-02-17 20:15 ` [Tarantool-patches] [PATCH 2/4] box/func: update module cache in one pass Cyrill Gorcunov via Tarantool-patches
2021-02-17 20:15 ` Cyrill Gorcunov via Tarantool-patches [this message]
2021-02-17 20:15 ` [Tarantool-patches] [PATCH 4/4] box/func: simplify func_c_call Cyrill Gorcunov via Tarantool-patches
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=20210217201521.436951-4-gorcunov@gmail.com \
--to=tarantool-patches@dev.tarantool.org \
--cc=gorcunov@gmail.com \
--cc=v.shpilevoy@tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH 3/4] cmod: export cmod_call helper' \
/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