From 3b14c75127c2172a48aca03127ecd5caa54f52dd Mon Sep 17 00:00:00 2001
From: Konstantin Osipov <kostja@tarantool.org>
Date: Thu, 14 Nov 2013 19:28:36 +0400
Subject: [PATCH] MessagePack: minor review fixes.

No semantical changes. Style fixes, comments.
---
 doc/box-protocol.txt    | 21 +++++++++++----------
 include/lua/utils.h     | 26 ++++++++++++++------------
 src/box/bitset_index.cc |  2 +-
 src/box/box_lua.cc      |  5 ++---
 src/box/hash_index.cc   |  2 +-
 src/box/index.cc        |  4 ++--
 src/box/schema.cc       |  2 +-
 src/box/tree_index.cc   |  2 +-
 src/box/tuple.cc        |  4 ++--
 9 files changed, 35 insertions(+), 33 deletions(-)

diff --git a/doc/box-protocol.txt b/doc/box-protocol.txt
index 3de24f9e1d..1654bb86ff 100644
--- a/doc/box-protocol.txt
+++ b/doc/box-protocol.txt
@@ -14,9 +14,12 @@ Tarantool IPROTO protocol.
 ; int8 - a single 8-bit byte (i.e. an octet)
 ;
 ; int32 - a 32-bit integer in little-endian format (Intel x86)
-
+;
 ; int64 - a 64-bit integer in little-endian format (Intel x86)
 ;
+; msgpack - a valid msgpack sequence for everything else, see
+; http://msgpack.org
+;
 ; All requests and responses utilize the same basic structure:
 
 <packet> ::= <request> | <response>
@@ -27,7 +30,7 @@ Tarantool IPROTO protocol.
 ; response is an error message.
 ;
 
-<response> ::= <header><return_code>{<response_body>}
+<response> ::= <header><response_body>
 
 ;
 ; <header> has a fixed structure of three 4-byte integers (12 bytes):
@@ -86,15 +89,13 @@ Tarantool IPROTO protocol.
 
 ;
 ; <response_body> carries command reply
-; It is only present if <return_code> is 0 (success).
-; <call_response_body> can be arbitrary, it purely depends
-; on what your procedure does.
+; If <return_code> is 0 (success), it contains zero or more
+; tuples, otherwise it carries an error message that corresponds 
+; the return code.
 ; 
 
-<response_body> ::= <select_response_body> |
-                    <insert_response_body> |
-                    <update_response_body> |
-                    <delete_response_body>
+<response_body> ::= <return_code><text> |
+                    <0><count><fq_tuple>*
 
 ; <select_request_body> (required <header> <type> is 17):
 ;
@@ -262,7 +263,7 @@ Tarantool IPROTO protocol.
 ; field data in case of splice argument contains 3 nested <field>
 ; objects, which store the arguments:
 
-<op_arg_splice> ::= <message_pack_array(3)><offset><length><string>
+<op_arg_splice> ::= <message_pack_array(3)> # <offset><length><string>
 
 <offset> ::= <message_pack_uint>
 <length> ::= <message_pack_uint>
