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 4F39C6EC61; Fri, 9 Apr 2021 23:07:01 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 4F39C6EC61 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1617998821; bh=3T5pnos7YkZCjF3hXDJre4SYKc14CGkHYZne0TpJAFk=; 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=yf3w3qLzBfwVMV28ZAeErz2FBC6wR1E7fewF7i9bTN94LxyGamzcNH6URKIGQL7iQ oQE8AA4PkFV01lU8k4L4GTB/V3KChUBdYjKjIxnmLoR2HrrP6kLPvtncBfdC3EQOpJ VY7Wp10Maq/EpEPRXted++4awA//ER/hnN+oOJ2s= 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 48A4B6EC5D for ; Fri, 9 Apr 2021 23:05:34 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 48A4B6EC5D Received: by smtpng2.m.smailru.net with esmtpa (envelope-from ) id 1lUxNl-0005s4-EB; Fri, 09 Apr 2021 23:05:33 +0300 To: v.shpilevoy@tarantool.org, tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Fri, 9 Apr 2021 23:05:33 +0300 Message-Id: <6d76eee6ea147188aced9dfa18603bd7d2c2e744.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: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD92FFCB8E6708E7480EBD5CA77A668ECB87DA2124B0A8E6609182A05F538085040C63FF36DA4149A3FDF393FF15C64CE7F957229D26FEF66267FF9623D647F4B22 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7F1942E6D70B4A2F0EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006378B49D47CE295E66E8638F802B75D45FF914D58D5BE9E6BC1A93B80C6DEB9DEE97C6FB206A91F05B2C2E11D0035E7D8BDA7BA8C49C6E00CEF85184F9B92705903D2E47CDBA5A96583C09775C1D3CA48CF2609375A3A81E2DD117882F4460429724CE54428C33FAD30A8DF7F3B2552694AC26CFBAC0749D213D2E47CDBA5A9658378DA827A17800CE799D27C14FCE6E5989FA2833FD35BB23DF004C906525384302BEBFE083D3B9BA73A03B725D353964B0B7D0EA88DDEDAC722CA9DD8327EE4930A3850AC1BE2E735C6EABA9B74D0DA47B5C8C57E37DE458BEDA766A37F9254B7 X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A2AD77751E876CB595E8F7B195E1C978310CCB944C547E9CAF3657BD1E38EB9DB5 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CD0035DD76F8A8A4F44A747E3D9CD28752F328240EDE6BCE59C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF0417BEADF48D1460699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D344F2126FF337FA651B38EC2BB44FB52DF876784376DC038D24257A53F649E222418B17902531A1FA61D7E09C32AA3244C6F30B87160CF78C2A0DD4B799F2DFA75795D98D676DD64D0FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojyO2lHpuZu4TTongOWi/+zA== X-Mailru-Sender: 689FA8AB762F73936BC43F508A063822050385F6F73B7244D27BF654AFC4D3B683D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v5 34/52] sql: refactor mem_set_ptr() 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" Thank you for the review! My answer and new patch below. On 30.03.2021 02:06, Vladislav Shpilevoy wrote: > Thanks for the patch! > > I think mem_set_ptr() name was better. Was shorter and still easy to > understand. > >> diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c >> index fd2710478..3701741ef 100644 >> --- a/src/box/sql/mem.c >> +++ b/src/box/sql/mem.c >> @@ -595,6 +595,15 @@ mem_set_undefined(struct Mem *mem) >> mem->field_type = field_type_MAX; >> } >> >> +void >> +mem_set_pointer(struct Mem *mem, void *ptr) >> +{ >> + mem_clear(mem); >> + mem->flags = MEM_Ptr; >> + mem->u.p = ptr; >> + mem->field_type = field_type_MAX; > > mem_clear() already sets the type. Fixed. New patch: commit 6d76eee6ea147188aced9dfa18603bd7d2c2e744 Author: Mergen Imeev Date: Tue Mar 16 14:36:24 2021 +0300 sql: refactor mem_set_ptr() This patch refactors mem_set_ptr() function. Also, it moves the function to all others mem_set_*() functions. Part of #5818 diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c index b97904f22..4091161ce 100644 --- a/src/box/sql/mem.c +++ b/src/box/sql/mem.c @@ -596,6 +596,14 @@ mem_set_invalid(struct Mem *mem) mem->flags = MEM_Undefined; } +void +mem_set_ptr(struct Mem *mem, void *ptr) +{ + mem_clear(mem); + mem->flags = MEM_Ptr; + mem->u.p = ptr; +} + int mem_copy(struct Mem *to, const struct Mem *from) { @@ -2241,14 +2249,6 @@ sqlVdbeMemClearAndResize(Mem * pMem, int szNew) return 0; } -void -mem_set_ptr(struct Mem *mem, void *ptr) -{ - mem_destroy(mem); - mem->flags = MEM_Ptr; - mem->u.p = ptr; -} - /* * Free an sql_value object */ diff --git a/src/box/sql/mem.h b/src/box/sql/mem.h index fe3d8d98f..ae5d78ecb 100644 --- a/src/box/sql/mem.h +++ b/src/box/sql/mem.h @@ -356,6 +356,10 @@ mem_set_array_allocated(struct Mem *mem, char *value, uint32_t size); void mem_set_invalid(struct Mem *mem); +/** Clear MEM and set pointer to be its value. */ +void +mem_set_ptr(struct Mem *mem, void *ptr); + /** * 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 @@ -625,14 +629,6 @@ mem_convert_to_numeric(struct Mem *mem, enum field_type type); int sqlVdbeMemClearAndResize(struct Mem * pMem, int n); -/** - * Set VDBE memory register with given pointer as a data. - * @param mem VDBE memory register to update. - * @param ptr Pointer to use. - */ -void -mem_set_ptr(struct Mem *mem, void *ptr); - void sqlValueFree(struct Mem *); struct Mem *sqlValueNew(struct sql *); diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c index 0031d2248..c21a6576f 100644 --- a/src/box/sql/vdbe.c +++ b/src/box/sql/vdbe.c @@ -2485,8 +2485,7 @@ case OP_OpenTEphemeral: { if (space == NULL) goto abort_due_to_error; - aMem[pOp->p1].u.p = space; - aMem[pOp->p1].flags = MEM_Ptr; + mem_set_ptr(&aMem[pOp->p1], space); break; }