From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 97417430411 for ; Fri, 14 Aug 2020 18:05:06 +0300 (MSK) From: imeevma@tarantool.org Date: Fri, 14 Aug 2020 18:05:05 +0300 Message-Id: <14bca5aab8484f9fcd0c93b29c183a8133b71d35.1597417321.git.imeevma@gmail.com> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v2 08/10] box: add param_list to 'struct func' List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: v.shpilevoy@tarantool.org, tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org This is needed to create an uniform way to check the types of arguments of SQL built-in functions. Part of #4159 --- src/box/alter.cc | 12 ++++++++++-- src/box/func.c | 1 + src/box/func_def.h | 2 ++ src/box/lua/call.c | 2 ++ src/box/sql/func.c | 1 + 5 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/box/alter.cc b/src/box/alter.cc index ba96d9c62..0914a7615 100644 --- a/src/box/alter.cc +++ b/src/box/alter.cc @@ -3293,7 +3293,11 @@ func_def_new_from_tuple(struct tuple *tuple) diag_set(OutOfMemory, def_sz, "malloc", "def"); return NULL; } - auto def_guard = make_scoped_guard([=] { free(def); }); + def->param_list = NULL; + auto def_guard = make_scoped_guard([=] { + free(def->param_list); + free(def); + }); if (func_def_get_ids_from_tuple(tuple, &def->fid, &def->uid) != 0) return NULL; if (def->fid > BOX_FUNCTION_MAX) { @@ -3403,6 +3407,8 @@ func_def_new_from_tuple(struct tuple *tuple) if (param_list == NULL) return NULL; uint32_t argc = mp_decode_array(¶m_list); + uint32_t size = sizeof(enum field_type) * argc; + def->param_list = (enum field_type *)malloc(size); for (uint32_t i = 0; i < argc; i++) { if (mp_typeof(*param_list) != MP_STR) { diag_set(ClientError, ER_FIELD_TYPE, @@ -3412,7 +3418,8 @@ func_def_new_from_tuple(struct tuple *tuple) } uint32_t len; const char *str = mp_decode_str(¶m_list, &len); - if (STRN2ENUM(field_type, str, len) == field_type_MAX) { + def->param_list[i] = STRN2ENUM(field_type, str, len); + if (def->param_list[i] == field_type_MAX) { diag_set(ClientError, ER_CREATE_FUNCTION, def->name, "invalid argument type"); return NULL; @@ -3433,6 +3440,7 @@ func_def_new_from_tuple(struct tuple *tuple) /* By default export to Lua, but not other frontends. */ def->exports.lua = true; def->param_count = 0; + assert(def->param_list == NULL); } if (func_def_check(def) != 0) return NULL; diff --git a/src/box/func.c b/src/box/func.c index 8087c953f..1d20f8872 100644 --- a/src/box/func.c +++ b/src/box/func.c @@ -510,6 +510,7 @@ func_c_destroy(struct func *base) { assert(base->vtab == &func_c_vtab); assert(base != NULL && base->def->language == FUNC_LANGUAGE_C); + free(base->def->param_list); struct func_c *func = (struct func_c *) base; func_c_unload(func); TRASH(base); diff --git a/src/box/func_def.h b/src/box/func_def.h index bab2186da..712a5123b 100644 --- a/src/box/func_def.h +++ b/src/box/func_def.h @@ -129,6 +129,8 @@ struct func_def { bool is_sandboxed; /** The count of function's input arguments. */ int param_count; + /** List of input arguments to the function. */ + enum field_type *param_list; /** The type of the value returned by function. */ enum field_type returns; /** Function aggregate option. */ diff --git a/src/box/lua/call.c b/src/box/lua/call.c index 0315e720c..1dc4589dd 100644 --- a/src/box/lua/call.c +++ b/src/box/lua/call.c @@ -783,6 +783,7 @@ func_lua_destroy(struct func *func) { assert(func != NULL && func->def->language == FUNC_LANGUAGE_LUA); assert(func->vtab == &func_lua_vtab); + free(func->def->param_list); TRASH(func); free(func); } @@ -812,6 +813,7 @@ func_persistent_lua_destroy(struct func *base) assert(base != NULL && base->def->language == FUNC_LANGUAGE_LUA && base->def->body != NULL); assert(base->vtab == &func_persistent_lua_vtab); + free(base->def->param_list); struct func_lua *func = (struct func_lua *) base; func_persistent_lua_unload(func); free(func); diff --git a/src/box/sql/func.c b/src/box/sql/func.c index 1fbffa535..c289f2de0 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -2979,6 +2979,7 @@ func_sql_builtin_destroy(struct func *func) { assert(func->vtab == &func_sql_builtin_vtab); assert(func->def->language == FUNC_LANGUAGE_SQL_BUILTIN); + free(func->def->param_list); free(func); } -- 2.25.1