[Tarantool-patches] [PATCH v2 05/15] lua: don't raise a Lua error from luaT_tuple_new()

Alexander Turenko alexander.turenko at tarantool.org
Mon Oct 12 21:41:03 MSK 2020


> > > > +	/* Calculate absolute value in the stack. */
> > > 
> > > At first, it was tough to me to understand the reason you transform the
> > > given relative index to an absolute one, since there is everything
> > > within <lua_pushvalue> for it. I finally got the issue after Vlad's
> > > comments and another (more thorough) look to the sources. I believe it's
> > > nice to drop a few words regarding it. Here are the key points (IMHO):
> > > * whether index is less than zero, it is considered relative to the top
> > >   Lua stack slot
> > > * when you obtain the function object to be called, top pointer is
> > >   incremented, so index ought to be adjusted respectively
> 
> I hope, we are on the same page here, aren't we?

Not sure I understood your proposal right. Anyway, I'll leave short
descriptions regarding ideas behind the code. I hope it is better now.

diff --git a/src/box/lua/tuple.c b/src/box/lua/tuple.c
index 6cccb0ce1..8c3d29f71 100644
--- a/src/box/lua/tuple.c
+++ b/src/box/lua/tuple.c
@@ -158,9 +158,13 @@ luaT_tuple_encode_on_lua_ibuf(struct lua_State *L, int idx,
 		return NULL;
 	}
 
+	/* To restore before leaving the function. */
 	int top = lua_gettop(L);
 
-	/* Calculate absolute value in the stack. */
+	/*
+	 * An absolute index doesn't need to be recalculated after
+	 * the stack size change.
+	 */
 	if (idx < 0)
 		idx = top + idx + 1;


More information about the Tarantool-patches mailing list