Merge lp:~3v1n0/unity/glib-signal-safer-cb into lp:unity

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Christopher Townsend
Approved revision: no longer in the source branch.
Merged at revision: 3880
Proposed branch: lp:~3v1n0/unity/glib-signal-safer-cb
Merge into: lp:unity
Diff against target: 92 lines (+9/-24)
2 files modified
UnityCore/GLibSignal-inl.h (+5/-1)
unity-shared/StaticCairoText.cpp (+4/-23)
To merge this branch: bzr merge lp:~3v1n0/unity/glib-signal-safer-cb
Reviewer Review Type Date Requested Status
Christopher Townsend Approve
PS Jenkins bot (community) continuous-integration Needs Fixing
Review via email: mp+238387@code.launchpad.net

Commit message

GLibSignal: don't call callback function if the object_ value is not matching the CB

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Christopher Townsend (townsend) wrote :

Great, looks good and no longer crashes. Thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'UnityCore/GLibSignal-inl.h'
--- UnityCore/GLibSignal-inl.h 2012-08-30 18:14:19 +0000
+++ UnityCore/GLibSignal-inl.h 2014-10-15 05:28:09 +0000
@@ -52,7 +52,11 @@
52template <typename R, typename G, typename... Ts>52template <typename R, typename G, typename... Ts>
53R Signal<R, G, Ts...>::Callback(G object, Ts... vs, Signal* self)53R Signal<R, G, Ts...>::Callback(G object, Ts... vs, Signal* self)
54{54{
55 return self->callback_(object, vs...);55 /* For some weird reasons, this might not be always true (see bug #1366351) */
56 if (reinterpret_cast<GObject*>(object) == self->object_)
57 return self->callback_(object, vs...);
58
59 return R();
56}60}
5761
58}62}
5963
=== modified file 'unity-shared/StaticCairoText.cpp'
--- unity-shared/StaticCairoText.cpp 2014-03-20 05:05:21 +0000
+++ unity-shared/StaticCairoText.cpp 2014-10-15 05:28:09 +0000
@@ -34,6 +34,7 @@
34#include <pango/pangocairo.h>34#include <pango/pangocairo.h>
3535
36#include <UnityCore/GLibWrapper.h>36#include <UnityCore/GLibWrapper.h>
37#include <UnityCore/GLibSignal.h>
3738
38#include "CairoTexture.h"39#include "CairoTexture.h"
39#include "UnitySettings.h"40#include "UnitySettings.h"
@@ -45,7 +46,6 @@
45struct StaticCairoText::Impl : sigc::trackable46struct StaticCairoText::Impl : sigc::trackable
46{47{
47 Impl(StaticCairoText* parent, std::string const& text);48 Impl(StaticCairoText* parent, std::string const& text);
48 ~Impl();
4949
50 PangoEllipsizeMode GetPangoEllipsizeMode() const;50 PangoEllipsizeMode GetPangoEllipsizeMode() const;
51 PangoAlignment GetPangoAlignment() const;51 PangoAlignment GetPangoAlignment() const;
@@ -77,8 +77,6 @@
77 void UpdateTexture();77 void UpdateTexture();
78 void OnFontChanged();78 void OnFontChanged();
7979
80 static void FontChanged(GObject* gobject, GParamSpec* pspec, gpointer data);
81
82 StaticCairoText* parent_;80 StaticCairoText* parent_;
83 bool accept_key_nav_focus_;81 bool accept_key_nav_focus_;
84 mutable bool need_new_extent_cache_;82 mutable bool need_new_extent_cache_;
@@ -106,6 +104,8 @@
106 int actual_lines_;104 int actual_lines_;
107 float line_spacing_;105 float line_spacing_;
108 double scale_;106 double scale_;
107
108 glib::Signal<void, GtkSettings*, GParamSpec*> font_changed_;
109};109};
110110
111StaticCairoText::Impl::Impl(StaticCairoText* parent, std::string const& text)111StaticCairoText::Impl::Impl(StaticCairoText* parent, std::string const& text)
@@ -126,21 +126,10 @@
126 , line_spacing_(0.5)126 , line_spacing_(0.5)
127 , scale_(1.0f)127 , scale_(1.0f)
128{128{
129 GtkSettings* settings = gtk_settings_get_default(); // not ref'ed129 font_changed_.Connect(gtk_settings_get_default(), "notify::gtk-font-name", sigc::hide(sigc::hide(sigc::mem_fun(this, &Impl::OnFontChanged))));
130 g_signal_connect(settings, "notify::gtk-font-name",
131 (GCallback)FontChanged, this);
132
133 Settings::Instance().font_scaling.changed.connect(sigc::hide(sigc::mem_fun(this, &Impl::OnFontChanged)));130 Settings::Instance().font_scaling.changed.connect(sigc::hide(sigc::mem_fun(this, &Impl::OnFontChanged)));
134}131}
135132
136StaticCairoText::Impl::~Impl()
137{
138 GtkSettings* settings = gtk_settings_get_default(); // not ref'ed
139 g_signal_handlers_disconnect_by_func(settings,
140 (void*)FontChanged,
141 this);
142}
143
144PangoEllipsizeMode StaticCairoText::Impl::GetPangoEllipsizeMode() const133PangoEllipsizeMode StaticCairoText::Impl::GetPangoEllipsizeMode() const
145{134{
146 switch (ellipsize_)135 switch (ellipsize_)
@@ -780,14 +769,6 @@
780 }769 }
781}770}
782771
783void StaticCairoText::Impl::FontChanged(GObject* gobject,
784 GParamSpec* pspec,
785 gpointer data)
786{
787 StaticCairoText::Impl* self = static_cast<StaticCairoText::Impl*>(data);
788 self->OnFontChanged();
789}
790
791void StaticCairoText::Impl::OnFontChanged()772void StaticCairoText::Impl::OnFontChanged()
792{773{
793 need_new_extent_cache_ = true;774 need_new_extent_cache_ = true;