2010/3/13 Karl Schultz <karl.w.schu...@gmail.com>:
> In some locales, a comma can be used as a decimal place.  That is, 5,2 is a
> number between 5 and 6.  (I think I have that right)  I would guess that the
> shader language, like C, wouldn't allow this form in code.  So, it makes
> sense to force the C locale when parsing numbers from shader source code, as
> the code does above.
>
> strtof doesn't show up until C99 and not all compilers support it, including
> the MSFT Windows compilers.  Ian says that all usages of this function want
> a float anyway, so we may end up with something like:
>
> float
> _mesa_strtof( const char *s, char **end )
> {
> #ifdef _GNU_SOURCE
>    static locale_t loc = NULL;
>    if (!loc) {
>       loc = newlocale(LC_CTYPE_MASK, "C", NULL);
>    }
>    return (float) strtod_l(s, end, loc);
> #else
>    return (float) strtod(s, end);
> #endif
> }
>
> And then change all _mesa_strtod to _mesa_strtof.
>
> If Ian doesn't care for the casts here, then I'm fine with silencing
> warnings in the Studio with a compiler option.

Attached patch uses strtof when it is available.
From 845eaaf540de58efcef6bec9152aed610126100d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marcin=20Baczy=C5=84ski?= <marb...@gmail.com>
Date: Sat, 13 Mar 2010 14:26:45 +0100
Subject: [PATCH] Replace _mesa_strtod with _mesa_strtof.

---
 src/mesa/main/imports.c               |   12 +++++++-----
 src/mesa/main/imports.h               |    4 ++--
 src/mesa/shader/lex.yy.c              |    8 ++++----
 src/mesa/shader/nvfragparse.c         |    2 +-
 src/mesa/shader/program_lexer.l       |    8 ++++----
 src/mesa/shader/slang/slang_compile.c |    4 ++--
 6 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/src/mesa/main/imports.c b/src/mesa/main/imports.c
index 56e8195..1ae0853 100644
--- a/src/mesa/main/imports.c
+++ b/src/mesa/main/imports.c
@@ -795,18 +795,20 @@ _mesa_strdup( const char *s )
    }
 }
 
-/** Wrapper around strtod() */
-double
-_mesa_strtod( const char *s, char **end )
+/** Wrapper around strtof() */
+float
+_mesa_strtof( const char *s, char **end )
 {
 #ifdef _GNU_SOURCE
    static locale_t loc = NULL;
    if (!loc) {
       loc = newlocale(LC_CTYPE_MASK, "C", NULL);
    }
-   return strtod_l(s, end, loc);
+   return strtof_l(s, end, loc);
+#elif defined(_ISOC99_SOURCE) || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 
600)
+   return strtof(s, end);
 #else
-   return strtod(s, end);
+   return (float)strtod(s, end);
 #endif
 }
 
diff --git a/src/mesa/main/imports.h b/src/mesa/main/imports.h
index fb4a00e..d28f4ad 100644
--- a/src/mesa/main/imports.h
+++ b/src/mesa/main/imports.h
@@ -575,8 +575,8 @@ _mesa_getenv( const char *var );
 extern char *
 _mesa_strdup( const char *s );
 
-extern double
-_mesa_strtod( const char *s, char **end );
+extern float
+_mesa_strtof( const char *s, char **end );
 
 extern unsigned int
 _mesa_str_checksum(const char *str);
diff --git a/src/mesa/shader/lex.yy.c b/src/mesa/shader/lex.yy.c
index a08617f..4c5c644 100644
--- a/src/mesa/shader/lex.yy.c
+++ b/src/mesa/shader/lex.yy.c
@@ -2198,7 +2198,7 @@ case 142:
 YY_RULE_SETUP
 #line 326 "program_lexer.l"
 {
-   yylval->real = (float) _mesa_strtod(yytext, NULL);
+   yylval->real = _mesa_strtof(yytext, NULL);
    return REAL;
 }
        YY_BREAK
