[Tarantool-patches] [PATCH v1 05/13] sql: remove sql_vdbemem_finalize()

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Wed Sep 15 00:23:15 MSK 2021


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));
> +


More information about the Tarantool-patches mailing list