diff options
author | Seungha Yang <seungha@centricular.com> | 2021-07-08 18:37:06 +0900 |
---|---|---|
committer | Seungha Yang <seungha@centricular.com> | 2021-07-08 18:37:06 +0900 |
commit | 79c819cd445e993800f71b1d015a45bc8fe610d7 (patch) | |
tree | 3bf154681898db61c232af0dae99f3b34a2a935f | |
parent | d872ccfd1c542eb45e6efdd0090607644bfed7a3 (diff) |
glib: Fix hang on Windows when G_SLICE env is configured
Apply upstream fix https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1698
Part-of: <https://gitlab.freedesktop.org/gstreamer/cerbero/-/merge_requests/712>
-rw-r--r-- | recipes/glib.recipe | 2 | ||||
-rw-r--r-- | recipes/glib/0001-gslice-Inline-win32-implementation-of-g_getenv-to-av.patch | 89 |
2 files changed, 91 insertions, 0 deletions
diff --git a/recipes/glib.recipe b/recipes/glib.recipe index 8f86494b..e6f3a2d5 100644 --- a/recipes/glib.recipe +++ b/recipes/glib.recipe @@ -60,6 +60,8 @@ class Recipe(recipe.Recipe): 'glib/0001-Windows-fix-FD_READ-condition-flag-still-set-on-reco.patch', # https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1428 'glib/0001-Add-missing-extern-to-the-dllexport-version-of-GLIB_.patch', + # https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1698 + 'glib/0001-gslice-Inline-win32-implementation-of-g_getenv-to-av.patch', ] files_libs = [ diff --git a/recipes/glib/0001-gslice-Inline-win32-implementation-of-g_getenv-to-av.patch b/recipes/glib/0001-gslice-Inline-win32-implementation-of-g_getenv-to-av.patch new file mode 100644 index 00000000..c4920a87 --- /dev/null +++ b/recipes/glib/0001-gslice-Inline-win32-implementation-of-g_getenv-to-av.patch @@ -0,0 +1,89 @@ +From b538cb0c8c829ba76d4a04be0c198e5d3b7c311c Mon Sep 17 00:00:00 2001 +From: Philip Withnall <pwithnall@endlessos.org> +Date: Thu, 15 Oct 2020 10:20:10 +0100 +Subject: [PATCH] gslice: Inline win32 implementation of g_getenv() to avoid + deadlock + +The win32 implementation of `g_getenv()` uses GSlice (from within +GQuark), which results in a deadlock when examining the `G_SLICE` +environment variable. + +Fix that by inlining a basic implementation of `g_getenv()` at that call +site. + +Signed-off-by: Philip Withnall <pwithnall@endlessos.org> + +Fixes: #2225 +--- + glib/gslice.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 44 insertions(+) + +diff --git a/glib/gslice.c b/glib/gslice.c +index e6f278539..589619080 100644 +--- a/glib/gslice.c ++++ b/glib/gslice.c +@@ -361,10 +361,52 @@ static void + slice_config_init (SliceConfig *config) + { + const gchar *val; ++ gchar *val_allocated = NULL; + + *config = slice_config; + ++ /* Note that the empty string (`G_SLICE=""`) is treated differently from the ++ * envvar being unset. In the latter case, we also check whether running under ++ * valgrind. */ ++#ifndef G_OS_WIN32 + val = g_getenv ("G_SLICE"); ++#else ++ /* The win32 implementation of g_getenv() has to do UTF-8 ↔ UTF-16 conversions ++ * which use the slice allocator, leading to deadlock. Use a simple in-place ++ * implementation here instead. ++ * ++ * Ignore references to other environment variables: only support values which ++ * are a combination of always-malloc and debug-blocks. */ ++ { ++ ++ wchar_t wvalue[128]; /* at least big enough for `always-malloc,debug-blocks` */ ++ int len; ++ ++ len = GetEnvironmentVariableW (L"G_SLICE", wvalue, G_N_ELEMENTS (wvalue)); ++ ++ if (len == 0) ++ { ++ if (GetLastError () == ERROR_ENVVAR_NOT_FOUND) ++ val = NULL; ++ else ++ val = ""; ++ } ++ else if (len >= G_N_ELEMENTS (wvalue)) ++ { ++ /* @wvalue isn’t big enough. Give up. */ ++ g_warning ("Unsupported G_SLICE value"); ++ val = NULL; ++ } ++ else ++ { ++ /* it’s safe to use g_utf16_to_utf8() here as it only allocates using ++ * malloc() rather than GSlice */ ++ val = val_allocated = g_utf16_to_utf8 (wvalue, -1, NULL, NULL, NULL); ++ } ++ ++ } ++#endif /* G_OS_WIN32 */ ++ + if (val != NULL) + { + gint flags; +@@ -392,6 +434,8 @@ slice_config_init (SliceConfig *config) + config->always_malloc = TRUE; + #endif + } ++ ++ g_free (val_allocated); + } + + static void +-- +2.25.1 + |