[Tarantool-patches] [PATCH v2 3/3] sql: replace MEM-type flags by enum mem_type
Mergen Imeev
imeevma at tarantool.org
Tue May 25 14:13:13 MSK 2021
Hi! Thank you for the review! My answers and diff below.
On Mon, May 24, 2021 at 05:26:22PM +0200, Vladislav Shpilevoy wrote:
> Hi! Thanks for the fixes!
>
> See 4 new comments below, somehow I didn't notice them first time.
>
> > diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c
> > index b6ff6397f..1bd70c37f 100644
> > --- a/src/box/sql/mem.c
> > +++ b/src/box/sql/mem.c
> > @@ -1236,7 +1297,8 @@ mem_move(struct Mem *to, struct Mem *from)
> > {
> > mem_destroy(to);
> > memcpy(to, from, sizeof(*to));
> > - from->flags = MEM_Null;
> > + from->type = MEM_TYPE_NULL;
> > + from->flags = 0;
>
> 1. Flags are already 0 after mem_destroy().
>
No, mem_destroy() is called for MEM "to".
> > from->szMalloc = 0;
> > from->zMalloc = NULL;
> > }
> > @@ -1295,8 +1357,9 @@ mem_concat(struct Mem *a, struct Mem *b, struct Mem *result)
> > if (sqlVdbeMemGrow(result, size, result == a) != 0)
> > return -1;
> >
> > - result->flags = a->flags & (MEM_Str | MEM_Blob);
> > - if ((result->flags & MEM_Blob) != 0)
> > + result->type = a->type == MEM_TYPE_STR ? MEM_TYPE_STR : MEM_TYPE_BIN;
>
> 2. You could also make `result->type = a->type;`. Without `?:`. A->type
> is anyway either STR or BIN.
>
Fixed.
> > + result->flags = 0;
> > + if (result->type == MEM_TYPE_BIN)
> > result->field_type = FIELD_TYPE_VARBINARY;
> > if (result != a)
> > @@ -2322,12 +2395,13 @@ sql_vdbemem_finalize(struct Mem *mem, struct func *func)
> > assert(func != NULL);
> > assert(func->def->language == FUNC_LANGUAGE_SQL_BUILTIN);
> > assert(func->def->aggregate == FUNC_AGGREGATE_GROUP);
> > - assert((mem->flags & MEM_Null) != 0 || func == mem->u.func);
> > + assert(mem->type == MEM_TYPE_NULL || func == mem->u.func);
> > sql_context ctx;
> > memset(&ctx, 0, sizeof(ctx));
> > Mem t;
> > memset(&t, 0, sizeof(t));
> > - t.flags = MEM_Null;
> > + t.type = MEM_TYPE_NULL;
> > + t.flags = 0;
>
> 3. It is already 0 after memset() above.
>
Fixed.
> > t.db = mem->db;
> > t.field_type = field_type_MAX;
> > ctx.pOut = &t;
> > diff --git a/src/box/sql/vdbemem.c b/src/box/sql/vdbemem.c
> > index ba5c08a00..1aa201466 100644
> > --- a/src/box/sql/vdbemem.c
> > +++ b/src/box/sql/vdbemem.c
> > @@ -93,7 +93,8 @@ valueNew(sql * db, struct ValueNewStat4Ctx *p)
> > pRec->aMem = (Mem *)((char *) pRec +
> > ROUND8(sizeof(UnpackedRecord)));
> > for (uint32_t i = 0; i < part_count; i++) {
> > - pRec->aMem[i].flags = MEM_Null;
> > + pRec->aMem[i].type = MEM_NULL;
> > + pRec->aMem[i].flags = 0;
>
> 4. Flags are already 0 - the memory was allocated using sqlDbMallocZero().
>
Fixed.
> > pRec->aMem[i].db = db;
> > }
> > p->ppRec[0] = pRec;
>
Diff:
diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c
index 1bd70c37f..03fbffc7f 100644
--- a/src/box/sql/mem.c
+++ b/src/box/sql/mem.c
@@ -1357,7 +1357,7 @@ mem_concat(struct Mem *a, struct Mem *b, struct Mem *result)
if (sqlVdbeMemGrow(result, size, result == a) != 0)
return -1;
- result->type = a->type == MEM_TYPE_STR ? MEM_TYPE_STR : MEM_TYPE_BIN;
+ result->type = a->type;
result->flags = 0;
if (result->type == MEM_TYPE_BIN)
result->field_type = FIELD_TYPE_VARBINARY;
@@ -2401,7 +2401,7 @@ sql_vdbemem_finalize(struct Mem *mem, struct func *func)
Mem t;
memset(&t, 0, sizeof(t));
t.type = MEM_TYPE_NULL;
- t.flags = 0;
+ assert(t.flags == 0);
t.db = mem->db;
t.field_type = field_type_MAX;
ctx.pOut = &t;
diff --git a/src/box/sql/vdbemem.c b/src/box/sql/vdbemem.c
index 1aa201466..2c5099616 100644
--- a/src/box/sql/vdbemem.c
+++ b/src/box/sql/vdbemem.c
@@ -94,7 +94,7 @@ valueNew(sql * db, struct ValueNewStat4Ctx *p)
ROUND8(sizeof(UnpackedRecord)));
for (uint32_t i = 0; i < part_count; i++) {
pRec->aMem[i].type = MEM_NULL;
- pRec->aMem[i].flags = 0;
+ assert(pRec->aMem[i].flags == 0);
pRec->aMem[i].db = db;
}
p->ppRec[0] = pRec;
More information about the Tarantool-patches
mailing list