[Tarantool-patches] [PATCH v2 3/3] sql: replace MEM-type flags by enum mem_type
Vladislav Shpilevoy
v.shpilevoy at tarantool.org
Mon May 24 18:26:22 MSK 2021
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().
> 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.
> + 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.
> 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().
> pRec->aMem[i].db = db;
> }
> p->ppRec[0] = pRec;
More information about the Tarantool-patches
mailing list