Tarantool development patches archive
 help / color / mirror / Atom feed
From: Kirill Shcherbatov <kshcherbatov@tarantool.org>
To: tarantool-patches@freelists.org
Cc: "v.shpilevoy@tarantool.org" <v.shpilevoy@tarantool.org>
Subject: [tarantool-patches] Re: [PATCH v2 1/1] schema:frommap() to create table or tuple
Date: Mon, 2 Apr 2018 22:42:32 +0300	[thread overview]
Message-ID: <01c64ee0-2344-41ac-1ff3-b39172d99fd4@tarantool.org> (raw)
In-Reply-To: <E303D89E-172B-4967-8806-876FE67332E6@tarantool.org>

I've also updated commit message content.

diff --git a/src/box/lua/space.cc b/src/box/lua/space.cc
index f8583a2..2ff9a11 100644
--- a/src/box/lua/space.cc
+++ b/src/box/lua/space.cc
@@ -38,6 +38,7 @@ extern "C" {
  	#include <lua.h>
  	#include <lauxlib.h>
  	#include <lualib.h>
+	#include <trivia/util.h>
  } /* extern "C" */

  #include "box/space.h"
@@ -175,7 +176,7 @@ lbox_fillspace(struct lua_State *L, struct space 
*space, int i)
  	lua_pushstring(L, space->def->engine_name);
  	lua_settable(L, i);

-	/* space.schema_version */
+	/* space._schema_version */
  	lua_pushstring(L, "_schema_version");
  	luaL_pushuint64(L, box_schema_version());
  	lua_settable(L, i);
@@ -400,8 +401,8 @@ static struct trigger on_alter_space_in_lua = {
  /**
   * Get a C pointer for space structure.
   * Caches the result. Cleans the user(negative) stack itself.
- * @param Lua space object at top of the Lua stack
- * @return C structure pointer
+ * @param Lua space object at top of the Lua stack.
+ * @retval C structure pointer.
   */
  static int
  lbox_space_ptr_cached(struct lua_State *L)
@@ -422,6 +423,8 @@ 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");

  		/** update the cache */
  		luaL_pushuint64(L, global_shema_version);
@@ -435,11 +438,11 @@ lbox_space_ptr_cached(struct lua_State *L)
  }

  /**
- * Make a tuple or a table Lua object by map
- * @param Lua space object
- * @param Lua map table object
- * @param Lua opts table object (optional)
- * @return C structure pointer
+ * Make a tuple or a table Lua object by map.
+ * @param Lua space object.
+ * @param Lua map table object.
+ * @param Lua opts table object (optional).
+ * @retval C structure pointer.
   */
  static int
  lbox_space_frommap(struct lua_State *L)
@@ -461,7 +464,6 @@ lbox_space_frommap(struct lua_State *L)

  	lbox_space_ptr_cached(L);
  	space = (struct space *)lua_topointer(L, -1);
-
  	dict = space->format->dict;
  	lua_createtable(L, space->def->field_count, 0);

@@ -472,8 +474,9 @@ lbox_space_frommap(struct lua_State *L)
  		const char *key = lua_tolstring(L, -2, &key_len);
  		uint32_t key_hash = lua_hashstring(L, -2);
  		if (tuple_fieldno_by_name(dict, key, key_len, key_hash, &fieldno)) {
+			const char *err_msg = tt_sprintf("Unknown field '%s'", key);
  			lua_pushnil(L);
-			lua_pushstring(L, "Unknown field");
+			lua_pushstring(L, err_msg);
  			return 2;
  		}
  		lua_rawseti(L, -3, fieldno+1);


On 02.04.2018 14:19, v.shpilevoy@tarantool.org wrote:
> Hello. Thanks for your contributing! A several (5) minor fixes are left:
> 
> 1. Please, describe the patch in a commit message body. It would be good, if you
> write why the feature is needed, who needs this, and very short description of
> the feature itself: API usage example, options description. See Vladimir Davydov
> patches as the perfect example.
> 
>> 	/* space.schema_version */
>> 	lua_pushstring(L, "_schema_version");
>> 	luaL_pushuint64(L, box_schema_version());
>> 	lua_settable(L, i);
> 
> 2. Please, update the comment too: /* space._schema_version */ (added '_').
> 
>> /**
>>   * Get a C pointer for space structure.
>>   * Caches the result. Cleans the user(negative) stack itself.
>>   * @param Lua space object at top of the Lua stack
>>   * @return C structure pointer
>>   */
>> static int
>> lbox_space_ptr_cached(struct lua_State *L)
> 
> 3. Please, use @retval instead of @return, and put '.' at the end of a sentence.
> 
> 4. Seems like the following test crashes Tarantool. Please, fix it.
> 
> box.cfg{}
> format = {{'field1', 'unsigned'}}
> s = box.schema.create_space('test', {format = format})
> pk = s:create_index('pk')
> s:drop()
> s:frommap({field1 = 100})
> 
> Process 67761 stopped
> * thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0xe8)
>      frame #0: 0x0000000100100b68 tarantool`lbox_space_frommap(L=0x0000000103200378) at space.cc:465
>     462 		lbox_space_ptr_cached(L);
>     463 		space = (struct space *)lua_topointer(L, -1);
>     464 	
> -> 465 		dict = space->format->dict;
>     466 		lua_createtable(L, space->def->field_count, 0);
>     467 	
>     468 		lua_pushnil(L);
> Target 0: (tarantool) stopped.
> 
> 
> 
>> 		if (tuple_fieldno_by_name(dict, key, key_len, key_hash, &fieldno)) {
>> 			lua_pushnil(L);
>> 			lua_pushstring(L, "Unknown field");
>> 			return 2;
>> 		}
>> 		lua_rawseti(L, -3, fieldno+1);
> 
> 
> 5. Please, return field name into error message. In the previous patch the error message
> was ok. Just do not throw it. And put spaces before and after arithmetic operations.
> 
> 

  reply	other threads:[~2018-04-02 19:42 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 [this message]
2018-04-03  9:47             ` Vladislav Shpilevoy
2018-04-04 14:14               ` Kirill Shcherbatov
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=01c64ee0-2344-41ac-1ff3-b39172d99fd4@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