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 E37CF71828; Tue, 23 Mar 2021 12:39:15 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org E37CF71828 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1616492355; bh=R2dSiCyF70ybsMcR4xrQATRkH/46vRXCYdTw5GEmbzg=; 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=SVLD4iweUMIZxLUF3P75GbeNZDQk56MNtBQ6MNQEEwLTO2+KcJDDiI5zlnBbsKoil SeBRj0A/JGZ+MzGc1701jcJvqsTIyJFTzgz+AtcmUydTu8IVyRqwq2n/ks8Lu7MmDx m5YqrSYCSeGW8LRI24lPHXBlqsq+txO9Sb1zv32Y= Received: from smtp17.mail.ru (smtp17.mail.ru [94.100.176.154]) (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 644656BD34 for ; Tue, 23 Mar 2021 12:35:14 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 644656BD34 Received: by smtp17.mail.ru with esmtpa (envelope-from ) id 1lOdRR-0000VI-Ik; Tue, 23 Mar 2021 12:35:13 +0300 To: v.shpilevoy@tarantool.org, tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Tue, 23 Mar 2021 12:35:13 +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: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD95D6E7CC48CB1F5F19D4B90E2C0E110A6B701D7D268243E19182A05F53808504012B6BE9BD325CD0C864018677BA44C726A4D386862B023515EA50A8F6ABA475D X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7260723E369DE2609EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063764FE777F378F21448638F802B75D45FF914D58D5BE9E6BC131B5C99E7648C95C686AF563A045C75E73230E2E46D54CB24C6F95E5CAB9E7F8A471835C12D1D9774AD6D5ED66289B5278DA827A17800CE7850F8B975A76562C9FA2833FD35BB23D2EF20D2F80756B5F868A13BD56FB6657A471835C12D1D977725E5C173C3A84C390BCC82C2C62A6D1117882F4460429728AD0CFFFB425014E868A13BD56FB6657D81D268191BDAD3DC09775C1D3CA48CF26163BE27A4E3063BA3038C0950A5D36C8A9BA7A39EFB766EC990983EF5C0329BA3038C0950A5D36D5E8D9A59859A8B6E8E471CADDBA01B476E601842F6C81A1F004C906525384307823802FF610243DF43C7A68FF6260569E8FC8737B5C2249EC8D19AE6D49635B3BBE47FD9DD3FB59A8DF7F3B2552694A57739F23D657EF2B13377AFFFEAFD26923F8577A6DFFEA7CE1AEB6AF2DA18B6293EC92FD9297F6715571747095F342E857739F23D657EF2BD5E8D9A59859A8B698B1B85E56A716AC089D37D7C0E48F6C5571747095F342E857739F23D657EF2B6825BDBE14D8E7024847893F9AA87235E5BFE6E7EFDEDCD789D4C264860C145E X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A24A6D60772A99906F8E1CD14B953EB46D6CC99F0F55B1640A355D89D7DBCDD132 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C686AF563A045C75E73230E2E46D54CB24C6F95E5CAB9E7F89C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF0417BEADF48D1460699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34A246DFF68F0EE19E11B44D561988C0912D7142AC22660E19730D1E9B0B8931DB0BE74FEE80F16AF61D7E09C32AA3244CDEDAC61C5134439145D0CAFF627B9133259227199D06760AFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojWJZv20R+6Uiw3h0bdB4lVw== X-Mailru-Sender: 5C3750E245F362008BC1685FEC6306ED9E13E96EB945ADF2864018677BA44C721AB5AE572836FD895105BD0848736F9966FEC6BF5C9C28D97E07721503EA2E00ED97202A5A4E92BF7402F9BA4338D657ED14614B50AE0675 X-Mras: Ok Subject: [Tarantool-patches] [PATCH v4 09/53] 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/func.c | 2 +- src/box/sql/mem.c | 49 +++++++++++++++++-------------------------- src/box/sql/mem.h | 14 ++++++------- src/box/sql/vdbe.c | 2 +- src/box/sql/vdbeaux.c | 8 +++++-- 5 files changed, 33 insertions(+), 42 deletions(-) diff --git a/src/box/sql/func.c b/src/box/sql/func.c index 5ece28d6d..5e4eff931 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -95,7 +95,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.c b/src/box/sql/mem.c index 0ed5e38d4..242360a66 100644 --- a/src/box/sql/mem.c +++ b/src/box/sql/mem.c @@ -70,6 +70,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) { @@ -1339,21 +1358,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. * @@ -1438,21 +1442,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) { diff --git a/src/box/sql/mem.h b/src/box/sql/mem.h index 740c7dfba..9a3b275fc 100644 --- a/src/box/sql/mem.h +++ b/src/box/sql/mem.h @@ -94,6 +94,12 @@ 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. * @@ -321,8 +327,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); @@ -332,12 +336,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 9b392f9cb..5378bc92b 100644 --- a/src/box/sql/vdbe.c +++ b/src/box/sql/vdbe.c @@ -4710,7 +4710,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 f270b0ed1..55d4fc14f 100644 --- a/src/box/sql/vdbeaux.c +++ b/src/box/sql/vdbeaux.c @@ -1565,9 +1565,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