From: Yaroslav Dynnikov via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Vladimir Davydov <vdavydov@tarantool.org>
Cc: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>,
Yaroslav Dynnikov <yaroslav.dynnikov@tarantool.org>,
tml <tarantool-patches@dev.tarantool.org>
Subject: Re: [Tarantool-patches] [PATCH v2] net.box: add __serialize and __tostring methods for future objects
Date: Thu, 26 Aug 2021 17:56:46 +0300 [thread overview]
Message-ID: <CAK0MaD0BoUdfP4Eg4rcmWOin-Kv7-=LHTq39+QPDDbFQAWiKoQ@mail.gmail.com> (raw)
In-Reply-To: <20210825133504.mwquu2s7tzvcf7m2@esperanza>
[-- Attachment #1: Type: text/plain, Size: 4394 bytes --]
Hi! Thanks for the patch.
While reviewing it, I've noticed that the autocompletion doesn't work
for a net.box.future object. I guess it's a topic for another issue,
isn't it? Besides that, LGTM.
Best regards
Yaroslav Dynnikov
On Wed, 25 Aug 2021 at 16:35, Vladimir Davydov <vdavydov@tarantool.org>
wrote:
> 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
> ---
>
[-- Attachment #2: Type: text/html, Size: 5695 bytes --]
next prev parent reply other threads:[~2021-08-26 14:57 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-13 12:58 [Tarantool-patches] [PATCH] " Vladimir Davydov via Tarantool-patches
2021-08-13 17:41 ` Yaroslav Dynnikov via Tarantool-patches
2021-08-17 7:58 ` Vladimir Davydov via Tarantool-patches
2021-08-17 8:00 ` [Tarantool-patches] [PATCH v2] " Vladimir Davydov via Tarantool-patches
2021-08-24 22:39 ` Vladislav Shpilevoy via Tarantool-patches
2021-08-25 13:35 ` Vladimir Davydov via Tarantool-patches
2021-08-25 20:08 ` Vladislav Shpilevoy via Tarantool-patches
2021-08-26 14:56 ` Yaroslav Dynnikov via Tarantool-patches [this message]
2021-08-26 15:05 ` Vladimir Davydov via Tarantool-patches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAK0MaD0BoUdfP4Eg4rcmWOin-Kv7-=LHTq39+QPDDbFQAWiKoQ@mail.gmail.com' \
--to=tarantool-patches@dev.tarantool.org \
--cc=v.shpilevoy@tarantool.org \
--cc=vdavydov@tarantool.org \
--cc=yaroslav.dynnikov@tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH v2] net.box: add __serialize and __tostring methods for future objects' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox