From b6a3ae43fb2cc22ecaa66f0f95bfea653ed477d7 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Fri, 30 Sep 2016 11:04:22 +0200 Subject: [PATCH] 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 --- lib/gears/object/properties.lua | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/lib/gears/object/properties.lua b/lib/gears/object/properties.lua index d0c80e01b..63484ba32 100644 --- a/lib/gears/object/properties.lua +++ b/lib/gears/object/properties.lua @@ -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