Merge lp:~3v1n0/bamf/correctly-remove-cached-children into lp:bamf/0.4

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: 467
Merged at revision: 432
Proposed branch: lp:~3v1n0/bamf/correctly-remove-cached-children
Merge into: lp:bamf/0.4
Diff against target: 259 lines (+57/-36)
5 files modified
lib/libbamf/Makefile.am (+1/-1)
lib/libbamf/bamf-matcher.c (+3/-3)
lib/libbamf/bamf-view.c (+52/-30)
lib/libbamf/bamf-window.c (+1/-0)
lib/libbamf/bamf-window.h (+0/-2)
To merge this branch: bzr merge lp:~3v1n0/bamf/correctly-remove-cached-children
Reviewer Review Type Date Requested Status
Jason Smith (community) Approve
Review via email: mp+89489@code.launchpad.net

Description of the change

Fixed bug #919366 that was caused by the fact that the list of the cached children were not correctly updated on children removal.

Reffing the objects on the list and manually looking for the removed one, does the work.
In the case we can't find the removed object, we just free the cached list, that will be eventually repopulated on next request.

To post a comment you must log in.
Revision history for this message
Jason Smith (jassmith) wrote :

Good work dude, thanks a lot!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/libbamf/Makefile.am'
2--- lib/libbamf/Makefile.am 2012-01-19 20:29:47 +0000
3+++ lib/libbamf/Makefile.am 2012-01-27 23:24:23 +0000
4@@ -35,7 +35,6 @@
5 bamf-window.h \
6 bamf-tab-source.h \
7 bamf-tab.h \
8- bamf-marshal.h \
9 libbamf.h \
10 $(NULL)
11
12@@ -45,6 +44,7 @@
13 $(sources_h) \
14 $(libbamf_sources) \
15 bamf-tab-source-glue.h \
16+ bamf-marshal.h \
17 $(NULL)
18
19 libbamf_la_LIBADD = \
20
21=== modified file 'lib/libbamf/bamf-matcher.c'
22--- lib/libbamf/bamf-matcher.c 2012-01-10 18:20:26 +0000
23+++ lib/libbamf/bamf-matcher.c 2012-01-27 23:24:23 +0000
24@@ -477,7 +477,7 @@
25 g_return_val_if_fail (array, NULL);
26
27 len = g_strv_length (array);
28- for (i = 0; i < len; i++)
29+ for (i = len-1; i >= 0; i--)
30 {
31 view = bamf_factory_view_for_path (bamf_factory_get_default (), array[i]);
32
33@@ -518,7 +518,7 @@
34 g_return_val_if_fail (array, NULL);
35
36 len = g_strv_length (array);
37- for (i = 0; i < len; i++)
38+ for (i = len-1; i >= 0; i--)
39 {
40 view = bamf_factory_view_for_path (bamf_factory_get_default (), array[i]);
41
42@@ -619,7 +619,7 @@
43 g_return_val_if_fail (array, NULL);
44
45 len = g_strv_length (array);
46- for (i = 0; i < len; i++)
47+ for (i = len-1; i >= 0; i--)
48 {
49 view = bamf_factory_view_for_path (bamf_factory_get_default (), array[i]);
50
51
52=== modified file 'lib/libbamf/bamf-view.c'
53--- lib/libbamf/bamf-view.c 2012-01-24 23:18:17 +0000
54+++ lib/libbamf/bamf-view.c 2012-01-27 23:24:23 +0000
55@@ -160,7 +160,7 @@
56 priv = view->priv;
57
58 if (priv->cached_children)
59- return g_list_copy(priv->cached_children);
60+ return g_list_copy (priv->cached_children);
61
62 if (!dbus_g_proxy_call (priv->proxy,
63 "Children",
64@@ -178,14 +178,14 @@
65
66 len = g_strv_length (children);
67
68- for (i = 0; i < len; i++)
69+ for (i = len-1; i >= 0; i--)
70 {
71 BamfView *view = bamf_factory_view_for_path (bamf_factory_get_default (), children[i]);
72- results = g_list_prepend (results, view);
73+ results = g_list_prepend (results, g_object_ref (view));
74 }
75-
76+
77 priv->cached_children = results;
78- return g_list_copy(priv->cached_children);
79+ return g_list_copy (priv->cached_children);
80 }
81
82 static gboolean
83@@ -197,7 +197,7 @@
84
85 g_return_val_if_fail (BAMF_IS_VIEW (self), FALSE);
86 priv = self->priv;
87-
88+
89 if (bamf_view_flag_is_set (self, flag))
90 return bamf_view_get_flag (self, flag);
91
92@@ -213,10 +213,10 @@
93 {
94 g_warning ("Failed to fetch boolean: %s", error->message);
95 g_error_free (error);
96-
97+
98 return FALSE;
99 }
100-
101+
102 bamf_view_set_flag (self, flag, result);
103 return result;
104 }
105@@ -225,7 +225,7 @@
106 bamf_view_is_closed (BamfView *view)
107 {
108 g_return_val_if_fail (BAMF_IS_VIEW (view), TRUE);
109-
110+
111 return view->priv->is_closed;
112 }
113
114@@ -233,7 +233,7 @@
115 bamf_view_is_active (BamfView *view)
116 {
117 g_return_val_if_fail (BAMF_IS_VIEW (view), FALSE);
118-
119+
120 if (BAMF_VIEW_GET_CLASS (view)->is_active)
121 return BAMF_VIEW_GET_CLASS (view)->is_active (view);
122
123@@ -468,8 +468,11 @@
124 priv = self->priv;
125
126 if (priv->cached_children)
127- priv->cached_children = g_list_prepend(priv->cached_children, view);
128-
129+ {
130+ g_object_ref (view);
131+ priv->cached_children = g_list_prepend (priv->cached_children, view);
132+ }
133+
134 g_signal_emit (G_OBJECT (self), view_signals[CHILD_ADDED], 0, view);
135 }
136
137@@ -478,14 +481,34 @@
138 {
139 BamfView *view;
140 BamfViewPrivate *priv;
141-
142- view = bamf_factory_view_for_path (bamf_factory_get_default (), path);
143+ view = NULL;
144 priv = self->priv;
145
146 if (priv->cached_children)
147- priv->cached_children = g_list_remove(priv->cached_children, view);
148-
149+ {
150+ GList *l;
151+ for (l = priv->cached_children; l; l = l->next)
152+ {
153+ BamfView *cur_view = BAMF_VIEW (l->data);
154+ if (g_strcmp0 (bamf_view_get_path (cur_view), path) == 0)
155+ {
156+ view = cur_view;
157+ priv->cached_children = g_list_delete_link (priv->cached_children, l);
158+ break;
159+ }
160+ }
161+
162+ if (!BAMF_IS_VIEW (view))
163+ {
164+ g_list_free_full (priv->cached_children, g_object_unref);
165+ priv->cached_children = NULL;
166+ }
167+ }
168+
169 g_signal_emit (G_OBJECT (self), view_signals[CHILD_REMOVED], 0, view);
170+
171+ if (BAMF_IS_VIEW (view))
172+ g_object_unref (view);
173 }
174
175 static void
176@@ -540,19 +563,19 @@
177 bamf_view_on_closed (DBusGProxy *proxy, BamfView *self)
178 {
179 BamfViewPrivate *priv;
180-
181+
182 priv = self->priv;
183
184 priv->is_closed = TRUE;
185-
186+
187 if (priv->sticky && priv->proxy)
188 {
189 if (priv->cached_children)
190- {
191- g_list_free(priv->cached_children);
192- priv->cached_children = NULL;
193- }
194-
195+ {
196+ g_list_free_full (priv->cached_children, g_object_unref);
197+ priv->cached_children = NULL;
198+ }
199+
200 dbus_g_proxy_disconnect_signal (priv->proxy,
201 "ActiveChanged",
202 (GCallback) bamf_view_on_active_changed,
203@@ -658,14 +681,13 @@
204 view = BAMF_VIEW (object);
205
206 priv = view->priv;
207-
208+
209 if (priv->path)
210 {
211 g_free (priv->path);
212 priv->path = NULL;
213 }
214-
215-
216+
217 if (priv->type)
218 {
219 g_free (priv->type);
220@@ -673,10 +695,10 @@
221 }
222
223 if (priv->cached_children)
224- {
225- g_list_free(priv->cached_children);
226- priv->cached_children = NULL;
227- }
228+ {
229+ g_list_free_full (priv->cached_children, g_object_unref);
230+ priv->cached_children = NULL;
231+ }
232
233 if (priv->proxy)
234 {
235
236=== modified file 'lib/libbamf/bamf-window.c'
237--- lib/libbamf/bamf-window.c 2012-01-10 15:06:05 +0000
238+++ lib/libbamf/bamf-window.c 2012-01-27 23:24:23 +0000
239@@ -37,6 +37,7 @@
240 #include "bamf-view-private.h"
241 #include "bamf-window.h"
242 #include "bamf-factory.h"
243+#include "bamf-marshal.h"
244 #include <dbus/dbus.h>
245 #include <dbus/dbus-glib.h>
246 #include <dbus/dbus-glib-lowlevel.h>
247
248=== modified file 'lib/libbamf/bamf-window.h'
249--- lib/libbamf/bamf-window.h 2012-01-19 20:29:47 +0000
250+++ lib/libbamf/bamf-window.h 2012-01-27 23:24:23 +0000
251@@ -31,8 +31,6 @@
252 #include <glib-object.h>
253 #include <libbamf/bamf-view.h>
254
255-#include "bamf-marshal.h"
256-
257 G_BEGIN_DECLS
258
259 #define BAMF_TYPE_WINDOW (bamf_window_get_type ())

Subscribers

People subscribed via source and target branches