summaryrefslogtreecommitdiff
path: root/gsk
diff options
context:
space:
mode:
authorTimm Bäder <mail@baedert.org>2019-04-24 18:30:46 +0200
committerBenjamin Otte <otte@redhat.com>2019-05-05 07:18:39 +0200
commitdde69802cd2bcea34d51565ec51048ebdab545b1 (patch)
tree2afea256b4881efee0620168a4dd494dc1948e91 /gsk
parent5530331b356c8bf5ab9494eedefedb44f8f9e7ed (diff)
downloadgtk+-dde69802cd2bcea34d51565ec51048ebdab545b1.tar.gz
Add error func to node deserialization
Diffstat (limited to 'gsk')
-rw-r--r--gsk/gskrendernode.c7
-rw-r--r--gsk/gskrendernode.h10
-rw-r--r--gsk/gskrendernodeparser.c36
-rw-r--r--gsk/gskrendernodeparserprivate.h5
4 files changed, 33 insertions, 25 deletions
diff --git a/gsk/gskrendernode.c b/gsk/gskrendernode.c
index 5f30c70b05..1b1dd2d78f 100644
--- a/gsk/gskrendernode.c
+++ b/gsk/gskrendernode.c
@@ -387,12 +387,13 @@ gsk_render_node_write_to_file (GskRenderNode *node,
* error.
**/
GskRenderNode *
-gsk_render_node_deserialize (GBytes *bytes,
- GError **error)
+gsk_render_node_deserialize (GBytes *bytes,
+ GskParseErrorFunc error_func,
+ gpointer user_data)
{
GskRenderNode *node = NULL;
- node = gsk_render_node_deserialize_from_bytes (bytes, error);
+ node = gsk_render_node_deserialize_from_bytes (bytes, error_func, user_data);
return node;
}
diff --git a/gsk/gskrendernode.h b/gsk/gskrendernode.h
index 2aa270cb37..b1ae30785e 100644
--- a/gsk/gskrendernode.h
+++ b/gsk/gskrendernode.h
@@ -25,6 +25,7 @@
#include <gsk/gskroundedrect.h>
#include <gsk/gsktypes.h>
+#include <gtk/css/gtkcss.h>
G_BEGIN_DECLS
@@ -52,6 +53,10 @@ struct _GskShadow
float radius;
};
+typedef void (* GskParseErrorFunc) (const GtkCssSection *section,
+ const GError *error,
+ gpointer user_data);
+
GDK_AVAILABLE_IN_ALL
GType gsk_render_node_get_type (void) G_GNUC_CONST;
@@ -81,8 +86,9 @@ gboolean gsk_render_node_write_to_file (GskRenderNode *
const char *filename,
GError **error);
GDK_AVAILABLE_IN_ALL
-GskRenderNode * gsk_render_node_deserialize (GBytes *bytes,
- GError **error);
+GskRenderNode * gsk_render_node_deserialize (GBytes *bytes,
+ GskParseErrorFunc error_func,
+ gpointer user_data);
GDK_AVAILABLE_IN_ALL
GskRenderNode * gsk_debug_node_new (GskRenderNode *child,
diff --git a/gsk/gskrendernodeparser.c b/gsk/gskrendernodeparser.c
index 202800b0b4..9ebf4aab24 100644
--- a/gsk/gskrendernodeparser.c
+++ b/gsk/gskrendernodeparser.c
@@ -1072,28 +1072,34 @@ gsk_render_node_parser_error (GtkCssParser *parser,
const GError *error,
gpointer user_data)
{
- GString **error_string = user_data;
+ struct {
+ GskParseErrorFunc error_func;
+ gpointer user_data;
+ } *error_func_pair = user_data;
- if (!*error_string)
- *error_string = g_string_new (NULL);
+ if (error_func_pair->error_func)
+ {
+ GtkCssSection *section = gtk_css_section_new (gtk_css_parser_get_file (parser), start, end);
- g_string_append_printf (*error_string,
- "ERROR: %zu:%zu: %s\n",
- start->lines + 1,
- start->line_chars,
- error->message);
+ error_func_pair->error_func (section, error, error_func_pair->user_data);
+ gtk_css_section_unref (section);
+ }
}
GskRenderNode *
-gsk_render_node_deserialize_from_bytes (GBytes *bytes,
- GError **error)
+gsk_render_node_deserialize_from_bytes (GBytes *bytes,
+ GskParseErrorFunc error_func,
+ gpointer user_data)
{
GskRenderNode *root = NULL;
GtkCssParser *parser;
- GString *error_string = NULL;
+ struct {
+ GskParseErrorFunc error_func;
+ gpointer user_data;
+ } error_func_pair = { error_func, user_data };
parser = gtk_css_parser_new_for_bytes (bytes, NULL, NULL, gsk_render_node_parser_error,
- &error_string, NULL);
+ &error_func_pair, NULL);
root = parse_container_node (parser);
if (root && gsk_container_node_get_n_children (root) == 1)
@@ -1107,12 +1113,6 @@ 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 9d72643c00..a506244429 100644
--- a/gsk/gskrendernodeparserprivate.h
+++ b/gsk/gskrendernodeparserprivate.h
@@ -4,8 +4,9 @@
#include "gskrendernode.h"
-GskRenderNode * gsk_render_node_deserialize_from_bytes (GBytes *bytes,
- GError **error);
+GskRenderNode * gsk_render_node_deserialize_from_bytes (GBytes *bytes,
+ GskParseErrorFunc error_func,
+ gpointer user_data);
char * gsk_render_node_serialize_to_string (GskRenderNode *root);
#endif