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 160AC6EC5D; Fri, 9 Apr 2021 21:12:44 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 160AC6EC5D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1617991964; bh=12wjDywB9gQADIe15Id/DkrzTcOCloJLhDPqBsmXBTw=; 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=JIOuoqR4MjSpPFIabprZJEF/VaiPXxPWzQ6QYF4ZzW2/bKH06Ojgu8/BdCdnRKxkT PpdX9lgv3e726bIyKIjwhqNtSJ13YJPR+0g4Ckt+xMQfkxZNkxx81Nnd/QrfuB0H2v eK9u2NN41COsyGqrhLF5G/eM6ingEODZEzukWN4Y= Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [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 710E16EC5F for ; Fri, 9 Apr 2021 21:11:45 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 710E16EC5F Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1lUvbc-0004II-LD; Fri, 09 Apr 2021 21:11:45 +0300 To: v.shpilevoy@tarantool.org, tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Fri, 9 Apr 2021 21:11:44 +0300 Message-Id: <58d128b714ab205f03d6508bd34623ecf4e825e2.1617984948.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: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD92FFCB8E6708E74807BAE725B9AE625DE765B0E193B5B7687182A05F538085040B1E96DF89F8BC0CF35BC7F22A8034BB9957229D26FEF66203B0F1ACA136C49EF X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7D3E352D4AD7EBF54EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006374F897F3E43A934888638F802B75D45FF914D58D5BE9E6BC1A93B80C6DEB9DEE97C6FB206A91F05B2676FDB7005DFF13D83D57BD70495A94607164437C8F97EC6D2E47CDBA5A96583C09775C1D3CA48CFA12191B5F2BB8629117882F4460429724CE54428C33FAD30A8DF7F3B2552694AC26CFBAC0749D213D2E47CDBA5A9658378DA827A17800CE7E688A9D963DC14319FA2833FD35BB23DF004C906525384302BEBFE083D3B9BA73A03B725D353964B0B7D0EA88DDEDAC722CA9DD8327EE4930A3850AC1BE2E735E4A630A5B664A4FFC4224003CC83647689D4C264860C145E X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CD0035DD76F8A8A4FBB964BA8A99D96980F40CF6A5B51E6609C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF0417BEADF48D1460699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34C2E47CA9A5606090C1D3DF1B40EB9E9A0311851220ACDE29B8DDD54B6DBE48DBED2BDAD77BCEEA271D7E09C32AA3244CCE4F0CA53C29BDD82E83AD415BCE5A38725D5B54B2FE4575FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojyO2lHpuZu4SB1XLtOMdL9A== X-Mailru-Sender: 689FA8AB762F73936BC43F508A06382236535A4080255BBA3F940A6D4E1344ED83D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v5 23/52] 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(). This function clears MEM and sets it to NULL. Part of #5818 --- src/box/sql/mem.c | 64 +++++++++++++++++++------------------------ src/box/sql/mem.h | 7 +++-- src/box/sql/vdbe.c | 14 ++++------ src/box/sql/vdbeapi.c | 4 +-- 4 files changed, 40 insertions(+), 49 deletions(-) diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c index aeb801c7c..937fa3272 100644 --- a/src/box/sql/mem.c +++ b/src/box/sql/mem.c @@ -267,6 +267,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) { @@ -2058,24 +2064,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. @@ -2106,12 +2094,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 */ @@ -3001,21 +2983,27 @@ port_lua_get_vdbemem(struct port *base, uint32_t *size) NULL, -1 - i, &field) < 0) { goto error; } + mem_clear(&val[i]); switch (field.type) { case MP_BOOL: - mem_set_bool(&val[i], field.bval); + val[i].flags = MEM_Bool; + val[i].u.b = field.bval; break; case MP_FLOAT: - mem_set_double(&val[i], field.fval); + val[i].flags = MEM_Real; + val[i].u.r = field.fval; break; case MP_DOUBLE: - mem_set_double(&val[i], field.dval); + val[i].flags = MEM_Real; + val[i].u.r = field.dval; break; case MP_INT: - mem_set_i64(&val[i], field.ival); + val[i].flags = MEM_Int; + val[i].u.i = field.ival; break; case MP_UINT: - mem_set_u64(&val[i], field.ival); + val[i].flags = MEM_UInt; + val[i].u.i = field.ival; break; case MP_STR: if (sqlVdbeMemSetStr(&val[i], field.sval.data, @@ -3024,7 +3012,6 @@ port_lua_get_vdbemem(struct port *base, uint32_t *size) goto error; break; case MP_NIL: - sqlVdbeMemSetNull(&val[i]); break; default: diag_set(ClientError, ER_SQL_EXECUTE, @@ -3071,22 +3058,28 @@ port_c_get_vdbemem(struct port *base, uint32_t *size) data = pe->mp; } uint32_t len; + mem_clear(&val[i]); const char *str; switch (mp_typeof(*data)) { case MP_BOOL: - mem_set_bool(&val[i], mp_decode_bool(&data)); + val[i].flags = MEM_Bool; + val[i].u.b = mp_decode_bool(&data); break; case MP_FLOAT: - mem_set_double(&val[i], mp_decode_float(&data)); + val[i].flags = MEM_Real; + val[i].u.r = mp_decode_float(&data); break; case MP_DOUBLE: - mem_set_double(&val[i], mp_decode_double(&data)); + val[i].flags = MEM_Real; + val[i].u.r = mp_decode_double(&data); break; case MP_INT: - mem_set_i64(&val[i], mp_decode_int(&data)); + val[i].flags = MEM_Int; + val[i].u.i = mp_decode_int(&data); break; case MP_UINT: - mem_set_u64(&val[i], mp_decode_uint(&data)); + val[i].flags = MEM_UInt; + val[i].u.u = mp_decode_uint(&data); break; case MP_STR: str = mp_decode_str(&data, &len); @@ -3095,7 +3088,6 @@ port_c_get_vdbemem(struct port *base, uint32_t *size) goto error; break; case MP_NIL: - sqlVdbeMemSetNull(&val[i]); break; default: diag_set(ClientError, ER_SQL_EXECUTE, diff --git a/src/box/sql/mem.h b/src/box/sql/mem.h index e3b55644e..581ef007a 100644 --- a/src/box/sql/mem.h +++ b/src/box/sql/mem.h @@ -162,6 +162,10 @@ mem_create(struct Mem *mem); void mem_destroy(struct Mem *mem); +/** Clear MEM and set it to NULL. */ +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 @@ -468,12 +472,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 2ad681fa4..c7d21ddd5 100644 --- a/src/box/sql/vdbe.c +++ b/src/box/sql/vdbe.c @@ -276,7 +276,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; } @@ -862,19 +862,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 3e9f1ff6f..4398b41b1 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_agg(pMem)); if (nByte <= 0) { - sqlVdbeMemSetNull(pMem); + mem_set_null(pMem); pMem->z = 0; } else { sqlVdbeMemClearAndResize(pMem, nByte); -- 2.25.1