From 8da50ac40ca198d3b4e65414fe30988cdaefdadd Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Fri, 30 Nov 2018 17:29:56 +0000 Subject: [PATCH] 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 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; } /**