diff --git a/include/lua/utils.h b/include/lua/utils.h
index e7771a6bd9..9c1e86472c 100644
--- a/include/lua/utils.h
+++ b/include/lua/utils.h
@@ -50,7 +50,7 @@ struct lua_State;
 
 /**
  * @brief Allocate a new block of memory with the given size, push onto the
- * stack a new cdata of type ctypeid with the block address, and returns
+ * stack a new cdata of type ctypeid with the block address, and return
  * this address. Allocated memory is a subject of GC.
  * CTypeID must be used from FFI at least once.
  * @param L Lua State
@@ -95,8 +95,8 @@ struct luaL_field {
 
 /**
  * @brief Convert a value from the Lua stack to a lua_field structure.
- * This function is designed to use with lua bindings and data
- * serializators (YAML, MsgPack, JSON, etc.).
+ * This function is designed for use with Lua bindings and data
+ * serialization functions (YAML, MsgPack, JSON, etc.).
  *
  * Conversion rules:
  * - LUA_TNUMBER when is integer and >= 0 -> UINT
@@ -115,26 +115,28 @@ struct luaL_field {
  * - CTID_BOOL -> BOOL
  * - otherwise -> EXT
  *
- * By default all LUA_TTABLEs (incl. empty ones) are handled as ARRAYs.
- * If a table has non-numbering indexes or the table is too sparse when it will
- * be handles as a map. The user can force MAP or ARRAY serialization by
- * setting a metatable with "_serializer_type" = "map" | "array" value.
+ * By default all LUA_TTABLEs (including empty ones) are handled as ARRAYs.
+ * If a table has other than numeric indexes or is too
+ * sparse, then it is handled as a map. The user can force MAP or
+ * ARRAY serialization by setting * "_serializer_type" = "map" | "array"
+ * in the table's metatable.
  *
- * YAML also supports special "_serializer_compact" = true | false
+ * YAML also supports a special "_serializer_compact" = true | false
  * flag that controls block vs flow output ([1,2,3] vs - 1\n - 2\n - 3\n).
+ * It can be set in the table's metatable.
  *
  * MAP and ARRAY members are not saved to lua_field structure and should be
- * process manually.
+ * processed manually.
  *
- * Use the following code for ARRAYs:
+ * Use the following code for arrays:
  * field.max; // the maximal index of the array
  * for (uint32_t i = 0; i < field.max; i++) {
- * lua_rawgeti(L, index, i + 1);
+ *	lua_rawgeti(L, index, i + 1);
  *	handle_value(L, -1)
  *	lua_pop(L, 1);
  * }
  *
- * Use the following code for MAPs:
+ * Use the following code for maps:
  * field.size; // the number of members in the map
  * lua_pushnil(L);
  * while (lua_next(L, index) != 0) {
diff --git a/src/box/bitset_index.cc b/src/box/bitset_index.cc
index afcfda674e..86562ffaea 100644
--- a/src/box/bitset_index.cc
+++ b/src/box/bitset_index.cc
@@ -200,7 +200,7 @@ BitsetIndex::initIterator(struct iterator *iterator, enum iterator_type type,
 			  const char *key, uint32_t part_count) const
 {
 	assert(iterator->free == bitset_index_iterator_free);
-	assert (part_count != 0 || key == NULL);
+	assert(part_count != 0 || key == NULL);
 	(void) part_count;
 
 	struct bitset_index_iterator *it = bitset_index_iterator(iterator);
diff --git a/src/box/box_lua.cc b/src/box/box_lua.cc
index 5348d5e408..e07536d5c7 100644
--- a/src/box/box_lua.cc
+++ b/src/box/box_lua.cc
@@ -31,7 +31,6 @@
 #include "lua/init.h"
 #include "lua/utils.h"
 #include "lua/msgpack.h"
-#include <signal.h>
 #include <fiber.h>
 #include "box/box.h"
 #include "request.h"
@@ -538,14 +537,14 @@ lbox_tuple_next(struct lua_State *L)
 	struct tuple_iterator *it = NULL;
 	if (argc == 0 || (argc == 1 && lua_type(L, 2) == LUA_TNIL)) {
 		it = (struct tuple_iterator *) lua_newuserdata(L, sizeof(*it));
-		assert (it != NULL);
+		assert(it != NULL);
 		luaL_getmetatable(L, tuple_iteratorlib_name);
 		lua_setmetatable(L, -2);
 		tuple_rewind(it, tuple);
 	} else if (argc == 1 && lua_type(L, 2) == LUA_TUSERDATA) {
 		it = (struct tuple_iterator *)
 			luaL_checkudata(L, 2, tuple_iteratorlib_name);
-		assert (it != NULL);
+		assert(it != NULL);
 		lua_pushvalue(L, 2);
 	} else {
 		return luaL_error(L, "tuple.next(): bad arguments");
diff --git a/src/box/hash_index.cc b/src/box/hash_index.cc
index 68cc670697..d81aa7985d 100644
--- a/src/box/hash_index.cc
+++ b/src/box/hash_index.cc
@@ -285,7 +285,7 @@ void
 HashIndex::initIterator(struct iterator *ptr, enum iterator_type type,
 			const char *key, uint32_t part_count) const
 {
-	assert (key != NULL || part_count == 0);
+	assert(key != NULL || part_count == 0);
 	(void) part_count;
 	assert(ptr->free == hash_iterator_free);
 
diff --git a/src/box/index.cc b/src/box/index.cc
index b4a88a248c..94b9987e79 100644
--- a/src/box/index.cc
+++ b/src/box/index.cc
@@ -59,7 +59,7 @@ void
 key_validate(struct key_def *key_def, enum iterator_type type, const char *key,
 	     uint32_t part_count)
 {
-	assert (key != NULL || part_count == 0);
+	assert(key != NULL || part_count == 0);
 	if (part_count == 0) {
 		/*
 		 * Zero key parts are allowed:
@@ -89,7 +89,7 @@ void
 primary_key_validate(struct key_def *key_def, const char *key,
 		     uint32_t part_count)
 {
-	assert (key != NULL || part_count == 0);
+	assert(key != NULL || part_count == 0);
 	if (key_def->part_count != part_count) {
 		tnt_raise(ClientError, ER_EXACT_MATCH,
 			  key_def->part_count, part_count);
diff --git a/src/box/schema.cc b/src/box/schema.cc
index e22f817aed..2d54d9be55 100644
--- a/src/box/schema.cc
+++ b/src/box/schema.cc
@@ -88,7 +88,7 @@ space_foreach(void (*func)(struct space *sp, void *udata), void *udata)
 	mh_int_t i;
 	struct space *space;
 	char key[6];
-	assert (mp_sizeof_uint(SC_SYSTEM_ID_MIN) <= sizeof(key));
+	assert(mp_sizeof_uint(SC_SYSTEM_ID_MIN) <= sizeof(key));
 	mp_encode_uint(key, SC_SYSTEM_ID_MIN);
 
 	/*
diff --git a/src/box/tree_index.cc b/src/box/tree_index.cc
index 1576001c1c..caf1b75aee 100644
--- a/src/box/tree_index.cc
+++ b/src/box/tree_index.cc
@@ -286,7 +286,7 @@ void
 TreeIndex::initIterator(struct iterator *iterator, enum iterator_type type,
 			const char *key, uint32_t part_count) const
 {
-	assert (key != NULL || part_count == 0);
+	assert(key != NULL || part_count == 0);
 	struct tree_iterator *it = tree_iterator(iterator);
 
 	if (part_count == 0) {
diff --git a/src/box/tuple.cc b/src/box/tuple.cc
index 7e892c052e..d155a233a1 100644
--- a/src/box/tuple.cc
+++ b/src/box/tuple.cc
@@ -384,7 +384,7 @@ tuple_update(struct tuple_format *format,
 					&new_size);
 
 	/* Allocate a new tuple. */
-	assert (mp_typeof(*new_data) == MP_ARRAY);
+	assert(mp_typeof(*new_data) == MP_ARRAY);
 	struct tuple *new_tuple = tuple_new(format, &new_data,
 					    new_data + new_size);
 
@@ -401,7 +401,7 @@ struct tuple *
 tuple_new(struct tuple_format *format, const char **data, const char *end)
 {
 	size_t tuple_len = end - *data;
-	assert (mp_typeof(**data) == MP_ARRAY);
+	assert(mp_typeof(**data) == MP_ARRAY);
 	struct tuple *new_tuple = tuple_alloc(format, tuple_len);
 	memcpy(new_tuple->data, end - tuple_len, tuple_len);
 	try {
-- 
GitLab