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 3B6E36EC5F; Thu, 15 Apr 2021 02:49:50 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 3B6E36EC5F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1618444190; bh=ApRXkqvPfCELkUm2TAzZY8qD81obCKqb8xRy71tYkDA=; 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=ePpYzNx0NqvmZ45AigkFbv0Q4PgydLTWRwkceNLSfnAhdmIV08zszSwG2seMS8jbC oqDX667fa7XYo4qOXlYH04thTFraYEGwgOKMzWTmr0xvFqTnjXesWV828LdMH0T7qs VyIQYcvvZ7I8EQ1hQl/sxiAUnAM14UrWGUC6n+gM= 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 6894C6EC5F for ; Thu, 15 Apr 2021 02:49:48 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 6894C6EC5F Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1lWpGV-0000IM-Cq; Thu, 15 Apr 2021 02:49:47 +0300 To: Mergen Imeev References: <20210413213652.GA37176@tarantool.org> Message-ID: Date: Thu, 15 Apr 2021 01:49:46 +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: <20210413213652.GA37176@tarantool.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD92FFCB8E6708E74807BAE725B9AE625DE765B0E193B5B7687182A05F5380850400723E19E48E852C0630AB2F67FC690414A02ED6B85D131794C879A333C353212 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE70312E9A300D47E3BEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637790A9327A9AFEF4F8638F802B75D45FF914D58D5BE9E6BC1A93B80C6DEB9DEE97C6FB206A91F05B2A493FA10121888E157A8B8D56CC8260EFEEB761FB9071033D2E47CDBA5A96583C09775C1D3CA48CF53FA85A707D24CADCC7F00164DA146DAFE8445B8C89999729449624AB7ADAF37F6B57BC7E64490611E7FA7ABCAF51C92176DF2183F8FC7C068077CCD40B79AC98941B15DA834481F9449624AB7ADAF372E808ACE2090B5E1725E5C173C3A84C3C5EA940A35A165FF2DBA43225CD8A89F83C798A30B85E16BCE5475246E174218B5C8C57E37DE458BEDA766A37F9254B7 X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A2AD77751E876CB595E8F7B195E1C97831203FD8A2A04A0B721BBFD1EA3789D373 X-C1DE0DAB: 0D63561A33F958A533F51575DF716602B1579BB5F964A5959F0C902826F6A1FCD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7502E6951B79FF9A3F410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34D7D5115130EFC824ABFDB4E515BA344289A5C9D00FE994FB353AB74F4A25F538F8E57811ABE69F971D7E09C32AA3244CA933E1B77138EC7C6A248AB6006B9C76435BF7150578642FFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojrcJA+pXcDunvFl4MAHIS6Q== X-Mailru-Sender: 689FA8AB762F73936BC43F508A063822FD268B027A7CF25FB695CB83D53B4E2D3841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v5 27/52] sql: introduce mem_set_str_*() functions 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" Thanks for working on this! >>> index ae55e4c29..171cb8946 100644 >>> --- a/src/box/sql/vdbeaux.c >>> +++ b/src/box/sql/vdbeaux.c >>> @@ -1333,41 +1331,34 @@ sqlVdbeList(Vdbe * p) >>> mem_set_int(pMem, pOp->p3, pOp->p3 < 0); >>> pMem++; >>> >>> - if (sqlVdbeMemClearAndResize(pMem, 256)) { >>> - assert(p->db->mallocFailed); >>> + char *buf = sqlDbMallocRaw(sql_get(), 256); >> >> 2. I think you need some kind of mem_set_strlen(), or mem_grow()/mem_reserve(), >> or something else to reserve the memory. To extend zMalloc. Otherwise you >> can't reuse the memory which might already be in the mem object. > Wouldn't mem_copy_*() be enough? In general, allocated by MEM memory should not > be accessed for changing (except for MEM_Agg). Both your current solution and mem_copy suffer from unnecessary copying. In the old code the string was created in-place. This is what I am talking about. But nevermind, it is not a perf-critical place as I see. Can be tweaked later. > diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c > index 6c08e772d..484c66b29 100644 > --- a/src/box/sql/vdbeapi.c > +++ b/src/box/sql/vdbeapi.c > @@ -125,6 +125,12 @@ setResultStrOrError(sql_context * pCtx, /* Function context */ > void (*xDel) (void *) /* Destructor function */ > ) > { > + if (xDel == SQL_STATIC) > + return mem_set_strl_static(pCtx->pOut, (char *)z, n); > + if (xDel == SQL_DYNAMIC) > + return mem_set_strl_allocated(pCtx->pOut, (char *)z, n); > + if (xDel != SQL_TRANSIENT) > + return mem_set_strl_dynamic(pCtx->pOut, (char *)z, n); I just can't help myself. It makes my eyes bleed - for dynamic we use allocated, and for non-transient we use dynamic! I see why, but I would want us to hide it as deep inside of mem.c as possible, so as we at least could change the names in a not very intrusive manner in the future. Or delete it in future entirely. Please, move this hunk and the one below to a separate functions like mem_set_strl(Mem, str, len_hint, destructor). Then it would be in one terrible place instead of 2 terrible places. The same for the bins. > if (sqlVdbeMemSetStr(pCtx->pOut, z, n, 1, xDel) != 0) > pCtx->is_aborted = true; > } > @@ -762,7 +768,13 @@ bindText(sql_stmt * pStmt, /* The statement to bind against */ > if (zData == NULL) > return 0; > pVar = &p->aVar[i - 1]; > - if (sqlVdbeMemSetStr(pVar, zData, nData, 1, xDel) != 0) > + if (xDel == SQL_STATIC) > + mem_set_strl_static(pVar, (char *)zData, nData); > + else if (xDel == SQL_DYNAMIC) > + mem_set_strl_allocated(pVar, (char *)zData, nData); > + else if (xDel != SQL_TRANSIENT) > + mem_set_strl_dynamic(pVar, (char *)zData, nData); > + else if (sqlVdbeMemSetStr(pVar, zData, nData, 1, xDel) != 0) > return -1; > return sql_bind_type(p, i, "text"); > }