Tarantool development patches archive
 help / color / mirror / Atom feed
From: Mergen Imeev via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH v2 3/3] sql: replace MEM-type flags by enum mem_type
Date: Tue, 25 May 2021 14:13:13 +0300	[thread overview]
Message-ID: <20210525111313.GA35119@tarantool.org> (raw)
In-Reply-To: <ec5eb5b4-cd38-1db0-368b-aff3cbb7df67@tarantool.org>

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;

  reply	other threads:[~2021-05-25 11:13 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-27 16:55 [Tarantool-patches] [PATCH v2 0/3] Replace " Mergen Imeev via Tarantool-patches
2021-04-27 16:55 ` [Tarantool-patches] [PATCH v2 3/3] sql: replace " Mergen Imeev via Tarantool-patches
2021-04-29 21:09   ` Vladislav Shpilevoy via Tarantool-patches
2021-05-17 12:18     ` Mergen Imeev via Tarantool-patches
2021-05-17 12:34       ` Mergen Imeev via Tarantool-patches
2021-05-21 18:59       ` Vladislav Shpilevoy via Tarantool-patches
2021-05-24 10:56         ` Mergen Imeev via Tarantool-patches
2021-05-24 15:26           ` Vladislav Shpilevoy via Tarantool-patches
2021-05-25 11:13             ` Mergen Imeev via Tarantool-patches [this message]
2021-05-25 21:33 ` [Tarantool-patches] [PATCH v2 0/3] Replace " Vladislav Shpilevoy via Tarantool-patches
2021-05-26  8:06 ` Kirill Yukhin via Tarantool-patches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210525111313.GA35119@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=imeevma@tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v2 3/3] sql: replace MEM-type flags by enum mem_type' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox