Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: tarantool-patches@freelists.org, Nikita Pettik <korablev@tarantool.org>
Cc: Georgy Kirichenko <georgy@tarantool.org>
Subject: [tarantool-patches] Re: [PATCH 2/6] sql: annotate SQL functions with return type
Date: Thu, 27 Sep 2018 23:23:53 +0300	[thread overview]
Message-ID: <00abc300-9b7a-f247-cc34-90cb7e904483@tarantool.org> (raw)
In-Reply-To: <d68ec3c0531c456c4d81a7af037113b004e1d6d0.1537216078.git.korablev@tarantool.org>

My review fixes are on the branch in a separate
commit and here:

==========================================================================

diff --git a/src/box/lua/lua_sql.c b/src/box/lua/lua_sql.c
index e69e143db..f9e63aae6 100644
--- a/src/box/lua/lua_sql.c
+++ b/src/box/lua/lua_sql.c
@@ -130,10 +130,8 @@ int
  lbox_sql_create_function(struct lua_State *L)
  {
  	struct sqlite3 *db = sql_get();
-	if (db == NULL) {
-		luaL_error(L, "Please call box.cfg{} first");
-		return 0;
-	}
+	if (db == NULL)
+		return luaL_error(L, "Please call box.cfg{} first");
  	int argc = lua_gettop(L);
  	/*
  	 * Three function prototypes are possible:
@@ -149,53 +147,46 @@ lbox_sql_create_function(struct lua_State *L)
  	      lua_isfunction(L, 3) && lua_isnumber(L, 4)) &&
  	    !(argc == 5 && lua_isstring(L, 1) && lua_isstring(L, 2) &&
  	      lua_isfunction(L, 3) && lua_isnumber(L, 4) &&
-	      lua_isboolean(L, 5))) {
-		luaL_error(L, "Invalid arguments");
-		return 0;
-	}
+	      lua_isboolean(L, 5)))
+		return luaL_error(L, "Invalid arguments");
  	enum affinity_type type = AFFINITY_UNDEFINED;
  	const char *type_arg = lua_tostring(L, 2);
-	if (strcmp(type_arg, "INT") == 0 || strcmp(type_arg, "INTEGER") == 0) {
+	if (strcmp(type_arg, "INT") == 0 || strcmp(type_arg, "INTEGER") == 0)
  		type = AFFINITY_INTEGER;
-	} else if (strcmp(type_arg, "TEXT") == 0) {
+	else if (strcmp(type_arg, "TEXT") == 0)
  		type = AFFINITY_TEXT;
-	} else if (strcmp(type_arg, "FLOAT") == 0) {
+	else if (strcmp(type_arg, "FLOAT") == 0)
  		type = AFFINITY_REAL;
-	} else if (strcmp(type_arg, "NUM") == 0) {
+	else if (strcmp(type_arg, "NUM") == 0)
  		type = AFFINITY_NUMERIC;
-	} else if (strcmp(type_arg, "BLOB") == 0) {
+	else if (strcmp(type_arg, "BLOB") == 0)
  		type = AFFINITY_BLOB;
-	} else {
-		luaL_error(L, "Unknown type");
-	}
+	else
+		return luaL_error(L, "Unknown type");
  	/* -1 indicates any number of arguments. */
  	int func_arg_num = -1;
  	bool is_deterministic = false;
  	if (argc == 4) {
-		func_arg_num = (int) lua_tonumber(L, 4);
+		func_arg_num = lua_tointeger(L, 4);
  		lua_pop(L, 1);
  	} else if (argc == 5) {
  		is_deterministic = lua_toboolean(L, 5);
-		func_arg_num = (int) lua_tonumber(L, 4);
+		func_arg_num = lua_tointeger(L, 4);
  		lua_pop(L, 2);
  	}
-	const char *name = lua_tostring(L, 1);
-	size_t name_len = strlen(name);
+	size_t name_len;
+	const char *name = lua_tolstring(L, 1, &name_len);
  	char *normalized_name = (char *) region_alloc(&fiber()->gc,
  						      name_len + 1);
-	if (normalized_name == NULL) {
-		luaL_error(L, "out of memory");
-		return 0;
-	}
+	if (normalized_name == NULL)
+		return luaL_error(L, "out of memory");
  	memcpy(normalized_name, name, name_len);
  	normalized_name[name_len] = '\0';
  	sqlite3NormalizeName(normalized_name);
  	struct lua_sql_func_info *func_info =
  		(struct lua_sql_func_info *) malloc(sizeof(*func_info));
-	if (func_info == NULL) {
-		luaL_error(L, "out of memory");
-		return 0;
-	}
+	if (func_info == NULL)
+		return luaL_error(L, "out of memory");
  	func_info->func_ref = luaL_ref(L, LUA_REGISTRYINDEX);
  	sqlite3_create_function_v2(db, normalized_name, type, func_arg_num,
  				   is_deterministic ? SQLITE_DETERMINISTIC : 0,

  reply	other threads:[~2018-09-27 20:23 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-17 20:32 [tarantool-patches] [PATCH 0/6] Introduce strict typing for SQL Nikita Pettik
2018-09-17 20:32 ` [tarantool-patches] [PATCH 1/6] sql: split conflict action and affinity for Expr Nikita Pettik
2018-09-19  2:16   ` [tarantool-patches] " Konstantin Osipov
2018-09-27 20:24   ` Vladislav Shpilevoy
2018-10-12 11:18     ` n.pettik
2018-09-17 20:32 ` [tarantool-patches] [PATCH 2/6] sql: annotate SQL functions with return type Nikita Pettik
2018-09-27 20:23   ` Vladislav Shpilevoy [this message]
2018-10-12 11:18     ` [tarantool-patches] " n.pettik
2018-09-17 20:32 ` [tarantool-patches] [PATCH 3/6] sql: pass true types of columns to Tarantool Nikita Pettik
2018-09-19  2:23   ` [tarantool-patches] " Konstantin Osipov
2018-10-12 11:19     ` n.pettik
2018-09-27 20:23   ` Vladislav Shpilevoy
2018-10-12 11:18     ` n.pettik
2018-10-17 21:45       ` Vladislav Shpilevoy
2018-10-23 23:28         ` n.pettik
2018-10-29 21:32           ` Vladislav Shpilevoy
2018-11-02  2:36             ` n.pettik
2018-09-17 20:32 ` [tarantool-patches] [PATCH 4/6] sql: enforce implicit type conversions Nikita Pettik
2018-09-19  2:25   ` [tarantool-patches] " Konstantin Osipov
2018-09-27 20:24   ` Vladislav Shpilevoy
2018-10-12 11:19     ` n.pettik
2018-10-17 21:45       ` Vladislav Shpilevoy
2018-10-23 23:28         ` n.pettik
2018-10-29 21:32           ` Vladislav Shpilevoy
2018-11-02  2:36             ` n.pettik
2018-11-02 11:15               ` Vladislav Shpilevoy
2018-11-02 13:26                 ` n.pettik
2018-09-17 20:32 ` [tarantool-patches] [PATCH 5/6] sql: return result-set type via IProto Nikita Pettik
2018-09-19  2:26   ` [tarantool-patches] " Konstantin Osipov
2018-09-27 20:24   ` Vladislav Shpilevoy
2018-10-12 11:19     ` n.pettik
2018-10-17 21:45       ` Vladislav Shpilevoy
2018-10-23 23:28         ` n.pettik
2018-09-17 20:32 ` [tarantool-patches] [PATCH 6/6] sql: discard numeric conversion by unary plus Nikita Pettik
2018-09-27 20:24   ` [tarantool-patches] " Vladislav Shpilevoy
2018-10-12 11:19     ` n.pettik
2018-09-27 20:24 ` [tarantool-patches] Re: [PATCH 0/6] Introduce strict typing for SQL Vladislav Shpilevoy
2018-10-12 11:18   ` n.pettik
2018-11-03  2:41 ` Kirill Yukhin

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=00abc300-9b7a-f247-cc34-90cb7e904483@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=georgy@tarantool.org \
    --cc=korablev@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='[tarantool-patches] Re: [PATCH 2/6] sql: annotate SQL functions with return type' \
    /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