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 C70216BD38; Tue, 23 Mar 2021 12:50:17 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org C70216BD38 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1616493017; bh=e7Zox+5i/LBhCTh+JWWSk6L3dfTkgDY0hcENFEZfG1U=; 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=KlZvTmBVbdmiFikjvTRI2Ivk6fb3/a9UnF4sirT7PkGWCUDI0Sidm7Y7rslE3IGG8 TqAID2fuqJ5eMh0WkXeJ+xOFgS6HIIaP9j4XsBaKVcTrFbAmVndpEUmkzoQps7CjYG vno+l68OTQpGKIc2ImXu7USzx2YkHK9l4RxJkYsE= Received: from smtp55.i.mail.ru (smtp55.i.mail.ru [217.69.128.35]) (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 68A7C68F54 for ; Tue, 23 Mar 2021 12:36:03 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 68A7C68F54 Received: by smtp55.i.mail.ru with esmtpa (envelope-from ) id 1lOdSE-0001pS-PP; Tue, 23 Mar 2021 12:36:03 +0300 To: v.shpilevoy@tarantool.org, tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Tue, 23 Mar 2021 12:36:02 +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: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD95D6E7CC48CB1F5F1C82687294EF6886B62CC997B0B8C95C4182A05F538085040D654134B3AB0ADD7D9562C18D988F946EC00E403CA6E0230279FD96364DE4945 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7F68DA2F3749BB650EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637225475490A77DC518638F802B75D45FF914D58D5BE9E6BC131B5C99E7648C95C686AF563A045C75E47A6AA59B803CB02B4024D0F52B98716A471835C12D1D9774AD6D5ED66289B5278DA827A17800CE77E7E81EEA8A9722B8941B15DA834481FCF19DD082D7633A0EF3E4896CB9E6436389733CBF5DBD5E9D5E8D9A59859A8B69EAAB76869E07C3ECC7F00164DA146DA6F5DAA56C3B73B237318B6A418E8EAB8D32BA5DBAC0009BE9E8FC8737B5C2249D6D857AE2BC7FD8476E601842F6C81A12EF20D2F80756B5F7E9C4E3C761E06A776E601842F6C81A127C277FBC8AE2E8B020AB5FA1284452E3AA81AA40904B5D9DBF02ECDB25306B2201CA6A4E26CD07C3BBE47FD9DD3FB595F5C1EE8F4F765FC72CEEB2601E22B091A620F70A64A45A99449624AB7ADAF3735872C767BF85DA29E625A9149C048EE0A3850AC1BE2E73557739F23D657EF2BC8A9BA7A39EFB7666BA297DBC24807EA089D37D7C0E48F6C8AA50765F7900637C3090DF2C0002BD1EFF80C71ABB335746BA297DBC24807EA27F269C8F02392CDC58410348177836E285124B2A10EEC6C00306258E7E6ABB4E4A6367B16DE6309 X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A24A6D60772A99906F8E1CD14B953EB46D5F8D3D94CDFB6293355D89D7DBCDD132 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C686AF563A045C75E47A6AA59B803CB02B4024D0F52B987169C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF0417BEADF48D1460699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34197948450CB5442A1D7C79FED4D4C9E197E30FD35140C5A5BE51A906663331FD2511D8B9C7F4719A1D7E09C32AA3244CE73CC5FC51D94A67DB6F723F35E129A851E887DA02A9F7BFFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojWJZv20R+6UgBdg7iahs/Tw== X-Mailru-Sender: 5C3750E245F362008BC1685FEC6306EDF05DDF77400931EDD9562C18D988F946BE4EBEF89FC7D6FA5105BD0848736F9966FEC6BF5C9C28D97E07721503EA2E00ED97202A5A4E92BF7402F9BA4338D657ED14614B50AE0675 X-Mras: Ok Subject: [Tarantool-patches] [PATCH v4 31/53] sql: introduce mem_copy_binary() 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_copy_binary() function. Function mem_copy_binary() clears MEM, allocates enough memory and copies given binary to allocated memory. Part of #5818 --- src/box/sql/mem.c | 14 ++++++++++++++ src/box/sql/mem.h | 3 +++ src/box/sql/vdbe.c | 7 ++----- src/box/sql/vdbeapi.c | 4 ++-- src/box/sql/vdbesort.c | 6 +----- 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c index 5ee49cdca..99beec9ad 100644 --- a/src/box/sql/mem.c +++ b/src/box/sql/mem.c @@ -465,6 +465,20 @@ mem_set_allocated_binary(struct Mem *mem, char *value, uint32_t size) mem_set_dyn_bin(mem, value, size, 0); } +int +mem_copy_binary(struct Mem *mem, const char *value, uint32_t size) +{ + bool is_own_value = (mem->flags & MEM_Blob) != 0 && mem->z == value; + if (sqlVdbeMemGrow(mem, size, is_own_value) != 0) + return -1; + if (!is_own_value) + memcpy(mem->z, value, size); + mem->n = size; + mem->flags = MEM_Blob; + mem->field_type = FIELD_TYPE_VARBINARY; + return 0; +} + int mem_copy(struct Mem *to, const struct Mem *from) { diff --git a/src/box/sql/mem.h b/src/box/sql/mem.h index 3d33fa98b..f44bb9bcf 100644 --- a/src/box/sql/mem.h +++ b/src/box/sql/mem.h @@ -229,6 +229,9 @@ mem_set_dynamic_binary(struct Mem *mem, char *value, uint32_t size); void mem_set_allocated_binary(struct Mem *mem, char *value, uint32_t size); +int +mem_copy_binary(struct Mem *mem, const char *value, uint32_t size); + int mem_copy(struct Mem *to, const struct Mem *from); diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c index 6ae77db63..9fc08e30c 100644 --- a/src/box/sql/vdbe.c +++ b/src/box/sql/vdbe.c @@ -2105,11 +2105,8 @@ case OP_MakeRecord: { * routine. */ if (bIsEphemeral) { - if (sqlVdbeMemClearAndResize(pOut, tuple_size) != 0) + if (mem_copy_binary(pOut, tuple, tuple_size) != 0) goto abort_due_to_error; - pOut->flags = MEM_Blob; - pOut->n = tuple_size; - memcpy(pOut->z, tuple, tuple_size); region_truncate(region, used); } else { /* Allocate memory on the region for the tuple @@ -2449,7 +2446,7 @@ case OP_SequenceTest: { * Open a new cursor that points to a fake table that contains a single * row of data. The content of that one row is the content of memory * register P2. In other words, cursor P1 becomes an alias for the - * MEM_Blob content contained in register P2. + * MEM with binary content contained in register P2. * * A pseudo-table created by this opcode is used to hold a single * row output from the sorter so that the row can be decomposed into diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c index 0e51e4809..299172554 100644 --- a/src/box/sql/vdbeapi.c +++ b/src/box/sql/vdbeapi.c @@ -188,7 +188,7 @@ sql_result_blob(sql_context * pCtx, mem_set_allocated_binary(pCtx->pOut, (char *)z, n); else if (xDel != SQL_TRANSIENT) mem_set_dynamic_binary(pCtx->pOut, (char *)z, n); - else if (sqlVdbeMemSetStr(pCtx->pOut, z, n, 0, xDel) != 0) + else if (mem_copy_binary(pCtx->pOut, z, n) != 0) pCtx->is_aborted = true; } @@ -843,7 +843,7 @@ sql_bind_blob(sql_stmt * pStmt, mem_set_allocated_binary(var, (char *)zData, nData); else if (xDel != SQL_TRANSIENT) mem_set_dynamic_binary(var, (char *)zData, nData); - else if (sqlVdbeMemSetStr(var, zData, nData, 0, xDel) != 0) + else if (mem_copy_binary(var, zData, nData) != 0) return -1; return sql_bind_type(p, i, "varbinary"); } diff --git a/src/box/sql/vdbesort.c b/src/box/sql/vdbesort.c index a9a5f45af..51fe691d2 100644 --- a/src/box/sql/vdbesort.c +++ b/src/box/sql/vdbesort.c @@ -2164,12 +2164,8 @@ sqlVdbeSorterRowkey(const VdbeCursor * pCsr, Mem * pOut) assert(pCsr->eCurType == CURTYPE_SORTER); pSorter = pCsr->uc.pSorter; pKey = vdbeSorterRowkey(pSorter, &nKey); - if (sqlVdbeMemClearAndResize(pOut, nKey)) { + if (mem_copy_binary(pOut, pKey, nKey) != 0) return -1; - } - pOut->n = nKey; - MemSetTypeFlag(pOut, MEM_Blob); - memcpy(pOut->z, pKey, nKey); return 0; } -- 2.25.1