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 C39246EC5B; Tue, 30 Mar 2021 02:01:54 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org C39246EC5B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1617058914; bh=YyxmBGW8IG2CUCXG+jWURpzcpUn5XYiAv49SZ9/O6Sk=; 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=REznIhNuSDZACUwdck/I+DDenYNNlutCYqjps9sj8sxMNLbR1D4qout0n0Lqkm0W7 CF+yyPShuQRoojySze69anFB3Jo0/24AeKlbFX70Laq/Zyk92hA5J0YxCkhVCQqh3Q 1d9VGd1kMCTb2gC4jDvWyhdpsV22ucH6KZp1dJWs= 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 A137B6EC5B for ; Tue, 30 Mar 2021 02:01:20 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A137B6EC5B Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1lR0sp-0007qG-OT; Tue, 30 Mar 2021 02:01:20 +0300 To: imeevma@tarantool.org, tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org References: <36c5f57f22e685be0fbd657c6aa13ac5a807a7d0.1616491731.git.imeevma@gmail.com> Message-ID: Date: Tue, 30 Mar 2021 01:01:18 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.9.0 MIME-Version: 1.0 In-Reply-To: <36c5f57f22e685be0fbd657c6aa13ac5a807a7d0.1616491731.git.imeevma@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD9ED7173E37F4E32947427BE79D20CABD4ABD7C98AF5DBFD37182A05F5380850403380FEF081E95FF7759531838CA5033B9AF617CEC403AE502B27EE4F6D062C81 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7BF6702EC5472AA0FEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063752AC809489EC5B9C8638F802B75D45FF914D58D5BE9E6BC131B5C99E7648C95CE99938B3FD79E1DF5D33ED53BF672E06572E1D502B3E820CA471835C12D1D9774AD6D5ED66289B5278DA827A17800CE7ABB305BD10C6E5099FA2833FD35BB23D2EF20D2F80756B5F868A13BD56FB6657A471835C12D1D977725E5C173C3A84C3A7AC412AE061D850117882F4460429728AD0CFFFB425014E868A13BD56FB6657E2021AF6380DFAD1A18204E546F3947C0B7D0EA88DDEDAC722CA9DD8327EE4930A3850AC1BE2E735444A83B712AC0148C4224003CC83647689D4C264860C145E X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A2AD77751E876CB595E8F7B195E1C97831C64A76126C2EDECD11447ED96C72CD2D X-C1DE0DAB: 0D63561A33F958A501D82627BDECE5A110EA8BF4A17E86811E652F0F901FFF8AD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7502E6951B79FF9A3F410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34C5CF6F4B28551E3FAC802DB0F7930B8E3C838118FF1D0360DA0EE15892B4A2B125925DCD8CB1131B1D7E09C32AA3244C851CFD8BBFD6D915E222201B94698E67F165894D92D62706FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojljIiQOC84rSvjtcYfkGy/w== X-Mailru-Sender: 689FA8AB762F73936BC43F508A0638222AA66FA20F0A093BE2DDA3CB0B9A47D23841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v4 12/53] 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" I appreciate the work you did here! See 2 comments below. On 23.03.2021 10:35, Mergen Imeev via Tarantool-patches wrote: > This patch introduces mem_copy(). This function copies value from source > MEM to destination MEM. In case value is string or binary and have not > static allocation type, it is copied to newly allocated memory. > > Part of #5818 > --- > src/box/sql/func.c | 4 ++-- > src/box/sql/mem.c | 54 +++++++++++++++++++++++++------------------ > src/box/sql/mem.h | 9 +++++++- > src/box/sql/vdbeapi.c | 2 +- > src/box/sql/vdbeaux.c | 2 +- > 5 files changed, 44 insertions(+), 27 deletions(-) > > diff --git a/src/box/sql/func.c b/src/box/sql/func.c > index 81b537d9b..6b6081150 100644 > --- a/src/box/sql/func.c > +++ b/src/box/sql/func.c > @@ -2079,13 +2079,13 @@ minmaxStep(sql_context * context, int NotUsed, sql_value ** argv) > bool is_max = (func->flags & SQL_FUNC_MAX) != 0; > cmp = sqlMemCompare(pBest, pArg, pColl); > if ((is_max && cmp < 0) || (!is_max && cmp > 0)) { > - sqlVdbeMemCopy(pBest, pArg); 1. Still is "used" in stat4ValueFromExpr(). > + mem_copy(pBest, pArg); > } else { > sqlSkipAccumulatorLoad(context); > } > } else { > pBest->db = sql_context_db_handle(context); > - sqlVdbeMemCopy(pBest, pArg); > + mem_copy(pBest, pArg); > } > } > > diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c > index abc9291ef..f12441d7c 100644 > --- a/src/box/sql/mem.c > +++ b/src/box/sql/mem.c > @@ -257,6 +257,38 @@ 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)) { > + if (sqlVdbeMemExpandBlob(to) != 0) > + return -1; > + return 0; 2. You can make `returnsqlVdbeMemExpandBlob(to);`, no need to check its result. Also what was wrong with sqlVdbeMemCopy's way of using sqlVdbeMemMakeWriteable? > + } > + if (to->szMalloc == 0) > + to->zMalloc = sqlDbMallocRaw(to->db, to->n); > + else > + to->zMalloc = sqlDbReallocOrFree(to->db, to->zMalloc, to->n); > + 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; > +} > + > static inline bool > mem_has_msgpack_subtype(struct Mem *mem) > {