From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 46EA974144; Fri, 1 Oct 2021 15:52:02 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 46EA974144 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1633092722; bh=fPCvgU+tpALCiYnm6ZbrjOPvW3izFavgKagBTVvt3VA=; h=To:Cc:Date:In-Reply-To:References:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=oQDRDO6Y47ze3QpOl9VIFa8/GeTppqSzXFgkWpEG+hislo52AzGGXmlkKPe29kWBp d5ve0GN8GBa/SubmJgWUXQ7k2YB8CZH5W7Kg2qtCzbRtLd1oyttUU98g7xO2KDkv1m yNc47oXX09e3uOuIvbihaaQeoa2WCnw6F1rkQB/U= Received: from smtpng1.i.mail.ru (smtpng1.i.mail.ru [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 7A32B74146 for ; Fri, 1 Oct 2021 15:48:44 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 7A32B74146 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1mWHxz-0003w3-Fx; Fri, 01 Oct 2021 15:48:44 +0300 To: v.shpilevoy@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Fri, 1 Oct 2021 15:48:43 +0300 Message-Id: <1642a14989ce8e691a0665a7baf43243cf93d009.1633092363.git.imeevma@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-4EC0790: 10 X-7564579A: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD96A58C36AA2E99649BF631F26B0465AFD0E15652C7D51B98D182A05F538085040C7B816B4BC287080004DB46DA5C8E4ABE26766559FF4E7B52844BC5C7AD2140C X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7D4EF26BAC91EEE7FEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637013F392EFFCDE01C8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D882CB28DC373D2AD0B24B8B0B2877171C117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC60CDF180582EB8FBA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F4460429728776938767073520140C956E756FBB7A2CC0D3CB04F14752D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B66F6A3E018CF4DC80089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CBBB17C150BCA6793E506BAF1CD9F69E8967755636BCB13049C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF783E2B6F79C23BED699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D343F22CE0A71FDB37ED851D240128910120711CB67DAA4CFFB93DEE3315E4161F6626B6FF52C80AA751D7E09C32AA3244CE90EB718A986F3F073ED91FE626A9F31F26BFA4C8A6946B8729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojJNmX3owDPmFkIfuouH7IBw== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D33E7768B31B191265755C0921FDA168183D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v4 07/16] sql: remove sql_vdbemem_finalize() X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Mergen Imeev via Tarantool-patches Reply-To: imeevma@tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" We don't need this function, since it is easier to call finalizers directly. This patch also allows us to make further simplifications. Needed for #4145 --- src/box/sql/mem.c | 33 ++------------------------------- src/box/sql/mem.h | 12 ------------ src/box/sql/vdbe.c | 27 ++++++++++++++++++++------- 3 files changed, 22 insertions(+), 50 deletions(-) diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c index b8ead8f41..853f9efe9 100644 --- a/src/box/sql/mem.c +++ b/src/box/sql/mem.c @@ -217,15 +217,11 @@ mem_create(struct Mem *mem) static inline void mem_clear(struct Mem *mem) { - if ((mem->type & (MEM_TYPE_AGG | MEM_TYPE_FRAME)) != 0 || - (mem->flags & MEM_Dyn) != 0) { - if (mem->type == MEM_TYPE_AGG) - sql_vdbemem_finalize(mem, mem->u.func); - assert(mem->type != MEM_TYPE_AGG); + if (mem->type == MEM_TYPE_FRAME || (mem->flags & MEM_Dyn) != 0) { if ((mem->flags & MEM_Dyn) != 0) { assert(mem->xDel != SQL_DYNAMIC && mem->xDel != NULL); mem->xDel((void *)mem->z); - } else if (mem->type == MEM_TYPE_FRAME) { + } else { struct VdbeFrame *frame = mem->u.pFrame; frame->pParent = frame->v->pDelFrame; frame->v->pDelFrame = frame; @@ -2972,31 +2968,6 @@ sqlVdbeMemTooBig(Mem * p) return 0; } -int -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->type == MEM_TYPE_NULL || func == mem->u.func); - sql_context ctx; - memset(&ctx, 0, sizeof(ctx)); - Mem t; - memset(&t, 0, sizeof(t)); - t.type = MEM_TYPE_NULL; - assert(t.flags == 0); - t.db = mem->db; - ctx.pOut = &t; - ctx.pMem = mem; - ctx.func = func; - ((struct func_sql_builtin *)func)->finalize(&ctx); - assert((mem->flags & MEM_Dyn) == 0); - if (mem->szMalloc > 0) - sqlDbFree(mem->db, mem->zMalloc); - memcpy(mem, &t, sizeof(t)); - return ctx.is_aborted ? -1 : 0; -} - int sqlVdbeRecordCompareMsgpack(const void *key1, struct UnpackedRecord *key2) diff --git a/src/box/sql/mem.h b/src/box/sql/mem.h index b567aea50..7d5a750f5 100644 --- a/src/box/sql/mem.h +++ b/src/box/sql/mem.h @@ -949,18 +949,6 @@ int sqlVdbeMemTooBig(Mem *); #define VdbeMemDynamic(X) (((X)->flags & MEM_Dyn) != 0 ||\ ((X)->type & (MEM_TYPE_AGG | MEM_TYPE_FRAME)) != 0) -/** MEM manipulate functions. */ - -/** - * Memory cell mem contains the context of an aggregate function. - * This routine calls the finalize method for that function. The - * result of the aggregate is stored back into mem. - * - * Returns -1 if the finalizer reports an error. 0 otherwise. - */ -int -sql_vdbemem_finalize(struct Mem *mem, struct func *func); - /** * Perform comparison of two tuples: unpacked (key1) and packed (key2) * diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c index 7f1965492..067065a97 100644 --- a/src/box/sql/vdbe.c +++ b/src/box/sql/vdbe.c @@ -4196,16 +4196,29 @@ 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; + mem_create(&t); + 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)); + + if (ctx.is_aborted) goto abort_due_to_error; - UPDATE_MAX_BLOBSIZE(pMem); - if (sqlVdbeMemTooBig(pMem)) { + UPDATE_MAX_BLOBSIZE(pIn1); + if (sqlVdbeMemTooBig(pIn1) != 0) goto too_big; - } break; } -- 2.25.1