lua-users home
lua-l archive

Re: A crash in Lua 5.3.2

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


> > ```
> > local mt = {}
> > mt.__newindex = mt
> > local t = setmetatable({}, mt)
> > t[1] = 1
> > ```
> 
> Right :-( Thanks for the report. Probably it was introduced with the
> optimizations on table operations; it does not happen in 5.3.1.
The bug is quite subtle. Follows a fix:
diff for lvm.c:
----------------------------------------
193c193,194
< lua_assert(ttistable(t) && ttisnil(oldval));
---
> Table *h = hvalue(t);
> lua_assert(ttisnil(oldval));
195c196
< if ((tm = fasttm(L, hvalue(t)->metatable, TM_NEWINDEX)) == NULL &&
---
> if ((tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL &&
200c201
< (oldval = luaH_newkey(L, hvalue(t), key), 1))) {
---
> (oldval = luaH_newkey(L, h, key), 1))) {
203,204c204,205
< invalidateTMcache(hvalue(t));
< luaC_barrierback(L, hvalue(t), val);
---
> invalidateTMcache(h);
> luaC_barrierback(L, h, val);
----------------------------------------
-- Roberto

AltStyle によって変換されたページ (->オリジナル) /