From: imeevma@tarantool.org To: korablev@tarantool.org, tsafin@tarantool.org, tarantool-patches@dev.tarantool.org Subject: [Tarantool-patches] [PATCH v3 1/8] sql: introduce mem_set_double() Date: Thu, 25 Jun 2020 18:17:20 +0300 [thread overview] Message-ID: <908f67730f9ab461531d61a66fe2c885be77682e.1593096639.git.imeevma@gmail.com> (raw) In-Reply-To: <cover.1593096639.git.imeevma@gmail.com> The mem_set_double () function is used to properly set MEM as containing DOUBLE value. --- src/box/sql/func.c | 8 ++++---- src/box/sql/vdbe.c | 9 +++------ src/box/sql/vdbeInt.h | 5 ++++- src/box/sql/vdbeapi.c | 4 ++-- src/box/sql/vdbemem.c | 25 ++++++++++--------------- 5 files changed, 23 insertions(+), 28 deletions(-) diff --git a/src/box/sql/func.c b/src/box/sql/func.c index 4715ffabb..1856fe343 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -267,10 +267,10 @@ port_lua_get_vdbemem(struct port *base, uint32_t *size) mem_set_bool(&val[i], field.bval); break; case MP_FLOAT: - sqlVdbeMemSetDouble(&val[i], field.fval); + mem_set_double(&val[i], field.fval); break; case MP_DOUBLE: - sqlVdbeMemSetDouble(&val[i], field.dval); + mem_set_double(&val[i], field.dval); break; case MP_INT: mem_set_i64(&val[i], field.ival); @@ -338,10 +338,10 @@ port_c_get_vdbemem(struct port *base, uint32_t *size) mem_set_bool(&val[i], mp_decode_bool(&data)); break; case MP_FLOAT: - sqlVdbeMemSetDouble(&val[i], mp_decode_float(&data)); + mem_set_double(&val[i], mp_decode_float(&data)); break; case MP_DOUBLE: - sqlVdbeMemSetDouble(&val[i], mp_decode_double(&data)); + mem_set_double(&val[i], mp_decode_double(&data)); break; case MP_INT: mem_set_i64(&val[i], mp_decode_int(&data)); diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c index 6b769805c..950f72ddd 100644 --- a/src/box/sql/vdbe.c +++ b/src/box/sql/vdbe.c @@ -271,8 +271,7 @@ mem_apply_numeric_type(struct Mem *record) double float_value; if (sqlAtoF(record->z, &float_value, record->n) == 0) return -1; - record->u.r = float_value; - MemSetTypeFlag(record, MEM_Real); + mem_set_double(record, float_value); return 0; } @@ -1198,9 +1197,8 @@ case OP_Int64: { /* out2 */ */ case OP_Real: { /* same as TK_FLOAT, out2 */ pOut = vdbe_prepare_null_out(p, pOp->p2); - pOut->flags = MEM_Real; assert(!sqlIsNaN(*pOp->p4.pReal)); - pOut->u.r = *pOp->p4.pReal; + mem_set_double(pOut, *pOp->p4.pReal); break; } @@ -1673,8 +1671,7 @@ case OP_Remainder: { /* same as TK_REM, in1, in2, out3 */ if (sqlIsNaN(rB)) { goto arithmetic_result_is_null; } - pOut->u.r = rB; - MemSetTypeFlag(pOut, MEM_Real); + mem_set_double(pOut, rB); } break; diff --git a/src/box/sql/vdbeInt.h b/src/box/sql/vdbeInt.h index 2c50b6768..a3ecd13af 100644 --- a/src/box/sql/vdbeInt.h +++ b/src/box/sql/vdbeInt.h @@ -517,7 +517,10 @@ mem_set_u64(struct Mem *mem, uint64_t value); void mem_set_int(struct Mem *mem, int64_t value, bool is_neg); -void sqlVdbeMemSetDouble(Mem *, double); +/** Set double value and MEM_Real flag. */ +void +mem_set_double(struct Mem *mem, double value); + void sqlVdbeMemInit(Mem *, sql *, u32); void sqlVdbeMemSetNull(Mem *); void sqlVdbeMemSetZeroBlob(Mem *, int); diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c index 6e307e97f..4e103a653 100644 --- a/src/box/sql/vdbeapi.c +++ b/src/box/sql/vdbeapi.c @@ -330,7 +330,7 @@ sql_result_blob64(sql_context * pCtx, void sql_result_double(sql_context * pCtx, double rVal) { - sqlVdbeMemSetDouble(pCtx->pOut, rVal); + mem_set_double(pCtx->pOut, rVal); } void @@ -1021,7 +1021,7 @@ sql_bind_double(sql_stmt * pStmt, int i, double rValue) if (vdbeUnbind(p, i) != 0) return -1; int rc = sql_bind_type(p, i, "numeric"); - sqlVdbeMemSetDouble(&p->aVar[i - 1], rValue); + mem_set_double(&p->aVar[i - 1], rValue); return rc; } diff --git a/src/box/sql/vdbemem.c b/src/box/sql/vdbemem.c index 8dad2db9a..a721afc83 100644 --- a/src/box/sql/vdbemem.c +++ b/src/box/sql/vdbemem.c @@ -561,9 +561,7 @@ sqlVdbeMemRealify(Mem * pMem) double v; if (sqlVdbeRealValue(pMem, &v)) return -1; - - pMem->u.r = v; - MemSetTypeFlag(pMem, MEM_Real); + mem_set_double(pMem, v); return 0; } @@ -583,9 +581,10 @@ vdbe_mem_numerify(struct Mem *mem) if (sql_atoi64(mem->z, &i, &is_neg, mem->n) == 0) { mem_set_int(mem, i, is_neg); } else { - if (sqlAtoF(mem->z, &mem->u.r, mem->n) == 0) + double d; + if (sqlAtoF(mem->z, &d, mem->n) == 0) return -1; - MemSetTypeFlag(mem, MEM_Real); + mem_set_double(mem, d); } return 0; } @@ -839,18 +838,14 @@ mem_set_int(struct Mem *mem, int64_t value, bool is_neg) } } -/* - * Delete any previous value and set the value stored in *pMem to val, - * manifest type REAL. - */ void -sqlVdbeMemSetDouble(Mem * pMem, double val) +mem_set_double(struct Mem *mem, double value) { - sqlVdbeMemSetNull(pMem); - if (!sqlIsNaN(val)) { - pMem->u.r = val; - pMem->flags = MEM_Real; - } + sqlVdbeMemSetNull(mem); + if (sqlIsNaN(value)) + return; + mem->u.r = value; + MemSetTypeFlag(mem, MEM_Real); } /* -- 2.25.1
next prev parent reply other threads:[~2020-06-25 15:17 UTC|newest] Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-06-25 15:17 [Tarantool-patches] [PATCH v3 0/8] Remove implicit cast imeevma 2020-06-25 15:17 ` imeevma [this message] 2020-06-28 13:31 ` [Tarantool-patches] [PATCH v3 1/8] sql: introduce mem_set_double() Nikita Pettik 2020-07-06 14:02 ` Nikita Pettik 2020-06-25 15:17 ` [Tarantool-patches] [PATCH v3 2/8] sql: change implicit cast for assignment imeevma 2020-06-30 11:50 ` Nikita Pettik 2020-07-05 14:26 ` Mergen Imeev 2020-07-06 21:27 ` Nikita Pettik 2020-07-07 9:29 ` Mergen Imeev 2020-07-07 15:35 ` Nikita Pettik 2020-07-10 10:49 ` Nikita Pettik 2020-06-25 15:17 ` [Tarantool-patches] [PATCH v3 3/8] sql: remove mem_apply_type() from OP_MakeRecord imeevma 2020-06-25 15:17 ` [Tarantool-patches] [PATCH v3 4/8] sql: replace ApplyType by CheckType for IN operator imeevma 2020-06-29 12:56 ` Nikita Pettik 2020-07-05 14:28 ` Mergen Imeev 2020-07-06 22:06 ` Nikita Pettik 2020-07-07 11:26 ` Mergen Imeev 2020-07-07 16:29 ` Nikita Pettik 2020-06-25 15:17 ` [Tarantool-patches] [PATCH v3 5/8] sql: remove mem_apply_type() from OP_MustBeInt imeevma 2020-06-29 13:29 ` Nikita Pettik 2020-07-05 14:29 ` Mergen Imeev 2020-06-25 15:17 ` [Tarantool-patches] [PATCH v3 6/8] sql: remove implicit cast for comparison imeevma 2020-06-29 23:51 ` Nikita Pettik 2020-07-05 14:47 ` Mergen Imeev 2020-07-06 23:11 ` Nikita Pettik 2020-06-25 15:17 ` [Tarantool-patches] [PATCH v3 7/8] sql: remove unused functions imeevma 2020-06-29 23:52 ` Nikita Pettik 2020-07-05 14:50 ` Mergen Imeev 2020-06-25 15:17 ` [Tarantool-patches] [PATCH v3 8/8] sql: show value and its type in type mismatch error imeevma 2020-06-30 0:22 ` Nikita Pettik 2020-07-05 15:03 ` Mergen Imeev 2020-07-06 21:44 ` Nikita Pettik
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=908f67730f9ab461531d61a66fe2c885be77682e.1593096639.git.imeevma@gmail.com \ --to=imeevma@tarantool.org \ --cc=korablev@tarantool.org \ --cc=tarantool-patches@dev.tarantool.org \ --cc=tsafin@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH v3 1/8] sql: introduce mem_set_double()' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox