[Tarantool-patches] [PATCH v5 10/52] sql: introduce mem_create()
imeevma at tarantool.org
imeevma at tarantool.org
Fri Apr 9 19:59:55 MSK 2021
This patch introduces mem_create(). This function should be used to
initialize a MEM. MEM should be initialized before usage.
Part of #5818
---
src/box/sql/mem.c | 51 +++++++++++++++++--------------------------
src/box/sql/mem.h | 12 ++++------
src/box/sql/vdbe.c | 2 +-
src/box/sql/vdbeaux.c | 8 +++++--
4 files changed, 31 insertions(+), 42 deletions(-)
diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c
index a2a0fc33e..5135637d9 100644
--- a/src/box/sql/mem.c
+++ b/src/box/sql/mem.c
@@ -73,6 +73,25 @@ mem_str(const struct Mem *mem)
return "unknown";
}
+void
+mem_create(struct Mem *mem)
+{
+ mem->flags = MEM_Null;
+ mem->subtype = SQL_SUBTYPE_NO;
+ mem->field_type = field_type_MAX;
+ mem->n = 0;
+ mem->z = NULL;
+ mem->zMalloc = NULL;
+ mem->szMalloc = 0;
+ mem->uTemp = 0;
+ mem->db = sql_get();
+ mem->xDel = NULL;
+#ifdef SQL_DEBUG
+ mem->pScopyFrom = NULL;
+ mem->pFiller = NULL;
+#endif
+}
+
static inline bool
mem_has_msgpack_subtype(struct Mem *mem)
{
@@ -1299,21 +1318,6 @@ sqlVdbeMemSetStr(Mem * pMem, /* Memory cell to set to string value */
return 0;
}
-/*
- * Initialize bulk memory to be a consistent Mem object.
- *
- * The minimum amount of initialization feasible is performed.
- */
-void
-sqlVdbeMemInit(Mem * pMem, sql * db, u32 flags)
-{
- assert((flags & ~MEM_TypeMask) == 0);
- pMem->flags = flags;
- pMem->db = db;
- pMem->szMalloc = 0;
- pMem->field_type = field_type_MAX;
-}
-
/*
* Delete any previous value and set the value stored in *pMem to NULL.
*
@@ -1398,21 +1402,6 @@ sqlValueNew(sql * db)
return p;
}
-void
-initMemArray(Mem * p, int N, sql * db, u32 flags)
-{
- while ((N--) > 0) {
- p->db = db;
- p->flags = flags;
- p->szMalloc = 0;
- p->field_type = field_type_MAX;
-#ifdef SQL_DEBUG
- p->pScopyFrom = 0;
-#endif
- p++;
- }
-}
-
void
releaseMemArray(Mem * p, int N)
{
@@ -2373,7 +2362,7 @@ vdbemem_alloc_on_region(uint32_t count)
}
memset(ret, 0, count * sizeof(*ret));
for (uint32_t i = 0; i < count; i++) {
- sqlVdbeMemInit(&ret[i], sql_get(), MEM_Null);
+ mem_create(&ret[i]);
assert(memIsValid(&ret[i]));
}
return ret;
diff --git a/src/box/sql/mem.h b/src/box/sql/mem.h
index 7b9456426..2a3d1078e 100644
--- a/src/box/sql/mem.h
+++ b/src/box/sql/mem.h
@@ -94,6 +94,10 @@ struct Mem {
const char *
mem_str(const struct Mem *mem);
+/** Initialize MEM and set NULL. */
+void
+mem_create(struct Mem *mem);
+
/* One or more of the following flags are set to indicate the validOK
* representations of the value stored in the Mem struct.
*
@@ -304,8 +308,6 @@ mem_set_double(struct Mem *mem, double value);
int
sqlVdbeMemSetStr(struct Mem *, const char *, int, u8, void (*)(void *));
void
-sqlVdbeMemInit(struct Mem *, sql *, u32);
-void
sqlVdbeMemSetNull(struct Mem *);
void
sqlVdbeMemSetZeroBlob(struct Mem *, int);
@@ -315,12 +317,6 @@ void sqlValueSetNull(struct Mem *);
void sqlValueFree(struct Mem *);
struct Mem *sqlValueNew(struct sql *);
-/*
- * Initialize an array of N Mem element.
- */
-void
-initMemArray(Mem * p, int N, sql * db, u32 flags);
-
/*
* Release an array of N Mem elements
*/
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index ec3d23cb2..74bf7f903 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -4739,7 +4739,7 @@ case OP_AggStep: {
#endif
pMem->n++;
- sqlVdbeMemInit(&t, db, MEM_Null);
+ mem_create(&t);
pCtx->pOut = &t;
pCtx->is_aborted = false;
pCtx->skipFlag = 0;
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index b7e148422..850158572 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -1589,9 +1589,13 @@ sqlVdbeMakeReady(Vdbe * p, /* The VDBE */
} else {
p->nCursor = nCursor;
p->nVar = (ynVar) nVar;
- initMemArray(p->aVar, nVar, db, MEM_Null);
+ for (int i = 0; i < nVar; ++i)
+ mem_create(&p->aVar[i]);
p->nMem = nMem;
- initMemArray(p->aMem, nMem, db, MEM_Undefined);
+ for (int i = 0; i < nMem; ++i) {
+ mem_create(&p->aMem[i]);
+ p->aMem[i].flags = MEM_Undefined;
+ }
memset(p->apCsr, 0, nCursor * sizeof(VdbeCursor *));
}
sqlVdbeRewind(p);
--
2.25.1
More information about the Tarantool-patches
mailing list