[Mesa-dev] [PATCH v2 7/7] util: assert to verify that locale is initialized
Erik Faye-Lund
kusmabite at gmail.com
Thu Jun 25 14:05:26 PDT 2015
Add an assert to Verify that the locale has been initialized when
we call strtod. This might help some developers sleep better at
night.
Signed-off-by: Erik Faye-Lund <kusmabite at gmail.com>
---
src/util/strtod.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/src/util/strtod.c b/src/util/strtod.c
index 5c36b05..7a73041 100644
--- a/src/util/strtod.c
+++ b/src/util/strtod.c
@@ -25,6 +25,7 @@
#include <stdlib.h>
+#include <assert.h>
#ifdef _GNU_SOURCE
#include <locale.h>
@@ -43,6 +44,7 @@ _mesa_locale_init(void)
{
#if defined(_GNU_SOURCE) && defined(HAVE_XLOCALE_H)
loc = newlocale(LC_CTYPE_MASK, "C", NULL);
+ initialized = 1;
#endif
}
@@ -51,6 +53,7 @@ _mesa_locale_fini(void)
{
#if defined(_GNU_SOURCE) && defined(HAVE_XLOCALE_H)
freelocale(loc);
+ initialized = 0;
#endif
}
@@ -62,6 +65,7 @@ double
_mesa_strtod(const char *s, char **end)
{
#if defined(_GNU_SOURCE) && defined(HAVE_XLOCALE_H)
+ assert(initialized);
return strtod_l(s, end, loc);
#else
return strtod(s, end);
@@ -77,6 +81,7 @@ float
_mesa_strtof(const char *s, char **end)
{
#if defined(_GNU_SOURCE) && defined(HAVE_XLOCALE_H)
+ assert(initialized);
return strtof_l(s, end, loc);
#elif defined(HAVE_STRTOF)
return strtof(s, end);
--
2.1.4
More information about the mesa-dev
mailing list