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 4F72D7105C; Thu, 11 Nov 2021 13:59:39 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 4F72D7105C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1636628379; bh=rbtxDQ18iIWCZ/x/07ZUeH5fs+nNCs8CWOhi7Q7zbHQ=; 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=xoRigsDUhw1ig+g8BTyYhflr+t7100Q0yZ4egvG6P6PC0ZDeMzdqwHnargqzWmPAJ feE1MWR4LJQ/6W29y3moHzCAaAIIej7TIVGbatZq2Ab+AdnnuqdaErsUiLNqUkc3mS vpKW5xtAbgLZDuR8rDTXkTQq+mJp045KI0eDzxuE= 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 56F0F71071 for ; Thu, 11 Nov 2021 13:49:24 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 56F0F71071 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1ml7dz-00059m-FD; Thu, 11 Nov 2021 13:49:23 +0300 To: kyukhin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Thu, 11 Nov 2021 13:49:23 +0300 Message-Id: <041e1087fdee0163c625778491c8450502845c24.1636627580.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: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD9731B3922EC063979EC8F5BB1F79852547911E65F5173D5CB00894C459B0CD1B926AB4635166740BE61FAD64AB6FBA832BD7B9CED87D255679799EF890AE2FCA9 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE771540F9ECFC94C4BEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637D16C0F49FB622D318638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8AC72C9EB3B52051FF3968C417A3C50CF117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC55B19328CBC4F849A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735209647ADFADE5905B16FD1C55BDD38FC3FD2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B66F6A3E018CF4DC80089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C7E9FEBB9C11794A18070A7B6F3D1CC6298AA8E67C10A72F09C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EFCDE59DDCCE53AF2B699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34A150564C13026C1832240B7085C1895938ACD7B62A235389F0AB1E08BE609865EEAB5BCD3B115CD51D7E09C32AA3244C0ED95F69171B5462E49DC11508655329725D5B54B2FE4575729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj4t8MBgWr8bKekL6UmagRGw== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5DE792BA71E3D9CE2BB547E09B0EF5BEBA83D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v1 19/21] sql: remove MEM_Dyn flag 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 removes the MEM_Dyn flag, because after changes in the SQL built-in functions, this flag is no longer used. Needed for #4145 --- src/box/sql/mem.c | 110 +++++++------------------------------------ src/box/sql/mem.h | 56 +--------------------- src/box/sql/sqlInt.h | 14 ------ 3 files changed, 18 insertions(+), 162 deletions(-) diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c index 70ca9e1b2..4150a24f0 100644 --- a/src/box/sql/mem.c +++ b/src/box/sql/mem.c @@ -207,7 +207,6 @@ mem_create(struct Mem *mem) mem->szMalloc = 0; mem->uTemp = 0; mem->db = sql_get(); - mem->xDel = NULL; #ifdef SQL_DEBUG mem->pScopyFrom = NULL; mem->pFiller = NULL; @@ -217,15 +216,10 @@ mem_create(struct Mem *mem) static inline void mem_clear(struct Mem *mem) { - 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 { - struct VdbeFrame *frame = mem->u.pFrame; - frame->pParent = frame->v->pDelFrame; - frame->v->pDelFrame = frame; - } + if (mem->type == MEM_TYPE_FRAME) { + struct VdbeFrame *frame = mem->u.pFrame; + frame->pParent = frame->v->pDelFrame; + frame->v->pDelFrame = frame; } mem->type = MEM_TYPE_NULL; mem->flags = 0; @@ -320,21 +314,14 @@ set_str_const(struct Mem *mem, char *value, uint32_t len, int alloc_type) static inline void set_str_dynamic(struct Mem *mem, char *value, uint32_t len, int alloc_type) { - assert((mem->flags & MEM_Dyn) == 0 || value != mem->z); assert(mem->szMalloc == 0 || value != mem->zMalloc); - assert(alloc_type == MEM_Dyn || alloc_type == 0); mem_destroy(mem); mem->z = value; mem->n = len; mem->type = MEM_TYPE_STR; mem->flags = alloc_type; - if (alloc_type == MEM_Dyn) { - mem->xDel = sql_free; - } else { - mem->xDel = NULL; - mem->zMalloc = mem->z; - mem->szMalloc = sqlDbMallocSize(mem->db, mem->zMalloc); - } + mem->zMalloc = mem->z; + mem->szMalloc = sqlDbMallocSize(mem->db, mem->zMalloc); } void @@ -349,12 +336,6 @@ mem_set_str_static(struct Mem *mem, char *value, uint32_t len) set_str_const(mem, value, len, MEM_Static); } -void -mem_set_str_dynamic(struct Mem *mem, char *value, uint32_t len) -{ - set_str_dynamic(mem, value, len, MEM_Dyn); -} - void mem_set_str_allocated(struct Mem *mem, char *value, uint32_t len) { @@ -375,13 +356,6 @@ mem_set_str0_static(struct Mem *mem, char *value) mem->flags |= MEM_Term; } -void -mem_set_str0_dynamic(struct Mem *mem, char *value) -{ - set_str_dynamic(mem, value, strlen(value), MEM_Dyn); - mem->flags |= MEM_Term; -} - void mem_set_str0_allocated(struct Mem *mem, char *value) { @@ -436,21 +410,14 @@ set_bin_const(struct Mem *mem, char *value, uint32_t size, int alloc_type) static inline void set_bin_dynamic(struct Mem *mem, char *value, uint32_t size, int alloc_type) { - assert((mem->flags & MEM_Dyn) == 0 || value != mem->z); assert(mem->szMalloc == 0 || value != mem->zMalloc); - assert(alloc_type == MEM_Dyn || alloc_type == 0); mem_destroy(mem); mem->z = value; mem->n = size; mem->type = MEM_TYPE_BIN; mem->flags = alloc_type; - if (alloc_type == MEM_Dyn) { - mem->xDel = sql_free; - } else { - mem->xDel = NULL; - mem->zMalloc = mem->z; - mem->szMalloc = sqlDbMallocSize(mem->db, mem->zMalloc); - } + mem->zMalloc = mem->z; + mem->szMalloc = sqlDbMallocSize(mem->db, mem->zMalloc); } void @@ -465,12 +432,6 @@ mem_set_bin_static(struct Mem *mem, char *value, uint32_t size) set_bin_const(mem, value, size, MEM_Static); } -void -mem_set_bin_dynamic(struct Mem *mem, char *value, uint32_t size) -{ - set_bin_dynamic(mem, value, size, MEM_Dyn); -} - void mem_set_bin_allocated(struct Mem *mem, char *value, uint32_t size) { @@ -524,13 +485,6 @@ mem_set_map_static(struct Mem *mem, char *value, uint32_t size) set_msgpack_value(mem, value, size, MEM_Static, MEM_TYPE_MAP); } -void -mem_set_map_dynamic(struct Mem *mem, char *value, uint32_t size) -{ - assert(mp_typeof(*value) == MP_MAP); - set_msgpack_value(mem, value, size, MEM_Dyn, MEM_TYPE_MAP); -} - void mem_set_map_allocated(struct Mem *mem, char *value, uint32_t size) { @@ -552,13 +506,6 @@ mem_set_array_static(struct Mem *mem, char *value, uint32_t size) set_msgpack_value(mem, value, size, MEM_Static, MEM_TYPE_ARRAY); } -void -mem_set_array_dynamic(struct Mem *mem, char *value, uint32_t size) -{ - assert(mp_typeof(*value) == MP_ARRAY); - set_msgpack_value(mem, value, size, MEM_Dyn, MEM_TYPE_ARRAY); -} - void mem_set_array_allocated(struct Mem *mem, char *value, uint32_t size) { @@ -1907,7 +1854,7 @@ mem_append(struct Mem *mem, const char *value, uint32_t len) if (len == 0) return 0; int new_size = mem->n + len; - if (((mem->flags & (MEM_Static | MEM_Dyn | MEM_Ephem)) != 0) || + if (((mem->flags & (MEM_Static | MEM_Ephem)) != 0) || mem->szMalloc < new_size) { /* * Force exponential buffer size growth to avoid having to call @@ -2648,18 +2595,6 @@ mem_mp_type(const struct Mem *mem) int sqlVdbeCheckMemInvariants(Mem * p) { - /* If MEM_Dyn is set then Mem.xDel!=0. - * Mem.xDel is might not be initialized if MEM_Dyn is clear. - */ - assert((p->flags & MEM_Dyn) == 0 || p->xDel != 0); - - /* MEM_Dyn may only be set if Mem.szMalloc==0. In this way we - * ensure that if Mem.szMalloc>0 then it is safe to do - * Mem.z = Mem.zMalloc without having to check Mem.flags&MEM_Dyn. - * That saves a few cycles in inner loops. - */ - assert((p->flags & MEM_Dyn) == 0 || p->szMalloc == 0); - /* The szMalloc field holds the correct memory allocation size */ assert(p->szMalloc == 0 || p->szMalloc == sqlDbMallocSize(p->db, p->zMalloc)); @@ -2674,7 +2609,6 @@ sqlVdbeCheckMemInvariants(Mem * p) */ if ((p->type & (MEM_TYPE_STR | MEM_TYPE_BIN)) != 0 && p->n > 0) { assert(((p->szMalloc > 0 && p->z == p->zMalloc) ? 1 : 0) + - ((p->flags & MEM_Dyn) != 0 ? 1 : 0) + ((p->flags & MEM_Ephem) != 0 ? 1 : 0) + ((p->flags & MEM_Static) != 0 ? 1 : 0) == 1); } @@ -2694,15 +2628,12 @@ sqlVdbeMemPrettyPrint(Mem *pMem, char *zBuf) if (pMem->type == MEM_TYPE_BIN) { int i; char c; - if (f & MEM_Dyn) { - c = 'z'; - assert((f & (MEM_Static|MEM_Ephem))==0); - } else if (f & MEM_Static) { + if ((f & MEM_Static) != 0) { c = 't'; - assert((f & (MEM_Dyn|MEM_Ephem))==0); + assert((f & MEM_Ephem) == 0); } else if (f & MEM_Ephem) { c = 'e'; - assert((f & (MEM_Static|MEM_Dyn))==0); + assert((f & MEM_Static) == 0); } else { c = 's'; } @@ -2726,15 +2657,12 @@ sqlVdbeMemPrettyPrint(Mem *pMem, char *zBuf) } else if (pMem->type == MEM_TYPE_STR) { int j, k; zBuf[0] = ' '; - if (f & MEM_Dyn) { - zBuf[1] = 'z'; - assert((f & (MEM_Static|MEM_Ephem))==0); - } else if (f & MEM_Static) { + if ((f & MEM_Static) != 0) { zBuf[1] = 't'; - assert((f & (MEM_Dyn|MEM_Ephem))==0); + assert((f & MEM_Ephem) == 0); } else if (f & MEM_Ephem) { zBuf[1] = 'e'; - assert((f & (MEM_Static|MEM_Dyn))==0); + assert((f & MEM_Static) == 0); } else { zBuf[1] = 's'; } @@ -2847,13 +2775,9 @@ sqlVdbeMemGrow(struct Mem *pMem, int n, int bPreserve) if (bPreserve && pMem->z && pMem->z != pMem->zMalloc) { memcpy(pMem->zMalloc, pMem->z, pMem->n); } - if ((pMem->flags & MEM_Dyn) != 0) { - assert(pMem->xDel != 0 && pMem->xDel != SQL_DYNAMIC); - pMem->xDel((void *)(pMem->z)); - } pMem->z = pMem->zMalloc; - pMem->flags &= ~(MEM_Dyn | MEM_Ephem | MEM_Static); + pMem->flags &= ~(MEM_Ephem | MEM_Static); return 0; } @@ -2872,11 +2796,9 @@ int sqlVdbeMemClearAndResize(Mem * pMem, int szNew) { assert(szNew > 0); - assert((pMem->flags & MEM_Dyn) == 0 || pMem->szMalloc == 0); if (pMem->szMalloc < szNew) { return sqlVdbeMemGrow(pMem, szNew, 0); } - assert((pMem->flags & MEM_Dyn) == 0); pMem->z = pMem->zMalloc; return 0; } diff --git a/src/box/sql/mem.h b/src/box/sql/mem.h index 9533833f2..d2e9cc135 100644 --- a/src/box/sql/mem.h +++ b/src/box/sql/mem.h @@ -87,7 +87,6 @@ struct Mem { int szMalloc; /* Size of the zMalloc allocation */ u32 uTemp; /* Transient storage for serial_type in OP_MakeRecord */ sql *db; /* The associated database connection */ - void (*xDel) (void *); /* Destructor for Mem.z - only valid if MEM_Dyn */ #ifdef SQL_DEBUG Mem *pScopyFrom; /* This Mem is a shallow copy of pScopyFrom */ void *pFiller; /* So that sizeof(Mem) is a multiple of 8 */ @@ -106,7 +105,6 @@ struct Mem { * string is \000 or \u0000 terminated */ #define MEM_Term 0x0400 /* String rep is nul terminated */ -#define MEM_Dyn 0x0800 /* Need to call Mem.xDel() on Mem.z */ #define MEM_Static 0x1000 /* Mem.z points to a static string */ #define MEM_Ephem 0x2000 /* Mem.z points to an ephemeral string */ @@ -217,13 +215,6 @@ mem_is_ephemeral(const struct Mem *mem) return (mem->flags & MEM_Ephem) != 0; } -static inline bool -mem_is_dynamic(const struct Mem *mem) -{ - assert(mem_is_bytes(mem)); - return (mem->flags & MEM_Dyn) != 0; -} - static inline bool mem_is_allocated(const struct Mem *mem) { @@ -234,8 +225,7 @@ mem_is_allocated(const struct Mem *mem) static inline bool mem_is_trivial(const struct Mem *mem) { - return mem->szMalloc == 0 && (mem->flags & MEM_Dyn) == 0 && - mem->type != MEM_TYPE_FRAME; + return mem->szMalloc == 0 && mem->type != MEM_TYPE_FRAME; } static inline bool @@ -314,14 +304,6 @@ mem_set_str_ephemeral(struct Mem *mem, char *value, uint32_t len); void mem_set_str_static(struct Mem *mem, char *value, uint32_t len); -/** - * Clear MEM and set it to STRING. The string was allocated by another object - * and passed to MEM. MEMs with this allocation type must free given memory - * whenever the MEM changes. - */ -void -mem_set_str_dynamic(struct Mem *mem, char *value, uint32_t len); - /** * Clear MEM and set it to STRING. The string was allocated by another object * and passed to MEM. MEMs with this allocation type only deallocate the string @@ -342,14 +324,6 @@ mem_set_str0_ephemeral(struct Mem *mem, char *value); void mem_set_str0_static(struct Mem *mem, char *value); -/** - * Clear MEM and set it to NULL-terminated STRING. The string was allocated by - * another object and passed to MEM. MEMs with this allocation type must free - * given memory whenever the MEM changes. - */ -void -mem_set_str0_dynamic(struct Mem *mem, char *value); - /** * Clear MEM and set it to NULL-terminated STRING. The string was allocated by * another object and passed to MEM. MEMs with this allocation type only @@ -381,14 +355,6 @@ mem_set_bin_ephemeral(struct Mem *mem, char *value, uint32_t size); void mem_set_bin_static(struct Mem *mem, char *value, uint32_t size); -/** - * Clear MEM and set it to VARBINARY. The binary value was allocated by another - * object and passed to MEM. MEMs with this allocation type must free given - * memory whenever the MEM changes. - */ -void -mem_set_bin_dynamic(struct Mem *mem, char *value, uint32_t size); - /** * Clear MEM and set it to VARBINARY. The binary value was allocated by another * object and passed to MEM. MEMs with this allocation type only deallocate the @@ -419,14 +385,6 @@ mem_set_map_ephemeral(struct Mem *mem, char *value, uint32_t size); void mem_set_map_static(struct Mem *mem, char *value, uint32_t size); -/** - * Clear MEM and set it to MAP. The binary value was allocated by another object - * and passed to MEM. The binary value must be msgpack of MAP type. MEMs with - * this allocation type must free given memory whenever the MEM changes. - */ -void -mem_set_map_dynamic(struct Mem *mem, char *value, uint32_t size); - /** * Clear MEM and set it to MAP. The binary value was allocated by another object * and passed to MEM. The binary value must be msgpack of MAP type. MEMs with @@ -451,15 +409,6 @@ mem_set_array_ephemeral(struct Mem *mem, char *value, uint32_t size); void mem_set_array_static(struct Mem *mem, char *value, uint32_t size); -/** - * Clear MEM and set it to ARRAY. The binary value was allocated by another - * object and passed to MEM. The binary value must be msgpack of ARRAY type. - * MEMs with this allocation type must free given memory whenever the MEM - * changes. - */ -void -mem_set_array_dynamic(struct Mem *mem, char *value, uint32_t size); - /** * Clear MEM and set it to ARRAY. The binary value was allocated by another * object and passed to MEM. The binary value must be msgpack of ARRAY type. @@ -869,8 +818,7 @@ int sqlVdbeMemTooBig(Mem *); /* Return TRUE if Mem X contains dynamically allocated content - anything * that needs to be deallocated to avoid a leak. */ -#define VdbeMemDynamic(X) (((X)->flags & MEM_Dyn) != 0 ||\ - ((X)->type & MEM_TYPE_FRAME) != 0) +#define VdbeMemDynamic(X) (((X)->type & MEM_TYPE_FRAME) != 0) /** * Perform comparison of two tuples: unpacked (key1) and packed (key2) diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h index 22a4aa5cd..148350d05 100644 --- a/src/box/sql/sqlInt.h +++ b/src/box/sql/sqlInt.h @@ -370,10 +370,6 @@ sql_vsnprintf(int, char *, const char *, va_list); #define MATCH_ONE_WILDCARD '_' #define MATCH_ALL_WILDCARD '%' -typedef void (*sql_destructor_type) (void *); -#define SQL_STATIC ((sql_destructor_type)0) -#define SQL_TRANSIENT ((sql_destructor_type)-1) - /** * Compile the UTF-8 encoded SQL statement into * a statement handle (struct Vdbe). @@ -873,16 +869,6 @@ typedef u64 uptr; */ #define IsPowerOfTwo(X) (((X)&((X)-1))==0) -/* - * The following value as a destructor means to use sqlDbFree(). - * The sqlDbFree() routine requires two parameters instead of the - * one parameter that destructors normally want. So we have to introduce - * this magic value that the code knows to handle differently. Any - * pointer will work here as long as it is distinct from sql_STATIC - * and sql_TRANSIENT. - */ -#define SQL_DYNAMIC ((sql_destructor_type)sqlMallocSize) - /* * The usual case where Writable Static Data (WSD) is supported, * the sql_WSD and GLOBAL macros become no-ops and have zero -- 2.25.1