From: Vladimir Davydov <vdavydov.dev@gmail.com> To: Kirill Shcherbatov <kshcherbatov@tarantool.org> Cc: tarantool-patches@freelists.org Subject: Re: [PATCH v3 2/6] box: rework box_lua_{call, eval} to use input port Date: Tue, 18 Jun 2019 16:58:06 +0300 [thread overview] Message-ID: <20190618135806.bg4e624m6aslr3hx@esperanza> (raw) In-Reply-To: <dafa79859cc2d4c3320f2ecf0afcd027dcb9f9b6.1560433806.git.kshcherbatov@tarantool.org> On Thu, Jun 13, 2019 at 05:08:22PM +0300, Kirill Shcherbatov wrote: > diff --git a/src/box/func.c b/src/box/func.c > index d1b8879ad..740fad3d7 100644 > --- a/src/box/func.c > +++ b/src/box/func.c > @@ -433,21 +436,39 @@ func_load(struct func *func) > } > > int > -func_call(struct func *func, box_function_ctx_t *ctx, const char *args, > - const char *args_end) > +func_call(struct func *func, struct port *in_port, struct port *out_port) > { > + assert(func != NULL && func->def->language == FUNC_LANGUAGE_C); > + /* Transaction is not started. */ > + assert(!in_txn()); > if (func->func == NULL) { > if (func_load(func) != 0) > return -1; > } > > + uint32_t args_sz; > + const char *args = port_get_msgpack(in_port, &args_sz); > + if (args == NULL) > + return -1; > + > + port_tuple_create(out_port); > + box_function_ctx_t ctx = { out_port }; > + > /* Module can be changed after function reload. */ > struct module *module = func->module; > assert(module != NULL); > ++module->calls; > - int rc = func->func(ctx, args, args_end); > + int rc = func->func(&ctx, args, args + args_sz); > --module->calls; > module_gc(module); > + if (rc != 0) { > + if (diag_last_error(&fiber()->diag) == NULL) { > + /* Stored procedure forget to set diag */ > + diag_set(ClientError, ER_PROC_C, "unknown error"); > + } > + port_destroy(out_port); > + return -1; > + } Shouldn't you call region_truncate() here to clean up after the function and possibly port_get_msgpack()? > return rc; > } > > diff --git a/src/lib/core/port.h b/src/lib/core/port.h > index 8ace40fc5..2f1bc5ed1 100644 > --- a/src/lib/core/port.h > +++ b/src/lib/core/port.h > @@ -74,6 +75,8 @@ struct port_vtab { > * @retval not nil Plain text. > */ > const char *(*dump_plain)(struct port *port, uint32_t *size); > + /** Get the content of a port as a msgpack data. */ > + const char *(*get_msgpack)(struct port *port, uint32_t *size); Please mention what's the lifetime of the returned data. I guess you should say that it's implementation dependent: it may either be returned directly from the port, in which case the data will stay alive as long as the port is alive, or it may be allocated on the fiber()->gc, in which case the caller is responsible for cleaning up.
next prev parent reply other threads:[~2019-06-18 13:58 UTC|newest] Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-06-13 14:08 [PATCH v3 0/6] box: rework functions machinery Kirill Shcherbatov 2019-06-13 14:08 ` [PATCH v3 1/6] box: rework func cache update machinery Kirill Shcherbatov 2019-06-18 10:52 ` Vladimir Davydov 2019-06-19 15:51 ` [tarantool-patches] " Kirill Shcherbatov 2019-06-13 14:08 ` [PATCH v3 2/6] box: rework box_lua_{call, eval} to use input port Kirill Shcherbatov 2019-06-17 9:35 ` [tarantool-patches] " Konstantin Osipov 2019-06-17 10:27 ` [tarantool-patches] " Kirill Shcherbatov 2019-06-18 12:12 ` Vladimir Davydov 2019-06-19 15:51 ` [tarantool-patches] " Kirill Shcherbatov 2019-06-19 16:11 ` Vladimir Davydov 2019-06-18 13:58 ` Vladimir Davydov [this message] 2019-06-19 18:28 ` [tarantool-patches] " Konstantin Osipov 2019-06-20 7:53 ` Kirill Shcherbatov 2019-06-20 8:09 ` Konstantin Osipov 2019-06-20 8:44 ` [tarantool-patches] " Kirill Shcherbatov 2019-06-19 18:30 ` [tarantool-patches] " Konstantin Osipov 2019-06-13 14:08 ` [PATCH v3 3/6] box: rework func object as a function frontend Kirill Shcherbatov 2019-06-18 13:23 ` Vladimir Davydov 2019-06-19 15:51 ` [tarantool-patches] " Kirill Shcherbatov 2019-06-13 14:08 ` [PATCH v3 4/6] box: export registered functions in box.func folder Kirill Shcherbatov 2019-06-18 14:06 ` Vladimir Davydov 2019-06-19 15:51 ` [tarantool-patches] " Kirill Shcherbatov 2019-06-18 16:11 ` Vladimir Davydov 2019-06-13 14:08 ` [PATCH v3 5/6] box: refactor box_lua_find helper Kirill Shcherbatov 2019-06-18 14:22 ` Vladimir Davydov 2019-06-19 15:51 ` [tarantool-patches] " Kirill Shcherbatov 2019-06-13 14:08 ` [PATCH v3 6/6] box: introduce Lua persistent functions Kirill Shcherbatov 2019-06-18 16:23 ` Vladimir Davydov 2019-06-19 15:51 ` [tarantool-patches] " Kirill Shcherbatov
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=20190618135806.bg4e624m6aslr3hx@esperanza \ --to=vdavydov.dev@gmail.com \ --cc=kshcherbatov@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='Re: [PATCH v3 2/6] box: rework box_lua_{call, eval} to use input port' \ /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