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 3AA5D6BD28; Tue, 13 Apr 2021 02:35:24 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 3AA5D6BD28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1618270524; bh=kpZXEG/UhUM4eKiTE7miNEa7DJcfBzCKWfCKe6X+4as=; h=To:Cc:References:Date:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=CZeVbIVpne2yxZR679r5cgacfqECqBWl1QT32Xo0lFRf8ycVLCJH5u1Szzuu9m03v lVrJaDmp7sVQ49JMDUvCjfdJVJEoVLU6H2lEy+GDPKOaeTlPooLWnXDBJPnOzVEXgu frSThsHpimYqqr3QLZrU1JKWw7UXCzURNcD6/y4k= Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (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 6BA376BD23 for ; Tue, 13 Apr 2021 02:35:21 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 6BA376BD23 Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1lW65Q-0004FO-Lh; Tue, 13 Apr 2021 02:35:21 +0300 To: imeevma@tarantool.org, tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org References: <2a22e2c47ad16b38bb7dcfb6b35a6a61b8b94e5e.1617984948.git.imeevma@gmail.com> Message-ID: <76e3ed67-6f88-8480-4a1d-080e3e01e788@tarantool.org> Date: Tue, 13 Apr 2021 01:35:19 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.9.1 MIME-Version: 1.0 In-Reply-To: <2a22e2c47ad16b38bb7dcfb6b35a6a61b8b94e5e.1617984948.git.imeevma@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD92FFCB8E6708E7480BE79914FF86F9151AC38CC435EA4A654182A05F5380850406D7136C85AF685F73E0C4BE0BF5662981C3234E72C15EA6B13E38214E58A43EC X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7A1DB0B089319D380EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637911538129B0A8D078638F802B75D45FF914D58D5BE9E6BC1A93B80C6DEB9DEE97C6FB206A91F05B2BD4F694DB30410A0B3A67110BC19F37E89428004B1FE94FDD2E47CDBA5A96583C09775C1D3CA48CF90D92131081DE748117882F4460429724CE54428C33FAD30A8DF7F3B2552694AC26CFBAC0749D213D2E47CDBA5A9658378DA827A17800CE70B7EC9B0538196269FA2833FD35BB23DF004C906525384302BEBFE083D3B9BA73A03B725D353964B0B7D0EA88DDEDAC722CA9DD8327EE4930A3850AC1BE2E7351CE60B8040019C36C4224003CC83647689D4C264860C145E X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A2AD77751E876CB595E8F7B195E1C97831A13B1FDF0624C310D5EE6400B98F466E X-C1DE0DAB: 0D63561A33F958A5503C4AD455DC54B3FF215096821F10E54D8E72756F3990ACD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7502E6951B79FF9A3F410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34324A9840C798D5000E3D8DFD5D41699751B7C98C89F32205B02C8BF853A05F1301E4DD4086798C9B1D7E09C32AA3244CF878611D32E0B200274321B88F2B2FDAC86C126E7119A0FEFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojq8JA+pXcDukHd7BO5gi9mw== X-Mailru-Sender: 689FA8AB762F73936BC43F508A063822EEE8B9B2606C7E66D3BCC12915C356EE3841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v5 28/52] sql: introduce mem_copy_str() and mem_copy_str0() 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: Vladislav Shpilevoy via Tarantool-patches Reply-To: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Thanks for the fixes! See 2 comments below. > diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c > index 87e1bcfd1..045c44e8f 100644 > --- a/src/box/sql/mem.c > +++ b/src/box/sql/mem.c > @@ -394,6 +394,34 @@ mem_set_str0_allocated(struct Mem *mem, char *value) > mem->flags |= MEM_Term; > } > > +int > +mem_copy_str(struct Mem *mem, const char *value, uint32_t len) > +{ > + if ((mem->flags & (MEM_Agg | MEM_Frame)) != 0) > + mem_clear(mem); 1. Why don't you call clear always? Anyway 'dynamic' memory can't be reused. It is freed in sqlVdbeMemGrow() AFAIS. > + bool is_own_value = (mem->flags & (MEM_Str | MEM_Blob)) != 0 && > + mem->z == value; > + if (sqlVdbeMemGrow(mem, len, is_own_value) != 0) > + return -1; > diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c > index e0903e3b0..ee095f36e 100644 > --- a/src/box/sql/vdbeapi.c > +++ b/src/box/sql/vdbeapi.c > @@ -798,8 +803,14 @@ bindText(sql_stmt * pStmt, /* The statement to bind against */ > mem_set_str0_dynamic(pVar, (char *)zData); > else > mem_set_str_dynamic(pVar, (char *)zData, nData); > - } else if (sqlVdbeMemSetStr(pVar, zData, nData, 1, xDel) != 0) { > - return -1; > + } else { > + if (nData < 0) { > + if (mem_copy_str0(pVar, zData) != 0) > + return -1; > + } else { > + if (mem_copy_str(pVar, zData, nData) != 0) > + return -1; > + } 2. For mem_set_str* and mem_copy_str* you could probably have 3 versions: mem_set_strn(const char *, uint32 len), mem_set_str0(const char *), and mem_set_str(const char *, uint32 len_hint). In the last version len_hint might be -1 and then strlen() is called. It would keep the places like that as simple as they were. > } > return sql_bind_type(p, i, "text"); > } >