[Tarantool-patches] [PATCH v3 1/8] sql: introduce mem_set_double()
imeevma at tarantool.org
imeevma at tarantool.org
Thu Jun 25 18:17:20 MSK 2020
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
More information about the Tarantool-patches
mailing list