Merge branch 'matthiasc/css-deprecation-warning' into 'main'

css: Emit deprecation warnings only under debug

See merge request GNOME/gtk!7330
This commit is contained in:
Matthias Clasen 2024-06-02 15:33:32 +00:00
commit 1080822ffa
3 changed files with 30 additions and 16 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -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:
*