Merge lp:~smspillaz/unity/unity.fix_1180970 into lp:unity

Proposed by Sam Spilsbury
Status: Superseded
Proposed branch: lp:~smspillaz/unity/unity.fix_1180970
Merge into: lp:unity
Diff against target: 268 lines (+95/-9)
10 files modified
CMakeLists.txt (+8/-0)
config.h.cmake (+1/-0)
dash/ResultRenderer.cpp (+3/-1)
launcher/LauncherIcon.cpp (+4/-3)
launcher/MockLauncherIcon.h (+3/-0)
panel/PanelIndicatorEntryView.cpp (+2/-2)
tests/test_icon_loader.cpp (+27/-0)
tests/test_result_renderer.cpp (+2/-1)
unity-shared/GtkUtil.h (+43/-0)
unity-shared/IconLoader.cpp (+2/-2)
To merge this branch: bzr merge lp:~smspillaz/unity/unity.fix_1180970
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Sam Spilsbury Pending
Ted Gould Pending
Review via email: mp+164306@code.launchpad.net

This proposal supersedes a proposal from 2013-05-17.

This proposal has been superseded by a proposal from 2013-05-17.

Commit message

Use gtk_icon_info_free on gtk < 3.8

GtkIconInfo is a GObject, but on < 3.8 callers are meant to free it with
gtk_icon_info_unref according to the documentation for it:

GtkIconInfo * gtk_icon_theme_lookup_icon (GtkIconTheme *icon_theme,
                                          const gchar *icon_name,
                                          gint size,
                                          GtkIconLookupFlags flags);
Looks up a named icon and returns a structure containing information such
as the filename of the icon. The icon can then be rendered into a pixbuf
using gtk_icon_info_load_icon(). (gtk_icon_theme_load_icon() combines
these two steps if all you need is the pixbuf.)

...

Returns :
a GtkIconInfo structure containing information about the icon, or NULL if
the icon wasn't found. Free with gtk_icon_info_free()

On > 3.8 the function is deprecated and g_object_unref should be used.

GtkUtilDeathTest::NoDeathOnUnreference verifies that there is no crash-on-unref.

