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 D41D86BD36; Tue, 23 Mar 2021 12:58:48 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org D41D86BD36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1616493528; bh=B+1K7+sor5xsoR/BtlFH0v0QkrKRMWfb8LK6SkhuT7E=; 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=QJiKS3tyVTWqwe4GXlqQtBnvx2urjLkRoVFbJxWt97b22e4KujSzxS5CxvJFIFcQE eYusSMHOfhSfFPETsAXl1TZH52eOMShQsa4RTe10fi8CJx2b7ROhU0HZQUxJqNruhN aNjCop5Kt5X8vGvU9arKfAW6G6GsslCR9qNEmxb0= Received: from smtp57.i.mail.ru (smtp57.i.mail.ru [217.69.128.37]) (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 705A46BD36 for ; Tue, 23 Mar 2021 12:36:44 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 705A46BD36 Received: by smtp57.i.mail.ru with esmtpa (envelope-from ) id 1lOdSt-0000x4-Mn; Tue, 23 Mar 2021 12:36:44 +0300 To: v.shpilevoy@tarantool.org, tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Tue, 23 Mar 2021 12:36:43 +0300 Message-Id: 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: 4F1203BC0FB41BD95D6E7CC48CB1F5F1DDD90A25A8FA528D0BFD61B598B81272182A05F5380850401BC5A17473E76441E87095A9177CE0938B6B28EB1C5AA9052E32FDA01574F4CC X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE74BE895B46187343CEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637CD1DFD3ABA64F6568638F802B75D45FF914D58D5BE9E6BC131B5C99E7648C95C686AF563A045C75EA01E4C73BFB7A1503AB6648A583C0ED7A471835C12D1D9774AD6D5ED66289B5278DA827A17800CE71AE4D56B06699BBC9FA2833FD35BB23D2EF20D2F80756B5F868A13BD56FB6657A471835C12D1D977725E5C173C3A84C3ED8438A78DFE0A9E117882F4460429728AD0CFFFB425014E868A13BD56FB6657D81D268191BDAD3DC09775C1D3CA48CF16CE50F2CCFF8978BA3038C0950A5D36C8A9BA7A39EFB766EC990983EF5C0329BA3038C0950A5D36D5E8D9A59859A8B6089B52FA77B685F076E601842F6C81A1F004C906525384307823802FF610243DF43C7A68FF6260569E8FC8737B5C2249EC8D19AE6D49635B3BBE47FD9DD3FB59A8DF7F3B2552694A57739F23D657EF2B13377AFFFEAFD26923F8577A6DFFEA7CD1D040B6C1ECEA3F93EC92FD9297F6715571747095F342E857739F23D657EF2BD5E8D9A59859A8B6A1DCCEB63E2F10FB089D37D7C0E48F6C5571747095F342E857739F23D657EF2B6825BDBE14D8E70285AA09D4B315C2C6BD9CCCA9EDD067B1EDA766A37F9254B7 X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A24A6D60772A99906F8E1CD14B953EB46D871FFF678EDA2553355D89D7DBCDD132 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C686AF563A045C75EA01E4C73BFB7A1503AB6648A583C0ED79C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF0417BEADF48D1460699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34A63B03BCD35E0C0AE4C5FC9F54D46EAFE180F1646E11DD62116CDFE50AF51D0043825D2C08A8E55D1D7E09C32AA3244C0A8BC63DC8FFB4CCB5E41A7857C25CD84DBEAD0ED6C55A80FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojWJZv20R+6UgPX316hNvPXw== X-Mailru-Sender: 5C3750E245F362008BC1685FEC6306ED224AA8ACF2988052E87095A9177CE0935F9045B74F665CC85105BD0848736F9966FEC6BF5C9C28D97E07721503EA2E00ED97202A5A4E92BF7402F9BA4338D657ED14614B50AE0675 X-Mras: Ok Subject: [Tarantool-patches] [PATCH v4 48/53] sql: introduce mem_get_unsigned() 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_get_unsigned() function which is used to receive unsigned value from MEM. Part of #5818 --- src/box/sql/func.c | 16 +++++++++++----- src/box/sql/mem.c | 37 +++++++++++++++++++++++++++---------- src/box/sql/mem.h | 6 +++--- src/box/sql/sqlInt.h | 3 --- src/box/sql/vdbeapi.c | 6 ------ 5 files changed, 41 insertions(+), 27 deletions(-) diff --git a/src/box/sql/func.c b/src/box/sql/func.c index 0fa0f6ac7..a851d98f2 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -118,9 +118,12 @@ port_vdbemem_dump_lua(struct port *base, struct lua_State *L, bool is_flat) luaL_pushint64(L, n); break; } - case MP_UINT: - luaL_pushuint64(L, sql_value_uint64(param)); + case MP_UINT: { + uint64_t u; + mem_get_unsigned(param, &u); + luaL_pushuint64(L, u); break; + } case MP_DOUBLE: lua_pushnumber(L, sql_value_double(param)); break; @@ -171,7 +174,8 @@ port_vdbemem_get_msgpack(struct port *base, uint32_t *size) FALLTHROUGH; } case MP_UINT: { - sql_uint64 val = sql_value_uint64(param); + uint64_t val; + mem_get_unsigned(param, &val); mpstream_encode_uint(&stream, val); break; } @@ -511,7 +515,9 @@ absFunc(sql_context * context, int argc, sql_value ** argv) UNUSED_PARAMETER(argc); switch (sql_value_type(argv[0])) { case MP_UINT: { - sql_result_uint(context, sql_value_uint64(argv[0])); + uint64_t u; + mem_get_unsigned(argv[0], &u); + sql_result_uint(context, u); break; } case MP_INT: { @@ -1487,7 +1493,7 @@ charFunc(sql_context * context, int argc, sql_value ** argv) if (sql_value_type(argv[i]) == MP_INT) x = 0xfffd; else - x = sql_value_uint64(argv[i]); + mem_get_unsigned(argv[i], &x); if (x > 0x10ffff) x = 0xfffd; c = (unsigned)(x & 0x1fffff); diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c index 540931723..6ab6d77ad 100644 --- a/src/box/sql/mem.c +++ b/src/box/sql/mem.c @@ -1259,6 +1259,33 @@ mem_get_integer(const struct Mem *mem, int64_t *i, bool *is_neg) return -1; } +int +mem_get_unsigned(const struct Mem *mem, uint64_t *u) +{ + if ((mem->flags & MEM_Int) != 0) + return -1; + if ((mem->flags & MEM_UInt) != 0) { + *u = mem->u.u; + return 0; + } + if ((mem->flags & (MEM_Str | MEM_Blob)) != 0) { + bool is_neg; + if (sql_atoi64(mem->z, (int64_t *)u, &is_neg, mem->n) != 0 || + is_neg) + return -1; + return 0; + } + if ((mem->flags & MEM_Real) != 0) { + double d = mem->u.r; + if (d >= 0 && d < (double)UINT64_MAX) { + *u = (uint64_t)d; + return 0; + } + return -1; + } + return -1; +} + int mem_copy(struct Mem *to, const struct Mem *from) { @@ -2497,16 +2524,6 @@ sql_value_boolean(sql_value *val) return b; } -uint64_t -sql_value_uint64(sql_value *val) -{ - int64_t i = 0; - bool is_neg; - mem_get_integer((struct Mem *) val, &i, &is_neg); - assert(!is_neg); - return i; -} - const unsigned char * sql_value_text(sql_value * pVal) { diff --git a/src/box/sql/mem.h b/src/box/sql/mem.h index 7857efc1d..ebc9c6c20 100644 --- a/src/box/sql/mem.h +++ b/src/box/sql/mem.h @@ -348,6 +348,9 @@ mem_implicit_cast_old(struct Mem *mem, enum field_type type); int mem_get_integer(const struct Mem *mem, int64_t *i, bool *is_neg); +int +mem_get_unsigned(const struct Mem *mem, uint64_t *u); + /** * Simple type to str convertor. It is used to simplify * error reporting. @@ -439,9 +442,6 @@ sql_value_double(struct Mem *); bool sql_value_boolean(struct Mem *val); -uint64_t -sql_value_uint64(struct Mem *val); - const unsigned char * sql_value_text(struct Mem *); diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h index 14385705f..7f9539aea 100644 --- a/src/box/sql/sqlInt.h +++ b/src/box/sql/sqlInt.h @@ -448,9 +448,6 @@ sql_column_double(sql_stmt *, int iCol); bool sql_column_boolean(struct sql_stmt *stmt, int column); -uint64_t -sql_column_uint64(struct sql_stmt *stmt, int column); - const unsigned char * sql_column_text(sql_stmt *, int iCol); diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c index abdc5f0d0..b6db98031 100644 --- a/src/box/sql/vdbeapi.c +++ b/src/box/sql/vdbeapi.c @@ -497,12 +497,6 @@ sql_column_boolean(struct sql_stmt *stmt, int i) return sql_value_boolean(columnMem(stmt, i)); } -uint64_t -sql_column_uint64(sql_stmt * pStmt, int i) -{ - return sql_value_uint64(columnMem(pStmt, i)); -} - const unsigned char * sql_column_text(sql_stmt * pStmt, int i) { -- 2.25.1