summaryrefslogtreecommitdiff
path: root/gtk/gtkcssprovider.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2015-09-09 10:55:31 -0400
committerMatthias Clasen <mclasen@redhat.com>2015-09-09 11:17:13 -0400
commit2d29ae4159a084262e3aefd79d61987476e54a91 (patch)
treeed017134462e3277561a1f9b667ad2900f412a8b /gtk/gtkcssprovider.c
parent117b50f8fb033eb47335abc2743adec71f3d9d41 (diff)
downloadgtk+-2d29ae4159a084262e3aefd79d61987476e54a91.tar.gz
Handle match_all returning NULL
This is in preparation for not allocating an array at all if there are no matches.
Diffstat (limited to 'gtk/gtkcssprovider.c')
-rw-r--r--gtk/gtkcssprovider.c130
1 files changed, 68 insertions, 62 deletions
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index 66e7d85f86..18a2c9c12d 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -1638,15 +1638,20 @@ verify_tree_get_change_results (GtkCssProvider *provider,
int i;
tree_rules = _gtk_css_selector_tree_match_all (provider->priv->tree, matcher);
- verify_tree_match_results (provider, matcher, tree_rules);
-
- for (i = tree_rules->len - 1; i >= 0; i--)
+ if (tree_rules)
{
- GtkCssRuleset *ruleset;
+ verify_tree_match_results (provider, matcher, tree_rules);
+
+ for (i = tree_rules->len - 1; i >= 0; i--)
+ {
+ GtkCssRuleset *ruleset;
- ruleset = tree_rules->pdata[i];
+ ruleset = tree_rules->pdata[i];
+
+ verify_change |= _gtk_css_selector_get_change (ruleset->selector);
+ }
- verify_change |= _gtk_css_selector_get_change (ruleset->selector);
+ g_ptr_array_free (tree_rules, TRUE);
}
if (change != verify_change)
@@ -1671,8 +1676,6 @@ verify_tree_get_change_results (GtkCssProvider *provider,
g_warning (s->str);
g_string_free (s, TRUE);
}
-
- g_ptr_array_free (tree_rules, TRUE);
}
#endif
}
@@ -1711,46 +1714,46 @@ gtk_css_provider_get_style_property (GtkStyleProvider *provider,
}
tree_rules = _gtk_css_selector_tree_match_all (priv->tree, &matcher);
- verify_tree_match_results (css_provider, &matcher, tree_rules);
-
- prop_name = g_strdup_printf ("-%s-%s",
- g_type_name (pspec->owner_type),
- pspec->name);
-
- for (i = tree_rules->len - 1; i >= 0; i--)
+ if (tree_rules)
{
- GtkCssRuleset *ruleset = tree_rules->pdata[i];
+ verify_tree_match_results (css_provider, &matcher, tree_rules);
- if (ruleset->widget_style == NULL)
- continue;
+ prop_name = g_strdup_printf ("-%s-%s",
+ g_type_name (pspec->owner_type),
+ pspec->name);
- for (val = ruleset->widget_style; val != NULL; val = val->next)
- {
- if (strcmp (val->name, prop_name) == 0)
- {
- GtkCssScanner *scanner;
-
- scanner = gtk_css_scanner_new (css_provider,
- NULL,
- val->section,
- val->section != NULL ? gtk_css_section_get_file (val->section) : NULL,
- val->value);
+ for (i = tree_rules->len - 1; i >= 0; i--)
+ {
+ GtkCssRuleset *ruleset = tree_rules->pdata[i];
- found = _gtk_css_style_funcs_parse_value (value,
- scanner->parser);
+ if (ruleset->widget_style == NULL)
+ continue;
- gtk_css_scanner_destroy (scanner);
+ for (val = ruleset->widget_style; val != NULL; val = val->next)
+ {
+ if (strcmp (val->name, prop_name) == 0)
+ {
+ GtkCssScanner *scanner;
+
+ scanner = gtk_css_scanner_new (css_provider,
+ NULL,
+ val->section,
+ val->section != NULL ? gtk_css_section_get_file (val->section) : NULL,
+ val->value);
+ found = _gtk_css_style_funcs_parse_value (value, scanner->parser);
+ gtk_css_scanner_destroy (scanner);
+ break;
+ }
+ }
- break;
- }
- }
+ if (found)
+ break;
+ }
- if (found)
- break;
+ g_free (prop_name);
+ g_ptr_array_free (tree_rules, TRUE);
}
- g_free (prop_name);
- g_ptr_array_free (tree_rules, TRUE);
gtk_widget_path_unref (path);
return found;
@@ -1797,39 +1800,42 @@ gtk_css_style_provider_lookup (GtkStyleProviderPrivate *provider,
priv = css_provider->priv;
tree_rules = _gtk_css_selector_tree_match_all (priv->tree, matcher);
- verify_tree_match_results (css_provider, matcher, tree_rules);
-
- for (i = tree_rules->len - 1; i >= 0; i--)
+ if (tree_rules)
{
- ruleset = tree_rules->pdata[i];
+ verify_tree_match_results (css_provider, matcher, tree_rules);
- if (ruleset->styles == NULL)
- continue;
-
- if (!_gtk_bitmask_intersects (_gtk_css_lookup_get_missing (lookup),
- ruleset->set_styles))
- continue;
-
- for (j = 0; j < ruleset->n_styles; j++)
+ for (i = tree_rules->len - 1; i >= 0; i--)
{
- GtkCssStyleProperty *prop = ruleset->styles[j].property;
- guint id = _gtk_css_style_property_get_id (prop);
+ ruleset = tree_rules->pdata[i];
- if (!_gtk_css_lookup_is_missing (lookup, id))
+ if (ruleset->styles == NULL)
continue;
- _gtk_css_lookup_set (lookup,
- id,
- ruleset->styles[j].section,
- ruleset->styles[j].value);
+ if (!_gtk_bitmask_intersects (_gtk_css_lookup_get_missing (lookup),
+ ruleset->set_styles))
+ continue;
+
+ for (j = 0; j < ruleset->n_styles; j++)
+ {
+ GtkCssStyleProperty *prop = ruleset->styles[j].property;
+ guint id = _gtk_css_style_property_get_id (prop);
+
+ if (!_gtk_css_lookup_is_missing (lookup, id))
+ continue;
+
+ _gtk_css_lookup_set (lookup,
+ id,
+ ruleset->styles[j].section,
+ ruleset->styles[j].value);
+ }
+
+ if (_gtk_bitmask_is_empty (_gtk_css_lookup_get_missing (lookup)))
+ break;
}
- if (_gtk_bitmask_is_empty (_gtk_css_lookup_get_missing (lookup)))
- break;
+ g_ptr_array_free (tree_rules, TRUE);
}
- g_ptr_array_free (tree_rules, TRUE);
-
if (change)
{
GtkCssMatcher change_matcher;