[Tarantool-patches] [PATCH v4 36/53] sql: introduce mem_set_pointer()
imeevma at tarantool.org
imeevma at tarantool.org
Tue Mar 23 12:36:11 MSK 2021
This patch introduces mem_set_pointer() function. Function
mem_set_pointer() sets a pointer to MEM. This pointer used for internal
VDBE operations.
Part of #5818
---
src/box/sql/mem.c | 17 +++++++++--------
src/box/sql/mem.h | 11 +++--------
src/box/sql/vdbe.c | 3 +--
src/box/sql/vdbeapi.c | 2 +-
4 files changed, 14 insertions(+), 19 deletions(-)
diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c
index fd2710478..3701741ef 100644
--- a/src/box/sql/mem.c
+++ b/src/box/sql/mem.c
@@ -595,6 +595,15 @@ mem_set_undefined(struct Mem *mem)
mem->field_type = field_type_MAX;
}
+void
+mem_set_pointer(struct Mem *mem, void *ptr)
+{
+ mem_clear(mem);
+ mem->flags = MEM_Ptr;
+ mem->u.p = ptr;
+ mem->field_type = field_type_MAX;
+}
+
int
mem_copy(struct Mem *to, const struct Mem *from)
{
@@ -2213,14 +2222,6 @@ sqlVdbeMemClearAndResize(Mem * pMem, int szNew)
return 0;
}
-void
-mem_set_ptr(struct Mem *mem, void *ptr)
-{
- mem_destroy(mem);
- mem->flags = MEM_Ptr;
- mem->u.p = ptr;
-}
-
/*
* Free an sql_value object
*/
diff --git a/src/box/sql/mem.h b/src/box/sql/mem.h
index 75486ba3a..9fec6ed8a 100644
--- a/src/box/sql/mem.h
+++ b/src/box/sql/mem.h
@@ -265,6 +265,9 @@ mem_set_allocated_array(struct Mem *mem, char *value, uint32_t size);
void
mem_set_undefined(struct Mem *mem);
+void
+mem_set_pointer(struct Mem *mem, void *ptr);
+
int
mem_copy(struct Mem *to, const struct Mem *from);
@@ -492,14 +495,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);
-/**
- * Set VDBE memory register with given pointer as a data.
- * @param mem VDBE memory register to update.
- * @param ptr Pointer to use.
- */
-void
-mem_set_ptr(struct Mem *mem, void *ptr);
-
void sqlValueFree(struct Mem *);
struct Mem *sqlValueNew(struct sql *);
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index f899dfe7a..b9c2142e8 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -2394,8 +2394,7 @@ case OP_OpenTEphemeral: {
if (space == NULL)
goto abort_due_to_error;
- aMem[pOp->p1].u.p = space;
- aMem[pOp->p1].flags = MEM_Ptr;
+ mem_set_pointer(&aMem[pOp->p1], space);
break;
}
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index d6d6e54f5..3ad89b87c 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -930,7 +930,7 @@ sql_bind_ptr(struct sql_stmt *stmt, int i, void *ptr)
int rc = vdbeUnbind(p, i);
if (rc == 0) {
rc = sql_bind_type(p, i, "varbinary");
- mem_set_ptr(&p->aVar[i - 1], ptr);
+ mem_set_pointer(&p->aVar[i - 1], ptr);
}
return rc;
}
--
2.25.1
More information about the Tarantool-patches
mailing list