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 754EC6BD0D; Sun, 11 Apr 2021 21:06:28 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 754EC6BD0D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1618164388; bh=50fwMQRHYUI7hueJS5cj9Q95ve6gQJJhZP9dyRZPO0w=; 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=PwPkfGckbeuZu7l3k2Au0oMA+3grXffGtMthbpkbXKkfICCes+rtMeg+FwvnhWVKC WUPTdGPvg3cyjkwwySUHm8c3FOxAbBjGjrPcm29WWyA14+41285G8tk13iGQVEVe0G t8vGmAiB/3qggJrmTvN2y28CI31MHdI7UbpA9jZ8= 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 232CE6BD0C for ; Sun, 11 Apr 2021 21:06:26 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 232CE6BD0C Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1lVeTZ-0007uG-6m; Sun, 11 Apr 2021 21:06:25 +0300 To: imeevma@tarantool.org, tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org References: <14bb43fcd1f34bef5c92279ae6c274d1e437cc86.1617984948.git.imeevma@gmail.com> Message-ID: Date: Sun, 11 Apr 2021 20:06:24 +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: <14bb43fcd1f34bef5c92279ae6c274d1e437cc86.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: 4F1203BC0FB41BD92FFCB8E6708E7480BE79914FF86F9151AC38CC435EA4A654182A05F5380850403257EB618445A8010CE9581C171DB0B9554E6DA4ACE3114A246299CCE3A4B586 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7EED5D2FAB4CEB1EDEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637E16D8B060A9A23898638F802B75D45FF914D58D5BE9E6BC1A93B80C6DEB9DEE97C6FB206A91F05B2BE2E6BE9FEA0B7C9F4527C961E5707DC32051A2C76225635D2E47CDBA5A96583C09775C1D3CA48CF1E02C13459908652117882F4460429724CE54428C33FAD30A8DF7F3B2552694AC26CFBAC0749D213D2E47CDBA5A9658378DA827A17800CE7A3E15B919BF433779FA2833FD35BB23DF004C906525384302BEBFE083D3B9BA73A03B725D353964B0B7D0EA88DDEDAC722CA9DD8327EE4930A3850AC1BE2E735463FC242DBD691A6C4224003CC83647689D4C264860C145E X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A2AD77751E876CB595E8F7B195E1C9783189D722210C5DC2CE7E6ED54993E2D80B X-C1DE0DAB: 0D63561A33F958A5585299DA7D854E66B6BB4AF751708B9B8DA3033812251AAFD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7502E6951B79FF9A3F410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34AF61ACC197BF517A1D1F9FD21D3AA50F1271CE3044A9B7018C3AB5D5FE9B66623FE6A71049A9BD7D1D7E09C32AA3244CD744213899CCD0D2A81B86F5EE74926A3E8609A02908F271FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojyKKJYJ15DtJpvyIBmf5NcA== X-Mailru-Sender: 689FA8AB762F73936BC43F508A06382237F677F3E3F19437293654E705D6A94D3841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v5 13/52] sql: introduce mem_copy() 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 patch! >> Also what was wrong with sqlVdbeMemCopy's way of using sqlVdbeMemMakeWriteable? >> > I see that this as a hack. It changes dynamic or allocated type (only type!) to > ephemeral and then calls sqlVdbeMemMakeWriteable(), which converts ephemeral > value to allocated value. Isn't it better to just directly copy? Yes, your way sounds better. > diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c > index 25b2e75ee..ea3917fe3 100644 > --- a/src/box/sql/mem.c > +++ b/src/box/sql/mem.c > @@ -267,6 +267,35 @@ mem_destroy(struct Mem *mem) > mem->zMalloc = NULL; > } > > +int > +mem_copy(struct Mem *to, const struct Mem *from) > +{ > + mem_clear(to); > + to->u = from->u; > + to->flags = from->flags; > + to->subtype = from->subtype; > + to->field_type = from->field_type; > + to->n = from->n; > + to->z = from->z; > + if ((to->flags & (MEM_Str | MEM_Blob)) == 0) > + return 0; > + if ((to->flags & MEM_Static) != 0) > + return 0; > + if ((to->flags & (MEM_Zero | MEM_Blob)) == (MEM_Zero | MEM_Blob)) > + return sqlVdbeMemExpandBlob(to); > + if (to->szMalloc == 0) > + to->zMalloc = sqlDbMallocRaw(to->db, to->n); > + else > + to->zMalloc = sqlDbReallocOrFree(to->db, to->zMalloc, to->n); You can call realloc always. It turns into malloc when the pointer is NULL, which is the case for szMalloc == 0 I think. > + if (to->zMalloc == NULL) > + return -1; > + to->szMalloc = sqlDbMallocSize(to->db, to->zMalloc); > + memcpy(to->zMalloc, to->z, to->n); > + to->z = to->zMalloc; > + to->flags &= (MEM_Str | MEM_Blob | MEM_Term | MEM_Subtype); > + return 0; > +}