mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-22 15:40:11 +01:00
util: port _mesa_strto[df] to C
_mesa_strtod and _mesa_strtof are only used from the GLSL compiler and the ARB_[vertex|fragment]_program code, meaning that the locale doesn't need to be initialized before the first OpenGL context gets initialized. So let's use explicit initialization from the one-time init code instead of depending on a C++ compiler to initialize at image-load time. Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com> Reviewed-by: Matt Turner <mattst88@gmail.com> Reviewed-by: Brian Paul <brianp@vmware.com>
This commit is contained in:
parent
de3e323be1
commit
c61bc6ed84
6 changed files with 21 additions and 7 deletions
|
|
@ -29,6 +29,7 @@
|
||||||
#include "glcpp.h"
|
#include "glcpp.h"
|
||||||
#include "main/mtypes.h"
|
#include "main/mtypes.h"
|
||||||
#include "main/shaderobj.h"
|
#include "main/shaderobj.h"
|
||||||
|
#include "util/strtod.h"
|
||||||
|
|
||||||
extern int glcpp_parser_debug;
|
extern int glcpp_parser_debug;
|
||||||
|
|
||||||
|
|
@ -168,6 +169,8 @@ main (int argc, char *argv[])
|
||||||
if (shader == NULL)
|
if (shader == NULL)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
_mesa_locale_init();
|
||||||
|
|
||||||
ret = glcpp_preprocess(ctx, &shader, &info_log, NULL, &gl_ctx);
|
ret = glcpp_preprocess(ctx, &shader, &info_log, NULL, &gl_ctx);
|
||||||
|
|
||||||
printf("%s", shader);
|
printf("%s", shader);
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@
|
||||||
#include "program/hash_table.h"
|
#include "program/hash_table.h"
|
||||||
#include "loop_analysis.h"
|
#include "loop_analysis.h"
|
||||||
#include "standalone_scaffolding.h"
|
#include "standalone_scaffolding.h"
|
||||||
|
#include "util/strtod.h"
|
||||||
|
|
||||||
static int glsl_version = 330;
|
static int glsl_version = 330;
|
||||||
|
|
||||||
|
|
@ -46,6 +47,8 @@ initialize_context(struct gl_context *ctx, gl_api api)
|
||||||
{
|
{
|
||||||
initialize_context_to_defaults(ctx, api);
|
initialize_context_to_defaults(ctx, api);
|
||||||
|
|
||||||
|
_mesa_locale_init();
|
||||||
|
|
||||||
/* The standalone compiler needs to claim support for almost
|
/* The standalone compiler needs to claim support for almost
|
||||||
* everything in order to compile the built-in functions.
|
* everything in order to compile the built-in functions.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -120,6 +120,7 @@
|
||||||
#include "shaderobj.h"
|
#include "shaderobj.h"
|
||||||
#include "shaderimage.h"
|
#include "shaderimage.h"
|
||||||
#include "util/simple_list.h"
|
#include "util/simple_list.h"
|
||||||
|
#include "util/strtod.h"
|
||||||
#include "state.h"
|
#include "state.h"
|
||||||
#include "stencil.h"
|
#include "stencil.h"
|
||||||
#include "texcompress_s3tc.h"
|
#include "texcompress_s3tc.h"
|
||||||
|
|
@ -374,6 +375,8 @@ one_time_init( struct gl_context *ctx )
|
||||||
assert( sizeof(GLint) == 4 );
|
assert( sizeof(GLint) == 4 );
|
||||||
assert( sizeof(GLuint) == 4 );
|
assert( sizeof(GLuint) == 4 );
|
||||||
|
|
||||||
|
_mesa_locale_init();
|
||||||
|
|
||||||
_mesa_one_time_init_extension_overrides();
|
_mesa_one_time_init_extension_overrides();
|
||||||
|
|
||||||
_mesa_get_cpu_features();
|
_mesa_get_cpu_features();
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ MESA_UTIL_FILES := \
|
||||||
set.c \
|
set.c \
|
||||||
set.h \
|
set.h \
|
||||||
simple_list.h \
|
simple_list.h \
|
||||||
strtod.cpp \
|
strtod.c \
|
||||||
strtod.h \
|
strtod.h \
|
||||||
texcompress_rgtc_tmp.h \
|
texcompress_rgtc_tmp.h \
|
||||||
u_atomic.h
|
u_atomic.h
|
||||||
|
|
|
||||||
|
|
@ -30,18 +30,20 @@
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#ifdef HAVE_XLOCALE_H
|
#ifdef HAVE_XLOCALE_H
|
||||||
#include <xlocale.h>
|
#include <xlocale.h>
|
||||||
|
static locale_t loc;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "strtod.h"
|
#include "strtod.h"
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
_mesa_locale_init(void)
|
||||||
|
{
|
||||||
#if defined(_GNU_SOURCE) && defined(HAVE_XLOCALE_H)
|
#if defined(_GNU_SOURCE) && defined(HAVE_XLOCALE_H)
|
||||||
static struct locale_initializer {
|
loc = newlocale(LC_CTYPE_MASK, "C", NULL);
|
||||||
locale_initializer() { loc = newlocale(LC_CTYPE_MASK, "C", NULL); }
|
|
||||||
locale_t loc;
|
|
||||||
} loc_init;
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper around strtod which uses the "C" locale so the decimal
|
* Wrapper around strtod which uses the "C" locale so the decimal
|
||||||
|
|
@ -51,7 +53,7 @@ double
|
||||||
_mesa_strtod(const char *s, char **end)
|
_mesa_strtod(const char *s, char **end)
|
||||||
{
|
{
|
||||||
#if defined(_GNU_SOURCE) && defined(HAVE_XLOCALE_H)
|
#if defined(_GNU_SOURCE) && defined(HAVE_XLOCALE_H)
|
||||||
return strtod_l(s, end, loc_init.loc);
|
return strtod_l(s, end, loc);
|
||||||
#else
|
#else
|
||||||
return strtod(s, end);
|
return strtod(s, end);
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -66,7 +68,7 @@ float
|
||||||
_mesa_strtof(const char *s, char **end)
|
_mesa_strtof(const char *s, char **end)
|
||||||
{
|
{
|
||||||
#if defined(_GNU_SOURCE) && defined(HAVE_XLOCALE_H)
|
#if defined(_GNU_SOURCE) && defined(HAVE_XLOCALE_H)
|
||||||
return strtof_l(s, end, loc_init.loc);
|
return strtof_l(s, end, loc);
|
||||||
#elif defined(HAVE_STRTOF)
|
#elif defined(HAVE_STRTOF)
|
||||||
return strtof(s, end);
|
return strtof(s, end);
|
||||||
#else
|
#else
|
||||||
|
|
@ -31,6 +31,9 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
extern void
|
||||||
|
_mesa_locale_init(void);
|
||||||
|
|
||||||
extern double
|
extern double
|
||||||
_mesa_strtod(const char *s, char **end);
|
_mesa_strtod(const char *s, char **end);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue