Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: Imeev Mergen <imeevma@tarantool.org>, tarantool-patches@freelists.org
Subject: [tarantool-patches] Re: [PATCH v1 1/1] lua: wrong 'tomap' work with nullable fields
Date: Fri, 24 Aug 2018 13:23:29 +0300	[thread overview]
Message-ID: <5143a8a1-5857-9f43-7135-68999228fcaa@tarantool.org> (raw)
In-Reply-To: <10fa1a23-736c-9c45-3023-9c69ed7793a1@tarantool.org>

Hi! Thanks for the fixes!

> commit 066db38393316c486b9edef0d71e854c3e4fdc78
> Author: Mergen Imeev <imeevma@gmail.com>
> Date:   Wed Aug 22 13:33:22 2018 +0300
> 
>      lua: wrong 'tomap' work with nullable fields
> 
>      Tuple method 'tomap' in some cases worked improperly if tuple
>      length less than it should be according to space format. Fixed
>      in this patch.
> 
>      Closes #3631
> 
> diff --git a/src/box/lua/tuple.c b/src/box/lua/tuple.c
> index 7ca4299..cd96152 100644
> --- a/src/box/lua/tuple.c
> +++ b/src/box/lua/tuple.c
> @@ -284,12 +284,11 @@ lbox_tuple_to_map(struct lua_State *L)
>           luaL_error(L, "Usage: tuple:tomap()");
>       const struct tuple *tuple = lua_checktuple(L, 1);
>       const struct tuple_format *format = tuple_format(tuple);
> -    const struct tuple_field *field = &format->fields[0];
>       const char *pos = tuple_data(tuple);
>       int field_count = (int)mp_decode_array(&pos);
>       int n_named = format->dict->name_count;
>       lua_createtable(L, field_count, n_named);
> -    for (int i = 0; i < n_named; ++i, ++field) {
> +    for (int i = 0; i < MIN(field_count, n_named); ++i) {

It is not ok to calculate MIN on each iteration.
Either N_named and field_count can not change during
iteration. I fixed it in a separate commit on the
branch. Please, look and squash. And send the patch
as v2 to Vova D.

>           /* Access by name. */
>           const char *name = format->dict->names[i];
>           lua_pushstring(L, name);

My diff (so far it is required by SOP since recently):

diff --git a/src/box/lua/tuple.c b/src/box/lua/tuple.c
index cd961526c..5acbecb23 100644
--- a/src/box/lua/tuple.c
+++ b/src/box/lua/tuple.c
@@ -288,7 +288,8 @@ lbox_tuple_to_map(struct lua_State *L)
  	int field_count = (int)mp_decode_array(&pos);
  	int n_named = format->dict->name_count;
  	lua_createtable(L, field_count, n_named);
-	for (int i = 0; i < MIN(field_count, n_named); ++i) {
+	int named_and_presented = MIN(field_count, n_named);
+	for (int i = 0; i < named_and_presented; ++i) {
  		/* Access by name. */
  		const char *name = format->dict->names[i];
  		lua_pushstring(L, name);

      reply	other threads:[~2018-08-24 10:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-22 10:43 [tarantool-patches] " imeevma
2018-08-22 14:16 ` [tarantool-patches] " Vladislav Shpilevoy
2018-08-22 15:31   ` Imeev Mergen
2018-08-24 10:23     ` Vladislav Shpilevoy [this message]

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=5143a8a1-5857-9f43-7135-68999228fcaa@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=imeevma@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='[tarantool-patches] Re: [PATCH v1 1/1] lua: wrong '\''tomap'\'' work with nullable fields' \
    /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