[glibmm] Gio::Tls[Client, Server]ConnectionImpl: Improve the wrap*() functions



commit bb806ba91b7c8ae08b721826996d877b748200b2
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date:   Sun Aug 2 15:43:07 2020 +0200

    Gio::Tls[Client,Server]ConnectionImpl: Improve the wrap*() functions
    
    Make Glib::wrap_tls_[client,server]_connection_impl() do like other
    wrap() functions for ref-counted objects when they are given a nullptr:
    return an empty RefPtr.

 gio/giomm/tlsclientconnectionimpl.cc | 15 +++++++++------
 gio/giomm/tlsserverconnectionimpl.cc | 15 +++++++++------
 2 files changed, 18 insertions(+), 12 deletions(-)
---
diff --git a/gio/giomm/tlsclientconnectionimpl.cc b/gio/giomm/tlsclientconnectionimpl.cc
index 9207924a..003993c5 100644
--- a/gio/giomm/tlsclientconnectionimpl.cc
+++ b/gio/giomm/tlsclientconnectionimpl.cc
@@ -31,14 +31,17 @@ Glib::RefPtr<Gio::TlsClientConnectionImpl> wrap_tls_client_connection_impl(
 {
   using IfaceImpl = Gio::TlsClientConnectionImpl;
 
-  ObjectBase* pCppObject = ObjectBase::_get_current_wrapper((GObject*)object);
+  ObjectBase* pCppObject = nullptr;
+  if (object)
+  {
+    pCppObject = ObjectBase::_get_current_wrapper((GObject*)object);
 
-  if (!pCppObject)
-    pCppObject = new IfaceImpl(object);
-
-  if (take_copy)
-    pCppObject->reference();
+    if (!pCppObject)
+      pCppObject = new IfaceImpl(object);
 
+    if (take_copy)
+      pCppObject->reference();
+  }
   return Glib::make_refptr_for_instance<IfaceImpl>(dynamic_cast<IfaceImpl*>(pCppObject));
 }
 
diff --git a/gio/giomm/tlsserverconnectionimpl.cc b/gio/giomm/tlsserverconnectionimpl.cc
index 4a4779e0..42bac7f3 100644
--- a/gio/giomm/tlsserverconnectionimpl.cc
+++ b/gio/giomm/tlsserverconnectionimpl.cc
@@ -31,14 +31,17 @@ Glib::RefPtr<Gio::TlsServerConnectionImpl> wrap_tls_server_connection_impl(
 {
   using IfaceImpl = Gio::TlsServerConnectionImpl;
 
-  ObjectBase* pCppObject = ObjectBase::_get_current_wrapper((GObject*)object);
+  ObjectBase* pCppObject = nullptr;
+  if (object)
+  {
+    pCppObject = ObjectBase::_get_current_wrapper((GObject*)object);
 
-  if (!pCppObject)
-    pCppObject = new IfaceImpl(object);
-
-  if (take_copy)
-    pCppObject->reference();
+    if (!pCppObject)
+      pCppObject = new IfaceImpl(object);
 
+    if (take_copy)
+      pCppObject->reference();
+  }
   return Glib::make_refptr_for_instance<IfaceImpl>(dynamic_cast<IfaceImpl*>(pCppObject));
 }
 


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