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 0BD936B962; Wed, 14 Apr 2021 04:29:20 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 0BD936B962 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1618363760; bh=yRpL3LYTlgSmk9t4D5HnitFyFu5L3Aq3s/mpcphtXQY=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=HmAz2heYLRV2CWoY6MRw5wBNccOfk97ciFWR7GUgWQ7F+1i8Z8oWLhYICQOYh5Fzd lw1I55zC5Vj47I0Pdv6NlODwJm521uxU7yGuclQqX/TnZBdQKRvta33wEtA7/2NbIB Tht1pUf0UK8XoFGX82DBZ6ulGQMyWjL2TagqeHYo= Received: from smtp54.i.mail.ru (smtp54.i.mail.ru [217.69.128.34]) (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 E900A6EC5B for ; Wed, 14 Apr 2021 04:29:18 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org E900A6EC5B Received: by smtp54.i.mail.ru with esmtpa (envelope-from ) id 1lWULF-0003CO-Tv; Wed, 14 Apr 2021 04:29:18 +0300 Date: Wed, 14 Apr 2021 04:29:16 +0300 To: Vladislav Shpilevoy Message-ID: <20210414012916.GA168748@tarantool.org> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD92FFCB8E6708E7480B1C8842CE613979723F2FB4628545A35182A05F538085040D615810B62E7CFFCE0BFAD5EE90C5689995D6738EF8B6C9ABD87675CFF062A24 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE78736B27BC39BD580EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637578F58D66D7052C48638F802B75D45FF914D58D5BE9E6BC1A93B80C6DEB9DEE97C6FB206A91F05B2D08EF63CA4C326B93A1633937A3505C08CCF7685675CC1A7D2E47CDBA5A96583C09775C1D3CA48CFCA5A41EBD8A3A0199FA2833FD35BB23D2EF20D2F80756B5F868A13BD56FB6657A471835C12D1D977725E5C173C3A84C327ED053E960B195E117882F4460429728AD0CFFFB425014E868A13BD56FB6657D81D268191BDAD3DC09775C1D3CA48CF2ACA9C30ED78B5B6BA3038C0950A5D36C8A9BA7A39EFB766EC990983EF5C0329BA3038C0950A5D36D5E8D9A59859A8B6B1F0E46EA745084D76E601842F6C81A1F004C906525384307823802FF610243D2EB15956EA79C166A417C69337E82CC275ECD9A6C639B01B78DA827A17800CE754A400A07F115C59731C566533BA786AA5CC5B56E945C8DA X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A2368A440D3B0F6089093C9A16E5BC824A2A04A2ABAA09D25379311020FFC8D4ADB200D727D4285EA204C48D451EAF5DCD X-C1DE0DAB: 0D63561A33F958A564169290BC31C5B17033F121A808155DE85A2F6DB1B5DBC1D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7502E6951B79FF9A3F410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3480665FBD8F49180C8FB552D6AFB6810ECCAF413E40C79435F57C1BEA8AB844F92144271FB25522681D7E09C32AA3244CB19AE3537AEF02FFF77E7D385BD99B5960759606DA2E136AFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojnA7/qPBUIXEcv+66Dr11ng== X-Mailru-Sender: 5C3750E245F362008BC1685FEC6306EDE0831FD2E632C40EE0BFAD5EE90C5689CA71892AC981DD5F5105BD0848736F9966FEC6BF5C9C28D97E07721503EA2E00ED97202A5A4E92BF7402F9BA4338D657ED14614B50AE0675 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v5 48/52] sql: introduce mem_get_bool() 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: Mergen Imeev Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Thank you for the review! My answer, diff and new patch below. On Wed, Apr 14, 2021 at 01:04:46AM +0200, Vladislav Shpilevoy wrote: > The same as for the previous getters. Added mem_get_bool_unsafe(). Diff: diff --git a/src/box/sql/func.c b/src/box/sql/func.c index cd52cb928..3d8028077 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -1121,9 +1121,8 @@ quoteFunc(sql_context * context, int argc, sql_value ** argv) break; } case MP_BOOL: { - bool b; - mem_get_bool(argv[0], &b); - sql_result_text(context, SQL_TOKEN_BOOLEAN(b), + sql_result_text(context, + SQL_TOKEN_BOOLEAN(mem_get_bool_unsafe(argv[0])), -1, SQL_TRANSIENT); break; } diff --git a/src/box/sql/mem.h b/src/box/sql/mem.h index 4a5b9f4ea..b59197e6c 100644 --- a/src/box/sql/mem.h +++ b/src/box/sql/mem.h @@ -820,6 +820,20 @@ mem_get_double_unsafe(const struct Mem *mem) int mem_get_bool(const struct Mem *mem, bool *b); +/** + * Return value of MEM converted to boolean. This function is not safe since + * there is no proper processing in case mem_get_bool() return an error. In + * this case this function returns FALSE. + */ +static inline bool +mem_get_bool_unsafe(const struct Mem *mem) +{ + bool b; + if (mem_get_bool(mem, &b) != 0) + return false; + return b; +} + /** * Simple type to str convertor. It is used to simplify * error reporting. New patch: commit 64a9dfb5535f6f858a0ccf233bc1f63536591d2d Author: Mergen Imeev Date: Wed Mar 17 14:20:37 2021 +0300 sql: introduce mem_get_bool() This patch introduces mem_get_bool(). This function is used to receive boolean value from MEM. If value of MEM is not boolean, it is converted to boolean if possible. MEM is not changed. Part of #5818 diff --git a/src/box/sql/func.c b/src/box/sql/func.c index dbf899c02..3d8028077 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -1122,7 +1122,7 @@ quoteFunc(sql_context * context, int argc, sql_value ** argv) } case MP_BOOL: { sql_result_text(context, - SQL_TOKEN_BOOLEAN(sql_value_boolean(argv[0])), + SQL_TOKEN_BOOLEAN(mem_get_bool_unsafe(argv[0])), -1, SQL_TRANSIENT); break; } diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c index 764735322..661764f9c 100644 --- a/src/box/sql/mem.c +++ b/src/box/sql/mem.c @@ -1124,6 +1124,16 @@ mem_get_double(const struct Mem *mem, double *d) return -1; } +int +mem_get_bool(const struct Mem *mem, bool *b) +{ + if ((mem->flags & MEM_Bool) != 0) { + *b = mem->u.b; + return 0; + } + return -1; +} + int mem_copy(struct Mem *to, const struct Mem *from) { @@ -2253,16 +2263,6 @@ releaseMemArray(Mem * p, int N) } } -int -mem_value_bool(const struct Mem *mem, bool *b) -{ - if ((mem->flags & MEM_Bool) != 0) { - *b = mem->u.b; - return 0; - } - return -1; -} - /**************************** sql_value_ ****************************** * The following routines extract information from a Mem or sql_value * structure. @@ -2289,16 +2289,6 @@ sql_value_bytes(sql_value * pVal) return sqlValueBytes(pVal); } -bool -sql_value_boolean(sql_value *val) -{ - bool b = false; - int rc = mem_value_bool((struct Mem *) val, &b); - assert(rc == 0); - (void) rc; - return b; -} - const unsigned char * sql_value_text(sql_value * pVal) { diff --git a/src/box/sql/mem.h b/src/box/sql/mem.h index d283aa76a..b59197e6c 100644 --- a/src/box/sql/mem.h +++ b/src/box/sql/mem.h @@ -812,6 +812,28 @@ mem_get_double_unsafe(const struct Mem *mem) return d; } +/** + * Return value for MEM of BOOLEAN type. For MEM of all other types convert + * value of the MEM to BOOLEAN if possible and return converted value. Original + * MEM is not changed. + */ +int +mem_get_bool(const struct Mem *mem, bool *b); + +/** + * Return value of MEM converted to boolean. This function is not safe since + * there is no proper processing in case mem_get_bool() return an error. In + * this case this function returns FALSE. + */ +static inline bool +mem_get_bool_unsafe(const struct Mem *mem) +{ + bool b; + if (mem_get_bool(mem, &b) != 0) + return false; + return b; +} + /** * Simple type to str convertor. It is used to simplify * error reporting. @@ -864,17 +886,12 @@ releaseMemArray(Mem * p, int N); /** Getters. */ -int -mem_value_bool(const struct Mem *mem, bool *b); const void * sql_value_blob(struct Mem *); int sql_value_bytes(struct Mem *); -bool -sql_value_boolean(struct Mem *val); - const unsigned char * sql_value_text(struct Mem *); diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h index 3f6fa1722..df9469941 100644 --- a/src/box/sql/sqlInt.h +++ b/src/box/sql/sqlInt.h @@ -442,9 +442,6 @@ sql_column_bytes(sql_stmt *, int iCol); int sql_column_bytes16(sql_stmt *, int iCol); -bool -sql_column_boolean(struct sql_stmt *stmt, int column); - const unsigned char * sql_column_text(sql_stmt *, int iCol); diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c index daa5e0809..c75322899 100644 --- a/src/box/sql/vdbeapi.c +++ b/src/box/sql/vdbeapi.c @@ -464,12 +464,6 @@ sql_column_bytes(sql_stmt * pStmt, int i) return sql_value_bytes(columnMem(pStmt, i)); } -bool -sql_column_boolean(struct sql_stmt *stmt, int i) -{ - return sql_value_boolean(columnMem(stmt, i)); -} - const unsigned char * sql_column_text(sql_stmt * pStmt, int i) {