Merge lp:~compiz-team/compiz/compiz.fix_1085590.1 into lp:compiz/0.9.9

Proposed by Sam Spilsbury
Status: Merged
Approved by: Daniel van Vugt
Approved revision: 3501
Merged at revision: 3496
Proposed branch: lp:~compiz-team/compiz/compiz.fix_1085590.1
Merge into: lp:compiz/0.9.9
Diff against target: 324 lines (+221/-9)
9 files modified
src/eventsource.cpp (+5/-4)
src/privateeventsource.h (+1/-1)
src/privateiosource.h (+13/-0)
src/screen.cpp (+17/-4)
src/signalsource.cpp (+1/-0)
src/timer/src/privatetimeoutsource.h (+1/-0)
tests/integration/CMakeLists.txt (+1/-0)
tests/integration/glib/CMakeLists.txt (+30/-0)
tests/integration/glib/glib_integration_test.cpp (+152/-0)
To merge this branch: bzr merge lp:~compiz-team/compiz/compiz.fix_1085590.1
Reviewer Review Type Date Requested Status
Daniel van Vugt Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+137426@code.launchpad.net

This proposal supersedes a proposal from 2012-12-02.

Commit message

In order to safely destroy a Glib::Source you need to g_source_destroy its
underlying gobj which will invoke the destructor for the Glib::Source.
Added an integration test to prove it.
(LP: #1085590)

Description of the change

In order to safely destroy a Glib::Source you need to g_source_destroy its underlying gobj
which will invoke the destructor for the Glib::Source.

Added an integration test to prove it

(LP: #1085590)

To post a comment you must log in.
3496. By Sam Spilsbury

Add missing files

3497. By Sam Spilsbury

Revert unneeded change

3498. By Sam Spilsbury

Fix omission

3499. By Sam Spilsbury

We already have the connnection number use the provided fd

3500. By Sam Spilsbury

Remove commented code

3501. By Sam Spilsbury

Check if the source exists before calling g_source_destroy

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
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
Daniel van Vugt (vanvugt) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/eventsource.cpp'
2--- src/eventsource.cpp 2012-05-10 12:58:01 +0000
3+++ src/eventsource.cpp 2012-12-02 18:31:23 +0000
4@@ -30,7 +30,8 @@
5 CompEventSource *
6 CompEventSource::create ()
7 {
8- return new CompEventSource ();
9+ return new CompEventSource (screen->dpy (),
10+ ConnectionNumber (screen->dpy ()));
11 }
12
13 sigc::connection
14@@ -39,10 +40,10 @@
15 return connect_generic (slot);
16 }
17
18-CompEventSource::CompEventSource () :
19+CompEventSource::CompEventSource (Display *dpy, int fd) :
20 Glib::Source (),
21- mDpy (screen->dpy ()),
22- mConnectionFD (ConnectionNumber (screen->dpy ()))
23+ mDpy (dpy),
24+ mConnectionFD (fd)
25 {
26 mPollFD.set_fd (mConnectionFD);
27 mPollFD.set_events (Glib::IO_IN);
28
29=== modified file 'src/privateeventsource.h'
30--- src/privateeventsource.h 2012-05-10 12:58:01 +0000
31+++ src/privateeventsource.h 2012-12-02 18:31:23 +0000
32@@ -50,7 +50,7 @@
33 bool dispatch (sigc::slot_base *slot);
34 bool callback ();
35
36- CompEventSource ();
37+ CompEventSource (Display *dpy, int fd);
38
39 private:
40
41
42=== modified file 'src/privateiosource.h'
43--- src/privateiosource.h 2012-03-12 12:47:04 +0000
44+++ src/privateiosource.h 2012-12-02 18:31:23 +0000
45@@ -26,6 +26,19 @@
46 #ifndef _COMPIZ_PRIVATEIOSOURCE_H
47 #define _COMPIZ_PRIVATEIOSOURCE_H
48
49+#include <glibmm/main.h>
50+
51+typedef boost::function<void (short int)> FdWatchCallBack;
52+typedef int CompWatchFdHandle;
53+
54+namespace compiz
55+{
56+ namespace private_screen
57+ {
58+ class EventManager;
59+ }
60+}
61+
62 class CompWatchFd :
63 public Glib::IOSource
64 {
65
66=== modified file 'src/screen.cpp'
67--- src/screen.cpp 2012-11-13 07:56:49 +0000
68+++ src/screen.cpp 2012-12-02 18:31:23 +0000
69@@ -5221,14 +5221,27 @@
70
71 cps::EventManager::~EventManager ()
72 {
73- delete timeout;
74+ /* Not guaranteed to be created by EventManager's constructor */
75+ if (timeout)
76+ {
77+ /* This will implicitly call ~CompTimeoutSource
78+ * See LP: #1085590 */
79+ g_source_destroy (timeout->gobj ());
80+ }
81 delete sigintSource;
82 delete sigtermSource;
83 delete sighupSource;
84- delete source;
85-
86+
87+ /* Not guaranteed to be created by EventManager's constructor */
88+ if (source)
89+ {
90+ /* This will implicitly call ~CompEventSource */
91+ g_source_destroy (source->gobj ());
92+ }
93+
94+ /* This will implicitly call ~CompWatchFd */
95 foreach (CompWatchFd *fd, watchFds)
96- delete fd;
97+ g_source_destroy (fd->gobj ());
98
99 watchFds.clear ();
100 }
101
102=== modified file 'src/signalsource.cpp'
103--- src/signalsource.cpp 2012-01-25 07:33:33 +0000
104+++ src/signalsource.cpp 2012-12-02 18:31:23 +0000
105@@ -65,6 +65,7 @@
106
107 CompSignalSource::~CompSignalSource ()
108 {
109+ /* Do not remove, see LP: #1085590 */
110 if (mSource)
111 g_source_remove (mSource);
112 }
113
114=== modified file 'src/timer/src/privatetimeoutsource.h'
115--- src/timer/src/privatetimeoutsource.h 2012-01-20 17:50:31 +0000
116+++ src/timer/src/privatetimeoutsource.h 2012-12-02 18:31:23 +0000
117@@ -23,6 +23,7 @@
118 * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com>
119 */
120
121+#include <glibmm/main.h>
122 #include <core/timer.h>
123 #include <core/timeouthandler.h>
124
125
126=== modified file 'tests/integration/CMakeLists.txt'
127--- tests/integration/CMakeLists.txt 2012-01-20 16:29:27 +0000
128+++ tests/integration/CMakeLists.txt 2012-12-02 18:31:23 +0000
129@@ -1,1 +1,2 @@
130 add_subdirectory (xig)
131+add_subdirectory (glib)
132
133=== added directory 'tests/integration/glib'
134=== added file 'tests/integration/glib/CMakeLists.txt'
135--- tests/integration/glib/CMakeLists.txt 1970-01-01 00:00:00 +0000
136+++ tests/integration/glib/CMakeLists.txt 2012-12-02 18:31:23 +0000
137@@ -0,0 +1,30 @@
138+include (FindPkgConfig)
139+
140+pkg_check_modules (COMPIZ_GLIB_INTEGRATION_TEST glibmm-2.4)
141+
142+if (COMPIZ_GLIB_INTEGRATION_TEST_FOUND)
143+
144+ include_directories (${compiz_SOURCE_DIR}/src/)
145+ include_directories (${compiz_SOURCE_DIR}/src/timer/include)
146+ include_directories (${compiz_SOURCE_DIR}/src/timer/src)
147+ include_directories (${compiz_SOURCE_DIR}/include)
148+ include_directories (${COMPIZ_GLIB_INTEGRATION_TEST_INCLUDE_DIRS})
149+
150+ link_directories (${compiz_BINARY_DIR}/src)
151+ link_directories (${COMPIZ_GLIB_INTEGRATION_TEST_LIBRARY_DIRS})
152+
153+ add_executable (compiz_glib_integration_test
154+ ${CMAKE_CURRENT_SOURCE_DIR}/glib_integration_test.cpp)
155+
156+ target_link_libraries (compiz_glib_integration_test
157+ compiz_core
158+ ${COMPIZ_GLIB_INTEGRATION_TEST_LIBRARIES}
159+ ${GTEST_BOTH_LIBRARIES}
160+ ${GMOCK_LIBRARY}
161+ ${GMOCK_MAIN_LIBRARY}
162+ ${CMAKE_THREAD_LIBS_INIT} # Link in pthread.
163+ )
164+
165+ compiz_discover_tests (compiz_glib_integration_test COVERAGE compiz_core)
166+
167+endif (COMPIZ_GLIB_INTEGRATION_TEST_FOUND)
168
169=== added file 'tests/integration/glib/glib_integration_test.cpp'
170--- tests/integration/glib/glib_integration_test.cpp 1970-01-01 00:00:00 +0000
171+++ tests/integration/glib/glib_integration_test.cpp 2012-12-02 18:31:23 +0000
172@@ -0,0 +1,152 @@
173+/*
174+ * Compiz GLib integration test
175+ *
176+ * Copyright (C) 2012 Sam Spilsbury <smspillaz@gmail.com>
177+ *
178+ * This library is free software; you can redistribute it and/or
179+ * modify it under the terms of the GNU Lesser General Public
180+ * License as published by the Free Software Foundation; either
181+ * version 2.1 of the License, or (at your option) any later version.
182+
183+ * This library is distributed in the hope that it will be useful,
184+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
185+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
186+ * Lesser General Public License for more details.
187+
188+ * You should have received a copy of the GNU Lesser General Public
189+ * License along with this library; if not, write to the Free Software
190+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
191+ *
192+ * Authored By:
193+ * Sam Spilsbury <smspillaz@gmail.com>
194+ */
195+#include <gtest/gtest.h>
196+#include <gmock/gmock.h>
197+
198+#include "privateeventsource.h"
199+#include "privatetimeoutsource.h"
200+#include "privateiosource.h"
201+
202+class DieVerifier
203+{
204+ public:
205+
206+ MOCK_METHOD0 (Die, void ());
207+};
208+
209+class GLibSourceDestroyIntegration :
210+ public ::testing::Test
211+{
212+ public:
213+
214+ GLibSourceDestroyIntegration () :
215+ context (Glib::MainContext::get_default ()),
216+ mainloop (Glib::MainLoop::create ())
217+ {
218+ }
219+
220+ DieVerifier die;
221+ Glib::RefPtr <Glib::MainContext> context;
222+ Glib::RefPtr <Glib::MainLoop> mainloop;
223+};
224+
225+class StubTimeoutSource :
226+ public CompTimeoutSource
227+{
228+ public:
229+
230+ StubTimeoutSource (DieVerifier *dieVerifier,
231+ Glib::RefPtr <Glib::MainContext> &context) :
232+ CompTimeoutSource (context),
233+ mDie (dieVerifier)
234+ {
235+ }
236+
237+ virtual ~StubTimeoutSource ()
238+ {
239+ mDie->Die ();
240+ }
241+
242+ private:
243+
244+ DieVerifier *mDie;
245+};
246+
247+class StubEventSource :
248+ public CompEventSource
249+{
250+ public:
251+
252+ StubEventSource (DieVerifier *dieVerifier) :
253+ CompEventSource (NULL, 0),
254+ mDie (dieVerifier)
255+ {
256+ }
257+
258+ virtual ~StubEventSource ()
259+ {
260+ mDie->Die ();
261+ }
262+
263+ private:
264+
265+ DieVerifier *mDie;
266+};
267+
268+class StubWatchFd :
269+ public CompWatchFd
270+{
271+ public:
272+
273+ StubWatchFd (DieVerifier *dieVerifier,
274+ int fd,
275+ Glib::IOCondition iocond,
276+ const FdWatchCallBack &cb) :
277+ CompWatchFd (fd, iocond, cb),
278+ mDie (dieVerifier)
279+ {
280+ }
281+
282+ virtual ~StubWatchFd ()
283+ {
284+ mDie->Die ();
285+ }
286+
287+ private:
288+
289+ DieVerifier *mDie;
290+};
291+
292+TEST_F (GLibSourceDestroyIntegration, TimeoutSourceGSourceDestroy)
293+{
294+ StubTimeoutSource *sts = new StubTimeoutSource (&die, context);
295+
296+ EXPECT_CALL (die, Die ());
297+
298+ g_source_destroy (sts->gobj ());
299+}
300+
301+TEST_F (GLibSourceDestroyIntegration, EventSourceGSourceDestroy)
302+{
303+ StubEventSource *sts = new StubEventSource (&die);
304+
305+ sts->attach (context);
306+
307+ EXPECT_CALL (die, Die ());
308+
309+ g_source_destroy (sts->gobj ());
310+}
311+
312+TEST_F (GLibSourceDestroyIntegration, FdSourceGSourceDestroy)
313+{
314+ Glib::IOCondition iocond = Glib::IO_IN;
315+ int fd = 0;
316+ FdWatchCallBack cb;
317+ StubWatchFd *sts = new StubWatchFd (&die, fd, iocond, cb);
318+
319+ sts->attach (context);
320+
321+ EXPECT_CALL (die, Die ());
322+
323+ g_source_destroy (sts->gobj ());
324+}

Subscribers

People subscribed via source and target branches