[Tarantool-patches] [PATCH v5 31/52] sql: introduce mem_set_zerobin()
imeevma at tarantool.org
imeevma at tarantool.org
Fri Apr 9 23:05:27 MSK 2021
This patch introduces mem_set_zerobin() function. This function clears
MEM and sets it to binary value that consists of given number of zero
bytes.
Part of #5818
---
src/box/sql/mem.c | 29 +++++++++++++----------------
src/box/sql/mem.h | 8 ++++++--
src/box/sql/vdbeapi.c | 6 +++---
3 files changed, 22 insertions(+), 21 deletions(-)
diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c
index e30795de5..508b1dee3 100644
--- a/src/box/sql/mem.c
+++ b/src/box/sql/mem.c
@@ -507,6 +507,19 @@ mem_copy_bin(struct Mem *mem, const char *value, uint32_t size)
return 0;
}
+void
+mem_set_zerobin(struct Mem *mem, int n)
+{
+ mem_destroy(mem);
+ if (n < 0)
+ n = 0;
+ mem->u.nZero = n;
+ mem->z = NULL;
+ mem->n = 0;
+ mem->flags = MEM_Blob | MEM_Zero;
+ mem->field_type = FIELD_TYPE_VARBINARY;
+}
+
int
mem_copy(struct Mem *to, const struct Mem *from)
{
@@ -2256,22 +2269,6 @@ sqlVdbeMemSetStr(Mem * pMem, /* Memory cell to set to string value */
return 0;
}
-/*
- * Delete any previous value and set the value to be a BLOB of length
- * n containing all zeros.
- */
-void
-sqlVdbeMemSetZeroBlob(Mem * pMem, int n)
-{
- mem_destroy(pMem);
- pMem->flags = MEM_Blob | MEM_Zero;
- pMem->n = 0;
- if (n < 0)
- n = 0;
- pMem->u.nZero = n;
- pMem->z = 0;
-}
-
/*
* Free an sql_value object
*/
diff --git a/src/box/sql/mem.h b/src/box/sql/mem.h
index e17a722f4..0aeb23496 100644
--- a/src/box/sql/mem.h
+++ b/src/box/sql/mem.h
@@ -274,6 +274,12 @@ mem_set_bin_dynamic(struct Mem *mem, char *value, uint32_t size);
void
mem_set_bin_allocated(struct Mem *mem, char *value, uint32_t size);
+/**
+ * Clear MEM and set it to VARBINARY. The binary value consist of n zero bytes.
+ */
+void
+mem_set_zerobin(struct Mem *mem, int n);
+
/**
* Copy binary value to a newly allocated memory. The MEM type becomes
* VARBINARY.
@@ -560,8 +566,6 @@ mem_set_ptr(struct Mem *mem, void *ptr);
int
sqlVdbeMemSetStr(struct Mem *, const char *, int, u8, void (*)(void *));
-void
-sqlVdbeMemSetZeroBlob(struct Mem *, int);
void sqlValueFree(struct Mem *);
struct Mem *sqlValueNew(struct sql *);
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index d16b92cf6..6d9103ff2 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -266,7 +266,7 @@ sql_result_value(sql_context * pCtx, sql_value * pValue)
void
sql_result_zeroblob(sql_context * pCtx, int n)
{
- sqlVdbeMemSetZeroBlob(pCtx->pOut, n);
+ mem_set_zerobin(pCtx->pOut, n);
}
int
@@ -278,7 +278,7 @@ sql_result_zeroblob64(sql_context * pCtx, u64 n)
"is too big");
return -1;
}
- sqlVdbeMemSetZeroBlob(pCtx->pOut, (int)n);
+ mem_set_zerobin(pCtx->pOut, (int)n);
return 0;
}
@@ -956,7 +956,7 @@ sql_bind_zeroblob(sql_stmt * pStmt, int i, int n)
Vdbe *p = (Vdbe *) pStmt;
if (vdbeUnbind(p, i) != 0)
return -1;
- sqlVdbeMemSetZeroBlob(&p->aVar[i - 1], n);
+ mem_set_zerobin(&p->aVar[i - 1], n);
return 0;
}
--
2.25.1
More information about the Tarantool-patches
mailing list