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 A1EE36EC5D; Fri, 9 Apr 2021 23:05:29 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A1EE36EC5D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1617998729; bh=bDRreFG+MV/eTXOiH1hty07ckVZwPml2x9VLPUZMPBQ=; 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=MPhOMP3Z861MiOkj1Mlarhf9Ha6PCrSXa1lvR+sh376b+/neMEnHcZoU0gYeC8kSf M+bLqVa7Vu/T3nh6PB8cAuZNVYGb4al9xuqKaOxmBBZYEOOZcOXyaAOlKib0cwqvT4 lrQaOKe/xOtUrhWIe1dvXHATW6ZVZ/Mu7s0AOArk= Received: from smtpng2.m.smailru.net (smtpng2.m.smailru.net [94.100.179.3]) (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 D2CB86EC5D for ; Fri, 9 Apr 2021 23:05:28 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org D2CB86EC5D Received: by smtpng2.m.smailru.net with esmtpa (envelope-from ) id 1lUxNf-0005qk-WF; Fri, 09 Apr 2021 23:05:28 +0300 To: v.shpilevoy@tarantool.org, tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Fri, 9 Apr 2021 23:05:27 +0300 Message-Id: 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: 4F1203BC0FB41BD92FFCB8E6708E7480EBD5CA77A668ECB87DA2124B0A8E6609182A05F5380850403220248EF9071605C1E10863614DA321957229D26FEF6622F737CB2B0C1F74ED X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7F2EC3597058CFA6DEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637CE3A619BB4CB99268638F802B75D45FF914D58D5BE9E6BC1A93B80C6DEB9DEE97C6FB206A91F05B2EB6F16C826077E3843AD375FDE6C494221114FFCE5AE9CDCD2E47CDBA5A96583C09775C1D3CA48CF643C8550F8485502117882F4460429724CE54428C33FAD30A8DF7F3B2552694AC26CFBAC0749D213D2E47CDBA5A9658378DA827A17800CE7934314F73869482B9FA2833FD35BB23DF004C906525384302BEBFE083D3B9BA73A03B725D353964B0B7D0EA88DDEDAC722CA9DD8327EE4930A3850AC1BE2E735C6EABA9B74D0DA47B5C8C57E37DE458BEDA766A37F9254B7 X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A2AD77751E876CB595E8F7B195E1C978310CCB944C547E9CAF8513B07AB14EF0B5 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CD0035DD76F8A8A4F63830152A87C95B58BBB33C60424CAD19C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF0417BEADF48D1460699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34F7CC4EA888783AE0117F877A95F924354F7B4A0545460A829DCB2EFBBEE51FBAA3F3E3CF2B900FB91D7E09C32AA3244CE2E42A6BCD5D6A6A4DAC8B591702B75835DA7DC5AF9B58C0FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojyO2lHpuZu4Q9TUMSwd57gQ== X-Mailru-Sender: 689FA8AB762F73936BC43F508A063822D82E3B41A2A6A9F8E5A8B36F94A323AE83D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v5 31/52] sql: introduce mem_set_zerobin() 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_zerobin() function. This function clears MEM and sets it to binary value that consists of given number of zero bytes. Part of #5818 --- src/box/sql/mem.c | 29 +++++++++++++---------------- src/box/sql/mem.h | 8 ++++++-- src/box/sql/vdbeapi.c | 6 +++--- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c index e30795de5..508b1dee3 100644 --- a/src/box/sql/mem.c +++ b/src/box/sql/mem.c @@ -507,6 +507,19 @@ mem_copy_bin(struct Mem *mem, const char *value, uint32_t size) return 0; } +void +mem_set_zerobin(struct Mem *mem, int n) +{ + mem_destroy(mem); + if (n < 0) + n = 0; + mem->u.nZero = n; + mem->z = NULL; + mem->n = 0; + mem->flags = MEM_Blob | MEM_Zero; + mem->field_type = FIELD_TYPE_VARBINARY; +} + int mem_copy(struct Mem *to, const struct Mem *from) { @@ -2256,22 +2269,6 @@ sqlVdbeMemSetStr(Mem * pMem, /* Memory cell to set to string value */ return 0; } -/* - * Delete any previous value and set the value to be a BLOB of length - * n containing all zeros. - */ -void -sqlVdbeMemSetZeroBlob(Mem * pMem, int n) -{ - mem_destroy(pMem); - pMem->flags = MEM_Blob | MEM_Zero; - pMem->n = 0; - if (n < 0) - n = 0; - pMem->u.nZero = n; - pMem->z = 0; -} - /* * Free an sql_value object */ diff --git a/src/box/sql/mem.h b/src/box/sql/mem.h index e17a722f4..0aeb23496 100644 --- a/src/box/sql/mem.h +++ b/src/box/sql/mem.h @@ -274,6 +274,12 @@ mem_set_bin_dynamic(struct Mem *mem, char *value, uint32_t size); void mem_set_bin_allocated(struct Mem *mem, char *value, uint32_t size); +/** + * Clear MEM and set it to VARBINARY. The binary value consist of n zero bytes. + */ +void +mem_set_zerobin(struct Mem *mem, int n); + /** * Copy binary value to a newly allocated memory. The MEM type becomes * VARBINARY. @@ -560,8 +566,6 @@ mem_set_ptr(struct Mem *mem, void *ptr); int sqlVdbeMemSetStr(struct Mem *, const char *, int, u8, void (*)(void *)); -void -sqlVdbeMemSetZeroBlob(struct Mem *, int); void sqlValueFree(struct Mem *); struct Mem *sqlValueNew(struct sql *); diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c index d16b92cf6..6d9103ff2 100644 --- a/src/box/sql/vdbeapi.c +++ b/src/box/sql/vdbeapi.c @@ -266,7 +266,7 @@ sql_result_value(sql_context * pCtx, sql_value * pValue) void sql_result_zeroblob(sql_context * pCtx, int n) { - sqlVdbeMemSetZeroBlob(pCtx->pOut, n); + mem_set_zerobin(pCtx->pOut, n); } int @@ -278,7 +278,7 @@ sql_result_zeroblob64(sql_context * pCtx, u64 n) "is too big"); return -1; } - sqlVdbeMemSetZeroBlob(pCtx->pOut, (int)n); + mem_set_zerobin(pCtx->pOut, (int)n); return 0; } @@ -956,7 +956,7 @@ sql_bind_zeroblob(sql_stmt * pStmt, int i, int n) Vdbe *p = (Vdbe *) pStmt; if (vdbeUnbind(p, i) != 0) return -1; - sqlVdbeMemSetZeroBlob(&p->aVar[i - 1], n); + mem_set_zerobin(&p->aVar[i - 1], n); return 0; } -- 2.25.1