Free C locale on exit

This commit is contained in:
Kovid Goyal 2025-12-30 22:11:05 +05:30
parent 7bb8433c8b
commit 051b0ff30d
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
3 changed files with 10 additions and 4 deletions

View file

@ -8,11 +8,10 @@
#include "state.h"
#include <structmember.h>
#include "colors.h"
#include <locale.h>
#ifdef __APPLE__
// Needed for strod_l
#include <xlocale.h>
#endif
locale_t c_locale;
static uint32_t FG_BG_256[256] = {
@ -806,7 +805,7 @@ static bool
parse_double(const char *src, double *out) {
char *endptr;
errno = 0;
*out = strtod_l(src, &endptr, c_locale);
*out = strtod_l(src, &endptr, get_c_locale());
return endptr != src && *endptr == 0 && errno == 0;
}
@ -1128,7 +1127,6 @@ static PyMethodDef module_methods[] = {
};
int init_ColorProfile(PyObject *module) {\
c_locale = newlocale(LC_NUMERIC_MASK, "C", (locale_t)0);
if (PyType_Ready(&ColorProfile_Type) < 0) return 0;
if (PyModule_AddObject(module, "ColorProfile", (PyObject *)&ColorProfile_Type) != 0) return 0;
Py_INCREF(&ColorProfile_Type);

View file

@ -617,6 +617,9 @@ py_timed_debug_print(PyObject *self UNUSED, PyObject *args) {
Py_RETURN_NONE;
}
static locale_t c_locale = 0;
locale_t get_c_locale(void) { return c_locale; }
static PyObject*
py_run_atexit_cleanup_functions(PyObject *self UNUSED, PyObject *args UNUSED) {
run_at_exit_cleanup_functions();
@ -726,6 +729,7 @@ static PyMethodDef module_methods[] = {
static void
free_fast_data_types_module(void *m UNUSED) {
freelocale(c_locale);
run_at_exit_cleanup_functions();
}
@ -877,6 +881,8 @@ PyInit_fast_data_types(void) {
if (PyModule_AddObject(m, "StreamingBase64Decoder", (PyObject *) &StreamingBase64Decoder_Type) < 0) return NULL;
if (PyType_Ready(&StreamingBase64Encoder_Type) < 0) return NULL;
if (PyModule_AddObject(m, "StreamingBase64Encoder", (PyObject *) &StreamingBase64Encoder_Type) < 0) return NULL;
c_locale = newlocale(LC_NUMERIC_MASK, "C", (locale_t)0);
if (!c_locale) { PyErr_NoMemory(); return NULL; }
return m;
}

View file

@ -18,6 +18,7 @@
#include <stdbool.h>
#include <poll.h>
#include <pthread.h>
#include <locale.h>
#include "glfw-wrapper.h"
#include "banned.h"
// Required minimum OpenGL version
@ -331,6 +332,7 @@ void focus_in_event(void);
void scroll_event(double, double, int, int);
void on_key_input(const GLFWkeyevent *ev);
void request_window_attention(id_type, bool);
locale_t get_c_locale(void);
#ifndef __APPLE__
void play_canberra_sound(const char *which_sound, const char *event_id, bool is_path, const char *role, const char *theme_name);
#endif