(LP: #1180790)

Description of the change

Use gtk_icon_info_free on gtk < 3.8

GtkIconInfo is a GObject, but on < 3.8 callers are meant to free it with
gtk_icon_info_unref according to the documentation for it:

GtkIconInfo * gtk_icon_theme_lookup_icon (GtkIconTheme *icon_theme,
                                          const gchar *icon_name,
                                          gint size,
                                          GtkIconLookupFlags flags);
Looks up a named icon and returns a structure containing information such
as the filename of the icon. The icon can then be rendered into a pixbuf
using gtk_icon_info_load_icon(). (gtk_icon_theme_load_icon() combines
these two steps if all you need is the pixbuf.)

...

Returns :
a GtkIconInfo structure containing information about the icon, or NULL if
the icon wasn't found. Free with gtk_icon_info_free()

On > 3.8 the function is deprecated and g_object_unref should be used.

GtkUtilDeathTest::NoDeathOnUnreference verifies that there is no crash-on-unref.

(LP: #1180790)

I haven't used glib::Object<> here. As much as I would have liked to - it doesn't support a concept of custom deleters which would be required to support anything like GtkIconInfo. Given that this is the only usecase so far and its actually just for a previous ubuntu version, it probably didn't make sense to add a new constructor there.

To post a comment you must log in.
Revision history for this message
Ted Gould (ted) wrote : Posted in a previous version of this proposal
review: Needs Fixing
Revision history for this message
Ted Gould (ted) wrote : Posted in a previous version of this proposal

Proposed a different merge to handle the bad object in bug 1180970.

https://code.launchpad.net/~ted/unity/null-icon-info/+merge/164214

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Approve (continuous-integration)
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote : Posted in a previous version of this proposal

Please move everything to glib::Object<GtkIconInfo>.

Revision history for this message
Sam Spilsbury (smspillaz) wrote : Posted in a previous version of this proposal

g_object_clear / g_object_unref is broken on < 3.8 and gtk_icon_info_free is deprecated on >= 3.8. I like it when libraries do this. We'll have to ifdef it.

review: Needs Resubmitting
Revision history for this message
Sam Spilsbury (smspillaz) wrote : Posted in a previous version of this proposal

Ah, frick. Forgot to add the file.

review: Needs Fixing
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

I'd prefer to have a wrapper for this, I'm submitting a proposal to superseed this.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2013-05-16 23:30:28 +0000
3+++ CMakeLists.txt 2013-05-17 06:49:34 +0000
4@@ -161,6 +161,14 @@
5 execute_process (COMMAND ${PKG_CONFIG_EXECUTABLE} indicator3-0.4 --variable indicatordir OUTPUT_VARIABLE INDICATORDIR OUTPUT_STRIP_TRAILING_WHITESPACE)
6 execute_process (COMMAND ${PKG_CONFIG_EXECUTABLE} indicator3-0.4 --variable iconsdir OUTPUT_VARIABLE INDICATORICONDIR OUTPUT_STRIP_TRAILING_WHITESPACE)
7
8+pkg_check_modules (GTK_3_8 gtk+-3.0>=3.8)
9+
10+if (GTK_3_8_FOUND)
11+ set (HAVE_GTK_3_8 TRUE)
12+else (GTK_3_8_FOUND)
13+ set (HAVE_GTK_3_8 FALSE)
14+endif (GTK_3_8_FOUND)
15+
16 configure_file (${CMAKE_SOURCE_DIR}/config.h.cmake ${CMAKE_BINARY_DIR}/config.h)
17
18 #
19
20=== modified file 'config.h.cmake'
21--- config.h.cmake 2013-02-18 19:38:46 +0000
22+++ config.h.cmake 2013-05-17 06:49:34 +0000
23@@ -20,5 +20,6 @@
24 #ifndef INDICATOR_SERVICE_DIR
25 #cmakedefine INDICATOR_SERVICE_DIR "@INDICATOR_SERVICE_DIR@"
26 #endif
27+#cmakedefine HAVE_GTK_3_8
28
29 #endif // CONFIG_H
30
31=== modified file 'dash/ResultRenderer.cpp'
32--- dash/ResultRenderer.cpp 2013-05-16 10:58:57 +0000
33+++ dash/ResultRenderer.cpp 2013-05-17 06:49:34 +0000
34@@ -26,6 +26,8 @@
35 #include <unity-protocol.h>
36 #include <NuxGraphics/GdkGraphics.h>
37
38+#include "unity-shared/GtkUtil.h"
39+
40 namespace unity
41 {
42 namespace dash
43@@ -109,7 +111,7 @@
44 pbuf = NULL;
45 }
46
47- g_object_unref(G_OBJECT(info));
48+ gtk::UnreferenceIconInfo(info);
49 return pbuf;
50 }
51
52
53=== modified file 'launcher/LauncherIcon.cpp'
54--- launcher/LauncherIcon.cpp 2013-05-16 10:58:57 +0000
55+++ launcher/LauncherIcon.cpp 2013-05-17 06:49:34 +0000
56@@ -32,6 +32,7 @@
57 #include "LauncherIcon.h"
58 #include "Launcher.h"
59 #include "unity-shared/TimeUtil.h"
60+#include "unity-shared/GtkUtil.h"
61
62 #include "QuicklistManager.h"
63 #include "QuicklistMenuItem.h"
64@@ -341,7 +342,7 @@
65 if (g_strrstr(gtk_icon_info_get_filename(info), "ubuntu-mono") != NULL)
66 _current_theme_is_mono = (int)true;
67
68- g_object_unref(G_OBJECT(info));
69+ gtk::UnreferenceIconInfo(info);
70 return (bool)_current_theme_is_mono;
71
72 }
73@@ -396,7 +397,7 @@
74 bool update_glow_colors,
75 bool is_default_theme)
76 {
77- GtkIconInfo* info;
78+ GtkIconInfo* info = NULL;
79 nux::BaseTexture* result = NULL;
80 GIcon* icon;
81 GtkIconLookupFlags flags = (GtkIconLookupFlags) 0;
82@@ -429,7 +430,7 @@
83
84 glib::Error error;
85 glib::Object<GdkPixbuf> pbuf(gtk_icon_info_load_icon(info, &error));
86- g_object_unref(G_OBJECT(info));
87+ gtk::UnreferenceIconInfo(info);
88
89 if (GDK_IS_PIXBUF(pbuf.RawPtr()))
90 {
91
92=== modified file 'launcher/MockLauncherIcon.h'
93--- launcher/MockLauncherIcon.h 2013-05-14 15:54:28 +0000
94+++ launcher/MockLauncherIcon.h 2013-05-17 06:49:34 +0000
95@@ -32,6 +32,7 @@
96
97 #include <libdbusmenu-glib/menuitem.h>
98 #include "unity-shared/ApplicationManager.h"
99+#include "unity-shared/GtkUtil.h"
100
101 #include "AbstractLauncherIcon.h"
102
103@@ -365,6 +366,8 @@
104 g_error_free(error);
105 }
106
107+ gtk::UnreferenceIconInfo(info);
108+
109 return result;
110 }
111
112
113=== modified file 'panel/PanelIndicatorEntryView.cpp'
114--- panel/PanelIndicatorEntryView.cpp 2013-05-14 15:54:28 +0000
115+++ panel/PanelIndicatorEntryView.cpp 2013-05-17 06:49:34 +0000
116@@ -36,7 +36,7 @@
117 #include "PanelIndicatorEntryView.h"
118 #include "unity-shared/PanelStyle.h"
119 #include "unity-shared/WindowManager.h"
120-
121+#include "unity-shared/GtkUtil.h"
122
123 namespace unity
124 {
125@@ -214,7 +214,7 @@
126 if (info)
127 {
128 pixbuf = gtk_icon_info_load_icon(info, nullptr);
129- g_object_unref(G_OBJECT(info));
130+ gtk::UnreferenceIconInfo(info);
131 }
132 }
133
134
135=== modified file 'tests/test_icon_loader.cpp'
136--- tests/test_icon_loader.cpp 2013-04-03 19:42:06 +0000
137+++ tests/test_icon_loader.cpp 2013-05-17 06:49:34 +0000
138@@ -21,6 +21,7 @@
139 #include <sigc++/sigc++.h>
140
141 #include "IconLoader.h"
142+#include "unity-shared/GtkUtil.h"
143 #include "test_utils.h"
144
145 using namespace testing;
146@@ -210,5 +211,31 @@
147 CheckResults(results);
148 }
149
150+TEST(GtkIconUtilDeathTest, NoDeathOnUnreference)
151+{
152+ GList *icons = gtk_icon_theme_list_icons(gtk_icon_theme_get_default(), "Emblems");
153+
154+ // Get the first icon name
155+ if (icons)
156+ {
157+ const char *icon_name = static_cast <const char *>(icons->data);
158+ GtkIconInfo *info = gtk_icon_theme_lookup_icon(gtk_icon_theme_get_default(), icon_name, 32, (GtkIconLookupFlags) 0);
159+ ASSERT_THAT(info, NotNull());
160+ EXPECT_EXIT({
161+ unity::gtk::UnreferenceIconInfo(info);
162+ fprintf(stderr, "Success\n");
163+ exit(0);
164+ }, ExitedWithCode(0), "Success");
165+
166+ unity::gtk::UnreferenceIconInfo(info);
167+ }
168+
169+ // Free all the icons
170+ for (GList *it = icons; it != NULL; it = it->next)
171+ g_free (it->data);
172+
173+ g_list_free (icons);
174+}
175+
176
177 }
178
179=== modified file 'tests/test_result_renderer.cpp'
180--- tests/test_result_renderer.cpp 2013-05-16 10:58:57 +0000
181+++ tests/test_result_renderer.cpp 2013-05-17 06:49:34 +0000
182@@ -24,6 +24,7 @@
183
184 #include "unity-shared/DashStyle.h"
185 #include "unity-shared/UnitySettings.h"
186+#include "unity-shared/GtkUtil.h"
187 #include "UnityCore/Result.h"
188 #include "dash/ResultRendererTile.h"
189
190@@ -59,7 +60,7 @@
191 g_error_free (error);
192 pbuf = NULL;
193 }
194- g_object_unref(G_OBJECT(info));
195+ gtk::UnreferenceIconInfo(info);
196 }
197
198 return pbuf;
199
200=== added file 'unity-shared/GtkUtil.h'
201--- unity-shared/GtkUtil.h 1970-01-01 00:00:00 +0000
202+++ unity-shared/GtkUtil.h 2013-05-17 06:49:34 +0000
203@@ -0,0 +1,43 @@
204+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
205+/*
206+* Copyright (C) 2013 Canonical Ltd
207+*
208+* This program is free software: you can redistribute it and/or modify
209+* it under the terms of the GNU General Public License version 3 as
210+* published by the Free Software Foundation.
211+*
212+* This program is distributed in the hope that it will be useful,
213+* but WITHOUT ANY WARRANTY; without even the implied warranty of
214+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
215+* GNU General Public License for more details.
216+*
217+* You should have received a copy of the GNU General Public License
218+* along with this program. If not, see <http://www.gnu.org/licenses/>.
219+*
220+* Authored by: Sam Spilsbury <smspillaz@gmail.com>
221+*/
222+
223+#ifndef GTK_UTIL_H
224+#define GTK_UTIL_H
225+
226+#include <glib-2.0/glib-object.h>
227+#include <gtk/gtk.h>
228+#include <config.h>
229+
230+namespace unity
231+{
232+namespace gtk
233+{
234+inline void UnreferenceIconInfo(GtkIconInfo *info)
235+{
236+#ifdef HAVE_GTK_3_8
237+ g_object_clear(info);
238+#else
239+ if (info)
240+ gtk_icon_info_free(info);
241+#endif
242+}
243+}
244+}
245+
246+#endif
247
248=== modified file 'unity-shared/IconLoader.cpp'
249--- unity-shared/IconLoader.cpp 2013-05-14 15:54:28 +0000
250+++ unity-shared/IconLoader.cpp 2013-05-17 06:49:34 +0000
251@@ -34,6 +34,7 @@
252 #include <UnityCore/GLibSignal.h>
253
254 #include "unity-shared/Timer.h"
255+#include "unity-shared/GtkUtil.h"
256
257 namespace unity
258 {
259@@ -124,8 +125,7 @@
260
261 ~IconLoaderTask()
262 {
263- if (icon_info)
264- ::g_object_unref(G_OBJECT(icon_info));
265+ gtk::UnreferenceIconInfo(icon_info);
266 if (helper_handle != 0)
267 impl->DisconnectHandle(helper_handle);
268 }