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:
Uli Schlachter 2016-09-30 11:04:22 +02:00
parent f9775b91de
commit b6a3ae43fb
1 changed files with 2 additions and 22 deletions

View File

@ -10,22 +10,6 @@
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.
-- Valid args:
@ -66,10 +50,8 @@ function object.capi_index_fallback(class, args)
return args.getter_fallback(cobj, prop)
end
local fallback = properties[cobj] or cobj_register(cobj)
-- Use the fallback property table
return fallback[prop]
return cobj.data[prop]
end
local setter = args.setter or function(cobj, prop, value)
@ -88,10 +70,8 @@ function object.capi_index_fallback(class, args)
return
end
local fallback = properties[cobj] or cobj_register(cobj)
-- Use the fallback property table
fallback[prop] = value
cobj.data[prop] = value
-- Emit the signal
if args.auto_emit then