[gtk+] cssprovider: Have a section on import error
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] cssprovider: Have a section on import error
- Date: Mon, 16 Nov 2015 16:39:48 +0000 (UTC)
commit 0a4e88b79b9fa20ae0bd61ff68e99abeb5753da3
Author: Benjamin Otte <otte redhat com>
Date: Mon Nov 16 17:36:50 2015 +0100
cssprovider: Have a section on import error
When loading a nonexisting CSS file using
gtk_css_provider_load_from_file() or gtk_css_provider_load_from_path()
we would emit the error using a NULL scanner. Don't do that, because
we'll have a NULL section in that case and error handlers don't like
that.
Testcase attached.
https://bugzilla.redhat.com/show_bug.cgi?id=1277959
gtk/gtkcssprovider.c | 22 ++++++++++++++--------
testsuite/gtk/cssprovider.c | 13 +++++++++++++
2 files changed, 27 insertions(+), 8 deletions(-)
---
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index 50108c3..fbe9163 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -1943,6 +1943,9 @@ gtk_css_provider_error (GtkCssProvider *provider,
GError *error;
va_list args;
+ gtk_internal_return_if_fail (GTK_IS_CSS_PROVIDER (provider));
+ gtk_internal_return_if_fail (scanner != NULL);
+
va_start (args, format);
error = g_error_new_valist (domain, code, format, args);
va_end (args);
@@ -2725,21 +2728,24 @@ gtk_css_provider_load_internal (GtkCssProvider *css_provider,
}
else
{
- GtkCssSection *section;
-
- if (parent)
- section = gtk_css_section_ref (parent->section);
- else
- section = _gtk_css_section_new_for_file (GTK_CSS_SECTION_DOCUMENT, file);
+ scanner = gtk_css_scanner_new (css_provider,
+ parent,
+ parent ? parent->section : NULL,
+ file,
+ "");
+
+ gtk_css_scanner_push_section (scanner, GTK_CSS_SECTION_DOCUMENT);
gtk_css_provider_error (css_provider,
- parent,
+ scanner,
GTK_CSS_PROVIDER_ERROR,
GTK_CSS_PROVIDER_ERROR_IMPORT,
"Failed to import: %s",
load_error->message);
- gtk_css_section_unref (section);
+ gtk_css_scanner_pop_section (scanner, GTK_CSS_SECTION_DOCUMENT);
+
+ gtk_css_scanner_destroy (scanner);
}
}
diff --git a/testsuite/gtk/cssprovider.c b/testsuite/gtk/cssprovider.c
index 5222620..413c750 100644
--- a/testsuite/gtk/cssprovider.c
+++ b/testsuite/gtk/cssprovider.c
@@ -50,6 +50,18 @@ G_GNUC_END_IGNORE_DEPRECATIONS;
g_object_unref (provider);
}
+static void
+test_section_load_nonexisting_file (void)
+{
+ GtkCssProvider *provider;
+
+ provider = gtk_css_provider_new ();
+ g_signal_connect (provider, "parsing-error",
+ G_CALLBACK (assert_section_is_not_null), NULL);
+ gtk_css_provider_load_from_path (provider, "this/path/does/absolutely/not/exist.css", NULL);
+ g_object_unref (provider);
+}
+
int
main (int argc, char *argv[])
{
@@ -58,6 +70,7 @@ main (int argc, char *argv[])
g_test_add_func ("/cssprovider/section-in-load-from-data", test_section_in_load_from_data);
g_test_add_func ("/cssprovider/section-in-style-property", test_section_in_style_property);
+ g_test_add_func ("/cssprovider/load-nonexisting-file", test_section_load_nonexisting_file);
return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]