From 5c7d24941902c75ad9c4ec1a67fabd4e298b496a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 31 Jan 2025 13:17:22 +0100 Subject: [PATCH] gobject: Add single function to check G_ENABLE_DIAGNOSTIC It was duplicated, and racing too --- gobject/gobject.c | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/gobject/gobject.c b/gobject/gobject.c index 8ab8e26e3..b029f1bef 100644 --- a/gobject/gobject.c +++ b/gobject/gobject.c @@ -1771,20 +1771,29 @@ g_object_real_dispose (GObject *object) g_datalist_id_set_data (&object->qdata, quark_closure_array, NULL); } +static gboolean +g_diagnostic_is_enabled (void) +{ + static const char *g_enable_diagnostic = NULL; + + if (g_once_init_enter_pointer (&g_enable_diagnostic)) + { + const gchar *value = g_getenv ("G_ENABLE_DIAGNOSTIC"); + + if (value == NULL) + value = "0"; + + g_once_init_leave_pointer (&g_enable_diagnostic, value); + } + + return g_enable_diagnostic[0] == '1'; +} + #ifdef G_ENABLE_DEBUG static gboolean floating_check (GObject *object) { - static const char *g_enable_diagnostic = NULL; - - if (G_UNLIKELY (g_enable_diagnostic == NULL)) - { - g_enable_diagnostic = g_getenv ("G_ENABLE_DIAGNOSTIC"); - if (g_enable_diagnostic == NULL) - g_enable_diagnostic = "0"; - } - - if (g_enable_diagnostic[0] == '1') + if (g_diagnostic_is_enabled ()) return g_object_is_floating (object); return FALSE; @@ -2082,21 +2091,10 @@ static void maybe_issue_property_deprecation_warning (const GParamSpec *pspec) { static GHashTable *already_warned_table; - static const gchar *enable_diagnostic; static GMutex already_warned_lock; gboolean already; - if (g_once_init_enter_pointer (&enable_diagnostic)) - { - const gchar *value = g_getenv ("G_ENABLE_DIAGNOSTIC"); - - if (!value) - value = "0"; - - g_once_init_leave_pointer (&enable_diagnostic, value); - } - - if (enable_diagnostic[0] == '0') + if (!g_diagnostic_is_enabled ()) return; /* We hash only on property names: this means that we could end up in