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 BDB546FC8F; Tue, 23 Mar 2021 12:47:48 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org BDB546FC8F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1616492868; bh=UcdXwCjsKb7Iqcf+RtV+4qgsx5pyLadDFPHze5o5PXY=; h=To:Cc:Date:In-Reply-To:References:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=hDtDS6+I9598HuzwGEbFUSJkHA0vc4jMvNZPnqrFA1c+d6sJOyLICnkcoNSwvvB8c NRU/p/gW4wsBze8aQQEXLoq9rYYXCftCnUgqUJbXgBa7JQrK1gek64PpmOKa5XCry9 aUta2C2Y17SSPfbFTVoRQI2CGDeLdoC3h3JeJ5Fo= Received: from smtp58.i.mail.ru (smtp58.i.mail.ru [217.69.128.38]) (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 F286A6FC8F for ; Tue, 23 Mar 2021 12:35:52 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org F286A6FC8F Received: by smtp58.i.mail.ru with esmtpa (envelope-from ) id 1lOdS4-0002Qh-52; Tue, 23 Mar 2021 12:35:52 +0300 To: v.shpilevoy@tarantool.org, tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Tue, 23 Mar 2021 12:35:51 +0300 Message-Id: <429bbd88eebf585476b443d769b25f13f9dd5ed1.1616491731.git.imeevma@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD95D6E7CC48CB1F5F1C82687294EF6886BAE1FA542CE3F1C38182A05F538085040297B19811B63CD4853BA6265FA7EFC09664C49811EA43B822E3011A20F932F8F X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7A41A3668A00E2636EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637D81244D2CF6B2D5F8638F802B75D45FF914D58D5BE9E6BC131B5C99E7648C95C686AF563A045C75EEB41CE5B7526B9C51B69F5F2B2E40239A471835C12D1D9774AD6D5ED66289B5278DA827A17800CE77FFCE1C639F4728C9FA2833FD35BB23D2EF20D2F80756B5F868A13BD56FB6657A471835C12D1D977725E5C173C3A84C3543F342AA183667F117882F4460429728AD0CFFFB425014E868A13BD56FB6657D81D268191BDAD3DC09775C1D3CA48CFD50D4057CCB9F19BBA3038C0950A5D36C8A9BA7A39EFB766EC990983EF5C0329BA3038C0950A5D36D5E8D9A59859A8B6E484B73EA07D088376E601842F6C81A1F004C906525384307823802FF610243DF43C7A68FF6260569E8FC8737B5C2249EC8D19AE6D49635B3BBE47FD9DD3FB59A8DF7F3B2552694A57739F23D657EF2B13377AFFFEAFD26923F8577A6DFFEA7CDDB9BF3B882869D593EC92FD9297F6715571747095F342E857739F23D657EF2BD5E8D9A59859A8B6B67FC62909E22F84089D37D7C0E48F6C5571747095F342E857739F23D657EF2B6825BDBE14D8E7024847893F9AA87235E5BFE6E7EFDEDCD789D4C264860C145E X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C686AF563A045C75EEB41CE5B7526B9C51B69F5F2B2E402399C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF0417BEADF48D1460699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D342C0B628602DFD0BC9F006CA6BA419A171E1C24E5220CCCC2F42328C51470CEB50B2DDFCEE25E63C21D7E09C32AA3244C17EB8D354F4598415B7337CABF217EDF97FE24653F78E668FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojWJZv20R+6UiJSD62W3SRnw== X-Mailru-Sender: 5C3750E245F362008BC1685FEC6306ED69EDA6416D4051B453BA6265FA7EFC0941B07CD4FDF173FB5105BD0848736F9966FEC6BF5C9C28D97E07721503EA2E00ED97202A5A4E92BF7402F9BA4338D657ED14614B50AE0675 X-Mras: Ok Subject: [Tarantool-patches] [PATCH v4 26/53] sql: introduce mem_set_boolean() 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: imeevma@tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" This patch introduces mem_set_boolean(). Function mem_set_boolean() clears MEM and sets it to given unsigned value. Part of #5818 --- src/box/sql/func.c | 4 ++-- src/box/sql/mem.c | 26 +++++++++++++------------- src/box/sql/mem.h | 6 +++--- src/box/sql/vdbe.c | 13 +++++++------ src/box/sql/vdbeapi.c | 4 ++-- 5 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/box/sql/func.c b/src/box/sql/func.c index d524c3d1e..6f5fe8cb6 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -269,7 +269,7 @@ port_lua_get_vdbemem(struct port *base, uint32_t *size) } switch (field.type) { case MP_BOOL: - mem_set_bool(&val[i], field.bval); + mem_set_boolean(&val[i], field.bval); break; case MP_FLOAT: mem_set_double(&val[i], field.fval); @@ -340,7 +340,7 @@ port_c_get_vdbemem(struct port *base, uint32_t *size) const char *str; switch (mp_typeof(*data)) { case MP_BOOL: - mem_set_bool(&val[i], mp_decode_bool(&data)); + mem_set_boolean(&val[i], mp_decode_bool(&data)); break; case MP_FLOAT: mem_set_double(&val[i], mp_decode_float(&data)); diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c index f7a1a9b8a..42a65d714 100644 --- a/src/box/sql/mem.c +++ b/src/box/sql/mem.c @@ -281,6 +281,15 @@ mem_set_unsigned(struct Mem *mem, uint64_t value) mem->field_type = FIELD_TYPE_UNSIGNED; } +void +mem_set_boolean(struct Mem *mem, bool value) +{ + mem_clear(mem); + mem->u.b = value; + mem->flags = MEM_Bool; + mem->field_type = FIELD_TYPE_BOOLEAN; +} + int mem_copy(struct Mem *to, const struct Mem *from) { @@ -1412,22 +1421,22 @@ sqlVdbeMemCast(Mem * pMem, enum field_type type) return 0; case FIELD_TYPE_BOOLEAN: if ((pMem->flags & MEM_Int) != 0) { - mem_set_bool(pMem, pMem->u.i); + mem_set_boolean(pMem, pMem->u.i); return 0; } if ((pMem->flags & MEM_UInt) != 0) { - mem_set_bool(pMem, pMem->u.u); + mem_set_boolean(pMem, pMem->u.u); return 0; } if ((pMem->flags & MEM_Real) != 0) { - mem_set_bool(pMem, pMem->u.r); + mem_set_boolean(pMem, pMem->u.r); return 0; } if ((pMem->flags & MEM_Str) != 0) { bool value; if (str_cast_to_boolean(pMem->z, &value) != 0) return -1; - mem_set_bool(pMem, value); + mem_set_boolean(pMem, value); return 0; } if ((pMem->flags & MEM_Bool) != 0) @@ -1899,15 +1908,6 @@ sqlVdbeMemClearAndResize(Mem * pMem, int szNew) return 0; } -void -mem_set_bool(struct Mem *mem, bool value) -{ - mem_clear(mem); - mem->u.b = value; - mem->flags = MEM_Bool; - mem->field_type = FIELD_TYPE_BOOLEAN; -} - void mem_set_ptr(struct Mem *mem, void *ptr) { diff --git a/src/box/sql/mem.h b/src/box/sql/mem.h index 8090fb9a0..bf3690b7c 100644 --- a/src/box/sql/mem.h +++ b/src/box/sql/mem.h @@ -176,6 +176,9 @@ mem_set_integer(struct Mem *mem, int64_t value, bool is_neg); void mem_set_unsigned(struct Mem *mem, uint64_t value); +void +mem_set_boolean(struct Mem *mem, bool value); + /** * Copy content of MEM from one MEM to another. In case source MEM contains * string or binary and allocation type is not STATIC, this value is copied to @@ -408,9 +411,6 @@ mem_convert_to_numeric(struct Mem *mem, enum field_type type); int sqlVdbeMemGrow(struct Mem * pMem, int n, int preserve); int sqlVdbeMemClearAndResize(struct Mem * pMem, int n); -void -mem_set_bool(struct Mem *mem, bool value); - /** * Set VDBE memory register with given pointer as a data. * @param mem VDBE memory register to update. diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c index dd196d299..a7b7c5011 100644 --- a/src/box/sql/vdbe.c +++ b/src/box/sql/vdbe.c @@ -743,7 +743,7 @@ case OP_Integer: { /* out2 */ case OP_Bool: { /* out2 */ pOut = vdbe_prepare_null_out(p, pOp->p2); assert(pOp->p1 == 1 || pOp->p1 == 0); - mem_set_bool(pOut, pOp->p1); + mem_set_boolean(pOut, pOp->p1); break; } @@ -1104,7 +1104,7 @@ case OP_Remainder: { /* same as TK_REM, in1, in2, out3 */ case OP_CollSeq: { assert(pOp->p4type==P4_COLLSEQ || pOp->p4.pColl == NULL); if (pOp->p1) { - mem_set_bool(&aMem[pOp->p1], false); + mem_set_boolean(&aMem[pOp->p1], false); } break; } @@ -1564,7 +1564,7 @@ case OP_Ge: { /* same as TK_GE, jump, in1, in3 */ if ((pOp->opcode==OP_Eq)==res2) break; } pOut = vdbe_prepare_null_out(p, pOp->p2); - mem_set_bool(pOut, res2); + mem_set_boolean(pOut, res2); REGISTER_TRACE(p, pOp->p2, pOut); } else { VdbeBranchTaken(res!=0, (pOp->p5 & SQL_NULLEQ)?2:3); @@ -1754,7 +1754,7 @@ case OP_Or: { /* same as TK_OR, in1, in2, out3 */ } pOut = vdbe_prepare_null_out(p, pOp->p3); if (v1 != 2) - mem_set_bool(pOut, v1); + mem_set_boolean(pOut, v1); break; } @@ -1775,7 +1775,7 @@ case OP_Not: { /* same as TK_NOT, in1, out2 */ mem_str(pIn1), "boolean"); goto abort_due_to_error; } - mem_set_bool(pOut, ! pIn1->u.b); + mem_set_boolean(pOut, ! pIn1->u.b); } break; } @@ -4365,7 +4365,8 @@ case OP_AggStep: { if (pCtx->skipFlag) { assert(pOp[-1].opcode==OP_CollSeq); i = pOp[-1].p1; - if (i) mem_set_bool(&aMem[i], true); + if (i != 0) + mem_set_boolean(&aMem[i], true); } break; } diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c index 0f41db21d..d76efcfcf 100644 --- a/src/box/sql/vdbeapi.c +++ b/src/box/sql/vdbeapi.c @@ -195,7 +195,7 @@ sql_result_int(sql_context *ctx, int64_t val) void sql_result_bool(struct sql_context *ctx, bool value) { - mem_set_bool(ctx->pOut, value); + mem_set_boolean(ctx->pOut, value); } void @@ -822,7 +822,7 @@ sql_bind_boolean(struct sql_stmt *stmt, int i, bool value) if (vdbeUnbind(p, i) != 0) return -1; int rc = sql_bind_type(p, i, "boolean"); - mem_set_bool(&p->aVar[i - 1], value); + mem_set_boolean(&p->aVar[i - 1], value); return rc; } -- 2.25.1