[gtk/wip/baedert/nodeeditor: 24/24] rendernodeparser: Actually set a GError if parsing fails
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/baedert/nodeeditor: 24/24] rendernodeparser: Actually set a GError if parsing fails
- Date: Tue, 23 Apr 2019 16:35:04 +0000 (UTC)
commit 4be5ee9546de14f7ac8f89aeeb28cb2be1982860
Author: Timm Bäder <mail baedert org>
Date: Tue Apr 23 18:30:57 2019 +0200
rendernodeparser: Actually set a GError if parsing fails
gsk/gskrendernode.c | 2 +-
gsk/gskrendernodeparser.c | 32 +++++++++++++++++++++++++++-----
gsk/gskrendernodeparserprivate.h | 3 ++-
3 files changed, 30 insertions(+), 7 deletions(-)
---
diff --git a/gsk/gskrendernode.c b/gsk/gskrendernode.c
index f785db11c0..5f30c70b05 100644
--- a/gsk/gskrendernode.c
+++ b/gsk/gskrendernode.c
@@ -392,7 +392,7 @@ gsk_render_node_deserialize (GBytes *bytes,
{
GskRenderNode *node = NULL;
- node = gsk_render_node_deserialize_from_bytes (bytes);
+ node = gsk_render_node_deserialize_from_bytes (bytes, error);
return node;
}
diff --git a/gsk/gskrendernodeparser.c b/gsk/gskrendernodeparser.c
index 66fa9156e6..4a976bfbc8 100644
--- a/gsk/gskrendernodeparser.c
+++ b/gsk/gskrendernodeparser.c
@@ -946,24 +946,40 @@ gsk_render_node_parser_error (GtkCssParser *parser,
const GError *error,
gpointer user_data)
{
+ GString **error_string = user_data;
+
+ if (!*error_string)
+ *error_string = g_string_new (NULL);
+
+ g_string_append_printf (*error_string,
+ "ERROR: %zu:%zu: %s\n",
+ start->lines + 1,
+ start->line_chars,
+ error->message);
+#if 0
g_print ("ERROR: %zu:%zu: %s\n",
- start->lines, start->line_chars,
- error->message);
+ start->lines + 1,
+ start->line_chars,
+ error->message);
+#endif
}
/**
* All errors are fatal.
*/
GskRenderNode *
-gsk_render_node_deserialize_from_bytes (GBytes *bytes)
+gsk_render_node_deserialize_from_bytes (GBytes *bytes,
+ GError **error)
{
GskRenderNode *root = NULL;
GtkCssParser *parser;
+ GString *error_string = NULL;
- parser = gtk_css_parser_new_for_bytes (bytes, NULL, NULL, gsk_render_node_parser_error, NULL, NULL);
+ parser = gtk_css_parser_new_for_bytes (bytes, NULL, NULL, gsk_render_node_parser_error,
+ &error_string, NULL);
root = parse_container_node (parser);
- if (gsk_container_node_get_n_children (root) == 1)
+ if (root && gsk_container_node_get_n_children (root) == 1)
{
GskRenderNode *child = gsk_container_node_get_child (root, 0);
@@ -974,6 +990,12 @@ gsk_render_node_deserialize_from_bytes (GBytes *bytes)
gtk_css_parser_unref (parser);
+ if (error_string != NULL)
+ {
+ *error = g_error_new_literal (GTK_CSS_PARSER_ERROR, 0, error_string->str);
+ g_string_free (error_string, TRUE);
+ }
+
return root;
}
diff --git a/gsk/gskrendernodeparserprivate.h b/gsk/gskrendernodeparserprivate.h
index cd5052dcf9..9d72643c00 100644
--- a/gsk/gskrendernodeparserprivate.h
+++ b/gsk/gskrendernodeparserprivate.h
@@ -4,7 +4,8 @@
#include "gskrendernode.h"
-GskRenderNode * gsk_render_node_deserialize_from_bytes (GBytes *bytes);
+GskRenderNode * gsk_render_node_deserialize_from_bytes (GBytes *bytes,
+ GError **error);
char * gsk_render_node_serialize_to_string (GskRenderNode *root);
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]