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 A90236F3F2; Fri, 8 Oct 2021 20:42:20 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A90236F3F2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1633714940; bh=izkheYHD3qSiDMzr1uyEdIkArDHWOOThjX92MMjY6cY=; 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=Vyot4npQ+2nmrqNfBQZJm4JTLkg62SraNKgBksGDtsEjKCwubQzkNFQisvyagOk1X jcR5nPfWtelQVgMBZk8CjEzCVZHfu84/xnZg2Yq50ukom3lVV15+4pbEiTkYWzWkB4 njgDUUmVG9SQNH86hyXVb/Ql8F/NY8oMjYi4fLGw= 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 6CCD26F3FC for ; Fri, 8 Oct 2021 20:32:12 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 6CCD26F3FC Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1mYtj9-0008E2-JA; Fri, 08 Oct 2021 20:32:12 +0300 To: v.shpilevoy@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Fri, 8 Oct 2021 20:32:11 +0300 Message-Id: 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: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD9A6D4E3B1981C4C7D7C82FE95BF26E3268CAB2FE89673C6C0182A05F538085040BE6DF360F1D8EF007BB4AC61CA34829832E7E65B6956201BC6E0AAB36ECFAF3C X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7811C3E343B302E2EEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063790A3F9E01CE65FDC8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8A3C62E92ED037E260F72B9559D70FCD9117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAA867293B0326636D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8BAA867293B0326636D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B62CFFCC7B69C47339089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C650BD2383FF25EF52C691420354496E137A80D00109524F59C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF520746E264B47742699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D340A4C04F5DECA7EE9D744C221D6EBB0DE8C00D0F12EAAC2F174A78C07179C556F5C16BD9640B1A8C81D7E09C32AA3244CDCDCBFC9F405121D9D2D11AF96E35C12A90944CA99CF22E3729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojMZ06aokA6bp9nh2GCVwcLA== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D7EB08C4FF15375A3E151221F54FD079E83D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B 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 | 92 ++++++++++++++++++++++---------------------- src/box/sql/sqlInt.h | 5 ++- 2 files changed, 50 insertions(+), 47 deletions(-) diff --git a/src/box/sql/func.c b/src/box/sql/func.c index 4e7404337..f1f063cb3 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; @@ -148,7 +148,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)) @@ -171,7 +171,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; @@ -204,7 +204,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; @@ -239,11 +239,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)); @@ -252,11 +252,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)); @@ -284,11 +284,11 @@ utf8_len_str(const char *str, uint32_t size) } 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); @@ -297,11 +297,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); @@ -350,7 +350,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; @@ -406,7 +406,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; @@ -485,7 +485,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; @@ -532,7 +532,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; @@ -555,7 +555,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; @@ -629,7 +630,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])) @@ -677,7 +678,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; @@ -740,7 +742,7 @@ func_substr_characters(struct sql_context *ctx, int argc, struct Mem *argv) /** Implementation of the CHAR() function. */ 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); @@ -779,7 +781,7 @@ func_char(struct sql_context *ctx, int argc, struct Mem *argv) /** Implementation of the GREATEST() and LEAST() functions. */ 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; @@ -807,11 +809,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 mem_set_null(ctx->pOut); @@ -835,11 +837,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); @@ -848,7 +850,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; @@ -882,7 +884,7 @@ func_printf(struct sql_context *ctx, int argc, struct Mem *argv) /** Implementation of the RANDOM() function. */ 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; @@ -893,11 +895,11 @@ func_random(struct sql_context *ctx, int argc, struct Mem *argv) /** Implementation of the RANDOMBLOB() 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; @@ -915,11 +917,11 @@ func_randomblob(struct sql_context *ctx, int argc, struct Mem *argv) /** Implementation of the ZEROBLOB() 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; @@ -936,7 +938,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; @@ -945,7 +947,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]))) @@ -971,7 +973,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; @@ -981,7 +983,7 @@ func_row_count(struct sql_context *ctx, int argc, struct Mem *argv) /** Implementation of the UUID() function. */ 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])) @@ -1000,7 +1002,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; @@ -1009,7 +1011,7 @@ func_version(struct sql_context *ctx, int argc, struct Mem *argv) /** Implementation of the UNICODE() function. */ 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; @@ -1240,7 +1242,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; @@ -1307,7 +1309,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); @@ -1392,7 +1394,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 */ @@ -1466,7 +1468,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]; @@ -1539,7 +1541,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, @@ -1643,7 +1645,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 9ccbe4ea3..51327f4fd 100644 --- a/src/box/sql/sqlInt.h +++ b/src/box/sql/sqlInt.h @@ -2460,7 +2460,8 @@ int sqlIsNaN(double); struct PrintfArguments { int nArg; /* Total number of arguments */ int nUsed; /* Number of arguments used so far */ - sql_value **apArg; /* The argument values */ + /** The argument values. */ + const sql_value **apArg; }; void sqlVXPrintf(StrAccum *, const char *, va_list); @@ -4303,7 +4304,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