[glibmm] IOChannel: Avoid creating a RefPtr to this.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm] IOChannel: Avoid creating a RefPtr to this.
- Date: Thu, 6 Apr 2017 10:24:54 +0000 (UTC)
commit 04f14381a5fcefa3cf78d792c604318ffed81427
Author: Murray Cumming <murrayc murrayc com>
Date: Wed Apr 5 12:23:49 2017 +0200
IOChannel: Avoid creating a RefPtr to this.
By adding a private IOSource constructor (and create()), accessible
via a friend declaration, that takes the raw GIOChannel.
See https://bugzilla.gnome.org/show_bug.cgi?id=755037#c20
glib/glibmm/main.cc | 12 ++++++++++++
glib/glibmm/main.h | 8 ++++++++
glib/src/iochannel.ccg | 5 +----
3 files changed, 21 insertions(+), 4 deletions(-)
---
diff --git a/glib/glibmm/main.cc b/glib/glibmm/main.cc
index 1f19f46..36317f8 100644
--- a/glib/glibmm/main.cc
+++ b/glib/glibmm/main.cc
@@ -1231,6 +1231,12 @@ IOSource::create(const Glib::RefPtr<IOChannel>& channel, IOCondition condition)
return Glib::RefPtr<IOSource>(new IOSource(channel, condition));
}
+Glib::RefPtr<IOSource>
+IOSource::create(GIOChannel* channel, IOCondition condition)
+{
+ return Glib::RefPtr<IOSource>(new IOSource(channel, condition));
+}
+
sigc::connection
IOSource::connect(const sigc::slot<bool(IOCondition)>& slot)
{
@@ -1248,6 +1254,12 @@ IOSource::IOSource(const Glib::RefPtr<IOChannel>& channel, IOCondition condition
{
}
+IOSource::IOSource(GIOChannel* channel, IOCondition condition)
+: Source(g_io_create_watch(channel, (GIOCondition)condition),
+ (GSourceFunc)&glibmm_iosource_callback)
+{
+}
+
IOSource::IOSource(GSource* cast_item, GSourceFunc callback_func) : Source(cast_item, callback_func)
{
}
diff --git a/glib/glibmm/main.h b/glib/glibmm/main.h
index 63b1ef1..4252103 100644
--- a/glib/glibmm/main.h
+++ b/glib/glibmm/main.h
@@ -870,6 +870,14 @@ protected:
bool dispatch(sigc::slot_base* slot) override;
private:
+ friend IOChannel;
+
+ // This is just to avoid the need for Gio::Socket to create a RefPtr<> to itself.
+ static Glib::RefPtr<IOSource> create(GIOChannel* channel, IOCondition condition);
+
+ // This is just to avoid the need for Gio::Socket to create a RefPtr<> to itself.
+ IOSource(GIOChannel* channel, IOCondition condition);
+
PollFD poll_fd_;
};
diff --git a/glib/src/iochannel.ccg b/glib/src/iochannel.ccg
index 93b5725..1a97d0d 100644
--- a/glib/src/iochannel.ccg
+++ b/glib/src/iochannel.ccg
@@ -276,10 +276,7 @@ IOChannel::get_line_term() const
Glib::RefPtr<IOSource>
IOChannel::create_watch(IOCondition condition)
{
- // The corresponding unreference() takes place in the dtor
- // of the Glib::RefPtr<IOChannel> object below.
- reference();
- return IOSource::create(Glib::RefPtr<IOChannel>(this), condition);
+ return IOSource::create(gobj(), condition);
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]