From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpng2.m.smailru.net (smtpng2.m.smailru.net [94.100.179.3]) (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 7CA41445320 for ; Sun, 5 Jul 2020 17:29:31 +0300 (MSK) Date: Sun, 5 Jul 2020 17:29:29 +0300 From: Mergen Imeev Message-ID: <20200705142929.GC135859@tarantool.org> References: <010e6a896440f240f504daf8c72b71095a17869b.1593096639.git.imeevma@gmail.com> <20200629132957.GB27240@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200629132957.GB27240@tarantool.org> Subject: Re: [Tarantool-patches] [PATCH v3 5/8] sql: remove mem_apply_type() from OP_MustBeInt List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Nikita Pettik Cc: tarantool-patches@dev.tarantool.org On Mon, Jun 29, 2020 at 01:29:57PM +0000, Nikita Pettik wrote: > On 25 Jun 18:17, imeevma@tarantool.org wrote: > > diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c > > index 276956170..a609fa985 100644 > > --- a/src/box/sql/vdbe.c > > +++ b/src/box/sql/vdbe.c > > @@ -2122,17 +2122,13 @@ case OP_AddImm: { /* in1 */ > > */ > > case OP_MustBeInt: { /* jump, in1 */ > > pIn1 = &aMem[pOp->p1]; > > - if ((pIn1->flags & (MEM_Int | MEM_UInt)) == 0) { > > - mem_apply_type(pIn1, FIELD_TYPE_INTEGER); > > - if ((pIn1->flags & (MEM_Int | MEM_UInt)) == 0) { > > - if (pOp->p2==0) { > > - diag_set(ClientError, ER_SQL_TYPE_MISMATCH, > > - sql_value_to_diag_str(pIn1), "integer"); > > - goto abort_due_to_error; > > - } else { > > - goto jump_to_p2; > > - } > > - } > > + if ((pIn1->flags & (MEM_Int | MEM_UInt)) == 0 && > > + mem_convert_to_integer(pIn1, true) != 0) { > > Please split this conditions into two branches. Like this: > > diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c > index 2bc8c9817..da76d7321 100644 > --- a/src/box/sql/vdbe.c > +++ b/src/box/sql/vdbe.c > @@ -2122,13 +2122,14 @@ case OP_AddImm: { /* in1 */ > */ > case OP_MustBeInt: { /* jump, in1 */ > pIn1 = &aMem[pOp->p1]; > - if ((pIn1->flags & (MEM_Int | MEM_UInt)) == 0 && > - mem_convert_to_integer(pIn1, true) != 0) { > - if (pOp->p2 != 0) > - goto jump_to_p2; > - diag_set(ClientError, ER_SQL_TYPE_MISMATCH, > - sql_value_to_diag_str(pIn1), "integer"); > - goto abort_due_to_error; > + if ((pIn1->flags & (MEM_Int | MEM_UInt)) == 0) { > + if (mem_convert_to_integer(pIn1, true) != 0) { > + if (pOp->p2 != 0) > + goto jump_to_p2; > + diag_set(ClientError, ER_SQL_TYPE_MISMATCH, > + sql_value_to_diag_str(pIn1), "integer"); > + goto abort_due_to_error; > + } > } > break; > > It ehcnances code readability. Or even integrate this check into > mem_covert_to_ingeger(). > I integrated this check in mem_convert_to_integer(). > The rest is OK (hope you carefully verified changed tests, since > I've only briefly looked through). >