@@ -2210,7 +2210,7 @@ YY_DO_BEFORE_ACTION; /* set up yytext again */
 YY_RULE_SETUP
 #line 330 "program_lexer.l"
 {
-   yylval->real = (float) _mesa_strtod(yytext, NULL);
+   yylval->real = _mesa_strtof(yytext, NULL);
    return REAL;
 }
        YY_BREAK
@@ -2218,7 +2218,7 @@ case 144:
 YY_RULE_SETUP
 #line 334 "program_lexer.l"
 {
-   yylval->real = (float) _mesa_strtod(yytext, NULL);
+   yylval->real = _mesa_strtof(yytext, NULL);
    return REAL;
 }
        YY_BREAK
@@ -2226,7 +2226,7 @@ case 145:
 YY_RULE_SETUP
 #line 338 "program_lexer.l"
 {
-   yylval->real = (float) _mesa_strtod(yytext, NULL);
+   yylval->real = _mesa_strtof(yytext, NULL);
    return REAL;
 }
        YY_BREAK
diff --git a/src/mesa/shader/nvfragparse.c b/src/mesa/shader/nvfragparse.c
index d03cb4e..0de3c58 100644
--- a/src/mesa/shader/nvfragparse.c
+++ b/src/mesa/shader/nvfragparse.c
@@ -456,7 +456,7 @@ Parse_ScalarConstant(struct parse_state *parseState, 
GLfloat *number)
 {
    char *end = NULL;
 
-   *number = (GLfloat) _mesa_strtod((const char *) parseState->pos, &end);
+   *number = (GLfloat) _mesa_strtof((const char *) parseState->pos, &end);
 
    if (end && end > (char *) parseState->pos) {
       /* got a number */
diff --git a/src/mesa/shader/program_lexer.l b/src/mesa/shader/program_lexer.l
index b007657..fe18272 100644
--- a/src/mesa/shader/program_lexer.l
+++ b/src/mesa/shader/program_lexer.l
@@ -324,19 +324,19 @@ ARRAYSHADOW2D             { 
return_token_or_IDENTIFIER(require_ARB_fp && require
    return INTEGER;
 }
 {num}?{frac}{exp}?        {
-   yylval->real = (float) _mesa_strtod(yytext, NULL);
+   yylval->real = _mesa_strtof(yytext, NULL);
    return REAL;
 }
 {num}"."/[^.]             {
-   yylval->real = (float) _mesa_strtod(yytext, NULL);
+   yylval->real = _mesa_strtof(yytext, NULL);
    return REAL;
 }
 {num}{exp}                {
-   yylval->real = (float) _mesa_strtod(yytext, NULL);
+   yylval->real = _mesa_strtof(yytext, NULL);
    return REAL;
 }
 {num}"."{exp}             {
-   yylval->real = (float) _mesa_strtod(yytext, NULL);
+   yylval->real = _mesa_strtof(yytext, NULL);
    return REAL;
 }
 
diff --git a/src/mesa/shader/slang/slang_compile.c 
b/src/mesa/shader/slang/slang_compile.c
index b95c15f..ad86676 100644
--- a/src/mesa/shader/slang/slang_compile.c
+++ b/src/mesa/shader/slang/slang_compile.c
@@ -246,7 +246,7 @@ parse_general_number(slang_parse_ctx *ctx, float *number)
    if (flt[strlen(flt) - 1] == 'f' || flt[strlen(flt) - 1] == 'F') {
       flt[strlen(flt) - 1] = '\0';
    }
-   *number = (float)_mesa_strtod(flt, (char **)NULL);
+   *number = _mesa_strtof(flt, (char **)NULL);
    free(flt);
 
    return 1;
@@ -312,7 +312,7 @@ parse_float(slang_parse_ctx * C, float *number)
       slang_string_concat(whole, "E");
       slang_string_concat(whole, exponent);
 
-      *number = (float) (_mesa_strtod(whole, (char **) NULL));
+      *number = _mesa_strtof(whole, (char **) NULL);
 
       _slang_free(whole);
    }
-- 
1.7.0.2

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Mesa3d-dev mailing list
Mesa3d-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mesa3d-dev

Reply via email to