libroot: Make glibc use the native Haiku locale structs.

It accesses values through macros, so just write functions that
fetch the appropriate value from Haiku's structures.

Note that the values for multibyte digit characters are hardcoded.
As far as I can tell, we never set or updated these in glibc's
locale structures, so it always just used the default, so this
should not be a behavioral change from before.
This commit is contained in:
Augustin Cavalier
2025-03-20 16:31:53 -04:00
parent 910fdeee84
commit 843c97b01f
12 changed files with 142 additions and 374 deletions
@@ -14,7 +14,6 @@
struct lc_time_t;
struct locale_data; // glibc
namespace BPrivate {
@@ -60,37 +59,12 @@ struct LocaleMonetaryDataBridge {
struct LocaleNumericDataBridge {
private:
// struct used by glibc to store numeric locale data
struct GlibcNumericLocale {
const char* name;
const char* filedata;
off_t filesize;
int mmaped;
unsigned int usage_count;
int use_translit;
const char *options;
unsigned int nstrings;
union locale_data_value
{
const uint32_t* wstr;
const char* string;
unsigned int word;
}
values[6];
};
locale_data* originalGlibcLocale;
GlibcNumericLocale glibcNumericLocaleData;
public:
const struct lconv* const posixLocaleConv;
GlibcNumericLocale* glibcNumericLocale;
bool isGlobal;
LocaleNumericDataBridge(bool isGlobal);
~LocaleNumericDataBridge();
void ApplyToCurrentThread();
};
+5 -31
View File
@@ -3,7 +3,6 @@
* All rights reserved. Distributed under the terms of the MIT License.
*/
#ifndef _THREAD_LOCALE_H
#define _THREAD_LOCALE_H
@@ -15,38 +14,13 @@ namespace BPrivate {
namespace Libroot {
// This struct is taken from glibc's __locale_struct
// from xlocale.h.
// It will also be used by glibc so it should have the same
// layout.
struct GlibcLocaleStruct {
void *__locales[7]; /* 7 = __LC_LAST. */
const unsigned short int *__ctype_b;
const int *__ctype_tolower;
const int *__ctype_toupper;
};
// Taken from glibc's bits/locale.h
// glibc uses different codes from our the native locale.h.
// This should be the values used for the indexes
// in GlibcLocaleStruct.
enum {
GLIBC_LC_CTYPE = 0,
GLIBC_LC_NUMERIC = 1,
GLIBC_LC_TIME = 2,
GLIBC_LC_COLLATE = 3,
GLIBC_LC_MONETARY = 4,
GLIBC_LC_MESSAGES = 5,
GLIBC_LC_ALL = 6,
};
// The pointer in the TLS will point to this struct.
struct ThreadLocale {
GlibcLocaleStruct glibcLocaleStruct;
LocaleBackendData* threadLocaleInfo;
LocaleBackendData* threadLocaleInfo;
const unsigned short int* ctype_b;
const int* ctype_tolower;
const int* ctype_toupper;
};