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 8BF3F71828; Tue, 23 Mar 2021 12:46:18 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 8BF3F71828 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1616492778; bh=ME2QWjQ+W4bOMagb16soR5BOhFkQnPZLNLiGlyyy7C4=; 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=dAJ4vEiPOq0ljia7NU3LZ0iD8J9+tb5Quc5h9qtm7+iJEQPrGQ7EFl8wWc54uqZNv j89PvG9u0IqzKQYwk+vaQ5Hj8CTjTccEQ6kjBV2ol2RGJX3p94aVvopol2nrPqbVmV y2XtLFngkoWUwehMPzsQTB1SlsfT/6roLxmXMAG0= 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 43AFC68F4D for ; Tue, 23 Mar 2021 12:35:47 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 43AFC68F4D Received: by smtp47.i.mail.ru with esmtpa (envelope-from ) id 1lOdRy-0006lA-Fr; Tue, 23 Mar 2021 12:35:46 +0300 To: v.shpilevoy@tarantool.org, tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Tue, 23 Mar 2021 12:35:46 +0300 Message-Id: <433d6a2d52500392bedeec79b259aba63ad7eec5.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: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD95D6E7CC48CB1F5F19D4B90E2C0E110A6B701D7D268243E19182A05F538085040AE35FB5F3D23A33D1A096E2C2329B8518747347CD0305D83EDC171BB39146ACD X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7DC6E0FF9A9D6BE87EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006378997215BCAA11D778638F802B75D45FF914D58D5BE9E6BC131B5C99E7648C95C686AF563A045C75ED06E4A7FBD10FF2ECB91075B1F1876B9A471835C12D1D9774AD6D5ED66289B5278DA827A17800CE75A31C54DA8CF07A79FA2833FD35BB23D2EF20D2F80756B5F868A13BD56FB6657A471835C12D1D977725E5C173C3A84C3F7ED4D6813B5CA04117882F4460429728AD0CFFFB425014E868A13BD56FB6657D81D268191BDAD3DC09775C1D3CA48CFF31731537A4A6991BA3038C0950A5D36C8A9BA7A39EFB766EC990983EF5C0329BA3038C0950A5D36D5E8D9A59859A8B686502E30F343167476E601842F6C81A1F004C906525384307823802FF610243DF43C7A68FF6260569E8FC8737B5C2249EC8D19AE6D49635B3BBE47FD9DD3FB59A8DF7F3B2552694A57739F23D657EF2B13377AFFFEAFD26923F8577A6DFFEA7CDDB9BF3B882869D593EC92FD9297F6715571747095F342E857739F23D657EF2BD5E8D9A59859A8B6B67FC62909E22F84089D37D7C0E48F6C5571747095F342E857739F23D657EF2B6825BDBE14D8E7024847893F9AA87235E5BFE6E7EFDEDCD789D4C264860C145E X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A24A6D60772A99906F8E1CD14B953EB46DDF6FAE44F673FC50355D89D7DBCDD132 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C686AF563A045C75ED06E4A7FBD10FF2ECB91075B1F1876B99C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF0417BEADF48D1460699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34023CA4E4726A7D6CC0BF27E51A53782C0F535D3720797FAE42AFD965F69B1214C188470EB9F750811D7E09C32AA3244CA50267B26D63C013A0826EC542C838DC3A76366E8A9DE7CAFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojWJZv20R+6UhwMfX75QWdWw== X-Mailru-Sender: 5C3750E245F362008BC1685FEC6306ED9808036DC5047A511A096E2C2329B851FA95C477BC5130F85105BD0848736F9966FEC6BF5C9C28D97E07721503EA2E00ED97202A5A4E92BF7402F9BA4338D657ED14614B50AE0675 X-Mras: Ok Subject: [Tarantool-patches] [PATCH v4 23/53] sql: introduce mem_set_null() 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_set_null(). Function mem_set_null() clears MEM and sets it to NULL. Part of #5818 --- src/box/sql/func.c | 4 ++-- src/box/sql/mem.c | 36 +++++++++--------------------------- src/box/sql/mem.h | 6 +++--- src/box/sql/vdbe.c | 14 ++++++-------- src/box/sql/vdbeapi.c | 4 ++-- 5 files changed, 22 insertions(+), 42 deletions(-) diff --git a/src/box/sql/func.c b/src/box/sql/func.c index 6b6081150..b61de18d8 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -290,7 +290,7 @@ port_lua_get_vdbemem(struct port *base, uint32_t *size) goto error; break; case MP_NIL: - sqlVdbeMemSetNull(&val[i]); + mem_set_null(&val[i]); break; default: diag_set(ClientError, ER_SQL_EXECUTE, @@ -361,7 +361,7 @@ port_c_get_vdbemem(struct port *base, uint32_t *size) goto error; break; case MP_NIL: - sqlVdbeMemSetNull(&val[i]); + mem_set_null(&val[i]); break; default: diag_set(ClientError, ER_SQL_EXECUTE, diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c index c84b3775d..da2aa5c94 100644 --- a/src/box/sql/mem.c +++ b/src/box/sql/mem.c @@ -257,6 +257,12 @@ mem_destroy(struct Mem *mem) mem->zMalloc = NULL; } +void +mem_set_null(struct Mem *mem) +{ + mem_clear(mem); +} + int mem_copy(struct Mem *to, const struct Mem *from) { @@ -323,7 +329,7 @@ int mem_concat(struct Mem *left, struct Mem *right, struct Mem *result) { assert(result != right); - sqlVdbeMemSetNull(result); + mem_clear(result); result->field_type = field_type_MAX; if (((left->flags | right->flags) & MEM_Null) != 0) { @@ -374,7 +380,7 @@ int mem_arithmetic(const struct Mem *left, const struct Mem *right, struct Mem *result, int op) { - sqlVdbeMemSetNull(result); + mem_clear(result); result->field_type = FIELD_TYPE_NUMBER; if (((left->flags | right->flags) & MEM_Null) != 0) return 0; @@ -559,7 +565,7 @@ mem_arithmetic(const struct Mem *left, const struct Mem *right, int mem_bitwise(struct Mem *left, struct Mem *right, struct Mem *result, int op) { - sqlVdbeMemSetNull(result); + mem_clear(result); result->field_type = FIELD_TYPE_INTEGER; if (((left->flags | right->flags) & MEM_Null) != 0) return 0; @@ -2033,24 +2039,6 @@ sqlVdbeMemSetStr(Mem * pMem, /* Memory cell to set to string value */ return 0; } -/* - * Delete any previous value and set the value stored in *pMem to NULL. - * - * This routine calls the Mem.xDel destructor to dispose of values that - * require the destructor. But it preserves the Mem.zMalloc memory allocation. - * To free all resources, use mem_destroy(), which both calls this - * routine to invoke the destructor and deallocates Mem.zMalloc. - * - * Use this routine to reset the Mem prior to insert a new value. - * - * Use mem_destroy() to complete erase the Mem prior to abandoning it. - */ -void -sqlVdbeMemSetNull(Mem * pMem) -{ - mem_clear(pMem); -} - /* * Delete any previous value and set the value to be a BLOB of length * n containing all zeros. @@ -2081,12 +2069,6 @@ sqlValueSetStr(sql_value * v, /* Value to be set */ sqlVdbeMemSetStr((Mem *) v, z, n, 1, xDel); } -void -sqlValueSetNull(sql_value * p) -{ - sqlVdbeMemSetNull((Mem *) p); -} - /* * Free an sql_value object */ diff --git a/src/box/sql/mem.h b/src/box/sql/mem.h index 3561b49b1..dc0d4a284 100644 --- a/src/box/sql/mem.h +++ b/src/box/sql/mem.h @@ -163,6 +163,9 @@ mem_create(struct Mem *mem); void mem_destroy(struct Mem *mem); +void +mem_set_null(struct Mem *mem); + /** * Copy content of MEM from one MEM to another. In case source MEM contains * string or binary and allocation type is not STATIC, this value is copied to @@ -431,12 +434,9 @@ mem_set_double(struct Mem *mem, double value); int sqlVdbeMemSetStr(struct Mem *, const char *, int, u8, void (*)(void *)); void -sqlVdbeMemSetNull(struct Mem *); -void sqlVdbeMemSetZeroBlob(struct Mem *, int); void sqlValueSetStr(struct Mem *, int, const void *, void (*)(void *)); -void sqlValueSetNull(struct Mem *); void sqlValueFree(struct Mem *); struct Mem *sqlValueNew(struct sql *); diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c index 80497b7b2..f0b56033a 100644 --- a/src/box/sql/vdbe.c +++ b/src/box/sql/vdbe.c @@ -244,7 +244,7 @@ vdbe_prepare_null_out(struct Vdbe *v, int n) assert(n <= (v->nMem + 1 - v->nCursor)); struct Mem *out = &v->aMem[n]; memAboutToChange(v, out); - sqlVdbeMemSetNull(out); + mem_set_null(out); out->field_type = field_type_MAX; return out; } @@ -830,19 +830,17 @@ case OP_String: { /* out2 */ */ case OP_Null: { /* out2 */ int cnt; - u16 nullFlag; pOut = vdbe_prepare_null_out(p, pOp->p2); cnt = pOp->p3-pOp->p2; assert(pOp->p3<=(p->nMem+1 - p->nCursor)); - pOut->flags = nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null; - pOut->n = 0; + if (pOp->p1 != 0) + pOut->flags = MEM_Null|MEM_Cleared; while( cnt>0) { pOut++; memAboutToChange(p, pOut); - sqlVdbeMemSetNull(pOut); - pOut->flags = nullFlag; - pOut->field_type = field_type_MAX; - pOut->n = 0; + mem_set_null(pOut); + if (pOp->p1 != 0) + pOut->flags = MEM_Null|MEM_Cleared; cnt--; } break; diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c index 04016ea54..76af333e8 100644 --- a/src/box/sql/vdbeapi.c +++ b/src/box/sql/vdbeapi.c @@ -201,7 +201,7 @@ sql_result_bool(struct sql_context *ctx, bool value) void sql_result_null(sql_context * pCtx) { - sqlVdbeMemSetNull(pCtx->pOut); + mem_set_null(pCtx->pOut); } void @@ -382,7 +382,7 @@ createAggContext(sql_context * p, int nByte) Mem *pMem = p->pMem; assert(!mem_is_aggregate(pMem)); if (nByte <= 0) { - sqlVdbeMemSetNull(pMem); + mem_set_null(pMem); pMem->z = 0; } else { sqlVdbeMemClearAndResize(pMem, nByte); -- 2.25.1