Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: imeevma@tarantool.org
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH v1 05/13] sql: remove sql_vdbemem_finalize()
Date: Tue, 14 Sep 2021 23:23:15 +0200	[thread overview]
Message-ID: <d6653f88-d205-2868-e989-3b1dc4822a7c@tarantool.org> (raw)
In-Reply-To: <91914a74a5efe636fab891ceee5bf1fba5678948.1631289462.git.imeevma@gmail.com>

Good job on the patch!

> diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
> index 12dc9126b..dfab86c50 100644
> --- a/src/box/sql/vdbe.c
> +++ b/src/box/sql/vdbe.c
> @@ -4204,16 +4204,32 @@ case OP_AggStep: {
>   * the step function was not previously called.
>   */
>  case OP_AggFinal: {
> -	Mem *pMem;
>  	assert(pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor));
> -	pMem = &aMem[pOp->p1];
> -	assert(mem_is_null(pMem) || mem_is_agg(pMem));
> -	if (sql_vdbemem_finalize(pMem, pOp->p4.func) != 0)
> +	struct func_sql_builtin *func = (struct func_sql_builtin *)pOp->p4.func;
> +	struct Mem *pIn1 = &aMem[pOp->p1];
> +	assert(mem_is_null(pIn1) || mem_is_agg(pIn1));
> +
> +	struct sql_context ctx;
> +	memset(&ctx, 0, sizeof(ctx));
> +	struct Mem t;

Please, use mem_create(). Also for the context I would propose to add
sql_context_create(). So as not to touch internals of the struct here
directly.

> +	memset(&t, 0, sizeof(t));
> +	t.type = MEM_TYPE_NULL;
> +	assert(t.flags == 0);
> +	t.db = pIn1->db;
> +	ctx.pOut = &t;
> +	ctx.pMem = pIn1;
> +	ctx.func = pOp->p4.func;
> +	func->finalize(&ctx);
> +	assert((pIn1->flags & MEM_Dyn) == 0);
> +	if (pIn1->szMalloc > 0)
> +		sqlDbFree(pIn1->db, pIn1->zMalloc);
> +	memcpy(pIn1, &t, sizeof(t));
> +

  reply	other threads:[~2021-09-14 21:23 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-10 16:01 [Tarantool-patches] [PATCH v1 00/13] sql: reworks aggregate functions Mergen Imeev via Tarantool-patches
2021-09-10 16:01 ` [Tarantool-patches] [PATCH v1 01/13] sql: use register P1 for number of arguments Mergen Imeev via Tarantool-patches
2021-09-10 16:01 ` [Tarantool-patches] [PATCH v1 02/13] sql: remove AggStep0 and OP_BuiltinFunction0 Mergen Imeev via Tarantool-patches
2021-09-10 16:27   ` Mergen Imeev via Tarantool-patches
2021-09-14 21:21   ` Vladislav Shpilevoy via Tarantool-patches
2021-09-10 16:01 ` [Tarantool-patches] [PATCH v1 03/13] sql: move collation to struct sql_context Mergen Imeev via Tarantool-patches
2021-09-14 21:22   ` Vladislav Shpilevoy via Tarantool-patches
2021-09-21 10:40     ` Mergen Imeev via Tarantool-patches
2021-09-10 16:02 ` [Tarantool-patches] [PATCH v1 04/13] sql: introduce mem_append() Mergen Imeev via Tarantool-patches
2021-09-10 16:02 ` [Tarantool-patches] [PATCH v1 05/13] sql: remove sql_vdbemem_finalize() Mergen Imeev via Tarantool-patches
2021-09-14 21:23   ` Vladislav Shpilevoy via Tarantool-patches [this message]
2021-09-21 10:47     ` Mergen Imeev via Tarantool-patches
2021-09-22 22:47       ` Vladislav Shpilevoy via Tarantool-patches
2021-09-10 16:02 ` [Tarantool-patches] [PATCH v1 06/13] sql: rework SUM() Mergen Imeev via Tarantool-patches
2021-09-10 16:02 ` [Tarantool-patches] [PATCH v1 07/13] sql: rework TOTAL() Mergen Imeev via Tarantool-patches
2021-09-10 16:02 ` [Tarantool-patches] [PATCH v1 08/13] sql: rework AVG() Mergen Imeev via Tarantool-patches
2021-09-14 21:24   ` Vladislav Shpilevoy via Tarantool-patches
2021-09-10 16:02 ` [Tarantool-patches] [PATCH v1 09/13] sql: rework COUNT() Mergen Imeev via Tarantool-patches
2021-09-10 16:02 ` [Tarantool-patches] [PATCH v1 10/13] sql: rework MIN() and MAX() Mergen Imeev via Tarantool-patches
2021-09-10 16:02 ` [Tarantool-patches] [PATCH v1 11/13] sql: rework GROUP_CONCAT() Mergen Imeev via Tarantool-patches
2021-09-10 16:02 ` [Tarantool-patches] [PATCH v1 12/13] sql: remove copying of result in finalizers Mergen Imeev via Tarantool-patches
2021-09-14 21:24   ` Vladislav Shpilevoy via Tarantool-patches
2021-09-21 10:49     ` Mergen Imeev via Tarantool-patches
2021-09-10 16:02 ` [Tarantool-patches] [PATCH v1 13/13] sql: remove MEM_TYPE_AGG Mergen Imeev 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=d6653f88-d205-2868-e989-3b1dc4822a7c@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=imeevma@tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v1 05/13] sql: remove sql_vdbemem_finalize()' \
    /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