From: Alexander Turenko <alexander.turenko@tarantool.org>
To: Igor Munkin <imun@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org,
Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Subject: Re: [Tarantool-patches] [PATCH v2 2/3] merger: clean fiber-local Lua stack after next()
Date: Thu, 16 Jul 2020 23:11:04 +0300 [thread overview]
Message-ID: <20200716201104.xkexzk2tpgtrgth3@tkn_work_nb> (raw)
In-Reply-To: <20200701203650.GB5559@tarantool.org>
> > Now those functions may be called only from Lua and if the fiber-local
> > Lua state is present it is the same as one that is passed to a Lua/C
>
> Typo: s/present/presented/.
Cited from [1]:
| "As presented" (verb) connotes deliberate placement. "As present"
| (adjective) just means it's there.
'It is there' meanging fits better here, IMHO.
Isn't I miss something about grammar here?
[1]: https://www.instructionalsolutions.com/blog/bid/102954/Tables-in-Report-Writing-Presented-or-Present
> > The merge_source_next() implementations do not leave any garbage on a
> > Lua stack at success path, but may left something when an error occurs
> > (say, when a Lua iterator generator returns more then two values). I
>
> Typo: s/then/than/.
Thanks! Fixed.
> > @@ -206,14 +216,10 @@ luaT_temp_luastate(int *coro_ref)
> > * It is the other half of `luaT_temp_luastate()`.
> > */
> > static void
> > -luaT_release_temp_luastate(int coro_ref)
> > +luaT_release_temp_luastate(struct lua_State *L, int coro_ref, int top)
> > {
> > - /*
> > - * FIXME: The reusable fiber-local Lua state is not
> > - * unreferenced here (coro_ref == LUA_REFNIL), but
> > - * it must be truncated to its past top to prevent
> > - * stack overflow.
> > - */
> > + if (top >= 0)
> > + lua_settop(L, top);
> > luaL_unref(tarantool_L, LUA_REGISTRYINDEX, coro_ref);
>
> Minor: You can just either restore top value for fiber-local Lua state
> or unreference Lua coroutine without restoring a pointer to its stack
> top slot. As a result you need to preserve the top value only for the
> first case (i.e. when the coro_ref is LUA_NOREF) and ignore the value
> for all other cases.
Are you propose the following?
| if (top >= 0)
| lua_settop(L, top);
| else
| luaL_unref(tarantool_L, LUA_REGISTRYINDEX, coro_ref);
When I look into the code locally, it does not seem to be logical: why
decision whether we should unreference a state should be made based on
`top` value?
Now the code seem to be logical for me: if `top` was saved, then we drop
it. If reference was saved, we unreference it.
Vlad even proposed to drop `top >= 0`, which works in fact, but Lua
Reference Manual does not guarantee it (it was discussed within this
mailing thread).
> > +static int
> > +lbox_check_merge_source_call_next(struct lua_State *L)
> > +{
> > + assert(lua_gettop(L) == 1);
> > +
> > + /*
> > + * Ensure that there is reusable temporary Lua stack.
> > + *
> > + * Note: It may be the same as L (and usually do).
>
> Minor: It would be nice to mention (at least for inquisitive persons) a
> case when <temporary_L> differs from the given <L> for Lua-born fibers.
No-no, it is always so for a Lua born fiber. It seems I should reword
the comment in a more strict way and explain why I use <temporary_L>
explicitly despite the fact that it is always the same as <L>.
The new comment:
| /*
| * Ensure that there is a reusable temporary Lua stack.
| *
| * Note: It is the same as <L> for a Lua born fiber (at
| * least at the moment of writing), but it is the
| * implementation detail and the test looks more clean
| * when we don't lean on this fact.
| */
next prev parent reply other threads:[~2020-07-16 20:11 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-17 21:06 [Tarantool-patches] [PATCH v2 0/3] Merger's NULL defererence Alexander Turenko
2020-06-17 21:06 ` [Tarantool-patches] [PATCH v2 1/3] merger: fix NULL dereference when called via iproto Alexander Turenko
2020-06-18 22:48 ` Vladislav Shpilevoy
2020-06-19 8:50 ` Alexander Turenko
2020-06-19 23:32 ` Vladislav Shpilevoy
2020-06-21 18:28 ` Alexander Turenko
2020-07-01 20:36 ` Igor Munkin
2020-07-16 20:10 ` Alexander Turenko
2020-07-16 21:42 ` Igor Munkin
2020-07-16 22:44 ` Igor Munkin
2020-07-17 3:08 ` Alexander Turenko
2020-06-17 21:06 ` [Tarantool-patches] [PATCH v2 2/3] merger: clean fiber-local Lua stack after next() Alexander Turenko
2020-06-19 8:50 ` Alexander Turenko
2020-07-01 20:36 ` Igor Munkin
2020-07-16 20:11 ` Alexander Turenko [this message]
2020-07-16 22:07 ` Igor Munkin
2020-07-17 3:08 ` Alexander Turenko
2020-06-17 21:06 ` [Tarantool-patches] [PATCH v2 3/3] lua: expose temporary Lua state for iproto calls Alexander Turenko
2020-07-01 20:37 ` Igor Munkin
2020-07-16 20:11 ` Alexander Turenko
2020-07-16 22:33 ` Igor Munkin
2020-07-17 3:09 ` Alexander Turenko
2020-06-22 20:38 ` [Tarantool-patches] [PATCH v2 0/3] Merger's NULL defererence Vladislav Shpilevoy
2020-07-17 11:28 ` Alexander Turenko
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=20200716201104.xkexzk2tpgtrgth3@tkn_work_nb \
--to=alexander.turenko@tarantool.org \
--cc=imun@tarantool.org \
--cc=tarantool-patches@dev.tarantool.org \
--cc=v.shpilevoy@tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH v2 2/3] merger: clean fiber-local Lua stack after next()' \
/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