* [PATCH alsa-lib 1/2] Check for thread-specific locale support
@ 2010-04-21 16:37 Rémi Denis-Courmont
2010-04-21 16:37 ` [PATCH alsa-lib 2/2] Use thread-safe locale functions if available Rémi Denis-Courmont
0 siblings, 1 reply; 3+ messages in thread
From: Rémi Denis-Courmont @ 2010-04-21 16:37 UTC (permalink / raw)
To: alsa-devel
---
configure.in | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/configure.in b/configure.in
index f6df502..abc4687 100644
--- a/configure.in
+++ b/configure.in
@@ -64,6 +64,7 @@ dnl Checks for library functions.
AC_PROG_GCC_TRADITIONAL
AC_CHECK_FUNC([hsearch_r], [HAVE_HSEARCH_R=yes])
AM_CONDITIONAL(ALSA_HSEARCH_R, [test "x$HAVE_HSEARCH_R" != xyes])
+AC_CHECK_FUNCS([uselocale])
SAVE_LIBRARY_VERSION
AC_SUBST(LIBTOOL_VERSION_INFO)
--
1.7.0.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH alsa-lib 2/2] Use thread-safe locale functions if available
2010-04-21 16:37 [PATCH alsa-lib 1/2] Check for thread-specific locale support Rémi Denis-Courmont
@ 2010-04-21 16:37 ` Rémi Denis-Courmont
2010-04-21 17:21 ` Jaroslav Kysela
0 siblings, 1 reply; 3+ messages in thread
From: Rémi Denis-Courmont @ 2010-04-21 16:37 UTC (permalink / raw)
To: alsa-devel
setlocale() is not thread-safe. It can actually trigger a crash if
another thread uses locale informations at the same time in the process.
Library code should use POSIX newlocale/duplocale/uselocale/freelocale
instead. Those functions only change the locale data for the calling
thread.
---
src/conf.c | 16 ++++++++++++++++
1 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/src/conf.c b/src/conf.c
index 570c90f..5d8c5c9 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -499,22 +499,38 @@ static int safe_strtod(const char *str, double *val)
{
char *end;
double v;
+#ifdef HAVE_USELOCALE
+ locale_t saved_locale, c_locale;
+#else
char *saved_locale;
char locstr[64]; /* enough? */
+#endif
int err;
if (!*str)
return -EINVAL;
+#ifdef HAVE_USELOCALE
+ c_locale = newlocale(LC_NUMERIC_MASK, "C", 0);
+ saved_locale = uselocale(c_locale);
+#else
saved_locale = setlocale(LC_NUMERIC, NULL);
if (saved_locale) {
snprintf(locstr, sizeof(locstr), "%s", saved_locale);
setlocale(LC_NUMERIC, "C");
}
+#endif
errno = 0;
v = strtod(str, &end);
err = -errno;
+#ifdef HAVE_USELOCALE
+ if (c_locale != (locale_t)0) {
+ uselocale(saved_locale);
+ freelocale(c_locale);
+ }
+#else
if (saved_locale)
setlocale(LC_NUMERIC, locstr);
+#endif
if (err)
return err;
if (*end)
--
1.7.0.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH alsa-lib 2/2] Use thread-safe locale functions if available
2010-04-21 16:37 ` [PATCH alsa-lib 2/2] Use thread-safe locale functions if available Rémi Denis-Courmont
@ 2010-04-21 17:21 ` Jaroslav Kysela
0 siblings, 0 replies; 3+ messages in thread
From: Jaroslav Kysela @ 2010-04-21 17:21 UTC (permalink / raw)
To: Rémi Denis-Courmont; +Cc: alsa-devel
[-- Attachment #1: Type: TEXT/PLAIN, Size: 532 bytes --]
On Wed, 21 Apr 2010, Rémi Denis-Courmont wrote:
> setlocale() is not thread-safe. It can actually trigger a crash if
> another thread uses locale informations at the same time in the process.
> Library code should use POSIX newlocale/duplocale/uselocale/freelocale
> instead. Those functions only change the locale data for the calling
> thread.
Thanks. I applied both patches to alsa-lib git repo.
Jaroslav
-----
Jaroslav Kysela <perex@perex.cz>
Linux Kernel Sound Maintainer
ALSA Project, Red Hat, Inc.
[-- Attachment #2: Type: text/plain, Size: 160 bytes --]
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-04-21 17:21 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-21 16:37 [PATCH alsa-lib 1/2] Check for thread-specific locale support Rémi Denis-Courmont
2010-04-21 16:37 ` [PATCH alsa-lib 2/2] Use thread-safe locale functions if available Rémi Denis-Courmont
2010-04-21 17:21 ` Jaroslav Kysela
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.