[Tarantool-patches] [PATCH v4 35/53] sql: introduce mem_set_undefined()

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


This patch introduces mem_set_undefined() function. Function
mem_set_undefined() invalidates MEM. It does not clears MEM prior to
invalidating it.

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

diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c
index 583de00a2..fd2710478 100644
--- a/src/box/sql/mem.c
+++ b/src/box/sql/mem.c
@@ -588,6 +588,13 @@ mem_set_allocated_array(struct Mem *mem, char *value, uint32_t size)
 	mem->field_type = FIELD_TYPE_ARRAY;
 }
 
+void
+mem_set_undefined(struct Mem *mem)
+{
+	mem->flags = MEM_Undefined;
+	mem->field_type = field_type_MAX;
+}
+
 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 b94495f89..75486ba3a 100644
--- a/src/box/sql/mem.h
+++ b/src/box/sql/mem.h
@@ -262,6 +262,9 @@ mem_set_dynamic_array(struct Mem *mem, char *value, uint32_t size);
 void
 mem_set_allocated_array(struct Mem *mem, char *value, uint32_t size);
 
+void
+mem_set_undefined(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 c91aeede3..f899dfe7a 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -597,7 +597,7 @@ case OP_Return: {           /* in1 */
 	pIn1 = &aMem[pOp->p1];
 	assert(mem_is_unsigned(pIn1));
 	pOp = &aOp[pIn1->u.u];
-	pIn1->flags = MEM_Undefined;
+	mem_set_undefined(pIn1);
 	break;
 }
 
@@ -640,7 +640,7 @@ case OP_EndCoroutine: {           /* in1 */
 	assert(pCaller->opcode==OP_Yield);
 	assert(pCaller->p2>=0 && pCaller->p2<p->nOp);
 	pOp = &aOp[pCaller->p2 - 1];
-	pIn1->flags = MEM_Undefined;
+	mem_set_undefined(pIn1);
 	break;
 }
 
@@ -4091,8 +4091,8 @@ case OP_Program: {        /* jump */
 
 		pEnd = &VdbeFrameMem(pFrame)[pFrame->nChildMem];
 		for(pMem=VdbeFrameMem(pFrame); pMem!=pEnd; pMem++) {
-			pMem->flags = MEM_Undefined;
-			pMem->db = db;
+			mem_create(pMem);
+			mem_set_undefined(pMem);
 		}
 	} else {
 		pFrame = pRt->u.pFrame;
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index 2e8669138..ccabf6035 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -1568,7 +1568,7 @@ sqlVdbeMakeReady(Vdbe * p,	/* The VDBE */
 		p->nMem = nMem;
 		for (int i = 0; i < nMem; ++i) {
 			mem_create(&p->aMem[i]);
-			p->aMem[i].flags = MEM_Undefined;
+			mem_set_undefined(&p->aMem[i]);
 		}
 		memset(p->apCsr, 0, nCursor * sizeof(VdbeCursor *));
 	}
-- 
2.25.1



More information about the Tarantool-patches mailing list