lua-users home
lua-l archive

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


> Maybe I just confirmed my original theory and demonstrated that my
> recollection was wrong:
> 
>   udsize = luaC_separateudata(L, 0);  /* separate userdata to be finalized */
>   marktmu(g);  /* mark `preserved' userdata */
>   udsize += propagateall(g);  /* remark, to propagate `preserveness' */
>   cleartable(g->weak);  /* remove collected objects from weak tables */
> 
> Basic lesson: Weak tables plus finalization are a dangerous mix?

Certainly this basic lesson is correct.

Nevertheless, if you did not find a bug, at least it seems an
inconsistency. Anything anchored through finalizing userdata should have
the same behavior (related to weak tables) of those userdata. Maybe
Lua should clear tables with weak values before marking userdata to be
finalized. (With that change, it seems that function 'iscleared' would
not need to treat finalized userdata in keys as a special case.)

-- Roberto