Tarantool development patches archive
 help / color / mirror / Atom feed
From: Kirill Shcherbatov <kshcherbatov@tarantool.org>
To: tarantool-patches@freelists.org
Cc: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Subject: [tarantool-patches] Re: [PATCH v2 1/1] schema:frommap() to create table or tuple
Date: Wed, 4 Apr 2018 17:14:53 +0300	[thread overview]
Message-ID: <832dae8c-3736-1547-b0a4-75f1c8debc52@tarantool.org> (raw)
In-Reply-To: <b92831b2-a7ec-4148-2c15-fcf3b9d0bd6c@tarantool.org>


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 <lua.h>
>>       #include <lauxlib.h>
>>       #include <lualib.h>
>> +    #include <trivia/util.h>
>>   } /* 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 <lua.h>
  	#include <lauxlib.h>
  	#include <lualib.h>
-	#include <trivia/util.h>
  } /* 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)

  reply	other threads:[~2018-04-04 14:14 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-28 17:51 [tarantool-patches] " Kirill Shcherbatov
2018-03-28 18:28 ` Kirill Shcherbatov
2018-03-29  7:36   ` [tarantool-patches] " Kirill Shcherbatov
2018-03-29 10:14     ` v.shpilevoy
2018-04-02 10:26       ` Kirill Shcherbatov
2018-04-02 11:19         ` v.shpilevoy
2018-04-02 19:42           ` Kirill Shcherbatov
2018-04-03  9:47             ` Vladislav Shpilevoy
2018-04-04 14:14               ` Kirill Shcherbatov [this message]
2018-04-04 16:35                 ` [tarantool-patches] " Kirill Shcherbatov
2018-04-04 16:43                   ` Vladislav Shpilevoy
2018-04-06 13:47                   ` Vladimir Davydov
2018-04-06 15:44                   ` [tarantool-patches] " Konstantin Osipov
2018-04-09  8:30                     ` Kirill Shcherbatov
2018-04-09 10:44                       ` Vladislav Shpilevoy
2018-04-09 17:23                         ` Kirill Shcherbatov
2018-04-09 17:45                           ` Vladislav Shpilevoy
2018-04-10 10:31                           ` Vladimir Davydov

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=832dae8c-3736-1547-b0a4-75f1c8debc52@tarantool.org \
    --to=kshcherbatov@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='[tarantool-patches] Re: [PATCH v2 1/1] schema:frommap() to create table or tuple' \
    /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