From: Mergen Imeev via Tarantool-patches <tarantool-patches@dev.tarantool.org> To: kyukhin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Subject: [Tarantool-patches] [PATCH v1 21/21] sql: make arguments to be const Date: Thu, 11 Nov 2021 13:49:30 +0300 [thread overview] Message-ID: <3e89273698c220849765ebf4339418b730902d30.1636627580.git.imeevma@gmail.com> (raw) In-Reply-To: <cover.1636627579.git.imeevma@gmail.com> This patch forces SQL built-in function implementations to accept 'const struct Mem *' instead of just 'struct Mem *'. Needed for #4145 --- src/box/sql/func.c | 94 ++++++++++++++++++++++---------------------- src/box/sql/sqlInt.h | 4 +- 2 files changed, 50 insertions(+), 48 deletions(-) diff --git a/src/box/sql/func.c b/src/box/sql/func.c index a0e599b5e..8fb225c0c 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -55,7 +55,7 @@ static struct func_sql_builtin **functions; /** Implementation of the SUM() function. */ static void -step_sum(struct sql_context *ctx, int argc, struct Mem *argv) +step_sum(struct sql_context *ctx, int argc, const struct Mem *argv) { assert(argc == 1); (void)argc; @@ -70,7 +70,7 @@ step_sum(struct sql_context *ctx, int argc, struct Mem *argv) /** Implementation of the TOTAL() function. */ static void -step_total(struct sql_context *ctx, int argc, struct Mem *argv) +step_total(struct sql_context *ctx, int argc, const struct Mem *argv) { assert(argc == 1); (void)argc; @@ -95,7 +95,7 @@ fin_total(struct Mem *mem) /** Implementation of the AVG() function. */ static void -step_avg(struct sql_context *ctx, int argc, struct Mem *argv) +step_avg(struct sql_context *ctx, int argc, const struct Mem *argv) { assert(argc == 1); (void)argc; @@ -143,7 +143,7 @@ fin_avg(struct Mem *mem) /** Implementation of the COUNT() function. */ static void -step_count(struct sql_context *ctx, int argc, struct Mem *argv) +step_count(struct sql_context *ctx, int argc, const struct Mem *argv) { assert(argc == 0 || argc == 1); if (mem_is_null(ctx->pOut)) @@ -166,7 +166,7 @@ fin_count(struct Mem *mem) /** Implementation of the MIN() and MAX() functions. */ static void -step_minmax(struct sql_context *ctx, int argc, struct Mem *argv) +step_minmax(struct sql_context *ctx, int argc, const struct Mem *argv) { assert(argc == 1); (void)argc; @@ -199,7 +199,7 @@ step_minmax(struct sql_context *ctx, int argc, struct Mem *argv) /** Implementation of the GROUP_CONCAT() function. */ static void -step_group_concat(struct sql_context *ctx, int argc, struct Mem *argv) +step_group_concat(struct sql_context *ctx, int argc, const struct Mem *argv) { assert(argc == 1 || argc == 2); (void)argc; @@ -234,11 +234,11 @@ step_group_concat(struct sql_context *ctx, int argc, struct Mem *argv) /** Implementations of the ABS() function. */ static void -func_abs_int(struct sql_context *ctx, int argc, struct Mem *argv) +func_abs_int(struct sql_context *ctx, int argc, const struct Mem *argv) { assert(argc == 1); (void)argc; - struct Mem *arg = &argv[0]; + const struct Mem *arg = &argv[0]; if (mem_is_null(arg)) return; assert(mem_is_int(arg)); @@ -247,11 +247,11 @@ func_abs_int(struct sql_context *ctx, int argc, struct Mem *argv) } static void -func_abs_double(struct sql_context *ctx, int argc, struct Mem *argv) +func_abs_double(struct sql_context *ctx, int argc, const struct Mem *argv) { assert(argc == 1); (void)argc; - struct Mem *arg = &argv[0]; + const struct Mem *arg = &argv[0]; if (mem_is_null(arg)) return; assert(mem_is_double(arg)); @@ -260,11 +260,11 @@ func_abs_double(struct sql_context *ctx, int argc, struct Mem *argv) /** Implementation of the CHAR_LENGTH() function. */ static void -func_char_length(struct sql_context *ctx, int argc, struct Mem *argv) +func_char_length(struct sql_context *ctx, int argc, const struct Mem *argv) { assert(argc == 1); (void)argc; - struct Mem *arg = &argv[0]; + const struct Mem *arg = &argv[0]; if (mem_is_null(arg)) return; assert(mem_is_str(arg) && arg->n >= 0); @@ -280,11 +280,11 @@ func_char_length(struct sql_context *ctx, int argc, struct Mem *argv) /** Implementation of the UPPER() and LOWER() functions. */ static void -func_lower_upper(struct sql_context *ctx, int argc, struct Mem *argv) +func_lower_upper(struct sql_context *ctx, int argc, const struct Mem *argv) { assert(argc == 1); (void)argc; - struct Mem *arg = &argv[0]; + const struct Mem *arg = &argv[0]; if (mem_is_null(arg)) return; assert(mem_is_str(arg) && arg->n >= 0); @@ -333,7 +333,7 @@ func_lower_upper(struct sql_context *ctx, int argc, struct Mem *argv) /** Implementation of the NULLIF() function. */ static void -func_nullif(struct sql_context *ctx, int argc, struct Mem *argv) +func_nullif(struct sql_context *ctx, int argc, const struct Mem *argv) { assert(argc == 2); (void)argc; @@ -382,7 +382,7 @@ trim_bin_start(const char *str, int end, const char *octets, int octets_size, } static void -func_trim_bin(struct sql_context *ctx, int argc, struct Mem *argv) +func_trim_bin(struct sql_context *ctx, int argc, const struct Mem *argv) { if (mem_is_null(&argv[0]) || (argc == 3 && mem_is_null(&argv[2]))) return; @@ -461,7 +461,7 @@ trim_str_start(const char *str, int end, const char *chars, uint8_t *chars_len, } static void -func_trim_str(struct sql_context *ctx, int argc, struct Mem *argv) +func_trim_str(struct sql_context *ctx, int argc, const struct Mem *argv) { if (mem_is_null(&argv[0]) || (argc == 3 && mem_is_null(&argv[2]))) return; @@ -511,7 +511,7 @@ func_trim_str(struct sql_context *ctx, int argc, struct Mem *argv) /** Implementation of the POSITION() function. */ static void -func_position_octets(struct sql_context *ctx, int argc, struct Mem *argv) +func_position_octets(struct sql_context *ctx, int argc, const struct Mem *argv) { assert(argc == 2); (void)argc; @@ -530,7 +530,8 @@ func_position_octets(struct sql_context *ctx, int argc, struct Mem *argv) } static void -func_position_characters(struct sql_context *ctx, int argc, struct Mem *argv) +func_position_characters(struct sql_context *ctx, int argc, + const struct Mem *argv) { assert(argc == 2); (void)argc; @@ -610,7 +611,7 @@ substr_normalize(int64_t base_start, bool is_start_neg, uint64_t base_length, } static void -func_substr_octets(struct sql_context *ctx, int argc, struct Mem *argv) +func_substr_octets(struct sql_context *ctx, int argc, const struct Mem *argv) { assert(argc == 2 || argc == 3); if (mem_is_any_null(&argv[0], &argv[1])) @@ -666,7 +667,8 @@ func_substr_octets(struct sql_context *ctx, int argc, struct Mem *argv) } static void -func_substr_characters(struct sql_context *ctx, int argc, struct Mem *argv) +func_substr_characters(struct sql_context *ctx, int argc, const + struct Mem *argv) { assert(argc == 2 || argc == 3); (void)argc; @@ -739,7 +741,7 @@ func_substr_characters(struct sql_context *ctx, int argc, struct Mem *argv) * Symbol '\0' used instead of NULL argument. */ static void -func_char(struct sql_context *ctx, int argc, struct Mem *argv) +func_char(struct sql_context *ctx, int argc, const struct Mem *argv) { if (argc == 0) return mem_set_str_static(ctx->pOut, "", 0); @@ -789,7 +791,7 @@ func_char(struct sql_context *ctx, int argc, struct Mem *argv) * The LEAST() function returns the smallest of the given arguments. */ static void -func_greatest_least(struct sql_context *ctx, int argc, struct Mem *argv) +func_greatest_least(struct sql_context *ctx, int argc, const struct Mem *argv) { assert(argc > 1); int mask = ctx->func->def->name[0] == 'G' ? -1 : 0; @@ -821,11 +823,11 @@ static const char hexdigits[] = { }; static void -func_hex(struct sql_context *ctx, int argc, struct Mem *argv) +func_hex(struct sql_context *ctx, int argc, const struct Mem *argv) { assert(argc == 1); (void)argc; - struct Mem *arg = &argv[0]; + const struct Mem *arg = &argv[0]; if (mem_is_null(arg)) return; @@ -849,11 +851,11 @@ func_hex(struct sql_context *ctx, int argc, struct Mem *argv) /** Implementation of the OCTET_LENGTH() function. */ static void -func_octet_length(struct sql_context *ctx, int argc, struct Mem *argv) +func_octet_length(struct sql_context *ctx, int argc, const struct Mem *argv) { assert(argc == 1); (void)argc; - struct Mem *arg = &argv[0]; + const struct Mem *arg = &argv[0]; if (mem_is_null(arg)) return; assert(mem_is_bytes(arg) && arg->n >= 0); @@ -862,7 +864,7 @@ func_octet_length(struct sql_context *ctx, int argc, struct Mem *argv) /** Implementation of the PRINTF() function. */ static void -func_printf(struct sql_context *ctx, int argc, struct Mem *argv) +func_printf(struct sql_context *ctx, int argc, const struct Mem *argv) { if (argc < 1 || mem_is_null(&argv[0])) return; @@ -891,7 +893,7 @@ func_printf(struct sql_context *ctx, int argc, struct Mem *argv) * This function returns a random INT64 value. */ static void -func_random(struct sql_context *ctx, int argc, struct Mem *argv) +func_random(struct sql_context *ctx, int argc, const struct Mem *argv) { (void)argc; (void)argv; @@ -907,11 +909,11 @@ func_random(struct sql_context *ctx, int argc, struct Mem *argv) * specified as an argument of the function. */ static void -func_randomblob(struct sql_context *ctx, int argc, struct Mem *argv) +func_randomblob(struct sql_context *ctx, int argc, const struct Mem *argv) { assert(argc == 1); (void)argc; - struct Mem *arg = &argv[0]; + const struct Mem *arg = &argv[0]; assert(mem_is_null(arg) || mem_is_int(arg)); if (mem_is_null(arg) || !mem_is_uint(arg)) return; @@ -934,11 +936,11 @@ func_randomblob(struct sql_context *ctx, int argc, struct Mem *argv) * is specified as an argument of the function. */ static void -func_zeroblob(struct sql_context *ctx, int argc, struct Mem *argv) +func_zeroblob(struct sql_context *ctx, int argc, const struct Mem *argv) { assert(argc == 1); (void)argc; - struct Mem *arg = &argv[0]; + const struct Mem *arg = &argv[0]; assert(mem_is_null(arg) || mem_is_int(arg)); if (mem_is_null(arg) || !mem_is_uint(arg)) return; @@ -955,7 +957,7 @@ func_zeroblob(struct sql_context *ctx, int argc, struct Mem *argv) /** Implementation of the TYPEOF() function. */ static void -func_typeof(struct sql_context *ctx, int argc, struct Mem *argv) +func_typeof(struct sql_context *ctx, int argc, const struct Mem *argv) { assert(argc == 1); (void)argc; @@ -964,7 +966,7 @@ func_typeof(struct sql_context *ctx, int argc, struct Mem *argv) /** Implementation of the ROUND() function. */ static void -func_round(struct sql_context *ctx, int argc, struct Mem *argv) +func_round(struct sql_context *ctx, int argc, const struct Mem *argv) { assert(argc == 1 || argc == 2); if (mem_is_null(&argv[0]) || (argc == 2 && mem_is_null(&argv[1]))) @@ -990,7 +992,7 @@ func_round(struct sql_context *ctx, int argc, struct Mem *argv) /** Implementation of the ROW_COUNT() function. */ static void -func_row_count(struct sql_context *ctx, int argc, struct Mem *argv) +func_row_count(struct sql_context *ctx, int argc, const struct Mem *argv) { (void)argc; (void)argv; @@ -1004,7 +1006,7 @@ func_row_count(struct sql_context *ctx, int argc, struct Mem *argv) * Returns a randomly generated UUID value. */ static void -func_uuid(struct sql_context *ctx, int argc, struct Mem *argv) +func_uuid(struct sql_context *ctx, int argc, const struct Mem *argv) { if (argc == 1) { if (mem_is_null(&argv[0])) @@ -1023,7 +1025,7 @@ func_uuid(struct sql_context *ctx, int argc, struct Mem *argv) /** Implementation of the VERSION() function. */ static void -func_version(struct sql_context *ctx, int argc, struct Mem *argv) +func_version(struct sql_context *ctx, int argc, const struct Mem *argv) { (void)argc; (void)argv; @@ -1037,11 +1039,11 @@ func_version(struct sql_context *ctx, int argc, struct Mem *argv) * string. */ static void -func_unicode(struct sql_context *ctx, int argc, struct Mem *argv) +func_unicode(struct sql_context *ctx, int argc, const struct Mem *argv) { assert(argc == 1); (void)argc; - struct Mem *arg = &argv[0]; + const struct Mem *arg = &argv[0]; if (mem_is_null(arg)) return; assert(mem_is_str(arg)); @@ -1274,7 +1276,7 @@ sql_utf8_pattern_compare(const char *pattern, * is NULL then result is NULL as well. */ static void -likeFunc(sql_context *context, int argc, struct Mem *argv) +likeFunc(sql_context *context, int argc, const struct Mem *argv) { u32 escape = SQL_END_OF_STRING; int nPat; @@ -1343,7 +1345,7 @@ likeFunc(sql_context *context, int argc, struct Mem *argv) * single-quote escapes. */ static void -quoteFunc(struct sql_context *context, int argc, struct Mem *argv) +quoteFunc(struct sql_context *context, int argc, const struct Mem *argv) { assert(argc == 1); UNUSED_PARAMETER(argc); @@ -1428,7 +1430,7 @@ quoteFunc(struct sql_context *context, int argc, struct Mem *argv) * must be exact. Collating sequences are not used. */ static void -replaceFunc(struct sql_context *context, int argc, struct Mem *argv) +replaceFunc(struct sql_context *context, int argc, const struct Mem *argv) { const unsigned char *zStr; /* The input string A */ const unsigned char *zPattern; /* The pattern string B */ @@ -1503,7 +1505,7 @@ replaceFunc(struct sql_context *context, int argc, struct Mem *argv) * soundex encoding of the string X. */ static void -soundexFunc(struct sql_context *context, int argc, struct Mem *argv) +soundexFunc(struct sql_context *context, int argc, const struct Mem *argv) { (void) argc; char zResult[8]; @@ -1576,7 +1578,7 @@ func_sql_builtin_call_stub(struct func *func, struct port *args, } static void -sql_builtin_stub(sql_context *ctx, int argc, struct Mem *argv) +sql_builtin_stub(sql_context *ctx, int argc, const struct Mem *argv) { (void) argc; (void) argv; diag_set(ClientError, ER_SQL_EXECUTE, @@ -1678,7 +1680,7 @@ struct sql_func_definition { /** Type of the result of the implementation. */ enum field_type result; /** Call implementation with given arguments. */ - void (*call)(sql_context *ctx, int argc, struct Mem *argv); + void (*call)(sql_context *ctx, int argc, const struct Mem *argv); /** Call finalization function for this implementation. */ int (*finalize)(struct Mem *mem); }; diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h index 148350d05..dcd71e5bd 100644 --- a/src/box/sql/sqlInt.h +++ b/src/box/sql/sqlInt.h @@ -2447,7 +2447,7 @@ struct PrintfArguments { int nArg; /* Total number of arguments */ int nUsed; /* Number of arguments used so far */ /** The argument values. */ - struct Mem *apArg; + const struct Mem *apArg; }; void sqlVXPrintf(StrAccum *, const char *, va_list); @@ -4270,7 +4270,7 @@ struct func_sql_builtin { * Access checks are redundant, because all SQL built-ins * are predefined and are executed on SQL privilege level. */ - void (*call)(struct sql_context *ctx, int argc, struct Mem *argv); + void (*call)(struct sql_context *ctx, int argc, const struct Mem *argv); /** * A VDBE-memory-compatible finalize method * (is valid only for aggregate function). -- 2.25.1
next prev parent reply other threads:[~2021-11-11 11:00 UTC|newest] Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-11-11 10:48 [Tarantool-patches] [PATCH v1 00/21] Refactor non-standard and non-aggragate functions Mergen Imeev via Tarantool-patches 2021-11-11 10:48 ` [Tarantool-patches] [PATCH v1 01/21] sql: rework CHAR() function Mergen Imeev via Tarantool-patches 2021-11-11 10:48 ` [Tarantool-patches] [PATCH v1 02/21] sql: refactor GREATEST() and LEAST() functions Mergen Imeev via Tarantool-patches 2021-11-11 10:48 ` [Tarantool-patches] [PATCH v1 03/21] sql: refactor HEX() function Mergen Imeev via Tarantool-patches 2021-11-11 10:48 ` [Tarantool-patches] [PATCH v1 04/21] sql: refactor LENGTH() function Mergen Imeev via Tarantool-patches 2021-11-11 10:48 ` [Tarantool-patches] [PATCH v1 05/21] sql: refactor PRINTF() function Mergen Imeev via Tarantool-patches 2021-11-11 10:48 ` [Tarantool-patches] [PATCH v1 06/21] sql: refactor RANDOM() function Mergen Imeev via Tarantool-patches 2021-11-11 10:49 ` [Tarantool-patches] [PATCH v1 07/21] sql: rework RANDOMBLOB() function Mergen Imeev via Tarantool-patches 2021-11-11 10:49 ` [Tarantool-patches] [PATCH v1 08/21] sql: refactor ZEROBLOB() function Mergen Imeev via Tarantool-patches 2021-11-11 10:49 ` [Tarantool-patches] [PATCH v1 09/21] sql: refactor TYPEOF() function Mergen Imeev via Tarantool-patches 2021-11-11 10:49 ` [Tarantool-patches] [PATCH v1 10/21] sql: refactor ROUND() function Mergen Imeev via Tarantool-patches 2021-11-11 10:49 ` [Tarantool-patches] [PATCH v1 11/21] sql: refactor ROW_COUNT() function Mergen Imeev via Tarantool-patches 2021-11-11 10:49 ` [Tarantool-patches] [PATCH v1 12/21] sql: rework UUID() function Mergen Imeev via Tarantool-patches 2021-11-11 10:49 ` [Tarantool-patches] [PATCH v1 13/21] sql: refactor VERSION() function Mergen Imeev via Tarantool-patches 2021-11-11 10:49 ` [Tarantool-patches] [PATCH v1 14/21] sql: refactor UNICODE() function Mergen Imeev via Tarantool-patches 2021-11-11 10:49 ` [Tarantool-patches] [PATCH v1 15/21] sql: refactor SOUNDEX() function Mergen Imeev via Tarantool-patches 2021-11-11 10:49 ` [Tarantool-patches] [PATCH v1 16/21] sql: refactor REPLACE() function Mergen Imeev via Tarantool-patches 2021-11-11 10:49 ` [Tarantool-patches] [PATCH v1 17/21] sql: refactor QUOTE() function Mergen Imeev via Tarantool-patches 2021-11-11 10:49 ` [Tarantool-patches] [PATCH v1 18/21] sql: remove unused code Mergen Imeev via Tarantool-patches 2021-11-11 10:49 ` [Tarantool-patches] [PATCH v1 19/21] sql: remove MEM_Dyn flag Mergen Imeev via Tarantool-patches 2021-11-11 10:49 ` [Tarantool-patches] [PATCH v1 20/21] sql: remove MEM_Term flag Mergen Imeev via Tarantool-patches 2021-11-11 10:49 ` Mergen Imeev via Tarantool-patches [this message] 2021-11-11 11:00 ` [Tarantool-patches] [PATCH v1 00/21] Refactor non-standard and non-aggragate functions Kirill Yukhin via Tarantool-patches -- strict thread matches above, loose matches on Subject: below -- 2021-10-08 17:31 Mergen Imeev via Tarantool-patches 2021-10-08 17:32 ` [Tarantool-patches] [PATCH v1 21/21] sql: make arguments to be const Mergen Imeev via Tarantool-patches
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=3e89273698c220849765ebf4339418b730902d30.1636627580.git.imeevma@gmail.com \ --to=tarantool-patches@dev.tarantool.org \ --cc=imeevma@tarantool.org \ --cc=kyukhin@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH v1 21/21] sql: make arguments to be const' \ /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