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 0788C6EC55; Wed, 25 Aug 2021 16:35:09 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 0788C6EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1629898509; bh=JrkxddPPemU/qaLe8oBxLgSTmiBdSDCLUnIteGpUDOA=; 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=P4RsBLDaEzKYIwpgsZj6vRF/qXfDYlRt2hMMmup2z/gl1ZCcrrC7q2qBMxQxGTD0Q tjmpKQzynJLJ4mLmjMNtY99KgnXPIfT5QWKDW1Kr1zjkwF7F6nFSweZXs/u3OsmYWR 0GwrS40UnG8acCxBlN9BkK+g5KHe9dGX0DYDAByg= 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 344256EC55 for ; Wed, 25 Aug 2021 16:35:07 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 344256EC55 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1mIt3a-0005rq-4R; Wed, 25 Aug 2021 16:35:06 +0300 Date: Wed, 25 Aug 2021 16:35:04 +0300 To: Vladislav Shpilevoy Cc: yaroslav.dynnikov@tarantool.org, tarantool-patches@dev.tarantool.org Message-ID: <20210825133504.mwquu2s7tzvcf7m2@esperanza> References: <20210817075856.xkelwdonp5kmdofs@esperanza> <38b7f8367e68ece293394d9cf88200e7929341de.1629186968.git.vdavydov@tarantool.org> <726cc8fe-c43b-26a3-b810-da7dc9c295fc@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <726cc8fe-c43b-26a3-b810-da7dc9c295fc@tarantool.org> X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD92087353F0EC44DD91BCCB18F2C129F87F36E61E9E4584E9D182A05F538085040563D47E722DBAEBE85C87D1E5953315E8727947559D95D5F013CD0715819A765 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7876E9C5582D2D91DEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637175EF79FCE26347D8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8732819BAA2A67CA5D2B3210A329974C8117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC974A882099E279BDA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735201E561CDFBCA1751FC26CFBAC0749D213D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B6045A9A90E9EED90B089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: 0D63561A33F958A5A72FEE25B4CB8C6E5FD71CB9F1A1BE47B50268A9C08E676FD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA753177526CD55AFC11410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34BD150993ED26DDF47670ECBCF39A7BC0BB3B33DCD3255860BA9011828EDC0528209E9B3BB06420E21D7E09C32AA3244CE49F6264F45B968C301612CE74231816A95CA90A1D8AC565927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj4xwK62BfefuWEq30RqkYNg== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D66ECEE160349A00ADC062A29403790DE274CEFED1673C562683ABF942079399BFB559BB5D741EB966A65DFF43FF7BE03240331F90058701C67EA787935ED9F1B X-Mras: Ok Subject: Re: [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" On Wed, Aug 25, 2021 at 12:39:27AM +0200, Vladislav Shpilevoy wrote: > > 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; > > +} > > 1. It does not look good that __serialize might return both a table > and a string depending on the object content. Perhaps it is worth to > return an empty table when it has no members. Otherwise, say, if I > store an optional value in the index and want to get it like this: > > serialized_req.member > > then I will get sometimes nil, sometimes an error would be thrown. > Agree. Fixed the patch to return an empty table in case there's no user data stored in the future object. > > + > > 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 }, > > 2. You have a whitespace after { in all the other lines. Could you > please add them here too? Sorry about that. Fixed. Incremental diff: -- diff --git a/src/box/lua/net_box.c b/src/box/lua/net_box.c index 3ed464a93437..7a72cb324df7 100644 --- a/src/box/lua/net_box.c +++ b/src/box/lua/net_box.c @@ -1443,14 +1443,10 @@ 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); + lua_newtable(L); } return 1; } @@ -2130,8 +2126,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 }, + { "__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 450934cd6593..98c9af953efa 100644 --- a/test/box/net.box_fiber-async_gh-3107.result +++ b/test/box/net.box_fiber-async_gh-3107.result @@ -263,7 +263,7 @@ tostring(future) ... future --- -- net.box.request +- [] ... future.abc = 123 ---