From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Stanislav Zudin Subject: [PATCH 06/13] sql: aux functions to support big integers Date: Fri, 15 Mar 2019 18:45:35 +0300 Message-Id: In-Reply-To: References: In-Reply-To: References: To: tarantool-patches@freelists.org, vdavydov.dev@gmail.com Cc: Stanislav Zudin List-ID: Adapts auxiliary functions for supporting arithmetic operations with unsigned integers. --- src/box/sql/vdbe.c | 21 ++++++++++++++------- src/box/sql/vdbemem.c | 3 +++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c index 8a7f7a12f..ea9d9d98f 100644 --- a/src/box/sql/vdbe.c +++ b/src/box/sql/vdbe.c @@ -404,15 +404,20 @@ sql_value_apply_type( * numeric type, if has one. Set the pMem->u.r and pMem->u.i fields * accordingly. */ -static u16 SQL_NOINLINE computeNumericType(Mem *pMem) +static u32 SQL_NOINLINE computeNumericType(Mem *pMem) { assert((pMem->flags & (MEM_Int|MEM_Real))==0); assert((pMem->flags & (MEM_Str|MEM_Blob))!=0); if (sqlAtoF(pMem->z, &pMem->u.r, pMem->n)==0) return 0; - if (sql_atoi64(pMem->z, (int64_t *)&pMem->u.i, pMem->n)==ATOI_SIGNED) - return MEM_Int; - return MEM_Real; + switch(sql_atoi64(pMem->z, (int64_t *)&pMem->u.i, pMem->n)) { + case ATOI_SIGNED: + return MEM_Int; + case ATOI_UNSIGNED: + return MEM_Int | MEM_Unsigned; + default: /* ATOI_OVERFLOW:*/ + return MEM_Real; + } } /* @@ -422,8 +427,10 @@ static u16 SQL_NOINLINE computeNumericType(Mem *pMem) * Unlike mem_apply_numeric_type(), this routine does not modify pMem->flags. * But it does set pMem->u.r and pMem->u.i appropriately. */ -static u16 numericType(Mem *pMem) +static u32 numericType(Mem *pMem) { + if ((pMem->flags & (MEM_Int|MEM_Unsigned)) == (MEM_Int|MEM_Unsigned)) + return (MEM_Int|MEM_Unsigned); if (pMem->flags & (MEM_Int|MEM_Real)) { return pMem->flags & (MEM_Int|MEM_Real); } @@ -1648,8 +1655,8 @@ case OP_Divide: /* same as TK_SLASH, in1, in2, out3 */ case OP_Remainder: { /* same as TK_REM, in1, in2, out3 */ char bIntint; /* Started out as two integer operands */ u32 flags; /* Combined MEM_* flags from both inputs */ - u16 type1; /* Numeric type of left operand */ - u16 type2; /* Numeric type of right operand */ + u32 type1; /* Numeric type of left operand */ + u32 type2; /* Numeric type of right operand */ i64 iA; /* Integer value of left operand */ i64 iB; /* Integer value of right operand */ double rA; /* Real value of left operand */ diff --git a/src/box/sql/vdbemem.c b/src/box/sql/vdbemem.c index 5e35a1720..2805d7a01 100644 --- a/src/box/sql/vdbemem.c +++ b/src/box/sql/vdbemem.c @@ -489,6 +489,9 @@ sqlVdbeRealValue(Mem * pMem, double *v) if (pMem->flags & MEM_Real) { *v = pMem->u.r; return 0; + } else if (pMem->flags & (MEM_Int | MEM_Unsigned)) { + *v = (double)(u64)pMem->u.i; + return 0; } else if (pMem->flags & MEM_Int) { *v = (double)pMem->u.i; return 0; -- 2.17.1