util: Cleanup strtod.(h|c) by introduce _mesa_get_locale

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28174>
This commit is contained in:
Yonggang Luo 2024-03-13 05:40:29 +08:00 committed by Marge Bot
parent 4ed3418a43
commit d17779430f
6 changed files with 15 additions and 29 deletions

View file

@ -170,8 +170,6 @@ main (int argc, char *argv[])
if (shader == NULL)
return 1;
_mesa_locale_init();
ret = glcpp_preprocess(ctx, &shader, &info_log, NULL, NULL, &gl_ctx);
fprintf(stderr, "%s", info_log);

View file

@ -288,8 +288,6 @@ void initialize_context_to_defaults(struct gl_context *ctx, gl_api api)
for (int sh = 0; sh < MESA_SHADER_STAGES; ++sh)
memcpy(&ctx->Const.ShaderCompilerOptions[sh], &options, sizeof(options));
_mesa_locale_init();
ctx->Driver.NewProgram = standalone_new_program;
}

View file

@ -1229,7 +1229,6 @@ VKAPI_ATTR VkResult VKAPI_CALL lvp_CreateInstance(
instance->vk.physical_devices.enumerate = lvp_enumerate_physical_devices;
instance->vk.physical_devices.destroy = lvp_destroy_physical_device;
// _mesa_locale_init();
// VG(VALGRIND_CREATE_MEMPOOL(instance, 0, false));
*pInstance = lvp_instance_to_handle(instance);
@ -1245,7 +1244,6 @@ VKAPI_ATTR void VKAPI_CALL lvp_DestroyInstance(
if (!instance)
return;
// _mesa_locale_fini();
pipe_loader_release(&instance->devs, instance->num_devices);

View file

@ -202,8 +202,6 @@ one_time_init(const char *extensions_override)
STATIC_ASSERT(sizeof(GLint) == 4);
STATIC_ASSERT(sizeof(GLuint) == 4);
_mesa_locale_init();
const char *env_const = os_get_option("MESA_EXTENSION_OVERRIDE");
if (env_const) {
if (extensions_override &&

View file

@ -31,35 +31,37 @@
#ifdef HAVE_XLOCALE_H
#include <xlocale.h>
#endif
static locale_t loc;
#endif
#include "strtod.h"
#include "util/u_call_once.h"
#if defined(_GNU_SOURCE) && defined(HAVE_STRTOD_L)
static locale_t loc;
static void
_mesa_locale_fini(void)
{
freelocale(loc);
}
static void
_mesa_locale_init_once(void)
{
#if defined(_GNU_SOURCE) && defined(HAVE_STRTOD_L)
loc = newlocale(LC_CTYPE_MASK, "C", NULL);
atexit(_mesa_locale_fini);
#endif
}
void
_mesa_locale_init(void)
static ALWAYS_INLINE locale_t
_mesa_get_locale(void)
{
static util_once_flag once = UTIL_ONCE_FLAG_INIT;
util_call_once(&once, _mesa_locale_init_once);
return loc;
}
void
_mesa_locale_fini(void)
{
#if defined(_GNU_SOURCE) && defined(HAVE_STRTOD_L)
freelocale(loc);
#endif
}
/**
* Wrapper around strtod which uses the "C" locale so the decimal
@ -69,8 +71,7 @@ double
_mesa_strtod(const char *s, char **end)
{
#if defined(_GNU_SOURCE) && defined(HAVE_STRTOD_L)
if (!loc) _mesa_locale_init();
return strtod_l(s, end, loc);
return strtod_l(s, end, _mesa_get_locale());
#else
return strtod(s, end);
#endif
@ -85,8 +86,7 @@ float
_mesa_strtof(const char *s, char **end)
{
#if defined(_GNU_SOURCE) && defined(HAVE_STRTOD_L)
if (!loc) _mesa_locale_init();
return strtof_l(s, end, loc);
return strtof_l(s, end, _mesa_get_locale());
#elif defined(HAVE_STRTOF)
return strtof(s, end);
#else

View file

@ -31,12 +31,6 @@
extern "C" {
#endif
extern void
_mesa_locale_init(void);
extern void
_mesa_locale_fini(void);
extern double
_mesa_strtod(const char *s, char **end);