[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: lua 5.4 calls __gc twice, sometimes
- From: 云风 Cloud Wu <cloudwu@...>
- Date: Sat, 25 Apr 2020 22:08:07 +0800
Payo Nel <payonel@hotmail.com> 于2020年4月25日周六 上午3:17写道:
> ```lua
> function wrapSingleUserdata(data)
> for k, v in pairs(wrappedUserdata) do
> if v == data then
> return k
> end
> end
> local proxy = {type = "userdata"}
> local methods = pcall(userdata.methods, data)
> for method in pairs(methods) do
> proxy[method] = setmetatable({name=method, proxy=proxy}, userdataCallback)
> end
> wrappedUserdata[proxy] = data
> return setmetatable(proxy, userdataWrapper)
> end
`data` could be in tobefnz (to be finalize) list , but not in
`wrappedUserdata` set at that time. So it's possible to create a new
proxy with the same data, and then the __gc of old proxy be called.
`wrapSingleUserdata` want to guarantee the proxy of a userdata is
unique. But iterating the `wrappedUserdata` can't offer this
guarantee.
_______________________________________________
lua-l mailing list -- lua-l@lists.lua.org
To unsubscribe send an email to lua-l-leave@lists.lua.org