From: imeevma@tarantool.org To: v.shpilevoy@tarantool.org, tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Subject: [Tarantool-patches] [PATCH v2 08/10] box: add param_list to 'struct func' Date: Fri, 14 Aug 2020 18:05:05 +0300 [thread overview] Message-ID: <14bca5aab8484f9fcd0c93b29c183a8133b71d35.1597417321.git.imeevma@gmail.com> (raw) In-Reply-To: <cover.1597417321.git.imeevma@gmail.com> 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
next prev parent reply other threads:[~2020-08-14 15:05 UTC|newest] Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-08-14 15:04 [Tarantool-patches] [PATCH v2 00/10] sql: properly check arguments types of built-in functions imeevma 2020-08-14 15:04 ` [Tarantool-patches] [PATCH v2 01/10] sql: do not return UNSIGNED in " imeevma 2020-08-22 14:23 ` Vladislav Shpilevoy 2020-08-14 15:04 ` [Tarantool-patches] [PATCH v2 02/10] sql: fix functions return types imeevma 2020-08-22 14:24 ` Vladislav Shpilevoy 2020-08-14 15:04 ` [Tarantool-patches] [PATCH v2 03/10] sql: change signature of trim() imeevma 2020-08-22 14:26 ` Vladislav Shpilevoy 2020-08-14 15:04 ` [Tarantool-patches] [PATCH v2 04/10] box: add new options for functions imeevma 2020-08-22 14:28 ` Vladislav Shpilevoy 2020-08-14 15:05 ` [Tarantool-patches] [PATCH v2 05/10] sql: use has_vararg for built-in functions imeevma 2020-08-14 15:05 ` [Tarantool-patches] [PATCH v2 06/10] sql: add overloaded versions of the functions imeevma 2020-08-22 14:29 ` Vladislav Shpilevoy 2020-08-14 15:05 ` [Tarantool-patches] [PATCH v2 07/10] sql: move built-in function definitions in _func imeevma 2020-08-22 14:30 ` Vladislav Shpilevoy 2020-08-14 15:05 ` imeevma [this message] 2020-08-22 14:30 ` [Tarantool-patches] [PATCH v2 08/10] box: add param_list to 'struct func' Vladislav Shpilevoy 2020-08-14 15:05 ` [Tarantool-patches] [PATCH v2 09/10] sql: check built-in functions argument types imeevma 2020-08-14 15:05 ` [Tarantool-patches] [PATCH v2 10/10] sql: refactor sql/func.c imeevma 2020-08-22 14:31 ` Vladislav Shpilevoy 2020-08-22 14:25 ` [Tarantool-patches] [PATCH v2 00/10] sql: properly check arguments types of built-in functions Vladislav Shpilevoy
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=14bca5aab8484f9fcd0c93b29c183a8133b71d35.1597417321.git.imeevma@gmail.com \ --to=imeevma@tarantool.org \ --cc=tarantool-patches@dev.tarantool.org \ --cc=tsafin@tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH v2 08/10] box: add param_list to '\''struct func'\''' \ /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