summaryrefslogtreecommitdiff
path: root/glib
diff options
context:
space:
mode:
authorMurray Cumming <murrayc@murrayc.com>2017-04-05 12:23:49 +0200
committerMurray Cumming <murrayc@murrayc.com>2017-04-05 12:25:01 +0200
commit04f14381a5fcefa3cf78d792c604318ffed81427 (patch)
treec38f93c8b75166e2a9aead8878fe1510c1650033 /glib
parentc5c5f3e0d63e61bda7477ab75f2d29e81a66af1a (diff)
downloadglibmm-04f14381a5fcefa3cf78d792c604318ffed81427.tar.gz
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
Diffstat (limited to 'glib')
-rw-r--r--glib/glibmm/main.cc12
-rw-r--r--glib/glibmm/main.h8
-rw-r--r--glib/src/iochannel.ccg5
3 files changed, 21 insertions, 4 deletions
diff --git a/glib/glibmm/main.cc b/glib/glibmm/main.cc
index 1f19f46e..36317f88 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 63b1ef1b..42521033 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 93b5725d..1a97d0dc 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