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 035E56EC5D; Fri, 9 Apr 2021 20:01:50 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 035E56EC5D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1617987710; bh=FUGlQJF/T/Kt8fi4IM5dbA9nyC4M8a3xw30MruBHAGM=; 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=jt3ZRPPfHIQxAVpwjfAHix3NSL9GlUhb/qvP0sd067xyTkEmeLDuJ9HuG6Ppw9LHw W3khSSKElXf4AeLVuL/ZmHJlCd6nMlEct94kPiiqMCKra+RMlB2i3SxOZ0p7Hbja1L pJtCrWHE64iRJ//5l5rvtZwhWC5HKyvyzudJLmJ8= Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [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 E5EED6EC61 for ; Fri, 9 Apr 2021 19:59:56 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org E5EED6EC61 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1lUuU8-0000Q2-7j; Fri, 09 Apr 2021 19:59:56 +0300 To: v.shpilevoy@tarantool.org, tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Fri, 9 Apr 2021 19:59:55 +0300 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD92FFCB8E6708E7480257C85EA0BB7A95D5E28B957962BB550182A05F538085040723D1AC3F2A4B0A5C6D5D9A36B4E62F38806DDF29DAF6A454024FA237F112FD0 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE79A2E61952DECAF71EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637B12C6B1582157D838638F802B75D45FF914D58D5BE9E6BC1A93B80C6DEB9DEE97C6FB206A91F05B2307CA4DF388D5309B238DFF694630AB8C7C2BEF539CC105AD2E47CDBA5A96583C09775C1D3CA48CF53FA85A707D24CADCC7F00164DA146DAFE8445B8C89999729449624AB7ADAF37F6B57BC7E64490611E7FA7ABCAF51C92176DF2183F8FC7C058C1844A7A85E7B68941B15DA834481F9449624AB7ADAF372E808ACE2090B5E1725E5C173C3A84C3C5EA940A35A165FF2DBA43225CD8A89FC0F9454058DFE53C35872C767BF85DA2F004C90652538430E4A6367B16DE6309 X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A2AD77751E876CB595E8F7B195E1C97831459719E9672C0D0A55037634962608ED X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CD0035DD76F8A8A4F2C9C1B5870C8BECC3A4094C7879ABC729C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF0417BEADF48D1460699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D349C39CCCDAABCB54B538825DB9FA4DE28FA52259716DCB7A161A5B7A90A23EDF977647905C091E96A1D7E09C32AA3244CD3AFBB3FC39B4981B2BA8998D644A13B1E098CBE561D6343FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojyO2lHpuZu4S0oskkbxPxUQ== X-Mailru-Sender: 689FA8AB762F73936BC43F508A063822D0A7F64EE0C9872217C366B1173BEFF183D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v5 10/52] sql: introduce mem_create() 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" This patch introduces mem_create(). This function should be used to initialize a MEM. MEM should be initialized before usage. Part of #5818 --- src/box/sql/mem.c | 51 +++++++++++++++++-------------------------- src/box/sql/mem.h | 12 ++++------ src/box/sql/vdbe.c | 2 +- src/box/sql/vdbeaux.c | 8 +++++-- 4 files changed, 31 insertions(+), 42 deletions(-) diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c index a2a0fc33e..5135637d9 100644 --- a/src/box/sql/mem.c +++ b/src/box/sql/mem.c @@ -73,6 +73,25 @@ mem_str(const struct Mem *mem) return "unknown"; } +void +mem_create(struct Mem *mem) +{ + mem->flags = MEM_Null; + mem->subtype = SQL_SUBTYPE_NO; + mem->field_type = field_type_MAX; + mem->n = 0; + mem->z = NULL; + mem->zMalloc = NULL; + mem->szMalloc = 0; + mem->uTemp = 0; + mem->db = sql_get(); + mem->xDel = NULL; +#ifdef SQL_DEBUG + mem->pScopyFrom = NULL; + mem->pFiller = NULL; +#endif +} + static inline bool mem_has_msgpack_subtype(struct Mem *mem) { @@ -1299,21 +1318,6 @@ sqlVdbeMemSetStr(Mem * pMem, /* Memory cell to set to string value */ return 0; } -/* - * Initialize bulk memory to be a consistent Mem object. - * - * The minimum amount of initialization feasible is performed. - */ -void -sqlVdbeMemInit(Mem * pMem, sql * db, u32 flags) -{ - assert((flags & ~MEM_TypeMask) == 0); - pMem->flags = flags; - pMem->db = db; - pMem->szMalloc = 0; - pMem->field_type = field_type_MAX; -} - /* * Delete any previous value and set the value stored in *pMem to NULL. * @@ -1398,21 +1402,6 @@ sqlValueNew(sql * db) return p; } -void -initMemArray(Mem * p, int N, sql * db, u32 flags) -{ - while ((N--) > 0) { - p->db = db; - p->flags = flags; - p->szMalloc = 0; - p->field_type = field_type_MAX; -#ifdef SQL_DEBUG - p->pScopyFrom = 0; -#endif - p++; - } -} - void releaseMemArray(Mem * p, int N) { @@ -2373,7 +2362,7 @@ vdbemem_alloc_on_region(uint32_t count) } memset(ret, 0, count * sizeof(*ret)); for (uint32_t i = 0; i < count; i++) { - sqlVdbeMemInit(&ret[i], sql_get(), MEM_Null); + mem_create(&ret[i]); assert(memIsValid(&ret[i])); } return ret; diff --git a/src/box/sql/mem.h b/src/box/sql/mem.h index 7b9456426..2a3d1078e 100644 --- a/src/box/sql/mem.h +++ b/src/box/sql/mem.h @@ -94,6 +94,10 @@ struct Mem { const char * mem_str(const struct Mem *mem); +/** Initialize MEM and set NULL. */ +void +mem_create(struct Mem *mem); + /* One or more of the following flags are set to indicate the validOK * representations of the value stored in the Mem struct. * @@ -304,8 +308,6 @@ mem_set_double(struct Mem *mem, double value); int sqlVdbeMemSetStr(struct Mem *, const char *, int, u8, void (*)(void *)); void -sqlVdbeMemInit(struct Mem *, sql *, u32); -void sqlVdbeMemSetNull(struct Mem *); void sqlVdbeMemSetZeroBlob(struct Mem *, int); @@ -315,12 +317,6 @@ void sqlValueSetNull(struct Mem *); void sqlValueFree(struct Mem *); struct Mem *sqlValueNew(struct sql *); -/* - * Initialize an array of N Mem element. - */ -void -initMemArray(Mem * p, int N, sql * db, u32 flags); - /* * Release an array of N Mem elements */ diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c index ec3d23cb2..74bf7f903 100644 --- a/src/box/sql/vdbe.c +++ b/src/box/sql/vdbe.c @@ -4739,7 +4739,7 @@ case OP_AggStep: { #endif pMem->n++; - sqlVdbeMemInit(&t, db, MEM_Null); + mem_create(&t); pCtx->pOut = &t; pCtx->is_aborted = false; pCtx->skipFlag = 0; diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c index b7e148422..850158572 100644 --- a/src/box/sql/vdbeaux.c +++ b/src/box/sql/vdbeaux.c @@ -1589,9 +1589,13 @@ sqlVdbeMakeReady(Vdbe * p, /* The VDBE */ } else { p->nCursor = nCursor; p->nVar = (ynVar) nVar; - initMemArray(p->aVar, nVar, db, MEM_Null); + for (int i = 0; i < nVar; ++i) + mem_create(&p->aVar[i]); p->nMem = nMem; - initMemArray(p->aMem, nMem, db, MEM_Undefined); + for (int i = 0; i < nMem; ++i) { + mem_create(&p->aMem[i]); + p->aMem[i].flags = MEM_Undefined; + } memset(p->apCsr, 0, nCursor * sizeof(VdbeCursor *)); } sqlVdbeRewind(p); -- 2.25.1