[Tarantool-patches] [PATCH v4 39/53] sql: introduce mem_set_cleared()

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


This patch introduces mem_set_cleared() function. Function
mem_set_cleared() sets a NULL to MEM, however this NULL should be used
only in internal VDBE operations.

Part of #5818
---
 src/box/sql/mem.c  | 7 +++++++
 src/box/sql/mem.h  | 3 +++
 src/box/sql/vdbe.c | 9 +++++----
 3 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c
index 0211069c6..83f17250d 100644
--- a/src/box/sql/mem.c
+++ b/src/box/sql/mem.c
@@ -636,6 +636,13 @@ mem_get_aggregate(struct Mem *mem)
 	return (void *)mem->z;
 }
 
+void
+mem_set_cleared(struct Mem *mem)
+{
+	mem_clear(mem);
+	mem->flags = MEM_Null | MEM_Cleared;
+}
+
 int
 mem_copy(struct Mem *to, const struct Mem *from)
 {
diff --git a/src/box/sql/mem.h b/src/box/sql/mem.h
index 51802b450..70224b55a 100644
--- a/src/box/sql/mem.h
+++ b/src/box/sql/mem.h
@@ -277,6 +277,9 @@ mem_prepare_aggregate(struct Mem *mem, struct func *func, int size);
 void *
 mem_get_aggregate(struct Mem *mem);
 
+void
+mem_set_cleared(struct Mem *mem);
+
 int
 mem_copy(struct Mem *to, const struct Mem *from);
 
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index b01b8d760..fdcb4d1e6 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -823,7 +823,7 @@ case OP_String: {          /* out2 */
  * is less than P2 (typically P3 is zero) then only register P2 is
  * set to NULL.
  *
- * If the P1 value is non-zero, then also set the MEM_Cleared flag so that
+ * If the P1 value is non-zero, then also set the Cleared flag so that
  * NULL values will not compare equal even if SQL_NULLEQ is set on
  * OP_Ne or OP_Eq.
  */
@@ -833,13 +833,14 @@ case OP_Null: {           /* out2 */
 	cnt = pOp->p3-pOp->p2;
 	assert(pOp->p3<=(p->nMem+1 - p->nCursor));
 	if (pOp->p1 != 0)
-		pOut->flags = MEM_Null|MEM_Cleared;
+		mem_set_cleared(pOut);
 	while( cnt>0) {
 		pOut++;
 		memAboutToChange(p, pOut);
-		mem_set_null(pOut);
 		if (pOp->p1 != 0)
-			pOut->flags = MEM_Null|MEM_Cleared;
+			mem_set_cleared(pOut);
+		else
+			mem_set_null(pOut);
 		cnt--;
 	}
 	break;
-- 
2.25.1



More information about the Tarantool-patches mailing list