From: imeevma@tarantool.org To: v.shpilevoy@tarantool.org Cc: tarantool-patches@dev.tarantool.org Subject: [Tarantool-patches] [PATCH v1 4/7] box: add param_list to 'struct func' Date: Wed, 12 Aug 2020 18:15:50 +0300 [thread overview] Message-ID: <7b30cdd9124c50b4f7e12801f6b0567097f00a4d.1597244875.git.imeevma@gmail.com> (raw) In-Reply-To: <cover.1597244875.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 89d5a404a..8b86167af 100644 --- a/src/box/func_def.h +++ b/src/box/func_def.h @@ -117,6 +117,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 df15d303a..91755380d 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -2937,6 +2937,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-12 15:15 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-08-12 15:15 [Tarantool-patches] [PATCH v1 0/7] sql: properly check arguments types of built-in functions imeevma 2020-08-12 15:15 ` [Tarantool-patches] [PATCH v1 1/7] box: add has_vararg option for functions imeevma 2020-08-12 15:15 ` [Tarantool-patches] [PATCH v1 2/7] sql: do not return UNSIGNED in built-in functions imeevma 2020-08-12 15:15 ` [Tarantool-patches] [PATCH v1 3/7] sql: move built-in function definitions in _func imeevma 2020-08-12 15:15 ` imeevma [this message] 2020-08-12 15:15 ` [Tarantool-patches] [PATCH v1 5/7] sql: check built-in functions argument types imeevma 2020-08-12 15:15 ` [Tarantool-patches] [PATCH v1 6/7] sql: VARBINARY and STRING in built-in functions imeevma 2020-08-12 15:15 ` [Tarantool-patches] [PATCH v1 7/7] sql: refactor sql/func.c imeevma
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=7b30cdd9124c50b4f7e12801f6b0567097f00a4d.1597244875.git.imeevma@gmail.com \ --to=imeevma@tarantool.org \ --cc=tarantool-patches@dev.tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH v1 4/7] 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