From 3fef45683c27e0c9a943e4da058a23d705a01e8b Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 2 Jun 2024 15:33:32 +0000 Subject: [PATCH] css: Emit deprecation warnings only under debug --- gtk/css/gtkcssparser.c | 39 +++++++++++++++++++++-------------- gtk/css/gtkcssparserprivate.h | 4 ++++ gtk/gtkcssprovider.c | 3 +++ 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/gtk/css/gtkcssparser.c b/gtk/css/gtkcssparser.c index b375a19107..40ec881ea7 100644 --- a/gtk/css/gtkcssparser.c +++ b/gtk/css/gtkcssparser.c @@ -26,6 +26,10 @@ #include "gtkcsserror.h" #include "gtkcsslocationprivate.h" +/* We cannot include gtkdebug.h, so we must keep this in sync */ +extern unsigned int gtk_get_debug_flags (void); +#define DEBUG_CHECK_CSS ((gtk_get_debug_flags () & GTK_CSS_PARSER_DEBUG_CSS) != 0) + static void clear_ref (GtkCssVariableValueReference *ref); #define GDK_ARRAY_NAME gtk_css_parser_references @@ -626,7 +630,7 @@ void gtk_css_parser_skip (GtkCssParser *self) { const GtkCssToken *token; - + token = gtk_css_parser_get_token (self); if (gtk_css_token_is_preserved (token, NULL)) { @@ -659,7 +663,7 @@ gtk_css_parser_skip_until (GtkCssParser *self, GtkCssTokenType token_type) { const GtkCssToken *token; - + for (token = gtk_css_parser_get_token (self); !gtk_css_token_is (token, token_type) && !gtk_css_token_is (token, GTK_CSS_TOKEN_EOF); @@ -817,19 +821,22 @@ gtk_css_parser_warn_deprecated (GtkCssParser *self, const char *format, ...) { - va_list args; - GError *error; + if (DEBUG_CHECK_CSS) + { + va_list args; + GError *error; - va_start (args, format); - error = g_error_new_valist (GTK_CSS_PARSER_WARNING, - GTK_CSS_PARSER_WARNING_DEPRECATED, - format, args); - gtk_css_parser_emit_error (self, - gtk_css_parser_get_start_location (self), - gtk_css_parser_get_end_location (self), - error); - g_error_free (error); - va_end (args); + va_start (args, format); + error = g_error_new_valist (GTK_CSS_PARSER_WARNING, + GTK_CSS_PARSER_WARNING_DEPRECATED, + format, args); + gtk_css_parser_emit_error (self, + gtk_css_parser_get_start_location (self), + gtk_css_parser_get_end_location (self), + error); + g_error_free (error); + va_end (args); + } } gboolean @@ -1153,7 +1160,7 @@ gtk_css_parser_parse_url_arg (GtkCssParser *parser, *out_url = gtk_css_parser_consume_string (parser); if (*out_url == NULL) return 0; - + return 1; } @@ -1199,7 +1206,7 @@ gtk_css_parser_consume_url (GtkCssParser *self) gtk_css_parser_error_syntax (self, "Expected a URL"); return NULL; } - + return url; } diff --git a/gtk/css/gtkcssparserprivate.h b/gtk/css/gtkcssparserprivate.h index 7e7ae11470..fc29771918 100644 --- a/gtk/css/gtkcssparserprivate.h +++ b/gtk/css/gtkcssparserprivate.h @@ -172,5 +172,9 @@ void gtk_css_parser_get_expanding_variables (GtkCssParser char ***names, gsize *n_variables); + +/* We cannot include gtkdebug.h, so we must keep this in sync */ +#define GTK_CSS_PARSER_DEBUG_CSS (1 << 20) + G_END_DECLS diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c index 9c833f350e..83f63e1a2b 100644 --- a/gtk/gtkcssprovider.c +++ b/gtk/gtkcssprovider.c @@ -52,6 +52,9 @@ #define GDK_ARRAY_PREALLOC 64 #include "gdk/gdkarrayimpl.c" +/* For lack of a better place, assert here that these two definitions match */ +G_STATIC_ASSERT (GTK_DEBUG_CSS == GTK_CSS_PARSER_DEBUG_CSS); + /** * GtkCssProvider: *