gears.object.properties: Use the new .data table
Previously, gears.object.properties used a weak table for adding additional information to a C object. However, weak tables can easily cause leaks when the value references the key. This commit makes the code instead use the new .data property that is available on all C objects. This means we have no more magic with a weak table and instead only use "regular" tables instead. Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
f9775b91de
commit
b6a3ae43fb
|
@ -10,22 +10,6 @@
|
||||||
|
|
||||||
local object = {}
|
local object = {}
|
||||||
|
|
||||||
local properties = setmetatable({}, { __mode = 'k' })
|
|
||||||
|
|
||||||
local function cobj_register(cobj)
|
|
||||||
local fallback = {}
|
|
||||||
|
|
||||||
function fallback:rawset(_, prop, val)
|
|
||||||
fallback[prop] = val
|
|
||||||
end
|
|
||||||
|
|
||||||
function fallback:rawget(_, prop)
|
|
||||||
return fallback[prop]
|
|
||||||
end
|
|
||||||
|
|
||||||
properties[cobj] = fallback
|
|
||||||
return fallback
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Add the missing properties handler to a CAPI object such as client/tag/screen.
|
--- Add the missing properties handler to a CAPI object such as client/tag/screen.
|
||||||
-- Valid args:
|
-- Valid args:
|
||||||
|
@ -66,10 +50,8 @@ function object.capi_index_fallback(class, args)
|
||||||
return args.getter_fallback(cobj, prop)
|
return args.getter_fallback(cobj, prop)
|
||||||
end
|
end
|
||||||
|
|
||||||
local fallback = properties[cobj] or cobj_register(cobj)
|
|
||||||
|
|
||||||
-- Use the fallback property table
|
-- Use the fallback property table
|
||||||
return fallback[prop]
|
return cobj.data[prop]
|
||||||
end
|
end
|
||||||
|
|
||||||
local setter = args.setter or function(cobj, prop, value)
|
local setter = args.setter or function(cobj, prop, value)
|
||||||
|
@ -88,10 +70,8 @@ function object.capi_index_fallback(class, args)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local fallback = properties[cobj] or cobj_register(cobj)
|
|
||||||
|
|
||||||
-- Use the fallback property table
|
-- Use the fallback property table
|
||||||
fallback[prop] = value
|
cobj.data[prop] = value
|
||||||
|
|
||||||
-- Emit the signal
|
-- Emit the signal
|
||||||
if args.auto_emit then
|
if args.auto_emit then
|
||||||
|
|
Loading…
Reference in New Issue