lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi, Roberto!

Shouldn't there be a luai_apicheck(L, ref != 0) at the beginning of luaL_unref ?


On Tue, Nov 12, 2013 at 12:07 AM, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
> Hi, list!
>
> For me it seems that there is a quirk in luaL_unref.
>
> There is a check at the beginning of luaL_unref:
> if (ref >= 0)
>
> But value 0 is used to store reference to the head of the freelist (there
> is a #define freelist 0 above)
>
> So passing 0 to luaL_unref will cause some trouble.
> It should not be a problem with correct usage of the API (luaL_ref never
> returns 0), but anyway this condition seems incorrect to me (should be
> "greater", not "greater and equal").

As you said, 0 is not a valid parameter to luaL_unref. The test
separates positive indices, which must be removed from the table, from
negative indices (LUA_REFNIL and LUA_NOREF), which must be ignored.
Whatever we do with zero, it will be wrong.  Changing the test to
(ref > 0) would only change what kind of wrong thing Lua would do with
an invalid input.

-- Roberto




--
С уважением,
Запольнов Николай