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 787086EC5F; Thu, 15 Apr 2021 02:54:34 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 787086EC5F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1618444474; bh=ppfEN+rGR18154P3j++yXND9MLcYv3/WgfhxKYGrzpQ=; h=To:References:Date:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=Jt1gx423WV6qd1m/nGl4dR42xIr6r9m7jrm6p6r509CclKGUIu+2rYwpXlXCX8SjD qkAvMLoYndAJ3BGYQ1mMVk+Am4QhjTnTPO20fpo/oN1o1JZfiF5dwzNY9dIchyCxfE y7qNnsaZYv/+Azv1/pOV5nY7KKalohlZ1iU/S1Ig= Received: from smtpng2.m.smailru.net (smtpng2.m.smailru.net [94.100.179.3]) (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 4083E6EC5F for ; Thu, 15 Apr 2021 02:54:33 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 4083E6EC5F Received: by smtpng2.m.smailru.net with esmtpa (envelope-from ) id 1lWpL6-0007Hv-Ea; Thu, 15 Apr 2021 02:54:32 +0300 To: Mergen Imeev References: <2a22e2c47ad16b38bb7dcfb6b35a6a61b8b94e5e.1617984948.git.imeevma@gmail.com> <76e3ed67-6f88-8480-4a1d-080e3e01e788@tarantool.org> <20210413220025.GA39274@tarantool.org> Message-ID: <2bb96d91-4b37-4160-98da-2302c3472b52@tarantool.org> Date: Thu, 15 Apr 2021 01:54:31 +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: <20210413220025.GA39274@tarantool.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD92FFCB8E6708E74807BAE725B9AE625DE765B0E193B5B7687182A05F538085040D18E4846D6BEFF0F60A540769137B2F683D6F3C18D8EF8FE4D8B540929F97CA4 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7A0175C48BD57B26BC2099A533E45F2D0395957E7521B51C2CFCAF695D4D8E9FCEA1F7E6F0F101C6778DA827A17800CE7AB524098FB2F2222EA1F7E6F0F101C67CDEEF6D7F21E0D1D9295C2E9FA3191EE1B59CA4C82EFA65850E6F5C441F9DDB9630705DAEA546486F6B57BC7E64490618DEB871D839B73339E8FC8737B5C2249042F1592492B88C6CC7F00164DA146DAFE8445B8C89999729449624AB7ADAF37F6B57BC7E64490611E7FA7ABCAF51C92176DF2183F8FC7C08B0023DF17FBB7E08941B15DA834481F9449624AB7ADAF372E808ACE2090B5E1725E5C173C3A84C3C5EA940A35A165FF2DBA43225CD8A89F83C798A30B85E16BCE5475246E174218B5C8C57E37DE458BEDA766A37F9254B7 X-C1DE0DAB: 0D63561A33F958A5E6EF7E06A754BAF78A79C335FDE88C2568116C2A7167E3D2D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7502E6951B79FF9A3F410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34128DEC38EFF4BE5A64D1FF46CD002E2ECE3589CA623D011F7FD85E1D1C0A10AE15E0421C1520596E1D7E09C32AA3244CD39DD919BB73F48085B5594B9D0E9B49E3D93501275E802FFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojrcJA+pXcDuka4qpR2HQ8Hg== X-Mailru-Sender: 689FA8AB762F73936BC43F508A06382272E0671FD39220210908E533597684A13841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B 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 Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Good job on the patch! > diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c > index 5cf067453..ded20315b 100644 > --- a/src/box/sql/mem.c > +++ b/src/box/sql/mem.c > @@ -252,6 +252,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); > + bool is_own_value = (mem->flags & (MEM_Str | MEM_Blob)) != 0 && > + mem->z == value; > + if (sqlVdbeMemGrow(mem, len, is_own_value) != 0) > + return -1; I would propose this change: ==================== @@ -256,14 +256,14 @@ mem_set_str0_allocated(struct Mem *mem, char *value) int mem_copy_str(struct Mem *mem, const char *value, uint32_t len) { - if ((mem->flags & (MEM_Agg | MEM_Frame)) != 0) - mem_clear(mem); - bool is_own_value = (mem->flags & (MEM_Str | MEM_Blob)) != 0 && - mem->z == value; - if (sqlVdbeMemGrow(mem, len, is_own_value) != 0) + if ((mem->flags & (MEM_Str | MEM_Blob)) != 0 && mem->z == value) { + /* Own value, but might be ephemeral. Make it own if so. */ + return sqlVdbeMemGrow(mem, len, 1); + } + mem_clear(mem); + if (sqlVdbeMemGrow(mem, len, 0) != 0) return -1; - if (!is_own_value) - memcpy(mem->z, value, len); + memcpy(mem->z, value, len); mem->n = len; mem->flags = MEM_Str; mem->field_type = FIELD_TYPE_STRING; ==================== The same for the bins. > + if (!is_own_value) > + memcpy(mem->z, value, len); > + mem->n = len; > + mem->flags = MEM_Str; > + mem->field_type = FIELD_TYPE_STRING; > + return 0; > +}