[Tarantool-patches] [PATCH v4 26/53] sql: introduce mem_set_boolean()
imeevma at tarantool.org
imeevma at tarantool.org
Tue Mar 23 12:35:51 MSK 2021
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
More information about the Tarantool-patches
mailing list