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 E35046DB05; Fri, 1 Oct 2021 10:45:48 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org E35046DB05 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1633074349; bh=LsPW+fqboE3hVjNWH2WwUTmxL7Wgvo8jLN1oeS+sUR0=; 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=tDGY85Jry7oxEptAp+VzxCwUIU1vyrNS3HEViVFGFn8CB/hW8iOu793DeCrKsi/iQ sU0u8WRFt3SDNEZmNypDdfHqMllVMsvObYjM0ZZGNl4TaUAykZnLKTSBDIwyggOFNH zqJOHcPpqDpf7Ok2NwcpujtsgF+y3xp2xkzcUP5w= 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 880386DB05 for ; Fri, 1 Oct 2021 10:42:57 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 880386DB05 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1mWDC4-0004X4-Ld; Fri, 01 Oct 2021 10:42:57 +0300 To: v.shpilevoy@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Fri, 1 Oct 2021 10:42:56 +0300 Message-Id: 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: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD96A58C36AA2E9964976B67DC8394C8DAB0EDC1900E6C7EF8D182A05F538085040551F0DFA7094ABD8F313AFBB44F2AD07A85AA7B8496124A5DF52A68A2748E099 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE755C0FA95D075C150EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063794BAA5DA89D799D78638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D818C8D642F21FF5165D4131B1A3217AAC117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAE9A1BBD95851C5BA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F4460429728776938767073520140C956E756FBB7A2CC0D3CB04F14752D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B6300D3B61E77C8D3B089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CBBB17C150BCA6793E26E5BF12374C60406D0704390735C729C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF783E2B6F79C23BED699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34023CA4E4726A7D6C996532B9E9CCC41D461075AD5A2977A97B7C39F211F1B642D710111436761FFB1D7E09C32AA3244C6C4845C859D80F8CF68CA26BA54EEF59D9ADFF0C0BDB8D1F729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojJNmX3owDPmF0tqdm9Q3IBA== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D5A2A90002A02F8BEED1C8BC99352AA3783D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v3 06/15] 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 f64cbe10a..e59935672 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; @@ -3067,31 +3063,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 54a1e931b..c0993e573 100644 --- a/src/box/sql/mem.h +++ b/src/box/sql/mem.h @@ -969,18 +969,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 12dc9126b..b101fc6c2 100644 --- a/src/box/sql/vdbe.c +++ b/src/box/sql/vdbe.c @@ -4204,16 +4204,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