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

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Thu Sep 23 01:47:02 MSK 2021


Thanks for the fixes!

>>> 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.
>>
> I suggest to leave it as it is for now, since I plan to completely drop
> struct sql_context from finalize functions in a few patches in this patch-set.
> What do you think?

mem_create() would be just -3 and +1 line in the patch. I suggest to
use it. Previously memset was tolerated because it was done in mem.c,
where it is allowed to touch Mem internals 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