diff options
-rw-r--r-- | demos/node-editor/node-editor-window.c | 9 | ||||
-rw-r--r-- | gsk/gskrendernode.h | 23 | ||||
-rw-r--r-- | gsk/gskrendernodeparser.c | 10 | ||||
-rw-r--r-- | tests/rendernode.c | 23 | ||||
-rw-r--r-- | tests/showrendernode.c | 23 | ||||
-rw-r--r-- | testsuite/gsk/compare-render.c | 24 | ||||
-rw-r--r-- | testsuite/gsk/node-parser.c | 25 |
7 files changed, 93 insertions, 44 deletions
diff --git a/demos/node-editor/node-editor-window.c b/demos/node-editor/node-editor-window.c index 73cf2b06ec..ff536d60ca 100644 --- a/demos/node-editor/node-editor-window.c +++ b/demos/node-editor/node-editor-window.c @@ -102,12 +102,11 @@ text_buffer_remove_all_tags (GtkTextBuffer *buffer) } static void -deserialize_error_func (const GtkCssSection *section, - const GError *error, - gpointer user_data) +deserialize_error_func (const GskParseLocation *start_location, + const GskParseLocation *end_location, + const GError *error, + gpointer user_data) { - const GtkCssLocation *start_location = gtk_css_section_get_start_location (section); - const GtkCssLocation *end_location = gtk_css_section_get_end_location (section); NodeEditorWindow *self = user_data; GtkTextIter start_iter, end_iter; TextViewError text_view_error; diff --git a/gsk/gskrendernode.h b/gsk/gskrendernode.h index dd655d3b35..683bf5d9ff 100644 --- a/gsk/gskrendernode.h +++ b/gsk/gskrendernode.h @@ -54,18 +54,31 @@ struct _GskShadow float radius; }; +typedef struct _GskParseLocation GskParseLocation; + +struct _GskParseLocation +{ + gsize bytes; + gsize chars; + gsize lines; + gsize line_bytes; + gsize line_chars; +}; + /** * GskParseErrorFunc: - * @section: the #GtkCssSection where the error occurred - * @error: the error + * @start: start of the error location + * @end: end of the error location + * @error: the error * @user_data: user data * * The type of callback that is called when a parse error occurs * during deserialization of node data. */ -typedef void (* GskParseErrorFunc) (const GtkCssSection *section, - const GError *error, - gpointer user_data); +typedef void (* GskParseErrorFunc) (const GskParseLocation *start, + const GskParseLocation *end, + const GError *error, + gpointer user_data); GDK_AVAILABLE_IN_ALL GType gsk_render_node_get_type (void) G_GNUC_CONST; diff --git a/gsk/gskrendernodeparser.c b/gsk/gskrendernodeparser.c index 320f74a13c..2be0a55393 100644 --- a/gsk/gskrendernodeparser.c +++ b/gsk/gskrendernodeparser.c @@ -1859,12 +1859,10 @@ gsk_render_node_parser_error (GtkCssParser *parser, } *error_func_pair = user_data; if (error_func_pair->error_func) - { - GtkCssSection *section = gtk_css_section_new (gtk_css_parser_get_file (parser), start, end); - - error_func_pair->error_func (section, error, error_func_pair->user_data); - gtk_css_section_unref (section); - } + error_func_pair->error_func ((const GskParseLocation *)start, + (const GskParseLocation *)end, + error, + error_func_pair->user_data); } GskRenderNode * diff --git a/tests/rendernode.c b/tests/rendernode.c index 786cc6d050..d0e3230663 100644 --- a/tests/rendernode.c +++ b/tests/rendernode.c @@ -14,15 +14,26 @@ static GOptionEntry options[] = { }; static void -deserialize_error_func (const GtkCssSection *section, - const GError *error, - gpointer user_data) +deserialize_error_func (const GskParseLocation *start, + const GskParseLocation *end, + const GError *error, + gpointer user_data) { - char *section_str = gtk_css_section_to_string (section); + GString *string = g_string_new ("<data>"); - g_warning ("Error at %s: %s", section_str, error->message); + g_string_append_printf (string, ":%zu:%zu", + start->lines + 1, start->line_chars + 1); + if (start->lines != end->lines || start->line_chars != end->line_chars) + { + g_string_append (string, "-"); + if (start->lines != end->lines) + g_string_append_printf (string, "%zu:", end->lines + 1); + g_string_append_printf (string, "%zu", end->line_chars + 1); + } + + g_warning ("Error at %s: %s", string->str, error->message); - g_free (section_str); + g_string_free (string, TRUE); } diff --git a/tests/showrendernode.c b/tests/showrendernode.c index 92bc6d40eb..5fafd3c00e 100644 --- a/tests/showrendernode.c +++ b/tests/showrendernode.c @@ -102,15 +102,26 @@ gtk_node_view_class_init (GtkNodeViewClass *klass) } static void -deserialize_error_func (const GtkCssSection *section, - const GError *error, - gpointer user_data) +deserialize_error_func (const GskParseLocation *start, + const GskParseLocation *end, + const GError *error, + gpointer user_data) { - char *section_str = gtk_css_section_to_string (section); + GString *string = g_string_new ("<data>"); - g_warning ("Error at %s: %s", section_str, error->message); + g_string_append_printf (string, ":%zu:%zu", + start->lines + 1, start->line_chars + 1); + if (start->lines != end->lines || start->line_chars != end->line_chars) + { + g_string_append (string, "-"); + if (start->lines != end->lines) + g_string_append_printf (string, "%zu:", end->lines + 1); + g_string_append_printf (string, "%zu", end->line_chars + 1); + } + + g_warning ("Error at %s: %s", string->str, error->message); - g_free (section_str); + g_string_free (string, TRUE); } static void diff --git a/testsuite/gsk/compare-render.c b/testsuite/gsk/compare-render.c index c71ee55b7c..562a82e5d7 100644 --- a/testsuite/gsk/compare-render.c +++ b/testsuite/gsk/compare-render.c @@ -111,16 +111,26 @@ save_image (cairo_surface_t *surface, } static void -deserialize_error_func (const GtkCssSection *section, - const GError *error, - gpointer user_data) +deserialize_error_func (const GskParseLocation *start, + const GskParseLocation *end, + const GError *error, + gpointer user_data) { - char *section_str = gtk_css_section_to_string (section); + GString *string = g_string_new ("<data>"); - g_print ("Error at %s: %s", section_str, error->message); - *((gboolean *) user_data) = FALSE; + g_string_append_printf (string, ":%zu:%zu", + start->lines + 1, start->line_chars + 1); + if (start->lines != end->lines || start->line_chars != end->line_chars) + { + g_string_append (string, "-"); + if (start->lines != end->lines) + g_string_append_printf (string, "%zu:", end->lines + 1); + g_string_append_printf (string, "%zu", end->line_chars + 1); + } + + g_warning ("Error at %s: %s", string->str, error->message); - free (section_str); + g_string_free (string, TRUE); } static const GOptionEntry options[] = { diff --git a/testsuite/gsk/node-parser.c b/testsuite/gsk/node-parser.c index cd3c930461..e7cf97887e 100644 --- a/testsuite/gsk/node-parser.c +++ b/testsuite/gsk/node-parser.c @@ -122,19 +122,26 @@ append_error_value (GString *string, } static void -deserialize_error_func (const GtkCssSection *section, - const GError *error, - gpointer user_data) +deserialize_error_func (const GskParseLocation *start, + const GskParseLocation *end, + const GError *error, + gpointer user_data) { GString *errors = user_data; - char *section_string; + GString *string = g_string_new ("<data>"); - section_string = gtk_css_section_to_string (section); + g_string_append_printf (string, ":%zu:%zu", + start->lines + 1, start->line_chars + 1); + if (start->lines != end->lines || start->line_chars != end->line_chars) + { + g_string_append (string, "-"); + if (start->lines != end->lines) + g_string_append_printf (string, "%zu:", end->lines + 1); + g_string_append_printf (string, "%zu", end->line_chars + 1); + } - g_string_append_printf (errors, - "%s: error: ", - section_string); - g_free (section_string); + g_string_append_printf (errors, "%s: error: ", string->str); + g_string_free (string, TRUE); if (error->domain == GTK_CSS_PARSER_ERROR) append_error_value (errors, GTK_TYPE_CSS_PARSER_ERROR, error->code); |