Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: Chris Sosnin <k.sosnin@tarantool.org>,
	tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH] box: frommap() bug fix
Date: Tue, 26 Nov 2019 22:01:24 +0100	[thread overview]
Message-ID: <ab97a7cf-e068-e97c-71eb-557ec4ae8097@tarantool.org> (raw)
In-Reply-To: <76faabe3149b2671950cea5b5c9bb18df15472f5.1574630240.git.k.sosnin@tarantool.org>

Thanks for the patch!

See 4 comments below.

On 24/11/2019 22:18, Chris Sosnin wrote:
> - If an optional argument is provided for
>   space_object:frommap() (which is {table = true|false}),
>   type match for first arguments is omitted, which is
>   incorrect. We should return the result only after making
>   sure it is possible to build a tuple.

1. This is a good catch. Please, provide a test. To ensure,
that it won't break again in the future.

I think you fit it in an existing test file, where other
frommap() cases are checked. It is not worth creating a new
test file just for this tiny ticket.

> 
> - If there is a type mismatch, however, frommap() does not
>   return nil, err as it is mentioned in the description, so we
>   change it to be this way.
> 
> Closes: #4262
> ---

2. All the same as for #4515 email.

>  src/box/lua/space.cc  | 11 +++++++----
>  test/box/tuple.result |  3 ++-
>  2 files changed, 9 insertions(+), 5 deletions(-)
> 
> diff --git a/src/box/lua/space.cc b/src/box/lua/space.cc
> index f6e96f0c0..a4ffa8240 100644
> --- a/src/box/lua/space.cc
> +++ b/src/box/lua/space.cc
> @@ -580,14 +580,17 @@ lbox_space_frommap(struct lua_State *L)
>  		}
>  		lua_rawseti(L, -3, fieldno+1);
>  	}
> -	if (table)
> -		return 1;
> 
>  	lua_replace(L, 1);
>  	lua_settop(L, 1);
>  	tuple = luaT_tuple_new(L, -1, space->format);
> -	if (tuple == NULL)
> -		return luaT_error(L);
> +	if (tuple == NULL) {
> +		struct error *e = diag_last_error(&fiber()->diag);
> +		lua_pushnil(L);
> +		lua_pushstring(L, e->errmsg);
> +		return 2;
> +	} else if (table)
> +		return 1;

3. Nit: I think you may omit 'else' keyword here. Anyway
the previous condition makes a return.

4. When any if's or else's body has {}, all the others
in the same chain should have it as well. So 'return 1;'
should also be in {}.

>  	luaT_pushtuple(L, tuple);
>  	return 1;
>  usage_error:

  reply	other threads:[~2019-11-26 21:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-24 21:18 Chris Sosnin
2019-11-26 21:01 ` Vladislav Shpilevoy [this message]
2020-01-10  7:31 Chris Sosnin
2020-01-14 10:49 Chris Sosnin
2020-01-14 11:38 ` Kirill Yukhin

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=ab97a7cf-e068-e97c-71eb-557ec4ae8097@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=k.sosnin@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH] box: frommap() bug fix' \
    /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