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 A7D826EC40; Tue, 17 Aug 2021 11:00:56 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A7D826EC40 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1629187256; bh=9y2Oezqf+Kd82iJz+QeDZd/ZLD7NAvnLzVfcOMsGu0Q=; 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=V5hoWn6hGDzgPf7vLDf2Za+c+tx2OkRvXdoK+mv8ek6BaZX2aWnR5KqlClbp9anSy NedbugNoWZodg8OTL4wORd5piOFNeQYnTZzf97Kssin96+miifrRR8S3R/H7KDfCkv IP/8CLz8tk+AjIJiEsHvPpEIScAvaWbZVf+r9g4A= 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 8356D6EC40 for ; Tue, 17 Aug 2021 11:00:54 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 8356D6EC40 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1mFu1l-00051W-GO; Tue, 17 Aug 2021 11:00:54 +0300 To: yaroslav.dynnikov@tarantool.org Cc: tarantool-patches@dev.tarantool.org, v.shpilevoy@tarantool.org Date: Tue, 17 Aug 2021 11:00:50 +0300 Message-Id: <38b7f8367e68ece293394d9cf88200e7929341de.1629186968.git.vdavydov@tarantool.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210817075856.xkelwdonp5kmdofs@esperanza> References: <20210817075856.xkelwdonp5kmdofs@esperanza> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD92087353F0EC44DD9ECFD080E047A606F6525B29142351271182A05F5380850402C4AF0C195174CD92BF568723A71EE656EF2791E1CA6934DE806B623610F59E5 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE74E2C4641A2CB07F2EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637305DC8BF02BF43818638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8C773ABDB97DD20633EA112D5FE878BA4117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC2EE5AD8F952D28FBA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD182CC0D3CB04F14752D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B613439FA09F3DCB32089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C5B73F950BC6E7FFBB78ACD36C92828493D7BBA0F235F439E9C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EFD827CA74CCEABFF3699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34D4140D813EC137C6E87EB8EE5D577E4C6F34F6916C89C5EB52E0DB2F73C3B68CF29CE9B27BAC6E411D7E09C32AA3244CC688CF450E8388824764F87AA90EB12A64EE5813BBCA3A9D927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojIrFL/N5KnVF5FhFX264d6g== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D6AA8331ADE916BE7C6C75D4B4B1932C2274CEFED1673C562683ABF942079399BFB559BB5D741EB966A65DFF43FF7BE03240331F90058701C67EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v2] net.box: add __serialize and __tostring methods for future objects 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" __tostring always returns the type name, which is 'net.box.request'. The output of __serialize depends on whether there are user-defined fields attached to the future. If yes, it returns the fields in a table, otherwise it falls back on __tostring. Closes #6314 --- https://github.com/tarantool/tarantool/issues/6314 https://github.com/tarantool/tarantool/tree/vdavydov/netbox-future-serialize Changes in v2: - Remove 'sync' from the __tostring output. - Remove inaccessible fields from the __serialize output. Return user-defined fields instead if any. src/box/lua/net_box.c | 25 ++++++++++++++ test/box/net.box_fiber-async_gh-3107.result | 33 +++++++++++++++++++ test/box/net.box_fiber-async_gh-3107.test.lua | 12 +++++++ 3 files changed, 70 insertions(+) diff --git a/src/box/lua/net_box.c b/src/box/lua/net_box.c index 1783da607dcc..3ed464a93437 100644 --- a/src/box/lua/net_box.c +++ b/src/box/lua/net_box.c @@ -1432,6 +1432,29 @@ luaT_netbox_request_gc(struct lua_State *L) return 0; } +static int +luaT_netbox_request_tostring(struct lua_State *L) +{ + lua_pushstring(L, netbox_request_typename); + return 1; +} + +static int +luaT_netbox_request_serialize(struct lua_State *L) +{ + struct netbox_request *request = luaT_check_netbox_request(L, 1); + /* + * If there are user-defined fields attached to the future object, + * return them, otherwise push the type name, like __tostring does. + */ + if (request->index_ref != LUA_NOREF) { + lua_rawgeti(L, LUA_REGISTRYINDEX, request->index_ref); + } else { + lua_pushstring(L, netbox_request_typename); + } + return 1; +} + static int luaT_netbox_request_index(struct lua_State *L) { @@ -2107,6 +2130,8 @@ luaopen_net_box(struct lua_State *L) static const struct luaL_Reg netbox_request_meta[] = { { "__gc", luaT_netbox_request_gc }, + {"__tostring", luaT_netbox_request_tostring }, + {"__serialize", luaT_netbox_request_serialize }, { "__index", luaT_netbox_request_index }, { "__newindex", luaT_netbox_request_newindex }, { "is_ready", luaT_netbox_request_is_ready }, diff --git a/test/box/net.box_fiber-async_gh-3107.result b/test/box/net.box_fiber-async_gh-3107.result index ae1c2c308092..450934cd6593 100644 --- a/test/box/net.box_fiber-async_gh-3107.result +++ b/test/box/net.box_fiber-async_gh-3107.result @@ -251,6 +251,39 @@ gc.data3 == nil --- - true ... +-- +-- __tostring and __serialize future methods +-- +future = c:eval('return 123', {}, {is_async = true}) +--- +... +tostring(future) +--- +- net.box.request +... +future +--- +- net.box.request +... +future.abc = 123 +--- +... +future.xyz = 'abc' +--- +... +tostring(future) +--- +- net.box.request +... +future +--- +- xyz: abc + abc: 123 +... +future:wait_result() +--- +- [123] +... box.schema.user.revoke('guest', 'execute', 'universe') --- ... 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 b6bf35ca2fa1..f93d962ae88e 100644 --- a/test/box/net.box_fiber-async_gh-3107.test.lua +++ b/test/box/net.box_fiber-async_gh-3107.test.lua @@ -89,6 +89,18 @@ _ = collectgarbage('collect') _ = collectgarbage('collect') gc.data3 == nil +-- +-- __tostring and __serialize future methods +-- +future = c:eval('return 123', {}, {is_async = true}) +tostring(future) +future +future.abc = 123 +future.xyz = 'abc' +tostring(future) +future +future:wait_result() + box.schema.user.revoke('guest', 'execute', 'universe') c:close() -- 2.25.1