Tarantool development patches archive
 help / color / mirror / Atom feed
From: Igor Munkin <imun@tarantool.org>
To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH 3/3] box: introduce box_return_mp() public C function
Date: Fri, 3 Apr 2020 17:13:01 +0300	[thread overview]
Message-ID: <20200403141301.GT22874@tarantool.org> (raw)
In-Reply-To: <cbf2f35a6fa8c2ad4b07126b1a33225cb3d1d6b4.1583689251.git.v.shpilevoy@tarantool.org>

Vlad,

Thanks for the patch! LGTM except the one nit.

On 08.03.20, Vladislav Shpilevoy wrote:
> Closes #4641
> 
> @TarantoolBot document
> Title: box_return_mp() public C function
> 
> Stored C functions could return a result only via
> `box_return_tuple()` function. That made users create a tuple
> every time they wanted to return something from a C function.
> 
> Now public C API offers another way to return - `box_return_mp()`.
> It allows to return arbitrary MessagePack, not wrapped into a
> tuple object. This is simpler to use for small results like a
> number, boolean, or a short string. Besides, `box_return_mp()` is
> much faster than `box_return_tuple()`, especially for small
> MessagePack.
> 
> Note, that it is faster only if an alternative is to create a
> tuple by yourself. If an already existing tuple was obtained from
> an iterator, and you want to return it, then of course it is
> faster to return via `box_return_tuple()`, than via extraction of
> tuple data, and calling `box_return_mp()`.
> 
> Here is the function declaration from module.h:
> ```C
> /**
>  * Return MessagePack from a stored C procedure. The MessagePack
>  * is copied, so it is safe to free/reuse the passed arguments
>  * after the call.
>  * MessagePack is not validated, for the sake of speed. It is
>  * expected to be a single encoded object. An attempt to encode
>  * and return multiple objects without wrapping them into an
>  * MP_ARRAY or MP_MAP is undefined behaviour.
>  *
>  * \param ctx An opaque structure passed to the stored C procedure
>  *        by Tarantool.
>  * \param mp Begin of MessagePack.
>  * \param mp_end End of MessagePack.
>  * \retval -1 Error.
>  * \retval 0 Success.
>  */
> API_EXPORT int
> box_return_mp(box_function_ctx_t *ctx, const char *mp, const char *mp_end);
> ```
> ---
>  extra/exports               |  1 +
>  src/box/box.cc              |  6 ++++++
>  src/box/box.h               | 19 +++++++++++++++++++
>  test/box/function1.c        | 37 +++++++++++++++++++++++++++++++++++++
>  test/box/function1.result   | 31 +++++++++++++++++++++++++++++++
>  test/box/function1.test.lua | 14 ++++++++++++++
>  6 files changed, 108 insertions(+)
> 

<snipped>

> diff --git a/test/box/function1.result b/test/box/function1.result
> index b91d63c51..301f666ef 100644
> --- a/test/box/function1.result
> +++ b/test/box/function1.result
> @@ -791,6 +791,37 @@ box.schema.func.drop("function1.multireturn")
>  ---
>  ...
>  --
> +-- gh-4641: box_return_mp() C API to return arbitrary MessagePack
> +-- from C functions.
> +--
> +name = 'function1.test_return_mp'
> +---
> +...
> +box.schema.func.create(name, {language = "C", exports = {'LUA'}})
> +---
> +...
> +box.func[name]:call()
> +---
> +- 1
> +- -1
> +- 18446744073709551615
> +- '123456789101112131415'
> +- [2]
> +...
> +box.schema.user.grant('guest', 'super')
> +---
> +...

Minor: I guess it worth to add a comment below referring the #4799 since
I was confused with the output below.

> +net:connect(box.cfg.listen):call(name)
> +---
> +- [1, -1, 18446744073709551615, '123456789101112131415', [2]]
> +...
> +box.schema.user.revoke('guest', 'super')
> +---
> +...
> +box.schema.func.drop(name)
> +---
> +...
> +--
>  -- gh-4182: Introduce persistent Lua functions.
>  --
>  test_run:cmd("setopt delimiter ';'")

<snipped>

> -- 
> 2.21.1 (Apple Git-122.3)
> 

-- 
Best regards,
IM

  parent reply	other threads:[~2020-04-03 14:19 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-08 17:47 [Tarantool-patches] [PATCH 0/3] box_return_mp Vladislav Shpilevoy
2020-03-08 17:47 ` [Tarantool-patches] [PATCH 1/3] box: fix struct port_tuple.size wrong type in Lua Vladislav Shpilevoy
2020-03-10 13:42   ` Nikita Pettik
2020-03-11  0:17     ` Vladislav Shpilevoy
2020-03-08 17:47 ` [Tarantool-patches] [PATCH 2/3] box: introduce port_c Vladislav Shpilevoy
2020-03-26 17:49   ` Nikita Pettik
2020-04-23  0:14     ` Vladislav Shpilevoy
2020-04-27 14:09       ` Nikita Pettik
2020-04-27 21:28         ` Vladislav Shpilevoy
2020-04-27 23:24           ` Nikita Pettik
2020-04-03 14:12   ` Igor Munkin
2020-04-23  0:14     ` Vladislav Shpilevoy
2020-03-08 17:47 ` [Tarantool-patches] [PATCH 3/3] box: introduce box_return_mp() public C function Vladislav Shpilevoy
2020-03-26 17:51   ` Nikita Pettik
2020-04-03 14:13   ` Igor Munkin [this message]
2020-04-23  0:14     ` Vladislav Shpilevoy

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=20200403141301.GT22874@tarantool.org \
    --to=imun@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH 3/3] box: introduce box_return_mp() public C function' \
    /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