Commit 6321ef7f authored by Natanael Copa's avatar Natanael Copa

main/glib: simplify gquark fix

parent db000eb5
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
From bc7c6ec8184750289d9d9103a6bdd40adbf4627a Mon Sep 17 00:00:00 2001
From: Natanael Copa <ncopa@alpinelinux.org>
Date: Thu, 30 Jun 2016 09:48:20 +0200
Subject: [PATCH] gquark: make sure quark is initialized before create new
quark
When g_quark_from_string/g_quark_from_static_string is used to
initialize a global variable it may be called before glib_init's ctor.
Make sure that quark is initialized in those cases.
https://bugzilla.gnome.org/show_bug.cgi?id=768215
---
glib/gquark.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/glib/gquark.c b/glib/gquark.c
index 9e51a92..2f145ae 100644
--- a/glib/gquark.c
+++ b/glib/gquark.c
@@ -57,6 +57,13 @@ static gint quark_block_offset = 0;
void
g_quark_init (void)
{
+ static gboolean quark_inited;
+
+ if (quark_inited)
+ return;
+
+ quark_inited = TRUE;
+
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);
@@ -209,6 +216,7 @@ g_quark_from_string (const gchar *string)
return 0;
G_LOCK (quark_global);
+ g_quark_init();
quark = quark_from_string (string, TRUE);
G_UNLOCK (quark_global);
@@ -243,6 +251,7 @@ g_quark_from_static_string (const gchar *string)
return 0;
G_LOCK (quark_global);
+ g_quark_init();
quark = quark_from_string (string, FALSE);
G_UNLOCK (quark_global);
--
2.9.0
......@@ -2,7 +2,7 @@
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=glib
pkgver=2.48.1
pkgrel=0
pkgrel=1
pkgdesc="Common C routines used by Gtk+ and other libs"
url="http://www.gtk.org"
arch="all"
......@@ -12,7 +12,7 @@ triggers="$pkgname.trigger=/usr/share/glib-2.0/schemas:/usr/lib/gio/modules"
depends_dev="perl python gettext-dev zlib-dev bzip2-dev libffi-dev"
makedepends="$depends_dev pcre-dev"
source="http://ftp.gnome.org/pub/gnome/sources/$pkgname/${pkgver%.*}/$pkgname-$pkgver.tar.xz
0001-gquark-make-sure-quark-is-initialized-before-create-.patch
0001-gquark-fix-initialization-with-c-constructors.patch
"
subpackages="$pkgname-dbg $pkgname-doc $pkgname-dev $pkgname-lang $pkgname-bash-completion:bashcomp"
......@@ -75,8 +75,8 @@ bashcomp() {
}
md5sums="67bd3b75c9f6d5587b457dc01cdcd5bb glib-2.48.1.tar.xz
6eb959b045db81dc552edd2695911671 0001-gquark-make-sure-quark-is-initialized-before-create-.patch"
6dc9823b4b7b7e6ae1de6fac1db5fb09 0001-gquark-fix-initialization-with-c-constructors.patch"
sha256sums="74411bff489cb2a3527bac743a51018841a56a4d896cc1e0d0d54f8166a14612 glib-2.48.1.tar.xz
bdddb06d2a3aaccb5846e4a3f9ae1b052d6606384d6159c2d6bf3796e28759dc 0001-gquark-make-sure-quark-is-initialized-before-create-.patch"
2024aa0723f657be4ade791acc4e8ca427f9a2caa1d82e0dd955494ee922ccba 0001-gquark-fix-initialization-with-c-constructors.patch"
sha512sums="5bbea7d07ba6d75c35c6be8f1ebc685aa2549bd20030741b2d6e2c30e9b2d476c2afa50a974bbdad98c305666c8b04357b51619c97fe50d3e9965700088aad9b glib-2.48.1.tar.xz
8a9cd51ee9f557772e35614d42071e1197c0164d40503871e3e79e116bed6f6a5c8f82fd3f377b5e334f342d2d1df60d404ea0ed885989d7e3412b6795fb5469 0001-gquark-make-sure-quark-is-initialized-before-create-.patch"
32e5aca9a315fb985fafa0b4355e4498c1f877fc1f0b58ad4ac261fb9fbced9f026c7756a5f2af7d61ce756b55c8cd02811bb08df397040e93510056f073756b 0001-gquark-fix-initialization-with-c-constructors.patch"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment