Merge lp:~azzar1/compiz/dont-crash-if-gsettings-key-not-found into lp:compiz/0.9.13

Proposed by Andrea Azzarone
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: 4075
Merged at revision: 4080
Proposed branch: lp:~azzar1/compiz/dont-crash-if-gsettings-key-not-found
Merge into: lp:compiz/0.9.13
Diff against target: 150 lines (+43/-18)
4 files modified
compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c (+27/-3)
compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c (+12/-11)
compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h (+1/-1)
compizconfig/gsettings/tests/test_gsettings_tests.cpp (+3/-3)
To merge this branch: bzr merge lp:~azzar1/compiz/dont-crash-if-gsettings-key-not-found
Reviewer Review Type Date Requested Status
Marco Trevisan (Treviño) Approve
Review via email: mp+301174@code.launchpad.net

Commit message

Don't crash if gsettings key is not found. Default value will be used.

To post a comment you must log in.
4073. By Andrea Azzarone

Unref the schema.

4074. By Andrea Azzarone

Avoid NULL unref.

4075. By Andrea Azzarone

Fix typo.

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c'
2--- compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c 2013-05-13 13:23:20 +0000
3+++ compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c 2016-07-26 15:08:17 +0000
4@@ -15,25 +15,49 @@
5 #define GSETTINGS_WRAPPER_PRIVATE(w) \
6 CCSGSettingsWrapperPrivate *gswPrivate = (CCSGSettingsWrapperPrivate *) ccsObjectGetPrivate (w);
7
8+static Bool keyIsValid (GSettings *settings, const char *key)
9+{
10+ GSettingsSchema *schema;
11+ Bool valid = FALSE;
12+
13+ if (!settings)
14+ return valid;
15+
16+ g_object_get (settings, "settings-schema", &schema, NULL);
17+
18+ if (schema)
19+ {
20+ valid = g_settings_schema_has_key (schema, key);
21+ g_settings_schema_unref (schema);
22+ }
23+
24+ return valid;
25+}
26+
27 static GVariant * ccsGSettingsWrapperGetValueDefault (CCSGSettingsWrapper *wrapper, const char *key)
28 {
29 GSETTINGS_WRAPPER_PRIVATE (wrapper);
30
31- return g_settings_get_value (gswPrivate->settings, key);
32+ if (keyIsValid (gswPrivate->settings, key))
33+ return g_settings_get_value (gswPrivate->settings, key);
34+ else
35+ return NULL;
36 }
37
38 static void ccsGSettingsWrapperSetValueDefault (CCSGSettingsWrapper *wrapper, const char *key, GVariant *variant)
39 {
40 GSETTINGS_WRAPPER_PRIVATE (wrapper);
41
42- g_settings_set_value (gswPrivate->settings, key, variant);
43+ if (keyIsValid (gswPrivate->settings, key))
44+ g_settings_set_value (gswPrivate->settings, key, variant);
45 }
46
47 static void ccsGSettingsWrapperResetKeyDefault (CCSGSettingsWrapper *wrapper, const char *key)
48 {
49 GSETTINGS_WRAPPER_PRIVATE (wrapper);
50
51- g_settings_reset (gswPrivate->settings, key);
52+ if (keyIsValid (gswPrivate->settings, key))
53+ g_settings_reset (gswPrivate->settings, key);
54 }
55
56 static char ** ccsGSettingsWrapperListKeysDefault (CCSGSettingsWrapper *wrapper)
57
58=== modified file 'compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c'
59--- compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c 2013-05-13 13:23:20 +0000
60+++ compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c 2016-07-26 15:08:17 +0000
61@@ -452,24 +452,24 @@
62 }
63
64 Bool
65-checkReadVariantIsValid (GVariant *gsettingsValue, CCSSettingType type, const gchar *pathName)
66+checkReadVariantIsValid (GVariant *gsettingsValue, CCSSettingType type, const gchar *pathName, const gchar *key)
67 {
68 /* first check if the key is set */
69 if (!gsettingsValue)
70 {
71- ccsWarning ("There is no key at the path %s. "
72- "Settings from this path won't be read. Try to remove "
73- "that value so that operation can continue properly.",
74- pathName);
75+ ccsWarning ("There is no key '%s' at the path %s. "
76+ "Settings from this path won't be read. Default value will be used."
77+ "Ensure this setting is available or the setting backend is properly configured.",
78+ key, pathName);
79 return FALSE;
80 }
81
82 if (!variantIsValidForCCSType (gsettingsValue, type))
83 {
84- ccsWarning ("There is an unsupported value at path %s. "
85- "Settings from this path won't be read. Try to remove "
86- "that value so that operation can continue properly.",
87- pathName);
88+ ccsWarning ("There is an unsupported value for key '%s' at path %s. "
89+ "Settings from this path won't be read. Default value will be used. "
90+ "Ensure this setting is available or the setting backend is properly configured.",
91+ key, pathName);
92 return FALSE;
93 }
94
95@@ -481,9 +481,10 @@
96 {
97 GVariant *gsettingsValue = ccsGSettingsWrapperGetValue (settings, key);
98
99- if (!checkReadVariantIsValid (gsettingsValue, type, pathName))
100+ if (!checkReadVariantIsValid (gsettingsValue, type, pathName, key))
101 {
102- g_variant_unref (gsettingsValue);
103+ if (gsettingsValue)
104+ g_variant_unref (gsettingsValue);
105 return NULL;
106 }
107
108
109=== modified file 'compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h'
110--- compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h 2012-11-13 15:51:59 +0000
111+++ compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h 2016-07-26 15:08:17 +0000
112@@ -109,7 +109,7 @@
113 getNameForCCSSetting (CCSSetting *setting);
114
115 Bool
116-checkReadVariantIsValid (GVariant *gsettingsValue, CCSSettingType type, const gchar *pathName);
117+checkReadVariantIsValid (GVariant *gsettingsValue, CCSSettingType type, const gchar *pathName, const gchar *key);
118
119 GVariant *
120 getVariantAtKey (CCSGSettingsWrapper *settings, const char *key, const char *pathName, CCSSettingType type);
121
122=== modified file 'compizconfig/gsettings/tests/test_gsettings_tests.cpp'
123--- compizconfig/gsettings/tests/test_gsettings_tests.cpp 2013-05-13 15:49:42 +0000
124+++ compizconfig/gsettings/tests/test_gsettings_tests.cpp 2016-07-26 15:08:17 +0000
125@@ -1207,14 +1207,14 @@
126
127 TEST_F(CCSGSettingsTestIndependent, TestReadVariantIsValidNULL)
128 {
129- EXPECT_FALSE (checkReadVariantIsValid (NULL, TypeNum, "foo/bar"));
130+ EXPECT_FALSE (checkReadVariantIsValid (NULL, TypeNum, "foo/bar", "key"));
131 }
132
133 TEST_F(CCSGSettingsTestIndependent, TestReadVariantIsValidTypeBad)
134 {
135 GVariant *v = g_variant_new ("i", 1);
136
137- EXPECT_FALSE (checkReadVariantIsValid (v, TypeString, "foo/bar"));
138+ EXPECT_FALSE (checkReadVariantIsValid (v, TypeString, "foo/bar", "key"));
139
140 g_variant_unref (v);
141 }
142@@ -1223,7 +1223,7 @@
143 {
144 GVariant *v = g_variant_new ("i", 1);
145
146- EXPECT_TRUE (checkReadVariantIsValid (v, TypeInt, "foo/bar"));
147+ EXPECT_TRUE (checkReadVariantIsValid (v, TypeInt, "foo/bar", "key"));
148
149 g_variant_unref (v);
150 }

Subscribers

People subscribed via source and target branches