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 1E86E6BD05; Tue, 30 Mar 2021 02:07:21 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 1E86E6BD05 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1617059241; bh=v1Hranejls12yNZ26CszCFEOLRnz69x914Sr5rJ/y/s=; 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=zmWB+DYwQ/JWkq6IPBPLwTVhuDlHdLhTJN3GrBd0zV0jcbLbwFmC0OT/NkXuosW9t FpEQew5BiyzbRw6yd0AxuKSwnYHKYu38oEBaIjp0FY/dRvr+TGcxhaz1DkL0Ig29aJ YgNykrzamr+8TVqNVcWs71JYJzsXIuy5U7b+9LVY= Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [94.100.181.251]) (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 5F7AD6BD0A for ; Tue, 30 Mar 2021 02:05:21 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 5F7AD6BD0A Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1lR0wi-0007Uo-Mg; Tue, 30 Mar 2021 02:05:21 +0300 To: imeevma@tarantool.org, tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org References: Message-ID: Date: Tue, 30 Mar 2021 01:05:19 +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: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD9ED7173E37F4E329498ADEA61F680B110809A4DE3E6FC56EA182A05F53808504006D1CEC7394C141AC168161E34FC8022F04A67E3C2944B90364236771A056069 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE72AC9FB60380F23AEEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637F10F1F3256FD32E28638F802B75D45FF914D58D5BE9E6BC131B5C99E7648C95CE99938B3FD79E1DF7236F81335000B96D0401841CAB44115A471835C12D1D9774AD6D5ED66289B5278DA827A17800CE7820CF4CC0E318EFB9FA2833FD35BB23D2EF20D2F80756B5F868A13BD56FB6657A471835C12D1D977725E5C173C3A84C345F93BA578C2B99F117882F4460429728AD0CFFFB425014E868A13BD56FB6657E2021AF6380DFAD1A18204E546F3947C0B7D0EA88DDEDAC722CA9DD8327EE4930A3850AC1BE2E735F409322A2F59C95CC4224003CC83647689D4C264860C145E X-C1DE0DAB: 0D63561A33F958A5EAA8514FBFF3689B548D0A5CBA24E687A51CD1EBAF773589D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7502E6951B79FF9A3F410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34AF12ADB97C97CD8998E56422B9E90AC86D018EFCAEC08AC6189D5D5BC24A2373EAE17B0E458747A11D7E09C32AA3244CDD31DDF797110B93F9804C9E32F414287C0C08F7987826B9FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojljIiQOC84rT4DI/40BcjTw== X-Mailru-Sender: 689FA8AB762F73936BC43F508A063822EB1D3FFCA97D742F4DFAABD389ED07293841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v4 30/53] sql: introduce mem_set_*_binary() 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! See 2 comments below. > diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c > index 59a378e1b..5ee49cdca 100644 > --- a/src/box/sql/mem.c > +++ b/src/box/sql/mem.c > @@ -410,6 +410,61 @@ mem_copy_string0(struct Mem *mem, const char *value) > return 0; > } > > +static inline void > +mem_set_const_bin(struct Mem *mem, char *value, uint32_t size, int alloc_type) > +{ > + assert((alloc_type & (MEM_Static | MEM_Ephem)) != 0); > + mem_clear(mem); > + mem->z = value; > + mem->n = size; > + mem->flags = MEM_Blob | alloc_type; > + mem->field_type = FIELD_TYPE_VARBINARY; > +} > + > +static inline void > +mem_set_dyn_bin(struct Mem *mem, char *value, uint32_t size, int alloc_type) > +{ > + assert((mem->flags & MEM_Dyn) == 0 || value != mem->z); > + assert(mem->szMalloc == 0 || value != mem->zMalloc); > + assert(alloc_type == MEM_Dyn || alloc_type == 0); > + mem_destroy(mem); 1. Why is it destroy here and clear above? > + mem->z = value; > + mem->n = size; > + mem->flags = MEM_Blob | alloc_type; > + mem->field_type = FIELD_TYPE_VARBINARY; > + if (alloc_type == MEM_Dyn) { > + mem->xDel = sql_free; > + } else { > + mem->xDel = NULL; > + mem->zMalloc = mem->z; > + mem->szMalloc = sqlDbMallocSize(mem->db, mem->zMalloc); > + } > +} > diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c > index 5b5e5b0c8..0e51e4809 100644 > --- a/src/box/sql/vdbeapi.c > +++ b/src/box/sql/vdbeapi.c > @@ -183,7 +182,13 @@ sql_result_blob(sql_context * pCtx, > ) > { > assert(n >= 0); > - if (sqlVdbeMemSetStr(pCtx->pOut, z, n, 0, xDel) != 0) > + if (xDel == SQL_STATIC) > + mem_set_static_binary(pCtx->pOut, (char *)z, n); > + else if (xDel == SQL_DYNAMIC) > + mem_set_allocated_binary(pCtx->pOut, (char *)z, n); > + else if (xDel != SQL_TRANSIENT) > + mem_set_dynamic_binary(pCtx->pOut, (char *)z, n); > + else if (sqlVdbeMemSetStr(pCtx->pOut, z, n, 0, xDel) != 0) > pCtx->is_aborted = true; 2. It seems to me you need to add a generic mem_set_binary which would take the xdel argument. Repeating this tree of ifs in each usage place is not any better. The same for the string API.