[Tarantool-patches] [PATCH v4 32/53] sql: introduce mem_set_zerobinary()

imeevma at tarantool.org imeevma at tarantool.org
Tue Mar 23 12:36:04 MSK 2021


This patch introduces mem_set_zerobinary() function. Function
mem_set_zerobinary() 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     |  5 +++--
 src/box/sql/vdbeapi.c |  6 +++---
 3 files changed, 19 insertions(+), 21 deletions(-)

diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c
index 99beec9ad..63a4d0d3c 100644
--- a/src/box/sql/mem.c
+++ b/src/box/sql/mem.c
@@ -479,6 +479,19 @@ mem_copy_binary(struct Mem *mem, const char *value, uint32_t size)
 	return 0;
 }
 
+void
+mem_set_zerobinary(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)
 {
@@ -2201,22 +2214,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 f44bb9bcf..4b34bba6c 100644
--- a/src/box/sql/mem.h
+++ b/src/box/sql/mem.h
@@ -229,6 +229,9 @@ mem_set_dynamic_binary(struct Mem *mem, char *value, uint32_t size);
 void
 mem_set_allocated_binary(struct Mem *mem, char *value, uint32_t size);
 
+void
+mem_set_zerobinary(struct Mem *mem, int n);
+
 int
 mem_copy_binary(struct Mem *mem, const char *value, uint32_t size);
 
@@ -469,8 +472,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 299172554..d6d6e54f5 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_zerobinary(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_zerobinary(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_zerobinary(&p->aVar[i - 1], n);
 	return 0;
 }
 
-- 
2.25.1



More information about the Tarantool-patches mailing list