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 3924E7030C; Mon, 24 May 2021 13:56:34 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 3924E7030C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1621853794; bh=bS5ZpMRMh4ByhBz0PcLvqXe/dC8/iIQStE8JmPwT+MA=; h=Date:To:Cc:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=i84oeDxBQqzoZhc/u30sthAL3AmTrTGoPjXWPIwPVo7FD/zqivZNddMXS9pC1l3eM s4Mgw84eeycfkXJN+8Nvzqzkee4fMkU5bEESauo/iowIpyNr0OgdDbBkInInt9SPRH brUuNMAPPGkPH3j6hiO9VpomBK1Fh+zuthknms/o= 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 D0F917030C for ; Mon, 24 May 2021 13:56:32 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org D0F917030C Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1ll8G7-0008V6-OU; Mon, 24 May 2021 13:56:32 +0300 Date: Mon, 24 May 2021 13:56:30 +0300 To: Vladislav Shpilevoy Cc: tarantool-patches@dev.tarantool.org Message-ID: <20210524105630.GA82983@tarantool.org> References: <3f495b512c6d1a0e494c111ad37083f98c9988ad.1619540891.git.imeevma@gmail.com> <2ee164bc-76e0-0a42-aaa1-64583c3d7105@tarantool.org> <20210517121811.GA177791@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD91B019B01C53E51AFA94C0B24B2C939D4C80F0683D6F6F7C600894C459B0CD1B93A06CC3405C0582A615AE847ED815D8362FA5AD22A4C0550D5DA017CF5BD799E X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE75AD53DF1D86BACA3EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063795AFAF91F541EBCE8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8C45226BE5D4838E2D2DC085B5D662878117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC3733B5EC72352B9FA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352026055571C92BF10FF04B652EEC242312D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B66F6A3E018CF4DC80089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: 0D63561A33F958A50DEDE3AF8467295E1717579D052060568EE2A6D0CB8543A8D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA753C350047980234DB410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34F7CC4EA888783AE0F2595DC6D95D406D534E743DF8B51C6B56A5B503865AE33608E250DE79FE7B721D7E09C32AA3244CC8632583085BEE4E785E3AD4DA748E65408A6A02710B7304729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj+gjVyQcIK6LLiX3qWMnyNg== X-Mailru-Sender: 689FA8AB762F73936BC43F508A063822FBA11982CBD483DB9A88511F17CF17EE83D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v2 3/3] sql: replace MEM-type flags by enum mem_type 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 Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi! Thank you for the review! My answers and diff below. On Fri, May 21, 2021 at 08:59:14PM +0200, Vladislav Shpilevoy wrote: > Hi! Thanks for the fixes! > > See 2 small comments below. > > > diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c > > index b6ff6397f..f7788021d 100644 > > --- a/src/box/sql/mem.c > > +++ b/src/box/sql/mem.c > > @@ -1155,11 +1214,11 @@ mem_get_str0(const struct Mem *mem, const char **s) > > int > > mem_get_bin(const struct Mem *mem, const char **s) > > { > > - if ((mem->flags & MEM_Str) != 0) { > > + if (mem->type == MEM_TYPE_STR) { > > *s = mem->n > 0 ? mem->z : NULL; > > return 0; > > } > > - if ((mem->flags & MEM_Blob) == 0 || (mem->flags & MEM_Zero) != 0) > > + if (mem->type != MEM_TYPE_BIN || (mem->flags & MEM_Zero) != 0) > > return -1; > > 1. AFAIR, it is not possible to have MEM_Zero for non-bin. Which makes > the second condition unreachable, right? The same in mem_len(). > It is true that it should be not possible to have MEM_Zero flag for non-VARBINARY value. However, here it is checked that the value is VARBINARY and if it is, the flag is checked. I think there is nothing wrong here. Still, In mem_len() I removed one condition and added assert instead. > > *s = mem->z; > > return 0; > > @@ -1644,14 +1717,15 @@ mem_bit_not(const struct Mem *mem, struct Mem *result) > > return -1; > > } > > result->u.i = ~i; > > - result->flags = result->u.i < 0 ? MEM_Int : MEM_UInt; > > + result->type = result->u.i < 0 ? MEM_TYPE_INT : MEM_TYPE_UINT; > > + assert(result->flags == 0); > > return 0; > > } > > > > int > > mem_cmp_bool(const struct Mem *a, const struct Mem *b, int *result) > > { > > - if ((a->flags & b->flags & MEM_Bool) == 0) > > + if (a->type != MEM_TYPE_BOOL || b->type != MEM_TYPE_BOOL) > > 2. You could leave the old way so as to avoid || (branching). > Thanks, fixed. Also fixed in one more place. > > return -1; > > if (a->u.b == b->u.b) > > *result = 0; Diff: diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c index f7788021d..1bd70c37f 100644 --- a/src/box/sql/mem.c +++ b/src/box/sql/mem.c @@ -1229,7 +1229,8 @@ mem_len(const struct Mem *mem, uint32_t *len) { if (!mem_is_bytes(mem)) return -1; - if (mem->type == MEM_TYPE_BIN && (mem->flags & MEM_Zero) != 0) + assert((mem->flags & MEM_Zero) == 0 || mem->type == MEM_TYPE_BIN); + if ((mem->flags & MEM_Zero) != 0) *len = mem->n + mem->u.nZero; else *len = mem->n; @@ -1725,7 +1726,7 @@ mem_bit_not(const struct Mem *mem, struct Mem *result) int mem_cmp_bool(const struct Mem *a, const struct Mem *b, int *result) { - if (a->type != MEM_TYPE_BOOL || b->type != MEM_TYPE_BOOL) + if ((a->type & b->type & MEM_TYPE_BOOL) == 0) return -1; if (a->u.b == b->u.b) *result = 0; @@ -2345,7 +2346,7 @@ sqlMemCompare(const Mem * pMem1, const Mem * pMem2, const struct coll * pColl) (int)(type1 == MEM_TYPE_NULL); if (((type1 | type2) & MEM_TYPE_BOOL) != 0) { - if (type1 == MEM_TYPE_BOOL && type2 == MEM_TYPE_BOOL) { + if ((type1 & type2 & MEM_TYPE_BOOL) != 0) { if (pMem1->u.b == pMem2->u.b) return 0; if (pMem1->u.b)