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 005C36B96C; Wed, 14 Apr 2021 02:06:12 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 005C36B96C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1618355173; bh=QabNk+tdU7QoRIOjWmP7N2nNg8KLN+D/sb+LAMqX4kI=; 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=jVcju6CBXqvCA5cp7SbQYmnm0WTi9ejYJZs/txl9tuRyWNxDahuZXBnrXtzGYmmwB dy6FQxHozsLmvQ+iMIfPGd+bB4Wqd6uu1FVWqbv1dgUV5q5KGhawKHj3ea1PBV9KzV ObMvXEKsJ9sTaUFozCAUNC1Eg90wf50eWmVHuX20= 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 CB2B96EC5B for ; Wed, 14 Apr 2021 02:06:11 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org CB2B96EC5B Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1lWS6k-0004LH-Vb; Wed, 14 Apr 2021 02:06:11 +0300 To: imeevma@tarantool.org, tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org References: <056987bba3f23e3298201d14728452f3033a166c.1618000037.git.imeevma@gmail.com> Message-ID: <57b42211-19a9-1629-5d91-bc2e729f7dee@tarantool.org> Date: Wed, 14 Apr 2021 01:06:09 +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: <056987bba3f23e3298201d14728452f3033a166c.1618000037.git.imeevma@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD92FFCB8E6708E748094FADAEB10E66ADA4C48BE3C291E66DA182A05F5380850400352CE2B6F8BD17B3DAF942541F0EB6F62E77F1DC3F252B3E3F476B6732479FD X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7B9FBA884A7C9B8BAEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006374FA524FBD8B89EAA8638F802B75D45FF914D58D5BE9E6BC1A93B80C6DEB9DEE97C6FB206A91F05B2F1ADE9E28A13C425E65EA7E347103658A2BB4B7391E66DBBD2E47CDBA5A96583C09775C1D3CA48CF62968DCAA3E4B45B117882F4460429724CE54428C33FAD30A8DF7F3B2552694AC26CFBAC0749D213D2E47CDBA5A9658378DA827A17800CE7E9512AC99003B6BE9FA2833FD35BB23DF004C906525384302BEBFE083D3B9BA73A03B725D353964B0B7D0EA88DDEDAC722CA9DD8327EE4930A3850AC1BE2E73542F54486E6D6388DC4224003CC83647689D4C264860C145E X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A2AD77751E876CB595E8F7B195E1C978316B1B2D719C25CD3160D789705920FE00 X-C1DE0DAB: 0D63561A33F958A5ED450FB33C9A953CDAF0C861090EBE90F4ECFE66A1FFECDDD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7502E6951B79FF9A3F410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3454CC76E5F54B410C8EE4CE20F0F1090479E0E504A089B1629CED5D3F8A7C1A62DAC1D9565B2AE95C1D7E09C32AA3244CB86103B5C3F6E604327D1F3C6FFF6DF95A1673A01BA68E40FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojnA7/qPBUIXEX2ww96sS2Rg== X-Mailru-Sender: 689FA8AB762F73936BC43F508A0638224E62A851AA6B74B586BEED5C0F3A183D3841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v5 49/52] sql: introduce mem_get_str0() and mem_as_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: Vladislav Shpilevoy via Tarantool-patches Reply-To: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Thanks for the discussion! See 2 comments below. 1. With this getter it is less trivial than with the previous ones. I just realized, that we call mem_as_str() on function arguments. What if a mem is passed to multiple functions, and one of them changes it affecting the other functions? What if the same function is called multiple times during a query? - the first execution affects the argument for the next executions? Does not look right. Am I missing something? It seems that could be fixed not so hard. If the value is already a 0-terminated string, we return it. If it is a blob or not terminated string, we extended it, add 0, and return. It does not really change the original value anyway. Mem.n stays the same, and the first n bytes stay the same. If it is a number, we can save its string representation to Mem.z, which is not used for numbers. Will it work? > diff --git a/src/box/sql/mem.h b/src/box/sql/mem.h > index e48e8788c..5848ae729 100644 > --- a/src/box/sql/mem.h > +++ b/src/box/sql/mem.h > @@ -568,6 +568,28 @@ mem_get_double(const struct Mem *mem, double *d); > int > mem_get_bool(const struct Mem *mem, bool *b); > > +/** > + * Return value for MEM of STRING type if MEM contains a NULL-terminated string. > + * Otherwise convert value of the MEM to NULL-terminated string if possible and > + * return converted value. Original MEM is not changed. > + */ > +int > +mem_get_str0(const struct Mem *mem, const char **s); > + > +/** > + * Return value for MEM of STRING type if MEM contains NULL-terminated string. > + * Otherwise convert MEM to MEM of string type that contains NULL-terminated > + * string and return its value. Return NULL if conversion is impossible. > + */ > +static inline const char * > +mem_as_str0(struct Mem *mem) > +{ > + const char *str; > + if (mem_to_str0(mem) != 0 || mem_get_str0(mem, &str) != 0) 2. If mem_to_str0 succeeded, why can't you return mem->z right away? > + return NULL; > + return str; > +}