Merge lp:~jjardon/indicator-datetime/fix-844741 into lp:indicator-datetime/0.3

Proposed by Javier Jardón
Status: Rejected
Rejected by: Charles Kerr
Proposed branch: lp:~jjardon/indicator-datetime/fix-844741
Merge into: lp:indicator-datetime/0.3
Diff against target: 76 lines (+20/-15)
1 file modified
src/timezone-completion.c (+20/-15)
To merge this branch: bzr merge lp:~jjardon/indicator-datetime/fix-844741
Reviewer Review Type Date Requested Status
Charles Kerr (community) Disapprove
Javier Jardón (community) Needs Resubmitting
Andrea Cimitan (community) Approve
Review via email: mp+77735@code.launchpad.net
To post a comment you must log in.
140. By Javier Jardón

timezone-completion: Do not get the version with every string request

Revision history for this message
Andrea Cimitan (cimi) :
review: Approve
Revision history for this message
Michal Hruby (mhr3) wrote :

Thanks for the patch!

It's definitely better this way, although I think it'd be best if it were executed lazily - ie keep the get_version () method and set the priv->version variable there the first time it's used, otherwise "if (priv->version != NULL)" just return it.

141. By Javier Jardón

timezone-completion: get the OS version lazily

Revision history for this message
Javier Jardón (jjardon) wrote :

Hi Michal, Here a new patch with your comments

review: Needs Resubmitting
Revision history for this message
Michal Hruby (mhr3) wrote :

My bad, I didn't actually notice the first time that the version variable in get_version is declared as static, which means that the process was spawned just once, although this could cause threading issues, it should be fairly safe, the only problem was the extra "g_free(version)", which should actually cause a segfault pretty much everytime (I wonder why it doesn't).

I think that this late in the cycle we should just remove the extra g_free and perhaps apply this thread-safe fix after release.

Revision history for this message
Charles Kerr (charlesk) wrote :

IMO this is overkill. The original get_version() function clearly intended to call lsb_release once and privately cache the result, so the only needed fix is to remove the g_free() and to follow the idiom by making get_version() return const.

review: Disapprove
Revision history for this message
Charles Kerr (charlesk) wrote :

Revision 149 fixes this in lp:indicator-datetime so I'm going to close this merge request.

Unmerged revisions

141. By Javier Jardón

timezone-completion: get the OS version lazily

140. By Javier Jardón

timezone-completion: Do not get the version with every string request

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/timezone-completion.c'
2--- src/timezone-completion.c 2011-09-06 12:47:37 +0000
3+++ src/timezone-completion.c 2011-10-04 19:52:25 +0000
4@@ -44,6 +44,7 @@
5 guint keypress_id;
6 GCancellable * cancel;
7 gchar * request_text;
8+ gchar * version;
9 GHashTable * request_table;
10 };
11
12@@ -312,19 +313,17 @@
13 }
14
15 static gchar *
16-get_version (void)
17+get_version (TimezoneCompletion *self)
18 {
19- static gchar *version = NULL;
20-
21- if (version == NULL) {
22- gchar *stdout = NULL;
23- g_spawn_command_line_sync ("lsb_release -rs", &stdout, NULL, NULL, NULL);
24-
25- if (stdout != NULL)
26- version = g_strstrip (stdout);
27- else
28- version = g_strdup("");
29- }
30+ TimezoneCompletionPrivate *priv = self->priv;
31+ gchar *version = NULL;
32+
33+ g_spawn_command_line_sync ("lsb_release -rs", &version, NULL, NULL, NULL);
34+
35+ if (version != NULL)
36+ priv->version = g_strstrip (version);
37+ else
38+ priv->version = g_strdup("");
39
40 return version;
41 }
42@@ -351,11 +350,11 @@
43 priv->request_text = g_strdup (text);
44
45 gchar * escaped = g_uri_escape_string (text, NULL, FALSE);
46- gchar * version = get_version ();
47 gchar * locale = get_locale ();
48- gchar * url = g_strdup_printf (GEONAME_URL, escaped, version, locale);
49+ if (priv->version == NULL)
50+ get_version (completion);
51+ gchar * url = g_strdup_printf (GEONAME_URL, escaped, priv->version, locale);
52 g_free (locale);
53- g_free (version);
54 g_free (escaped);
55
56 GFile * file = g_file_new_for_uri (url);
57@@ -609,6 +608,7 @@
58 priv = self->priv;
59
60 priv->initial_model = GTK_TREE_MODEL (get_initial_model ());
61+ priv->version = NULL;
62
63 g_object_set (G_OBJECT (self),
64 "text-column", TIMEZONE_COMPLETION_NAME,
65@@ -673,6 +673,11 @@
66 priv->request_text = NULL;
67 }
68
69+ if (priv->version != NULL) {
70+ g_free (priv->version);
71+ priv->version = NULL;
72+ }
73+
74 if (priv->request_table != NULL) {
75 g_hash_table_destroy (priv->request_table);
76 priv->request_table = NULL;

Subscribers

People subscribed via source and target branches