summaryrefslogtreecommitdiff
path: root/extra/glib/0001-gquark-fix-initialization-with-c-constructors.patch
blob: 50a9a8c28a12cf9f1e76466ec1963ef8065ee130 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
From e4216dee57f5156e192b2910f13eb855a104cb18 Mon Sep 17 00:00:00 2001
From: Natanael Copa <ncopa@alpinelinux.org>
Date: Wed, 6 Jul 2016 12:38:40 +0200
Subject: [PATCH] gquark: fix initialization with c++ constructors

C++ constructors may want create new quarks, but we can not guarantee
that the glib library ctor is executed first. Therefore we make sure
that quarks are always initialized from g_quark_from_string and
g_quark_from_static_string

This fixes crashes in glibmm with musl which likely happens on AIX too.

https://bugzilla.gnome.org/show_bug.cgi?id=768215
https://bugzilla.gnome.org/show_bug.cgi?id=756139#c14
---
 glib/gquark.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/glib/gquark.c b/glib/gquark.c
index 9e51a92..17ecd7f 100644
--- a/glib/gquark.c
+++ b/glib/gquark.c
@@ -57,6 +57,11 @@ static gint           quark_block_offset = 0;
 void
 g_quark_init (void)
 {
+  /* we may be initialized from c++ constructor or the glib ctor, but we
+  cannot guarantee in what order. So we check if we have been initialized */
+  if (quark_ht != NULL)
+    return;
+
   g_assert (quark_seq_id == 0);
   quark_ht = g_hash_table_new (g_str_hash, g_str_equal);
   quarks = g_new (gchar*, QUARK_BLOCK_SIZE);
@@ -179,6 +184,9 @@ quark_from_string (const gchar *string,
 {
   GQuark quark = 0;
 
+  if (G_UNLIKELY (quark_ht == NULL))
+    g_quark_init();
+
   quark = GPOINTER_TO_UINT (g_hash_table_lookup (quark_ht, string));
 
   if (!quark)
-- 
2.9.0