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 333C36AA80; Tue, 23 Mar 2021 12:51:21 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 333C36AA80 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1616493081; bh=atu47I2IJoHia4gGAfTWXNP0m/WWIuw1925mJynf7NM=; 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=YvVkFuKOhAfYmD4/fai7ifAhToi1vCcDdExqluLxzF7uO2L3aBn4vMOn+gKShpSwI 4koQfxYO6Ot8eH+A3nJUy/vOUUjEEPQoQaTOIqATZbErm4VyTBi6B6CXuwwfXr1I+X pcs1SroP3D2Wqnnm2Bx9u0AiHZk2jSEqsiTRFf4c= Received: from smtp35.i.mail.ru (smtp35.i.mail.ru [94.100.177.95]) (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 011DD68F56 for ; Tue, 23 Mar 2021 12:36:07 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 011DD68F56 Received: by smtp35.i.mail.ru with esmtpa (envelope-from ) id 1lOdSI-000610-9P; Tue, 23 Mar 2021 12:36:06 +0300 To: v.shpilevoy@tarantool.org, tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Tue, 23 Mar 2021 12:36:06 +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: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD95D6E7CC48CB1F5F1DDD90A25A8FA528D0BFD61B598B81272182A05F5380850400A44E02DDE6A05C34B104BB4BE259CA6EC00E403CA6E02304BB653351F379E34 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7A3295C83650092F9EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006377A9AC615CFEE341F8638F802B75D45FF914D58D5BE9E6BC131B5C99E7648C95C686AF563A045C75EF4DA451A14B7A4F246B133B1646920FBA471835C12D1D9774AD6D5ED66289B5278DA827A17800CE709B92020B71E24959FA2833FD35BB23D2EF20D2F80756B5F868A13BD56FB6657A471835C12D1D977725E5C173C3A84C311471C67CF6D96D5117882F4460429728AD0CFFFB425014E868A13BD56FB6657D81D268191BDAD3DC09775C1D3CA48CFA852295A8FD172E7BA3038C0950A5D36C8A9BA7A39EFB766EC990983EF5C0329BA3038C0950A5D36D5E8D9A59859A8B6A0B0F0505B2A513476E601842F6C81A1F004C906525384307823802FF610243DF43C7A68FF6260569E8FC8737B5C2249EC8D19AE6D49635B3BBE47FD9DD3FB59A8DF7F3B2552694A57739F23D657EF2B13377AFFFEAFD26923F8577A6DFFEA7C7D149460FF1CF91893EC92FD9297F6715571747095F342E857739F23D657EF2BD5E8D9A59859A8B6EC71F829093BE88A089D37D7C0E48F6C5571747095F342E857739F23D657EF2B6825BDBE14D8E7024847893F9AA87235E5BFE6E7EFDEDCD789D4C264860C145E X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C686AF563A045C75EF4DA451A14B7A4F246B133B1646920FB9C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF0417BEADF48D1460699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D340FE9920E7E3E5C6231F4DFC14FD8D24F3C617A1AC97DFD7BC71BC0BE061D467D4C2EB411324C149B1D7E09C32AA3244CEEC7923FBA58CAEC5DEE8E0D10BAA9F351E887DA02A9F7BFFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojWJZv20R+6Uho3FBCVgR06w== X-Mailru-Sender: 5C3750E245F362008BC1685FEC6306EDE684AFF70C9F41B24B104BB4BE259CA6BE4EBEF89FC7D6FA5105BD0848736F9966FEC6BF5C9C28D97E07721503EA2E00ED97202A5A4E92BF7402F9BA4338D657ED14614B50AE0675 X-Mras: Ok Subject: [Tarantool-patches] [PATCH v4 33/53] sql: introduce mem_append_to_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_append_to_binary() function. Function mem_append_to_binary() receives MEM with binary value and append to it another binary value. MEM is updated accordingly. Part of #5818 --- src/box/sql/mem.c | 16 ++++++++++++++++ src/box/sql/mem.h | 3 +++ src/box/sql/vdbeaux.c | 23 +++++++++++++++-------- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c index 63a4d0d3c..7885caaf5 100644 --- a/src/box/sql/mem.c +++ b/src/box/sql/mem.c @@ -492,6 +492,22 @@ mem_set_zerobinary(struct Mem *mem, int n) mem->field_type = FIELD_TYPE_VARBINARY; } +int +mem_append_to_binary(struct Mem *mem, const char *value, uint32_t size) +{ + if ((mem->flags & MEM_Blob) == 0) { + diag_set(ClientError, ER_INCONSISTENT_TYPES, "varbinary", + mem_type_to_str(mem)); + return -1; + } + assert(mem->field_type == FIELD_TYPE_VARBINARY); + if (sqlVdbeMemGrow(mem, mem->n + size, 1) != 0) + return -1; + memcpy(&mem->z[mem->n], value, size); + mem->n += size; + 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 4b34bba6c..3bd04bbbd 100644 --- a/src/box/sql/mem.h +++ b/src/box/sql/mem.h @@ -235,6 +235,9 @@ mem_set_zerobinary(struct Mem *mem, int n); int mem_copy_binary(struct Mem *mem, const char *value, uint32_t size); +int +mem_append_to_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/vdbeaux.c b/src/box/sql/vdbeaux.c index 86da1449c..2e8669138 100644 --- a/src/box/sql/vdbeaux.c +++ b/src/box/sql/vdbeaux.c @@ -1305,19 +1305,26 @@ sqlVdbeList(Vdbe * p) * has not already been seen. */ if (pOp->p4type == P4_SUBPROGRAM) { - int nByte = (nSub + 1) * sizeof(SubProgram *); int j; for (j = 0; j < nSub; j++) { if (apSub[j] == pOp->p4.pProgram) break; } - if (j == nSub && - sqlVdbeMemGrow(pSub, nByte, - nSub != 0) == 0) { - apSub = (SubProgram **) pSub->z; - apSub[nSub++] = pOp->p4.pProgram; - pSub->flags |= MEM_Blob; - pSub->n = nSub * sizeof(SubProgram *); + if (j == nSub) { + uint32_t size = sizeof(SubProgram *); + char *value = (char *)&pOp->p4.pProgram; + if (nSub == 0) { + if (mem_copy_binary(pSub, value, + size) != 0) + return -1; + } else { + assert(0); + if (mem_append_to_binary(pSub, + value, + size) != 0) + return -1; + } + ++nSub; } } } -- 2.25.1