[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: lua 5.4 calls __gc twice, sometimes
- From: Payo Nel <payonel@...>
- Date: Fri, 24 Apr 2020 21:32:12 +0000
From: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
> One more question: can you be sure the __gc of a table is being called
> twice? For what I saw in your code (the first version you sent), the
> problem of destroying the same userdata twice could be caused by
> some bug in the weak table, if it returned the same userdata for
> two different tables. That is, when cleaning the weak table from a
> deleted key, it might get corrupted and then could return a wrong
> value in a future query.
I added an id field to my proxy (key)
local PROXY_COUNT = 0
...
local proxy = {type = "userdata", id = PROXY_COUNT }
userdata.id(data, PROXY_COUNT)
...
userdata.id callback sets the id in the userdata too
then, on dispose, i pass the proxy's id
__gc = function(proxy)
local data = cache[proxy]
cache[proxy] = nil
userdata.dispose(data, proxy.id)
end
In my dispose callback, when this code segfaults, the id passed matches the id of the userdata id i stored at the beginging
p->id == 274, lua_tointeger(L, 2) == 274
p->id == 740, lua_tointeger(L, 2) == 740
_______________________________________________
lua-l mailing list -- lua-l@lists.lua.org
To unsubscribe send an email to lua-l-leave@lists.lua.org
- References:
- lua 5.4 calls __gc twice, sometimes, Payo Nel
- Re: lua 5.4 calls __gc twice, sometimes, Payo Nel
- Re: lua 5.4 calls __gc twice, sometimes, Roberto Ierusalimschy
- Re: lua 5.4 calls __gc twice, sometimes, Payo Nel
- Re: lua 5.4 calls __gc twice, sometimes, Roberto Ierusalimschy