Both core mesa and glsl have their own wrappers for strtof_l. Merge and move them to util/. They are compiled with a C++ compiler so that we can make them thread-safe in a following commit. Signed-off-by: Chia-I Wu <olv@lunarg.com> Reviewed-by: Kenneth Graunke <kenneth@whiteacpe.org>tags/10.4-branchpoint
@@ -104,8 +104,7 @@ LIBGLSL_FILES = \ | |||
$(GLSL_SRCDIR)/opt_swizzle_swizzle.cpp \ | |||
$(GLSL_SRCDIR)/opt_tree_grafting.cpp \ | |||
$(GLSL_SRCDIR)/opt_vectorize.cpp \ | |||
$(GLSL_SRCDIR)/s_expression.cpp \ | |||
$(GLSL_SRCDIR)/strtod.c | |||
$(GLSL_SRCDIR)/s_expression.cpp | |||
# glsl_compiler | |||
@@ -23,7 +23,7 @@ | |||
*/ | |||
#include <ctype.h> | |||
#include <limits.h> | |||
#include "strtod.h" | |||
#include "util/strtod.h" | |||
#include "ast.h" | |||
#include "glsl_parser_extras.h" | |||
#include "glsl_parser.h" | |||
@@ -451,23 +451,23 @@ layout { | |||
} | |||
[0-9]+\.[0-9]+([eE][+-]?[0-9]+)?[fF]? { | |||
yylval->real = glsl_strtof(yytext, NULL); | |||
yylval->real = _mesa_strtof(yytext, NULL); | |||
return FLOATCONSTANT; | |||
} | |||
\.[0-9]+([eE][+-]?[0-9]+)?[fF]? { | |||
yylval->real = glsl_strtof(yytext, NULL); | |||
yylval->real = _mesa_strtof(yytext, NULL); | |||
return FLOATCONSTANT; | |||
} | |||
[0-9]+\.([eE][+-]?[0-9]+)?[fF]? { | |||
yylval->real = glsl_strtof(yytext, NULL); | |||
yylval->real = _mesa_strtof(yytext, NULL); | |||
return FLOATCONSTANT; | |||
} | |||
[0-9]+[eE][+-]?[0-9]+[fF]? { | |||
yylval->real = glsl_strtof(yytext, NULL); | |||
yylval->real = _mesa_strtof(yytext, NULL); | |||
return FLOATCONSTANT; | |||
} | |||
[0-9]+[fF] { | |||
yylval->real = glsl_strtof(yytext, NULL); | |||
yylval->real = _mesa_strtof(yytext, NULL); | |||
return FLOATCONSTANT; | |||
} | |||
@@ -73,7 +73,7 @@ read_atom(void *ctx, const char *&src, char *&symbol_buffer) | |||
} else { | |||
// Check if the atom is a number. | |||
char *float_end = NULL; | |||
float f = glsl_strtof(src, &float_end); | |||
float f = _mesa_strtof(src, &float_end); | |||
if (float_end != src) { | |||
char *int_end = NULL; | |||
int i = strtol(src, &int_end, 10); |
@@ -27,7 +27,7 @@ | |||
#define S_EXPRESSION_H | |||
#include "main/core.h" /* for Elements */ | |||
#include "strtod.h" | |||
#include "util/strtod.h" | |||
#include "list.h" | |||
/* Type-safe downcasting macros (also safe to pass NULL) */ |
@@ -499,25 +499,6 @@ _mesa_strdup( const char *s ) | |||
} | |||
} | |||
/** Wrapper around strtof() */ | |||
float | |||
_mesa_strtof( const char *s, char **end ) | |||
{ | |||
#if defined(_GNU_SOURCE) && !defined(__CYGWIN__) && !defined(__FreeBSD__) && \ | |||
!defined(ANDROID) && !defined(__HAIKU__) && !defined(__UCLIBC__) && \ | |||
!defined(__NetBSD__) | |||
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) | |||
return strtof(s, end); | |||
#else | |||
return (float)strtod(s, end); | |||
#endif | |||
} | |||
/** Compute simple checksum/hash for a string */ | |||
unsigned int | |||
_mesa_str_checksum(const char *str) |
@@ -540,9 +540,6 @@ _mesa_half_is_negative(GLhalfARB h) | |||
extern char * | |||
_mesa_strdup( const char *s ); | |||
extern float | |||
_mesa_strtof( const char *s, char **end ); | |||
extern unsigned int | |||
_mesa_str_checksum(const char *str); | |||
@@ -28,6 +28,7 @@ | |||
#include "program/symbol_table.h" | |||
#include "program/program_parser.h" | |||
#include "program/program_parse.tab.h" | |||
#include "util/strtod.h" | |||
#define require_ARB_vp (yyextra->mode == ARB_vertex) | |||
#define require_ARB_fp (yyextra->mode == ARB_fragment) |
@@ -3,7 +3,8 @@ MESA_UTIL_FILES := \ | |||
ralloc.c \ | |||
register_allocate.c \ | |||
register_allocate.h \ | |||
rgtc.c | |||
rgtc.c \ | |||
strtod.cpp | |||
MESA_UTIL_GENERATED_FILES = \ | |||
format_srgb.c |
@@ -42,10 +42,11 @@ | |||
* point is always '.' | |||
*/ | |||
double | |||
glsl_strtod(const char *s, char **end) | |||
_mesa_strtod(const char *s, char **end) | |||
{ | |||
#if defined(_GNU_SOURCE) && !defined(__CYGWIN__) && !defined(__FreeBSD__) && \ | |||
!defined(__HAIKU__) && !defined(__UCLIBC__) | |||
!defined(ANDROID) && !defined(__HAIKU__) && !defined(__UCLIBC__) && \ | |||
!defined(__NetBSD__) | |||
static locale_t loc = NULL; | |||
if (!loc) { | |||
loc = newlocale(LC_CTYPE_MASK, "C", NULL); | |||
@@ -62,16 +63,17 @@ glsl_strtod(const char *s, char **end) | |||
* point is always '.' | |||
*/ | |||
float | |||
glsl_strtof(const char *s, char **end) | |||
_mesa_strtof(const char *s, char **end) | |||
{ | |||
#if defined(_GNU_SOURCE) && !defined(__CYGWIN__) && !defined(__FreeBSD__) && \ | |||
!defined(__HAIKU__) && !defined(__UCLIBC__) | |||
!defined(ANDROID) && !defined(__HAIKU__) && !defined(__UCLIBC__) && \ | |||
!defined(__NetBSD__) | |||
static locale_t loc = NULL; | |||
if (!loc) { | |||
loc = newlocale(LC_CTYPE_MASK, "C", NULL); | |||
} | |||
return strtof_l(s, end, loc); | |||
#elif _XOPEN_SOURCE >= 600 || _ISOC99_SOURCE | |||
#elif defined(_ISOC99_SOURCE) || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 600) | |||
return strtof(s, end); | |||
#else | |||
return (float) strtod(s, end); |
@@ -32,10 +32,10 @@ extern "C" { | |||
#endif | |||
extern double | |||
glsl_strtod(const char *s, char **end); | |||
_mesa_strtod(const char *s, char **end); | |||
extern float | |||
glsl_strtof(const char *s, char **end); | |||
_mesa_strtof(const char *s, char **end); | |||
#ifdef __cplusplus |