From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp5.mail.ru (smtp5.mail.ru [94.100.179.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 04E5C46970F for ; Mon, 25 Nov 2019 00:18:56 +0300 (MSK) Received: by smtp5.mail.ru with esmtpa (envelope-from ) id 1iYzHU-0000YS-Dd for tarantool-patches@dev.tarantool.org; Mon, 25 Nov 2019 00:18:56 +0300 From: Chris Sosnin Date: Mon, 25 Nov 2019 00:18:55 +0300 Message-Id: <76faabe3149b2671950cea5b5c9bb18df15472f5.1574630240.git.k.sosnin@tarantool.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH] box: frommap() bug fix List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@dev.tarantool.org - 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. - 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 --- 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; luaT_pushtuple(L, tuple); return 1; usage_error: diff --git a/test/box/tuple.result b/test/box/tuple.result index 9140211b7..bbb60d5e7 100644 --- a/test/box/tuple.result +++ b/test/box/tuple.result @@ -1121,7 +1121,8 @@ s:frommap() ... s:frommap({}) --- -- error: Tuple field 1 required by space format is missing +- null +- Tuple field 1 required by space format is missing ... s:frommap({ddd = 1, aaa = 2, ccc = 3, bbb = 4}, {table = true}) --- -- 2.24.0