From b0d283e49d44a360d9227bd525715e9501ec793e Mon Sep 17 00:00:00 2001
From: Ludovico de Nittis <ludovico.denittis@collabora.com>
Date: Tue, 6 Apr 2021 13:24:19 +0200
Subject: [PATCH] glib-backports-internal: Backport g_warning_once from glib

This is useful when we want to log a warning message without spamming
the same message over and over.

Signed-off-by: Ludovico de Nittis <ludovico.denittis@collabora.com>
---
 steam-runtime-tools/glib-backports-internal.h | 22 +++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/steam-runtime-tools/glib-backports-internal.h b/steam-runtime-tools/glib-backports-internal.h
index 3cc2516f7..5f82fa3a0 100644
--- a/steam-runtime-tools/glib-backports-internal.h
+++ b/steam-runtime-tools/glib-backports-internal.h
@@ -126,3 +126,25 @@ gchar *my_g_utf8_make_valid (const gchar *str,
                                G_LOG_LEVEL_INFO,     \
                                __VA_ARGS__)
 #endif
+
+#if !GLIB_CHECK_VERSION(2, 64, 0)
+#if defined(G_HAVE_ISO_VARARGS) && (!defined(G_ANALYZER_ANALYZING) || !G_ANALYZER_ANALYZING)
+#define g_warning_once(...) \
+  G_STMT_START { \
+    static int G_PASTE (_GWarningOnceBoolean, __LINE__) = 0;  /* (atomic) */ \
+    if (g_atomic_int_compare_and_exchange (&G_PASTE (_GWarningOnceBoolean, __LINE__), \
+                                           0, 1)) \
+      g_warning (__VA_ARGS__); \
+  } G_STMT_END
+#elif defined(G_HAVE_GNUC_VARARGS) && (!defined(G_ANALYZER_ANALYZING) || !G_ANALYZER_ANALYZING)
+#define g_warning_once(format...) \
+  G_STMT_START { \
+    static int G_PASTE (_GWarningOnceBoolean, __LINE__) = 0;  /* (atomic) */ \
+    if (g_atomic_int_compare_and_exchange (&G_PASTE (_GWarningOnceBoolean, __LINE__), \
+                                           0, 1)) \
+      g_warning (format); \
+  } G_STMT_END
+#else
+#define g_warning_once g_warning
+#endif
+#endif
-- 
GitLab