From: Vladimir Davydov <vdavydov.dev@gmail.com> To: Kirill Shcherbatov <kshcherbatov@tarantool.org> Cc: tarantool-patches@freelists.org Subject: Re: [PATCH v4 4/6] box: export registered functions in box.func folder Date: Mon, 24 Jun 2019 13:25:31 +0300 [thread overview] Message-ID: <20190624102531.hgaj6ltzvjagvmdg@esperanza> (raw) In-Reply-To: <7a2b2881f0c025d19a1d70728eef7d6175b9c6fc.1561298197.git.kshcherbatov@tarantool.org> On Sun, Jun 23, 2019 at 04:57:55PM +0300, Kirill Shcherbatov wrote: > diff --git a/src/box/lua/call.c b/src/box/lua/call.c > index 8b7223a7c..8c70c1088 100644 > --- a/src/box/lua/call.c > +++ b/src/box/lua/call.c > @@ -284,8 +287,13 @@ port_lua_create(struct port *port, struct lua_State *L) > } > > struct execute_lua_ctx { > - const char *name; > - uint32_t name_len; > + union { > + struct { > + const char *name; > + uint32_t name_len; > + }; > + struct mpstream *stream; > + }; > struct port *args; > }; > > @@ -340,58 +348,56 @@ execute_lua_eval(lua_State *L) > static int > encode_lua_call(lua_State *L) > { > - struct port_lua *port = (struct port_lua *) lua_topointer(L, -1); > + struct execute_lua_ctx *ctx = > + (struct execute_lua_ctx *) lua_topointer(L, 1); Using the same struct for executing a function and encoding its result looks ugly. I introduced a separate struct for this - see my changes below - and pushed the patch to master. diff --git a/src/box/lua/call.c b/src/box/lua/call.c index 8c70c108..b308924c 100644 --- a/src/box/lua/call.c +++ b/src/box/lua/call.c @@ -287,13 +287,8 @@ port_lua_create(struct port *port, struct lua_State *L) } struct execute_lua_ctx { - union { - struct { - const char *name; - uint32_t name_len; - }; - struct mpstream *stream; - }; + const char *name; + uint32_t name_len; struct port *args; }; @@ -345,22 +340,26 @@ execute_lua_eval(lua_State *L) return lua_gettop(L); } +struct encode_lua_ctx { + struct port_lua *port; + struct mpstream *stream; +}; + static int encode_lua_call(lua_State *L) { - struct execute_lua_ctx *ctx = - (struct execute_lua_ctx *) lua_topointer(L, 1); + struct encode_lua_ctx *ctx = + (struct encode_lua_ctx *) lua_topointer(L, 1); /* * Add all elements from Lua stack to the buffer. * * TODO: forbid explicit yield from __serialize or __index here */ struct luaL_serializer *cfg = luaL_msgpack_default; - struct port_lua *port = (struct port_lua *) ctx->args; - int size = lua_gettop(port->L); + int size = lua_gettop(ctx->port->L); for (int i = 1; i <= size; ++i) - luamp_encode(port->L, cfg, ctx->stream, i); - port->size = size; + luamp_encode(ctx->port->L, cfg, ctx->stream, i); + ctx->port->size = size; mpstream_flush(ctx->stream); return 0; } @@ -368,16 +367,15 @@ encode_lua_call(lua_State *L) static int encode_lua_call_16(lua_State *L) { - struct execute_lua_ctx *ctx = - (struct execute_lua_ctx *) lua_topointer(L, 1); + struct encode_lua_ctx *ctx = + (struct encode_lua_ctx *) lua_topointer(L, 1); /* * Add all elements from Lua stack to the buffer. * * TODO: forbid explicit yield from __serialize or __index here */ struct luaL_serializer *cfg = luaL_msgpack_default; - struct port_lua *port = (struct port_lua *) ctx->args; - port->size = luamp_encode_call_16(port->L, cfg, ctx->stream); + ctx->port->size = luamp_encode_call_16(ctx->port->L, cfg, ctx->stream); mpstream_flush(ctx->stream); return 0; } @@ -392,8 +390,8 @@ port_lua_do_dump(struct port *base, struct mpstream *stream, * Use the same global state, assuming the encoder doesn't * yield. */ - struct execute_lua_ctx ctx; - ctx.args = base; + struct encode_lua_ctx ctx; + ctx.port = port; ctx.stream = stream; struct lua_State *L = tarantool_L; int top = lua_gettop(L);
next prev parent reply other threads:[~2019-06-24 10:25 UTC|newest] Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-06-23 13:57 [PATCH v4 0/6] box: rework functions machinery Kirill Shcherbatov 2019-06-23 13:57 ` [PATCH v4 1/6] box: rework func cache update machinery Kirill Shcherbatov 2019-06-24 10:22 ` Vladimir Davydov 2019-06-23 13:57 ` [PATCH v4 2/6] box: rework box_lua_{call, eval} to use input port Kirill Shcherbatov 2019-06-24 10:23 ` Vladimir Davydov 2019-06-23 13:57 ` [PATCH v4 3/6] box: rework func object as a function frontend Kirill Shcherbatov 2019-06-24 10:23 ` Vladimir Davydov 2019-06-23 13:57 ` [PATCH v4 4/6] box: export registered functions in box.func folder Kirill Shcherbatov 2019-06-24 10:25 ` Vladimir Davydov [this message] 2019-06-23 13:57 ` [PATCH v4 5/6] box: refactor box_lua_find helper Kirill Shcherbatov 2019-06-24 12:35 ` Vladimir Davydov 2019-06-23 13:57 ` [PATCH v4 6/6] box: introduce Lua persistent functions Kirill Shcherbatov 2019-06-24 12:38 ` Vladimir Davydov 2019-06-25 8:22 ` [tarantool-patches] " Konstantin Osipov
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=20190624102531.hgaj6ltzvjagvmdg@esperanza \ --to=vdavydov.dev@gmail.com \ --cc=kshcherbatov@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='Re: [PATCH v4 4/6] box: export registered functions in box.func folder' \ /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