[glibmm] Gio::DBus::Object: Fix refcounts in some vfuncs



commit 1edbf498e791f6202442a24c51704ee84f31456d
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date:   Tue Jul 16 19:07:53 2019 +0200

    Gio::DBus::Object: Fix refcounts in some vfuncs
    
    Gio::DBus::Object::get_interface_vfunc() and get_interfaces_vfunc()
    must add a reference to the returned DBus interfaces. The caller shall
    unref them. g_dbus_object_get_interface() and g_dbus_object_get_interfaces()
    are marked (transfer full).

 gio/src/dbusobject.ccg | 19 +++++++++++++++++--
 gio/src/dbusobject.hg  | 15 ++++++++-------
 2 files changed, 25 insertions(+), 9 deletions(-)
---
diff --git a/gio/src/dbusobject.ccg b/gio/src/dbusobject.ccg
index 7e1543d8..eb1432da 100644
--- a/gio/src/dbusobject.ccg
+++ b/gio/src/dbusobject.ccg
@@ -18,7 +18,22 @@
 #include <giomm/dbusinterface.h>
 #include <glibmm/vectorutils.h>
 
-namespace Gio
+namespace
 {
+// Used in call to g_list_copy_deep().
+void* list_copy_ref(const void* src, void* /* data */)
+{
+  return g_object_ref(const_cast<void*>(src));
+}
+} // anonymous namespace
 
-} // namespace Gio
+namespace Glib
+{
+// Define a unwrap_copy() overload.
+// Can't use the template function in glibmm/wrap.h, because interface classes
+// don't override Glib::ObjectBase::gobj_copy(), which returns a GObject*.
+GDBusInterface* unwrap_copy(const Glib::RefPtr<Gio::DBus::Interface>& ptr)
+{
+  return ptr ? reinterpret_cast<GDBusInterface*>(ptr->gobj_copy()) : nullptr;
+}
+} // namespace Glib
diff --git a/gio/src/dbusobject.hg b/gio/src/dbusobject.hg
index 633898f1..d854ca94 100644
--- a/gio/src/dbusobject.hg
+++ b/gio/src/dbusobject.hg
@@ -48,11 +48,11 @@ class Object : public Glib::Interface
 public:
   _WRAP_METHOD(Glib::ustring get_object_path() const, g_dbus_object_get_object_path)
 
-#m4 _CONVERSION(`GList*',`std::vector< Glib::RefPtr<Gio::DBus::Interface> >',`Glib::ListHandler< 
Glib::RefPtr<Gio::DBus::Interface> >::list_to_vector($3, Glib::OWNERSHIP_DEEP)')
-  _WRAP_METHOD(std::vector< Glib::RefPtr<Gio::DBus::Interface> > get_interfaces(), 
g_dbus_object_get_interfaces)
+#m4 
_CONVERSION(`GList*',`std::vector<Glib::RefPtr<Gio::DBus::Interface>>',`Glib::ListHandler<Glib::RefPtr<Gio::DBus::Interface>>::list_to_vector($3,
 Glib::OWNERSHIP_DEEP)')
+  _WRAP_METHOD(std::vector<Glib::RefPtr<Gio::DBus::Interface>> get_interfaces(), 
g_dbus_object_get_interfaces)
 
-#m4 _CONVERSION(`GList*',`std::vector< Glib::RefPtr<const Gio::DBus::Interface> >',`Glib::ListHandler< 
Glib::RefPtr<const Gio::DBus::Interface> >::list_to_vector($3, Glib::OWNERSHIP_DEEP)')
-  _WRAP_METHOD(std::vector< Glib::RefPtr<const Gio::DBus::Interface> > get_interfaces() const, 
g_dbus_object_get_interfaces)
+#m4 _CONVERSION(`GList*',`std::vector<Glib::RefPtr<const 
Gio::DBus::Interface>>',`Glib::ListHandler<Glib::RefPtr<const Gio::DBus::Interface>>::list_to_vector($3, 
Glib::OWNERSHIP_DEEP)')
+  _WRAP_METHOD(std::vector<Glib::RefPtr<const Gio::DBus::Interface>> get_interfaces() const, 
g_dbus_object_get_interfaces)
 
   _WRAP_METHOD(Glib::RefPtr<Gio::DBus::Interface> get_interface(const Glib::ustring& interface_name), 
g_dbus_object_get_interface)
   _WRAP_METHOD(Glib::RefPtr<const Gio::DBus::Interface> get_interface(const Glib::ustring& interface_name) 
const, g_dbus_object_get_interface, constversion)
@@ -69,10 +69,11 @@ protected:
 #m4 _CONVERSION(`Glib::ustring',`const gchar*',`$3.c_str()')
   _WRAP_VFUNC(Glib::ustring get_object_path() const, "get_object_path", keep_return)
 
-#m4 _CONVERSION(`std::vector< Glib::RefPtr<Gio::DBus::Interface> >',`GList*',`g_list_copy(Glib::ListHandler< 
Glib::RefPtr<Gio::DBus::Interface> >::vector_to_list($3).data())')
-  _WRAP_VFUNC(std::vector< Glib::RefPtr<Gio::DBus::Interface> > get_interfaces() const, "get_interfaces")
+#m4 _CONVERSION(`std::vector<Glib::RefPtr<Gio::DBus::Interface>>',`GList*',
+#m4  `g_list_copy_deep(Glib::ListHandler<Glib::RefPtr<Gio::DBus::Interface>>::vector_to_list($3).data(), 
list_copy_ref, nullptr)')
+  _WRAP_VFUNC(std::vector<Glib::RefPtr<Gio::DBus::Interface>> get_interfaces() const, "get_interfaces")
 
-  _WRAP_VFUNC(Glib::RefPtr<Gio::DBus::Interface> get_interface(const Glib::ustring& interface_name) const, 
"get_interface")
+  _WRAP_VFUNC(Glib::RefPtr<Gio::DBus::Interface> get_interface(const Glib::ustring& interface_name) const, 
"get_interface", refreturn_ctype)
 };
 
 } // namespace DBus


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]