From: Bryan Henderson <bry...@giraffe-data.com>

[v2/Kayden: rebased version of Bryan's original patch from:
 https://bugs.freedesktop.org/show_bug.cgi?id=33447]

Cc: Jeremy Huddleston <jerem...@apple.com>
Cc: Chad Versace <chad.vers...@linux.intel.com>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=33447
Signed-off-by: Kenneth Graunke <kenn...@whitecape.org>
---
 src/glsl/strtod.c       |   11 +++++++----
 src/mesa/main/imports.c |   22 +++++++++++++++++-----
 2 files changed, 24 insertions(+), 9 deletions(-)

Hey guys,

I just got pinged on IRC by someone trying to build Mesa with ucLibc,
which doesn't support strtod_l or strtof_l.  I found this 1+ year old
patch from Bryan on Bugzilla which fixed up the feature macros to only
use locale_t on glibc, and figured it would help

I rebased it against master (adding the Haiku and Android changes), and
figured I'd send it out to the list for review.

Jeremy: Does this look right?  I wasn't sure if Apple used glibc or not,
        and was afraid this might break stuff there.

Chad: Why do we have !ANDROID for strtof_l but not strtod_l?  Oversight?
      Or does it actually support strtod_l?

Thanks!
 --Ken

diff --git a/src/glsl/strtod.c b/src/glsl/strtod.c
index a876e13..876ed21 100644
--- a/src/glsl/strtod.c
+++ b/src/glsl/strtod.c
@@ -26,7 +26,7 @@
 
 #include <stdlib.h>
 
-#ifdef _GNU_SOURCE
+#ifdef __GLIBC__
 #include <locale.h>
 #ifdef __APPLE__
 #include <xlocale.h>
@@ -35,7 +35,11 @@
 
 #include "strtod.h"
 
-
+#if defined(__GLIBC__) && __GLIBC__ >= 2 && __GLIBC_MINOR__ > 2 && 
!defined(__CYGWIN__) && !defined(__FreeBSD__) && !defined(__HAIKU__)
+  #define HAVE_STRTOD_L 1
+#else
+  #define HAVE_STRTOD_L 0
+#endif
 
 /**
  * Wrapper around strtod which uses the "C" locale so the decimal
@@ -44,8 +48,7 @@
 double
 glsl_strtod(const char *s, char **end)
 {
-#if defined(_GNU_SOURCE) && !defined(__CYGWIN__) && !defined(__FreeBSD__) && \
-   !defined(__HAIKU__)
+#if HAVE_STRTOD_L
    static locale_t loc = NULL;
    if (!loc) {
       loc = newlocale(LC_CTYPE_MASK, "C", NULL);
diff --git a/src/mesa/main/imports.c b/src/mesa/main/imports.c
index 2d592a6..c145101 100644
--- a/src/mesa/main/imports.c
+++ b/src/mesa/main/imports.c
@@ -42,20 +42,33 @@
  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 
-
+#define _XOPEN_SOURCE 600   /* We use strtof/strtof_l */
 
 #include "imports.h"
 #include "context.h"
 #include "mtypes.h"
 #include "version.h"
 
-#ifdef _GNU_SOURCE
+#ifdef __GLIBC__
 #include <locale.h>
 #ifdef __APPLE__
 #include <xlocale.h>
 #endif
 #endif
 
+#if defined(__GLIBC__) && __GLIBC__ >= 2 && __GLIBC_MINOR__ > 2 && 
!defined(__CYGWIN__) && !defined(__FreeBSD__) && !defined(ANDROID) && 
!defined(__HAIKU__)
+  #define HAVE_STRTOF_L 1
+#else
+  #define HAVE_STRTOF_L 0
+#endif
+
+#if defined(__GLIBC__)
+  #define HAVE_STRTOF 1
+  /* True at least as long as we declare _XOPEN_SOURCE >= 600 */
+#else
+  #define HAVE_STRTOF 0
+#endif
+
 
 #ifdef WIN32
 #define vsnprintf _vsnprintf
@@ -761,14 +774,13 @@ _mesa_strdup( const char *s )
 float
 _mesa_strtof( const char *s, char **end )
 {
-#if defined(_GNU_SOURCE) && !defined(__CYGWIN__) && !defined(__FreeBSD__) && \
-   !defined(ANDROID) && !defined(__HAIKU__)
+#if HAVE_STRTOF_L
    static locale_t loc = NULL;
    if (!loc) {
       loc = newlocale(LC_CTYPE_MASK, "C", NULL);
    }
    return strtof_l(s, end, loc);
-#elif defined(_ISOC99_SOURCE) || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 
600)
+#elif HAVE_STRTOF
    return strtof(s, end);
 #else
    return (float)strtod(s, end);
-- 
1.7.10.1

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to