From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp31.i.mail.ru (smtp31.i.mail.ru [94.100.177.91]) (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 A502E469719 for ; Mon, 12 Oct 2020 21:40:45 +0300 (MSK) Date: Mon, 12 Oct 2020 21:41:03 +0300 From: Alexander Turenko Message-ID: <20201012184103.e6yz3ett63o376iv@tkn_work_nb> References: <20201011174755.GX18920@tarantool.org> <20201012103719.fdzugbvvp4nfvcqi@tkn_work_nb> <20201012105105.GZ18920@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20201012105105.GZ18920@tarantool.org> Subject: Re: [Tarantool-patches] [PATCH v2 05/15] lua: don't raise a Lua error from luaT_tuple_new() List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Igor Munkin Cc: tarantool-patches@dev.tarantool.org, Vladislav Shpilevoy > > > > + /* 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 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;