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 EFD096EC5F; Thu, 15 Apr 2021 03:30:19 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org EFD096EC5F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1618446620; bh=NQj5fu40IONQPdObT9sxtr/usIldxGOT+KlUpy1vCto=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=gh84rPYGlfEd+CpkeeIR0fd0LENhJ/g4+r3G1ZLugzZsGRktuwUQlhmO53h2dBLxo IsalvMaDIxN20e4YY3uWrsYQnQErNJwRuQ2riwRtfwfrA3ylofr+MyJEkuDBdEc8+w H8ul4xbJVNdxgADqeggPyH9bjmdZDrVH+m9dlnag= Received: from smtp31.i.mail.ru (smtp31.i.mail.ru [94.100.177.91]) (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 943606EC5F for ; Thu, 15 Apr 2021 03:30:18 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 943606EC5F Received: by smtp31.i.mail.ru with esmtpa (envelope-from ) id 1lWpth-0008Sd-Ji; Thu, 15 Apr 2021 03:30:18 +0300 Date: Thu, 15 Apr 2021 03:30:16 +0300 To: Vladislav Shpilevoy Message-ID: <20210415003016.GA362135@tarantool.org> References: <2a22e2c47ad16b38bb7dcfb6b35a6a61b8b94e5e.1617984948.git.imeevma@gmail.com> <76e3ed67-6f88-8480-4a1d-080e3e01e788@tarantool.org> <20210413220025.GA39274@tarantool.org> <2bb96d91-4b37-4160-98da-2302c3472b52@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <2bb96d91-4b37-4160-98da-2302c3472b52@tarantool.org> X-7564579A: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD92FFCB8E6708E7480EBD5CA77A668ECB87DA2124B0A8E6609182A05F53808504084E4025C5A38ED9E985F5E9AFD4DA58A4FD0F1CD35E25DF65F70D973CC2CA7AB X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE758E3775C3D7FDEE4EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637461824C5F23D16228638F802B75D45FF914D58D5BE9E6BC1A93B80C6DEB9DEE97C6FB206A91F05B216629E131AF3FAB4F5BB9D0756B9F94A2AAFC1FEE5B068F7D2E47CDBA5A96583C09775C1D3CA48CF253F27DA5A70FAF3117882F4460429724CE54428C33FAD30A8DF7F3B2552694AC26CFBAC0749D213D2E47CDBA5A9658378DA827A17800CE7A46ADF0C403417779FA2833FD35BB23DF004C90652538430302FCEF25BFAB3454AD6D5ED66289B5278DA827A17800CE78F28311C2AE277AAD32BA5DBAC0009BE395957E7521B51C20BC6067A898B09E4090A508E0FED6299176DF2183F8FC7C0A6867689CCAA6064CD04E86FAF290E2DE7108DC36ECF87B51DD303D21008E298D5E8D9A59859A8B6B372FE9A2E580EFC725E5C173C3A84C3E0287E8A3902ECA435872C767BF85DA2F004C90652538430E4A6367B16DE6309 X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A2368A440D3B0F6089093C9A16E5BC824A2A04A2ABAA09D25379311020FFC8D4AD48C8163CD7E2ABE7C483FE0625FF1BE1 X-C1DE0DAB: 0D63561A33F958A598DAF1FA4CED9F403E5C3EB919C35948C8E5D3106573A6ECD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7502E6951B79FF9A3F410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3473688ED311681BF0673C608483F62AE4ABF9CE6D315CD636125690C18ACEC24F8389041951FB4EF61D7E09C32AA3244C7E62E5D40D7D6D6FB7D49B57CDDA156C39C99C45E8D137E9FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojrcJA+pXcDukKkIKif3PiHw== X-Mailru-Sender: 5C3750E245F362008BC1685FEC6306ED53E7A438493FE154985F5E9AFD4DA58AF43CCAED39DA92F15105BD0848736F9966FEC6BF5C9C28D97E07721503EA2E00ED97202A5A4E92BF7402F9BA4338D657ED14614B50AE0675 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: Mergen Imeev via Tarantool-patches Reply-To: Mergen Imeev Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Thank you! I applied your patch. However, I added a bit of changes since it was possible that after mem_copy_str() type of copied value will be MEM_Blob. Diff: diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c index d98b077ad..7676a29e3 100644 --- a/src/box/sql/mem.c +++ b/src/box/sql/mem.c @@ -258,7 +258,11 @@ mem_copy_str(struct Mem *mem, const char *value, uint32_t len) { 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); + if (sqlVdbeMemGrow(mem, len, 1) != 0) + return -1; + mem->flags = MEM_Str; + mem->field_type = FIELD_TYPE_STRING; + return 0; } mem_clear(mem); if (sqlVdbeMemGrow(mem, len, 0) != 0) On Thu, Apr 15, 2021 at 01:54:31AM +0200, Vladislav Shpilevoy wrote: > 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; > > +}