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 8D5F87034A; Tue, 23 Mar 2021 12:54:48 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 8D5F87034A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1616493288; bh=bDxw4rXwgfHehE6l40CiJzGGpwCvrCh8D2Zq2mNvCSg=; 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=Tc6s5k5fHWpa5rAztb4hGO7otaDQJn3Vfphq1B67nrlj6JVh3AuPoFOZLhe9RH9Ou 6Lr2/BE0JzZVmUMv2D3tkuQ3JKedd5luyxcxj1O98pupbgiAdirxzwHX5ubjOSkiMV x3YYbuzbSsvKdJyGgwd8V4sjWfYYmDGM4tl0Yh1I= Received: from smtp60.i.mail.ru (smtp60.i.mail.ru [217.69.128.40]) (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 49F6B7034A for ; Tue, 23 Mar 2021 12:36:26 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 49F6B7034A Received: by smtp60.i.mail.ru with esmtpa (envelope-from ) id 1lOdSb-0004jA-KH; Tue, 23 Mar 2021 12:36:26 +0300 To: v.shpilevoy@tarantool.org, tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Tue, 23 Mar 2021 12:36:25 +0300 Message-Id: <2fd0811b925fb9bfefa4976ddb48a0799a3914f4.1616491731.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-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD95D6E7CC48CB1F5F179C48A9DDACBFB6F5347129BC2C9341C182A05F5380850400D6E2C6CB0099EEBAD705E5A407F3DDBFAC7EC6EE1E708404261BC3103575F03 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE776377A057133B646EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006376AFB9B40001E44068638F802B75D45FF914D58D5BE9E6BC131B5C99E7648C95C686AF563A045C75EA67579C941881F8D54514B03127A8128A471835C12D1D9774AD6D5ED66289B5278DA827A17800CE767883B903EA3BAEA9FA2833FD35BB23D2EF20D2F80756B5F868A13BD56FB6657A471835C12D1D977725E5C173C3A84C3BCA4DA3BE1BC1572CC7F00164DA146DA6F5DAA56C3B73B237318B6A418E8EAB8D32BA5DBAC0009BE9E8FC8737B5C2249BD15B5E67D6DC3FB76E601842F6C81A12EF20D2F80756B5F7E9C4E3C761E06A776E601842F6C81A127C277FBC8AE2E8BD978FF95A8E6D49B3AA81AA40904B5D9DBF02ECDB25306B2201CA6A4E26CD07C3BBE47FD9DD3FB595F5C1EE8F4F765FC72CEEB2601E22B091A620F70A64A45A99449624AB7ADAF3735872C767BF85DA29E625A9149C048EE0A3850AC1BE2E7354E672349037D5FA54AD6D5ED66289B524E70A05D1297E1BB35872C767BF85DA227C277FBC8AE2E8BAEB924C2B054B06E75ECD9A6C639B01B4E70A05D1297E1BBC6867C52282FAC85D9B7C4F32B44FF5797B92FCB1594A39500306258E7E6ABB4E4A6367B16DE6309 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C686AF563A045C75EA67579C941881F8D54514B03127A81289C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF0417BEADF48D1460699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34E229BE567979C9402D42EA89743F0442890B437FB514F63A0A389A8B42ACC9DE362FC58BD9880D251D7E09C32AA3244CBA2A3D1121D82CDDE1F2C7D41637DEDD3A92A9747B6CC886FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojWJZv20R+6UiYqm/UqR2Aig== X-Mailru-Sender: 5C3750E245F362008BC1685FEC6306ED97C0C416000D2734AD705E5A407F3DDB228AB1844EA588C75105BD0848736F9966FEC6BF5C9C28D97E07721503EA2E00ED97202A5A4E92BF7402F9BA4338D657ED14614B50AE0675 X-Mras: Ok Subject: [Tarantool-patches] [PATCH v4 40/53] sql: move MEM flags to mem.c 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 moves MEM flags to mem.c. This allow us to have more control over MEM state. Part of #5818 --- src/box/sql/mem.c | 52 ++++++++++++++++++++++++++++++++++++++ src/box/sql/mem.h | 63 ++-------------------------------------------- src/box/sql/vdbe.c | 3 --- 3 files changed, 54 insertions(+), 64 deletions(-) diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c index 83f17250d..1209df1ce 100644 --- a/src/box/sql/mem.c +++ b/src/box/sql/mem.c @@ -37,6 +37,58 @@ #include "box/tuple.h" #include "mpstream/mpstream.h" +/* One or more of the following flags are set to indicate the validOK + * representations of the value stored in the Mem struct. + * + * If the MEM_Null flag is set, then the value is an SQL NULL value. + * No other flags may be set in this case. + * + * If the MEM_Str flag is set then Mem.z points at a string representation. + * Usually this is encoded in the same unicode encoding as the main + * database (see below for exceptions). If the MEM_Term flag is also + * set, then the string is nul terminated. The MEM_Int and MEM_Real + * flags may coexist with the MEM_Str flag. + */ +#define MEM_Null 0x0001 /* Value is NULL */ +#define MEM_Str 0x0002 /* Value is a string */ +#define MEM_Int 0x0004 /* Value is an integer */ +#define MEM_Real 0x0008 /* Value is a real number */ +#define MEM_Blob 0x0010 /* Value is a BLOB */ +#define MEM_Bool 0x0020 /* Value is a bool */ +#define MEM_UInt 0x0040 /* Value is an unsigned integer */ +#define MEM_Frame 0x0080 /* Value is a VdbeFrame object */ +#define MEM_Undefined 0x0100 /* Value is undefined */ +#define MEM_Cleared 0x0200 /* NULL set by OP_Null, not from data */ +#define MEM_TypeMask 0x83ff /* Mask of type bits */ + +/* Whenever Mem contains a valid string or blob representation, one of + * the following flags must be set to determine the memory management + * policy for Mem.z. The MEM_Term flag tells us whether or not the + * 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 */ +#define MEM_Agg 0x4000 /* Mem.z points to an agg function context */ +#define MEM_Zero 0x8000 /* Mem.i contains count of 0s appended to blob */ +#define MEM_Subtype 0x10000 /* Mem.eSubtype is valid */ +#define MEM_Ptr 0x20000 /* Value is a generic pointer */ + +/** + * In contrast to Mem_TypeMask, this one allows to get + * pure type of memory cell, i.e. without _Dyn/_Zero and other + * auxiliary flags. + */ +enum { + MEM_PURE_TYPE_MASK = 0x7f +}; + +static_assert(MEM_PURE_TYPE_MASK == (MEM_Null | MEM_Str | MEM_Int | MEM_Real | + MEM_Blob | MEM_Bool | MEM_UInt), + "value of type mask must consist of corresponding to memory "\ + "type bits"); + bool mem_is_null(const struct Mem *mem) { diff --git a/src/box/sql/mem.h b/src/box/sql/mem.h index 70224b55a..8b6f6749d 100644 --- a/src/box/sql/mem.h +++ b/src/box/sql/mem.h @@ -318,58 +318,6 @@ int mem_compare(const struct Mem *left, const struct Mem *right, int *result, enum field_type type, struct coll *coll); -/* One or more of the following flags are set to indicate the validOK - * representations of the value stored in the Mem struct. - * - * If the MEM_Null flag is set, then the value is an SQL NULL value. - * No other flags may be set in this case. - * - * If the MEM_Str flag is set then Mem.z points at a string representation. - * Usually this is encoded in the same unicode encoding as the main - * database (see below for exceptions). If the MEM_Term flag is also - * set, then the string is nul terminated. The MEM_Int and MEM_Real - * flags may coexist with the MEM_Str flag. - */ -#define MEM_Null 0x0001 /* Value is NULL */ -#define MEM_Str 0x0002 /* Value is a string */ -#define MEM_Int 0x0004 /* Value is an integer */ -#define MEM_Real 0x0008 /* Value is a real number */ -#define MEM_Blob 0x0010 /* Value is a BLOB */ -#define MEM_Bool 0x0020 /* Value is a bool */ -#define MEM_UInt 0x0040 /* Value is an unsigned integer */ -#define MEM_Frame 0x0080 /* Value is a VdbeFrame object */ -#define MEM_Undefined 0x0100 /* Value is undefined */ -#define MEM_Cleared 0x0200 /* NULL set by OP_Null, not from data */ -#define MEM_TypeMask 0x83ff /* Mask of type bits */ - -/* Whenever Mem contains a valid string or blob representation, one of - * the following flags must be set to determine the memory management - * policy for Mem.z. The MEM_Term flag tells us whether or not the - * 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 */ -#define MEM_Agg 0x4000 /* Mem.z points to an agg function context */ -#define MEM_Zero 0x8000 /* Mem.i contains count of 0s appended to blob */ -#define MEM_Subtype 0x10000 /* Mem.eSubtype is valid */ -#define MEM_Ptr 0x20000 /* Value is a generic pointer */ - -/** - * In contrast to Mem_TypeMask, this one allows to get - * pure type of memory cell, i.e. without _Dyn/_Zero and other - * auxiliary flags. - */ -enum { - MEM_PURE_TYPE_MASK = 0x7f -}; - -static_assert(MEM_PURE_TYPE_MASK == (MEM_Null | MEM_Str | MEM_Int | MEM_Real | - MEM_Blob | MEM_Bool | MEM_UInt), - "value of type mask must consist of corresponding to memory "\ - "type bits"); - /** * Simple type to str convertor. It is used to simplify * error reporting. @@ -402,7 +350,7 @@ registerTrace(int iReg, Mem *p); * Return true if a memory cell is not marked as invalid. This macro * is for use inside assert() statements only. */ -#define memIsValid(M) ((M)->flags & MEM_Undefined)==0 +#define memIsValid(M) !mem_is_undefined(M) #endif /* @@ -451,7 +399,7 @@ int mem_apply_integer_type(struct Mem *); int sqlVdbeMemStringify(struct Mem *); int sqlVdbeMemNulTerminate(struct Mem *); int sqlVdbeMemExpandBlob(struct Mem *); -#define ExpandBlob(P) (((P)->flags&MEM_Zero)?sqlVdbeMemExpandBlob(P):0) +#define ExpandBlob(P) (mem_is_zeroblob(P)? sqlVdbeMemExpandBlob(P) : 0) void sql_value_apply_type(struct Mem *val, enum field_type type); @@ -563,13 +511,6 @@ columnNullValue(void); 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_Agg|MEM_Dyn|MEM_Frame))!=0) - - int sqlMemCompare(const Mem *, const Mem *, const struct coll *); /** diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c index fdcb4d1e6..edf845d97 100644 --- a/src/box/sql/vdbe.c +++ b/src/box/sql/vdbe.c @@ -575,7 +575,6 @@ case OP_SetDiag: { /* jump */ case OP_Gosub: { /* jump */ assert(pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor)); pIn1 = &aMem[pOp->p1]; - assert(VdbeMemDynamic(pIn1)==0); memAboutToChange(p, pIn1); mem_set_unsigned(pIn1, pOp - aOp); REGISTER_TRACE(p, pOp->p1, pIn1); @@ -617,7 +616,6 @@ case OP_InitCoroutine: { /* jump */ assert(pOp->p2>=0 && pOp->p2nOp); assert(pOp->p3>0 && pOp->p3nOp); pOut = &aMem[pOp->p1]; - assert(!VdbeMemDynamic(pOut)); mem_set_unsigned(pOut, pOp->p3 - 1); if (pOp->p2) goto jump_to_p2; break; @@ -659,7 +657,6 @@ case OP_EndCoroutine: { /* in1 */ */ case OP_Yield: { /* in1, jump */ pIn1 = &aMem[pOp->p1]; - assert(VdbeMemDynamic(pIn1)==0); int pcDest = (int)pIn1->u.u; mem_set_unsigned(pIn1, pOp - aOp); REGISTER_TRACE(p, pOp->p1, pIn1); -- 2.25.1