[glib: 12/33] gutils: Refactor g_get_home_dir() to use a global variable
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 12/33] gutils: Refactor g_get_home_dir() to use a global variable
- Date: Mon, 17 Dec 2018 17:52:49 +0000 (UTC)
commit 8da50ac40ca198d3b4e65414fe30988cdaefdadd
Author: Philip Withnall <withnall endlessm com>
Date: Fri Nov 30 17:29:56 2018 +0000
gutils: Refactor g_get_home_dir() to use a global variable
While this might seem like a regression, it means that the home
directory can be overridden by GLib internal code, which will be done in
an upcoming commit. This brings g_get_home_dir() inline with functions
like g_get_user_data_dir().
Signed-off-by: Philip Withnall <withnall endlessm com>
https://gitlab.gnome.org/GNOME/glib/issues/538
glib/gutils.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
---
diff --git a/glib/gutils.c b/glib/gutils.c
index 3937ff5e5..49b87abfa 100644
--- a/glib/gutils.c
+++ b/glib/gutils.c
@@ -791,6 +791,9 @@ g_get_real_name (void)
return entry->real_name;
}
+/* Protected by @g_utils_global_lock. */
+static gchar *g_home_dir = NULL; /* (owned) (nullable before initialised) */
+
/**
* g_get_home_dir:
*
@@ -820,9 +823,9 @@ g_get_real_name (void)
const gchar *
g_get_home_dir (void)
{
- static gchar *home_dir;
+ G_LOCK (g_utils_global);
- if (g_once_init_enter (&home_dir))
+ if (g_home_dir == NULL)
{
gchar *tmp;
@@ -899,10 +902,12 @@ g_get_home_dir (void)
tmp = "/";
}
- g_once_init_leave (&home_dir, tmp);
+ g_home_dir = g_steal_pointer (&tmp);
}
- return home_dir;
+ G_UNLOCK (g_utils_global);
+
+ return g_home_dir;
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]