Use C locale for atof to ensure using a dot as decimal mark.

TRAC #14055 Signed-off-by: Daniel Koch Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/trunk@470 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 8860909e
......@@ -77,6 +77,8 @@
'compiler/preprocessor/symbols.h',
'compiler/preprocessor/tokens.c',
'compiler/preprocessor/tokens.h',
'compiler/util.cpp',
'compiler/util.h',
# Generated files
'<(glslang_cpp_file)',
'<(glslang_tab_cpp_file)',
......
......@@ -32,6 +32,7 @@ O [0-7]
#include <stdlib.h>
#include "compiler/ParseHelper.h"
#include "compiler/util.h"
#include "glslang_tab.h"
/* windows only pragma */
......@@ -176,9 +177,9 @@ Remove it when we can exclusively use the newer version.
0{D}+ { pyylval->lex.line = yylineno; parseContext.error(yylineno, "Invalid Octal number.", yytext, "", ""); parseContext.recover(); return 0;}
{D}+ { pyylval->lex.line = yylineno; pyylval->lex.i = strtol(yytext, 0, 0); return(INTCONSTANT); }
{D}+{E} { pyylval->lex.line = yylineno; pyylval->lex.f = static_cast<float>(atof(yytext)); return(FLOATCONSTANT); }
{D}+"."{D}*({E})? { pyylval->lex.line = yylineno; pyylval->lex.f = static_cast<float>(atof(yytext)); return(FLOATCONSTANT); }
"."{D}+({E})? { pyylval->lex.line = yylineno; pyylval->lex.f = static_cast<float>(atof(yytext)); return(FLOATCONSTANT); }
{D}+{E} { pyylval->lex.line = yylineno; pyylval->lex.f = static_cast<float>(atof_dot(yytext)); return(FLOATCONSTANT); }
{D}+"."{D}*({E})? { pyylval->lex.line = yylineno; pyylval->lex.f = static_cast<float>(atof_dot(yytext)); return(FLOATCONSTANT); }
"."{D}+({E})? { pyylval->lex.line = yylineno; pyylval->lex.f = static_cast<float>(atof_dot(yytext)); return(FLOATCONSTANT); }
"/*" { int ret = PaParseComment(pyylval->lex.line, parseContext); if (!ret) return ret; }
......
......@@ -59,7 +59,7 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endif
#include "compiler/preprocessor/slglobals.h"
#include "compiler/util.h"
typedef struct StringInputSrc {
InputSrc base;
......@@ -244,7 +244,7 @@ static int lFloatConst(int ch, int len, yystypepp * yylvalpp)
assert(len <= MAX_SYMBOL_NAME_LEN);
yylvalpp->symbol_name[len] = '\0';
yylvalpp->sc_fval = (float) atof(yylvalpp->symbol_name);
yylvalpp->sc_fval = (float) atof_dot(yylvalpp->symbol_name);
if (isinff(yylvalpp->sc_fval)) {
CPPErrorToInfoLog("FLOAT CONSTANT OVERFLOW");
}
......
......@@ -52,6 +52,7 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "compiler/debug.h"
#include "compiler/preprocessor/slglobals.h"
#include "compiler/util.h"
///////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////// Preprocessor and Token Recorder and Playback: ////////////////////////
......@@ -305,7 +306,7 @@ int ReadToken(TokenStream *pTok, yystypepp * yylvalpp)
symbol_name[len] = '\0';
assert(ch == '\0');
strcpy(yylvalpp->symbol_name,symbol_name);
yylvalpp->sc_fval=(float)atof(yylvalpp->symbol_name);
yylvalpp->sc_fval=(float)atof_dot(yylvalpp->symbol_name);
break;
case CPP_INTCONSTANT:
len = 0;
......
......@@ -266,6 +266,10 @@
>
</File>
<File
RelativePath=".\util.cpp"
>
</File>
<File
RelativePath=".\VariableInfo.cpp"
>
</File>
......@@ -412,6 +416,10 @@
>
</File>
<File
RelativePath=".\util.h"
>
</File>
<File
RelativePath=".\VariableInfo.h"
>
</File>
......
//
// Copyright (c) 2010 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#include <math.h>
#include <stdlib.h>
#include "util.h"
#ifdef _MSC_VER
#include <locale.h>
#else
#include <sstream>
#endif
double atof_dot(const char *str)
{
#ifdef _MSC_VER
return _atof_l(str, _create_locale(LC_NUMERIC, "C"));
#else
double result;
std::istringstream s(str);
std::locale l("C");
s.imbue(l);
s >> result;
return result;
#endif
}
//
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#ifndef COMPILER_UTIL_H
#define COMPILER_UTIL_H
#ifdef __cplusplus
extern "C" {
#endif
// atof_dot is like atof but forcing C locale, i.e. forcing '.' as decimal point.
double atof_dot(const char *str);
#ifdef __cplusplus
} // end extern "C"
#endif
#endif // COMPILER_UTIL_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment