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 E8BAD68F41; Tue, 23 Mar 2021 12:41:46 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org E8BAD68F41 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1616492506; bh=r4qj+f7aHYOmmVOntBv20DcyNZAlbkhN0P1quaQWUAM=; 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=GWn2gnWYYFy+xi0DNkIksSqkxqrAw8qobrBpzevj0MLdLB+l5GfGLUowKhsyRQq6w WqwL4feVFEw2fLWIW9nZThR9R98Nw3oZLkqHTUiJwXCTgHDqb5JlYiQ9OQjj9g2ghM /HNxYKpVadmlqaNmbZBmOHfG/jHN0k0wzTALi4KQ= Received: from smtp47.i.mail.ru (smtp47.i.mail.ru [94.100.177.107]) (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 8D46768F42 for ; Tue, 23 Mar 2021 12:35:25 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 8D46768F42 Received: by smtp47.i.mail.ru with esmtpa (envelope-from ) id 1lOdRc-0006TL-Ow; Tue, 23 Mar 2021 12:35:25 +0300 To: v.shpilevoy@tarantool.org, tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Tue, 23 Mar 2021 12:35:24 +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: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD95D6E7CC48CB1F5F179C48A9DDACBFB6F5347129BC2C9341C182A05F538085040122C6321630BF17B3CDC139B7D30C496CDB50BE02EB2F17FA5844592449B4C37 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7C8F626AC60F7C593C2099A533E45F2D0395957E7521B51C2CFCAF695D4D8E9FCEA1F7E6F0F101C6778DA827A17800CE7A0175C48BD57B26B8F08D7030A58E5ADC58D69EE07B14084C6CDE5D1141D2B1CF5450AD3DA2BBC42F198D559F070F20E86B005C4B27D37199FA2833FD35BB23D9E625A9149C048EE33AC447995A7AD1828451B159A507268D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8B1F8789D36234D406A471835C12D1D977C4224003CC836476EB9C4185024447017B076A6E789B0E975F5C1EE8F4F765FC87219392B7CF41693AA81AA40904B5D9CF19DD082D7633A078D18283394535A93AA81AA40904B5D98AA50765F79006375E9206C412E9D126D81D268191BDAD3D698AB9A7B718F8C4D1B931868CE1C5781A620F70A64A45A98AA50765F79006372E808ACE2090B5E14AD6D5ED66289B52BA9C0B312567BB23089D37D7C0E48F6CA18204E546F3947C36E876923B269E05A91E23F1B6B78B78C8A9BA7A39EFB7666BA297DBC24807EA089D37D7C0E48F6C8AA50765F79006370A138614880A1497EFF80C71ABB335746BA297DBC24807EA27F269C8F02392CDC58410348177836E285124B2A10EEC6C00306258E7E6ABB4E4A6367B16DE6309 X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A24A6D60772A99906F8E1CD14B953EB46D647909DA202E53DC355D89D7DBCDD132 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C686AF563A045C75E65DFC47E1E3886693698A188E077E22F9C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF0417BEADF48D1460699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34FDC9529E4578B99C4841706ECB6FD8DDE9129A22AE0B3326F1E8A52EF22328A13F6BBFC43BD66D561D7E09C32AA3244C893CF4CACF401A00D6929CFD94FF5692E8FBBEFAE1C4874CFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojWJZv20R+6Uh+sf9F3gLBFQ== X-Mailru-Sender: 5C3750E245F362008BC1685FEC6306ED171901C4FC6E144D3CDC139B7D30C4968A2AC75D222269F85105BD0848736F9966FEC6BF5C9C28D97E07721503EA2E00ED97202A5A4E92BF7402F9BA4338D657ED14614B50AE0675 X-Mras: Ok Subject: [Tarantool-patches] [PATCH v4 14/53] sql: rework mem_move() 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 reworks mem_move(). This function moves all content of source MEM to destination MEM. Source mem is set to NULL. Part of #5818 --- src/box/sql/mem.c | 57 +++++++++---------------------------------- src/box/sql/mem.h | 8 ++++-- src/box/sql/vdbe.c | 29 ++-------------------- src/box/sql/vdbeapi.c | 2 +- 4 files changed, 20 insertions(+), 76 deletions(-) diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c index 30c568970..3d42ac63c 100644 --- a/src/box/sql/mem.c +++ b/src/box/sql/mem.c @@ -308,6 +308,17 @@ mem_copy_as_ephemeral(struct Mem *to, const struct Mem *from) return 0; } +int +mem_move(struct Mem *to, struct Mem *from) +{ + mem_destroy(to); + memcpy(to, from, sizeof(*to)); + from->flags = MEM_Null; + from->szMalloc = 0; + from->zMalloc = NULL; + return 0; +} + static inline bool mem_has_msgpack_subtype(struct Mem *mem) { @@ -2033,52 +2044,6 @@ vdbe_mem_alloc_blob_region(struct Mem *vdbe_mem, uint32_t size) return 0; } -/* - * Transfer the contents of pFrom to pTo. Any existing value in pTo is - * freed. If pFrom contains ephemeral data, a copy is made. - * - * pFrom contains an SQL NULL when this routine returns. - */ -void -sqlVdbeMemMove(Mem * pTo, Mem * pFrom) -{ - assert(pFrom->db == 0 || pTo->db == 0 || pFrom->db == pTo->db); - - mem_destroy(pTo); - memcpy(pTo, pFrom, sizeof(Mem)); - pFrom->flags = MEM_Null; - pFrom->szMalloc = 0; -} - -/* - * Change pMem so that its MEM_Str or MEM_Blob value is stored in - * MEM.zMalloc, where it can be safely written. - * - * Return 0 on success or -1 if malloc fails. - */ -int -sqlVdbeMemMakeWriteable(Mem * pMem) -{ - if ((pMem->flags & (MEM_Str | MEM_Blob)) != 0) { - if (ExpandBlob(pMem)) - return -1; - if (pMem->szMalloc == 0 || pMem->z != pMem->zMalloc) { - if (sqlVdbeMemGrow(pMem, pMem->n + 2, 1)) { - return -1; - } - pMem->z[pMem->n] = 0; - pMem->z[pMem->n + 1] = 0; - pMem->flags |= MEM_Term; - } - } - pMem->flags &= ~MEM_Ephem; -#ifdef SQL_DEBUG - pMem->pScopyFrom = 0; -#endif - - return 0; -} - int sql_vdbemem_finalize(struct Mem *mem, struct func *func) { diff --git a/src/box/sql/mem.h b/src/box/sql/mem.h index 58220d215..801f3cba6 100644 --- a/src/box/sql/mem.h +++ b/src/box/sql/mem.h @@ -179,6 +179,12 @@ mem_copy(struct Mem *to, const struct Mem *from); int mem_copy_as_ephemeral(struct Mem *to, const struct Mem *from); +/** + * Move all content of source MEM to destination MEM. Source MEM is set to NULL. + */ +int +mem_move(struct Mem *to, struct Mem *from); + /* One or more of the following flags are set to indicate the validOK * representations of the value stored in the Mem struct. * @@ -495,8 +501,6 @@ mem_is_type_compatible(struct Mem *mem, enum field_type type); int vdbe_mem_alloc_blob_region(struct Mem *vdbe_mem, uint32_t size); -void sqlVdbeMemMove(Mem *, Mem *); -int sqlVdbeMemMakeWriteable(Mem *); /** * Memory cell mem contains the context of an aggregate function. diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c index 55083fb23..4654b1610 100644 --- a/src/box/sql/vdbe.c +++ b/src/box/sql/vdbe.c @@ -165,21 +165,6 @@ vdbeTakeBranch(int iSrcLine, u8 I, u8 M) } #endif -/* - * An ephemeral string value (signified by the MEM_Ephem flag) contains - * a pointer to a dynamically allocated string where some other entity - * is responsible for deallocating that string. Because the register - * does not control the string, it might be deleted without the register - * knowing it. - * - * This routine converts an ephemeral string into a dynamically allocated - * string that the register itself controls. In other words, it - * converts an MEM_Ephem string into a string with P.z==P.zMalloc. - */ -#define Deephemeralize(P) \ - if (((P)->flags&MEM_Ephem)!=0 \ - && sqlVdbeMemMakeWriteable(P)) { goto no_mem;} - /* Return true if the cursor was opened using the OP_OpenSorter opcode. */ #define isSorter(x) ((x)->eCurType==CURTYPE_SORTER) @@ -949,13 +934,7 @@ case OP_Move: { assert(pIn1<=&aMem[(p->nMem+1 - p->nCursor)]); assert(memIsValid(pIn1)); memAboutToChange(p, pOut); - sqlVdbeMemMove(pOut, pIn1); -#ifdef SQL_DEBUG - if (pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrompScopyFrom += pOp->p2 - p1; - } -#endif - Deephemeralize(pOut); + mem_move(pOut, pIn1); REGISTER_TRACE(p, p2++, pOut); pIn1++; pOut++; @@ -979,11 +958,7 @@ case OP_Copy: { pOut = &aMem[pOp->p2]; assert(pOut!=pIn1); while( 1) { - mem_copy_as_ephemeral(pOut, pIn1); - Deephemeralize(pOut); -#ifdef SQL_DEBUG - pOut->pScopyFrom = 0; -#endif + mem_copy(pOut, pIn1); REGISTER_TRACE(p, pOp->p2+pOp->p3-n, pOut); if ((n--)==0) break; pOut++; diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c index b13385647..2625a9115 100644 --- a/src/box/sql/vdbeapi.c +++ b/src/box/sql/vdbeapi.c @@ -980,7 +980,7 @@ sqlTransferBindings(sql_stmt * pFromStmt, sql_stmt * pToStmt) assert(pTo->db == pFrom->db); assert(pTo->nVar == pFrom->nVar); for (i = 0; i < pFrom->nVar; i++) { - sqlVdbeMemMove(&pTo->aVar[i], &pFrom->aVar[i]); + mem_move(&pTo->aVar[i], &pFrom->aVar[i]); } return 0; } -- 2.25.1