[Tarantool-patches] [PATCH 3/3] lua: expose temporary Lua state for iproto calls
Alexander Turenko
alexander.turenko at tarantool.org
Sun Jun 7 19:58:41 MSK 2020
> > + /*
> > + * A code that need a temporary fiber-local Lua state may
> > + * save some time and resources for creating a new state
> > + * and use this one.
> > + */
> > + bool has_lua_stack = fiber()->storage.lua.stack != NULL;
> > + if (! has_lua_stack)
> > + fiber()->storage.lua.stack = L;
>
> 1. According to recent code style changes, we should omit single
> whitespace after unary operators.
Fixed.
> > + /*
> > + * Since this field is optional we're not obligated to
> > + * keep it until the Lua state will be unreferenced in
> > + * port_lua_destroy().
> > + *
> > + * There is no much sense to keep it beyond the Lua call,
> > + * so let's zap now.
> > + *
> > + * But: keep the stack if it was present before the call,
> > + * because it would be counter-intuitive if the existing
> > + * state pointer would be zapped after this function call.
>
> 2. It is not just counter-intuitive. It would break Lua-born fibers,
> since they would suddenly loose their stack.
Nope, it'll work.
Once we put the stack into a Lua-born fiber, this field may be safely
zapped. (I looked into this, because I want to create a test case that
would verify whether we keep the existing state here, but failed to find
such scenario.)
> > /**
> > - * Lua stack and the optional
> > - * fiber.storage Lua reference.
> > + * Optional Lua state (may be NULL). Useful as a
> > + * temporary Lua state to save time and resources
> > + * on creating it. Should not be used in other
> > + * fibers.
> > + *
> > + * Optional fiber.storage Lua reference.
>
> 3. You change the comment anyway, so it would be better to make it
> right and put the member-related comments just above the members.
> One comment for the stack, and separate comment for the ref.
Fixed.
More information about the Tarantool-patches
mailing list