From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id BE43B70296; Thu, 11 Nov 2021 14:00:40 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org BE43B70296 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1636628440; bh=Bf/3+yORvcmp7rTrLSUGoBNa0W9SjrgIBk9XShNgdU0=; h=To:Cc:Date:In-Reply-To:References:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=lU0IYq+OvVcQQZbfZnEAu/vJWiVdhX108N2rZPYPSl+iUSLJTksao4+V3Z+cI+RD4 6Wq+QERobf3OVIUbjUHc12QBTsx2y5w+zj9hFka6ul47Yrg6hyhEJflclqL1SlB3QE CgxZLGrenz4V+dgX7f4enHPpE2qQaJcApq7WlBHM= Received: from smtpng1.i.mail.ru (smtpng1.i.mail.ru [94.100.181.251]) (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 5B08871073 for ; Thu, 11 Nov 2021 13:49:31 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 5B08871073 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1ml7e6-0005Hp-Dj; Thu, 11 Nov 2021 13:49:30 +0300 To: kyukhin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Thu, 11 Nov 2021 13:49:30 +0300 Message-Id: <3e89273698c220849765ebf4339418b730902d30.1636627580.git.imeevma@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9731B3922EC0639796A433260860B48E60A001AF1EB3A7EE600894C459B0CD1B9848B895E30E5F9300ACB7E9B309A4F53BD7B9CED87D255671E3A739F9B1F1DEB X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7B9D6DADD6B53929DEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063700ADE00200597A808638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D842F330D1082C2F5F3E21B6B0F566F550117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAA867293B0326636D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8B8C7ADC89C2F0B2A5A471835C12D1D977C4224003CC8364762BB6847A3DEAEFB0F43C7A68FF6260569E8FC8737B5C2249EC8D19AE6D49635B68655334FD4449CB9ECD01F8117BC8BEAAAE862A0553A39223F8577A6DFFEA7C289736CE4F78F08343847C11F186F3C59DAA53EE0834AAEE X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C7E9FEBB9C11794A1A10DBD33D1EA438D874BBE6DB7689DB49C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EFCDE59DDCCE53AF2B699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D345B8C2BEC800D102184ACA02151D7346550F3637C6AC34138E0F1ED33E60FB1AB2B2CF3BCC9AAA0101D7E09C32AA3244C87ADD0702E188619D7DF2C8AFBF2FE941E098CBE561D6343729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj4t8MBgWr8bIhFsLWsrkEJg== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D39F67510D1830C94E53F0D2E7723ADD083D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v1 21/21] sql: make arguments to be const X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Mergen Imeev via Tarantool-patches Reply-To: imeevma@tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 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