From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 4115E2B669 for ; Wed, 4 Apr 2018 10:14:56 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id XwGiTmwumS-1 for ; Wed, 4 Apr 2018 10:14:56 -0400 (EDT) Received: from smtp21.mail.ru (smtp21.mail.ru [94.100.179.250]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id F27C92B619 for ; Wed, 4 Apr 2018 10:14:55 -0400 (EDT) Subject: [tarantool-patches] Re: [PATCH v2 1/1] schema:frommap() to create table or tuple References: <90ece9a705197ded006ef50155f3b1bfca4c8d8f.1522261662.git.kshcherbatov@tarantool.org> <7a5c0afb-c030-fcd2-7d86-5c92cd7fa850@tarantool.org> <01c64ee0-2344-41ac-1ff3-b39172d99fd4@tarantool.org> From: Kirill Shcherbatov Message-ID: <832dae8c-3736-1547-b0a4-75f1c8debc52@tarantool.org> Date: Wed, 4 Apr 2018 17:14:53 +0300 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format="flowed" Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org Cc: Vladislav Shpilevoy On 03.04.2018 12:47, Vladislav Shpilevoy wrote: > Hello. Please, consider 4 comments below. >> diff --git a/src/box/lua/space.cc b/src/box/lua/space.cc >> index 29a9aca..2ff9a11 100644 >> --- a/src/box/lua/space.cc >> +++ b/src/box/lua/space.cc >> @@ -32,11 +32,13 @@ >>   #include "box/lua/tuple.h" >>   #include "lua/utils.h" >>   #include "lua/trigger.h" >> +#include "box/schema.h" >>   extern "C" { >>       #include >>       #include >>       #include >> +    #include >>   } /* extern "C" */ > 1. Schema.h is included below. Trivia/util.h is not needed here. diff --git a/src/box/lua/space.cc b/src/box/lua/space.cc index 2ff9a11..9004c0e 100644 --- a/src/box/lua/space.cc +++ b/src/box/lua/space.cc @@ -38,7 +38,6 @@ extern "C" { #include #include #include - #include } /* extern "C" */ #include "box/space.h" > >> +        space = space_by_id(id); >> +        if (!space) >> +            luaL_error(L, "Specified space is not exists"); >> + > 2. Please, for pointers use explicit != NULL. > > 3. As I noted earlier, a function must not raise an error. It must > return nil + error message/object. > And please, check your comments grammar: you can not say "is not > exists". Perhaps, > you meant "does not exist". > @@ -423,8 +422,14 @@ lbox_space_ptr_cached(struct lua_State *L) lua_getfield(L, 1, "id"); uint32_t id = luaL_touint64(L, -1); space = space_by_id(id); - if (!space) - luaL_error(L, "Specified space is not exists"); + if (space == NULL) { + const char *err_msg; + err_msg = tt_sprintf("Space with id '%d' doesn't exists", + id); + lua_pushnil(L); + lua_pushstring(L, err_msg); + return 2; + } /** update the cache */ luaL_pushuint64(L, global_shema_version); @@ -462,8 +467,14 @@ lbox_space_frommap(struct lua_State *L) table = lua_toboolean(L, -1); } - lbox_space_ptr_cached(L); - space = (struct space *)lua_topointer(L, -1); + if (lbox_space_ptr_cached(L) == 1) { + space = (struct space *) lua_topointer(L, -1); + } else { + const char *err_msg = lua_tostring(L, -1); + lua_pushnil(L); + lua_pushstring(L, err_msg); + return 2; + } dict = space->format->dict; lua_createtable(L, space->def->field_count, 0); > 4. I do not see my crash test in your space_frommap.test.lua. When I > provide you a test, or you > found an own, you must add it to the patch. > There is the same test case here: diff --git a/test/box/space_frommap.test.lua b/test/box/space_frommap.test.lua index ff7ef98..647d761 100644 --- a/test/box/space_frommap.test.lua +++ b/test/box/space_frommap.test.lua @@ -21,4 +21,7 @@ subscriber:frommap({ddd = 1, aaa = 2, ccc = 3, bbb = 4}, {dummy = true}) _ = subscriber:create_index('primary', {parts={'aaa'}}) tuple = subscriber:frommap({ddd = 1, aaa = 2, ccc = 3, bbb = 4}) subscriber:replace(tuple) +_ = box.internal.space._cptr(subscriber) subscriber:drop() +_ = subscriber:frommap({ddd = 1, aaa = 2, ccc = 3, bbb = 4}) +_ = box.internal.space._cptr(subscriber)