From: Mergen Imeev via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: v.shpilevoy@tarantool.org
Cc: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH v1 19/21] sql: remove MEM_Dyn flag
Date: Fri, 8 Oct 2021 20:32:06 +0300 [thread overview]
Message-ID: <86bc99060c5e4a37a4ee5df2c1b98cd8f77e4765.1633713433.git.imeevma@gmail.com> (raw)
In-Reply-To: <cover.1633713432.git.imeevma@gmail.com>
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 | 108 +++++++---------------------------------------
src/box/sql/mem.h | 53 +----------------------
2 files changed, 16 insertions(+), 145 deletions(-)
diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c
index 895003580..a001ac8c5 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)
{
@@ -2643,18 +2590,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));
@@ -2669,7 +2604,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);
}
@@ -2689,15 +2623,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) {
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';
}
@@ -2721,15 +2652,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) {
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';
}
@@ -2842,13 +2770,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;
}
@@ -2867,11 +2791,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 1d995726f..76769835d 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)
{
@@ -306,14 +297,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
@@ -334,14 +317,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
@@ -373,14 +348,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
@@ -411,14 +378,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
@@ -443,15 +402,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.
@@ -868,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)
--
2.25.1
next prev parent reply other threads:[~2021-10-08 17:41 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-08 17:31 [Tarantool-patches] [PATCH v1 00/21] Refactor non-standard and non-aggragate functions Mergen Imeev via Tarantool-patches
2021-10-08 17:31 ` [Tarantool-patches] [PATCH v1 01/21] sql: refactor CHAR() function Mergen Imeev via Tarantool-patches
2021-10-14 22:42 ` Vladislav Shpilevoy via Tarantool-patches
2021-10-25 8:02 ` Mergen Imeev via Tarantool-patches
2021-10-29 23:42 ` Vladislav Shpilevoy via Tarantool-patches
2021-11-02 11:35 ` Mergen Imeev via Tarantool-patches
2021-10-08 17:31 ` [Tarantool-patches] [PATCH v1 02/21] sql: refactor GREATEST() and LEAST() functions Mergen Imeev via Tarantool-patches
2021-10-14 22:42 ` Vladislav Shpilevoy via Tarantool-patches
2021-10-25 8:17 ` Mergen Imeev via Tarantool-patches
2021-10-08 17:31 ` [Tarantool-patches] [PATCH v1 03/21] sql: refactor HEX() function Mergen Imeev via Tarantool-patches
2021-10-14 22:43 ` Vladislav Shpilevoy via Tarantool-patches
2021-10-25 8:19 ` Mergen Imeev via Tarantool-patches
2021-10-08 17:31 ` [Tarantool-patches] [PATCH v1 04/21] sql: refactor LENGTH() function Mergen Imeev via Tarantool-patches
2021-10-14 22:43 ` Vladislav Shpilevoy via Tarantool-patches
2021-10-25 8:30 ` Mergen Imeev via Tarantool-patches
2021-10-29 23:42 ` Vladislav Shpilevoy via Tarantool-patches
2021-11-02 11:39 ` Mergen Imeev via Tarantool-patches
2021-10-08 17:31 ` [Tarantool-patches] [PATCH v1 05/21] sql: refactor PRINTF() function Mergen Imeev via Tarantool-patches
2021-10-14 22:44 ` Vladislav Shpilevoy via Tarantool-patches
2021-10-25 8:33 ` Mergen Imeev via Tarantool-patches
2021-10-08 17:31 ` [Tarantool-patches] [PATCH v1 06/21] sql: refactor RANDOM() function Mergen Imeev via Tarantool-patches
2021-10-25 8:35 ` Mergen Imeev via Tarantool-patches
2021-10-08 17:31 ` [Tarantool-patches] [PATCH v1 07/21] sql: rework RANDOMBLOB() function Mergen Imeev via Tarantool-patches
2021-10-25 8:36 ` Mergen Imeev via Tarantool-patches
2021-10-08 17:31 ` [Tarantool-patches] [PATCH v1 08/21] sql: refactor ZEROBLOB() function Mergen Imeev via Tarantool-patches
2021-10-25 8:37 ` Mergen Imeev via Tarantool-patches
2021-10-08 17:31 ` [Tarantool-patches] [PATCH v1 09/21] sql: refactor TYPEOF() function Mergen Imeev via Tarantool-patches
2021-10-08 17:31 ` [Tarantool-patches] [PATCH v1 10/21] sql: refactor ROUND() function Mergen Imeev via Tarantool-patches
2021-10-08 17:31 ` [Tarantool-patches] [PATCH v1 11/21] sql: refactor ROW_COUNT() function Mergen Imeev via Tarantool-patches
2021-10-08 17:31 ` [Tarantool-patches] [PATCH v1 12/21] sql: rework UUID() function Mergen Imeev via Tarantool-patches
2021-10-25 8:38 ` Mergen Imeev via Tarantool-patches
2021-10-08 17:31 ` [Tarantool-patches] [PATCH v1 13/21] sql: refactor VERSION() function Mergen Imeev via Tarantool-patches
2021-10-08 17:31 ` [Tarantool-patches] [PATCH v1 14/21] sql: refactor UNICODE() function Mergen Imeev via Tarantool-patches
2021-10-14 22:44 ` Vladislav Shpilevoy via Tarantool-patches
2021-10-25 8:40 ` Mergen Imeev via Tarantool-patches
2021-11-02 11:42 ` Mergen Imeev via Tarantool-patches
2021-10-08 17:32 ` [Tarantool-patches] [PATCH v1 15/21] sql: refactor of SOUNDEX() function Mergen Imeev via Tarantool-patches
2021-10-08 17:32 ` [Tarantool-patches] [PATCH v1 16/21] sql: refactor REPLACE() function Mergen Imeev via Tarantool-patches
2021-10-14 22:45 ` Vladislav Shpilevoy via Tarantool-patches
2021-10-25 8:45 ` Mergen Imeev via Tarantool-patches
2021-10-08 17:32 ` [Tarantool-patches] [PATCH v1 17/21] sql: refactor QUOTE() function Mergen Imeev via Tarantool-patches
2021-10-08 17:32 ` [Tarantool-patches] [PATCH v1 18/21] sql: remove unused code Mergen Imeev via Tarantool-patches
2021-10-25 8:51 ` Mergen Imeev via Tarantool-patches
2021-10-08 17:32 ` Mergen Imeev via Tarantool-patches [this message]
2021-10-14 22:46 ` [Tarantool-patches] [PATCH v1 19/21] sql: remove MEM_Dyn flag Vladislav Shpilevoy via Tarantool-patches
2021-10-25 8:54 ` Mergen Imeev via Tarantool-patches
2021-10-29 23:43 ` Vladislav Shpilevoy via Tarantool-patches
2021-11-02 11:43 ` Mergen Imeev via Tarantool-patches
2021-10-08 17:32 ` [Tarantool-patches] [PATCH v1 20/21] sql: remove MEM_Term flag Mergen Imeev via Tarantool-patches
2021-10-14 22:47 ` Vladislav Shpilevoy via Tarantool-patches
2021-10-25 9:57 ` Mergen Imeev via Tarantool-patches
2021-10-08 17:32 ` [Tarantool-patches] [PATCH v1 21/21] sql: make arguments to be const Mergen Imeev via Tarantool-patches
2021-11-02 22:15 ` [Tarantool-patches] [PATCH v1 00/21] Refactor non-standard and non-aggragate functions Vladislav Shpilevoy via Tarantool-patches
2021-11-11 10:48 Mergen Imeev via Tarantool-patches
2021-11-11 10:49 ` [Tarantool-patches] [PATCH v1 19/21] sql: remove MEM_Dyn flag Mergen Imeev via Tarantool-patches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86bc99060c5e4a37a4ee5df2c1b98cd8f77e4765.1633713433.git.imeevma@gmail.com \
--to=tarantool-patches@dev.tarantool.org \
--cc=imeevma@tarantool.org \
--cc=v.shpilevoy@tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH v1 19/21] sql: remove MEM_Dyn flag' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox