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 E60086EC40; Wed, 11 Aug 2021 10:49:40 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org E60086EC40 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1628668181; bh=P2hn3zBJrSklxV8Z47CP4QtqR0fOVPzaJw6tv7WQ3Fg=; h=Date:To:Cc:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=TimcwvFU5hoefcVxzi2rMEdTGKzBuyrTDzUuQh1oxW7HHeW+zZPSVs7hfMvrtlzvx 1h2ENGmCJg6W9Zn7LPWpmCW2UF0wESGbztnesN2OaCWArm59ahIKv1jNpLXHjjh0qO LeKTOcb3s/cI2XDlX9j+QRa94bogrsjMyPEBsCl8= Received: from smtpng1.i.mail.ru (smtpng1.i.mail.ru [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 F21206EC40 for ; Wed, 11 Aug 2021 10:49:39 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org F21206EC40 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1mDizb-0003Yu-Ap; Wed, 11 Aug 2021 10:49:39 +0300 Date: Wed, 11 Aug 2021 10:49:38 +0300 To: Cyrill Gorcunov via Tarantool-patches Cc: v.shpilevoy@tarantool.org Message-ID: <20210811074938.7ttf4sog77you5ml@esperanza> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD92087353F0EC44DD972FF4A7D76DB5E242D14FEF1BD8BF4AC182A05F5380850400E95161DA6B88BAAE82481A7A32375AE34E139141A3E69202627A99B0B66C578 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7DB84ED444C624799EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637CFA2FDEB3954FDBC8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8F1ACDA52D56262789ED23E159524AEA5117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC2EE5AD8F952D28FBA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18C26CFBAC0749D213D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B613439FA09F3DCB32089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: 0D63561A33F958A54A530A86CAA5CEBBA32CFF7EAC0BBC0F102B2D8CC6B92409D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA753177526CD55AFC11410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3468964757141B82E07C7072C45690BACA4931C4CC4957F03E44CDF42830C4DDB9ADF610193EEAC2061D7E09C32AA3244C87DBB1336550CA9C9814FC26EF44101A8894E9C85370243EFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj6qlzQV0oSZND8cwQ0xc0IA== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D94CD9C35718367B8AE71E673041E041D274CEFED1673C562683ABF942079399BFB559BB5D741EB966A65DFF43FF7BE03240331F90058701C67EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH] net.box: allow to store user-defined fields in future object 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: Vladimir Davydov via Tarantool-patches Reply-To: Vladimir Davydov Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" On Tue, Aug 10, 2021 at 08:15:27PM +0300, Cyrill Gorcunov via Tarantool-patches wrote: > On Tue, Aug 10, 2021 at 07:53:54PM +0300, Vladimir Davydov via Tarantool-patches wrote: > > + > > +static int > > +luaT_netbox_request_newindex(struct lua_State *L) > > +{ > > + struct netbox_request *request = luaT_check_netbox_request(L, 1); > > + struct mh_strnptr_t *h = request->index; > > + size_t field_name_len; > > + const char *field_name = lua_tolstring(L, 2, &field_name_len); > > + if (field_name == NULL) > > + return luaL_error(L, "invalid index"); > > + int field_value_ref = luaL_ref(L, LUA_REGISTRYINDEX); > > + if (field_value_ref == LUA_REFNIL) { > > + /* The field is set to nil. Delete it from the index. */ > > + if (h == NULL) > > + return 0; > > + mh_int_t k = mh_strnptr_find_inp(h, field_name, > > + field_name_len); > > We're guaranteed that field_name present in a hash and never > ever return nil, right? Of course, we are not. Fixed. Thanks! Incremental diff: -- diff --git a/src/box/lua/net_box.c b/src/box/lua/net_box.c index 162ff6c82fb0..6ab0f71cdbe9 100644 --- a/src/box/lua/net_box.c +++ b/src/box/lua/net_box.c @@ -1413,9 +1413,11 @@ luaT_netbox_request_newindex(struct lua_State *L) return 0; mh_int_t k = mh_strnptr_find_inp(h, field_name, field_name_len); - int ref = (intptr_t)mh_strnptr_node(h, k)->val; - luaL_unref(L, LUA_REGISTRYINDEX, ref); - mh_strnptr_del(h, k, NULL); + if (k != mh_end(h)) { + int ref = (intptr_t)mh_strnptr_node(h, k)->val; + luaL_unref(L, LUA_REGISTRYINDEX, ref); + mh_strnptr_del(h, k, NULL); + } return 0; } if (h == NULL) { diff --git a/test/box/net.box_fiber-async_gh-3107.result b/test/box/net.box_fiber-async_gh-3107.result index e44db726c8cb..1c48a115e6b5 100644 --- a/test/box/net.box_fiber-async_gh-3107.result +++ b/test/box/net.box_fiber-async_gh-3107.result @@ -109,6 +109,13 @@ future.abc -- nil --- - null ... +future.abc = nil +--- +... +future.abc -- nil +--- +- null +... future.abc = 'abc' --- ... @@ -123,6 +130,13 @@ future.abc -- nil --- - null ... +future.abc = nil +--- +... +future.abc -- nil +--- +- null +... future[{}] -- error --- - error: '[string "return future[{}] -- error "]:1: invalid index' diff --git a/test/box/net.box_fiber-async_gh-3107.test.lua b/test/box/net.box_fiber-async_gh-3107.test.lua index 5571aeb935e0..e08bad056cba 100644 --- a/test/box/net.box_fiber-async_gh-3107.test.lua +++ b/test/box/net.box_fiber-async_gh-3107.test.lua @@ -38,10 +38,14 @@ err:find('Usage') ~= nil -- Storing user data in future object. future = c:eval('return 123', {}, {is_async = true}) future.abc -- nil +future.abc = nil +future.abc -- nil future.abc = 'abc' future.abc -- abc future.abc = nil future.abc -- nil +future.abc = nil +future.abc -- nil future[{}] -- error future[{}] = 'abc' -- error future:wait_result() -- 123