locale: Refactor ctype storage and consolidate some files.
* Drop the global definitions from ctype.h, and move them to the internal LocaleData.h: the functions should be used always when building new applications (as they're thread-safe.) * Make __ctype_get_mb_cur_max thread-safe and move it to live alongside the other __ctype...() methods. * Put the __ctype...() methods in two files, clearly indicating versions: ctype_loc_global for the global (non-thread-safe) versions, used for the kernel, and ctype_loc_thread for the libroot versions. * Consolidate more internal functions into LocaleInternal.cpp.
This commit is contained in:
@@ -25,11 +25,13 @@ private:
|
||||
const unsigned short* localClassInfoTable;
|
||||
const int* localToLowerTable;
|
||||
const int* localToUpperTable;
|
||||
unsigned short localMbCurMax;
|
||||
|
||||
public:
|
||||
const unsigned short** addrOfClassInfoTable;
|
||||
const int** addrOfToLowerTable;
|
||||
const int** addrOfToUpperTable;
|
||||
unsigned short* addrOfMbCurMax;
|
||||
|
||||
const unsigned short* const posixClassInfo;
|
||||
const int* const posixToLowerMap;
|
||||
@@ -39,7 +41,6 @@ public:
|
||||
|
||||
LocaleCtypeDataBridge(bool isGlobal);
|
||||
|
||||
void setMbCurMax(unsigned short mbCurMax);
|
||||
void ApplyToCurrentThread();
|
||||
};
|
||||
|
||||
@@ -61,7 +62,6 @@ struct LocaleMonetaryDataBridge {
|
||||
struct LocaleNumericDataBridge {
|
||||
public:
|
||||
const struct lconv* const posixLocaleConv;
|
||||
bool isGlobal;
|
||||
|
||||
LocaleNumericDataBridge(bool isGlobal);
|
||||
~LocaleNumericDataBridge();
|
||||
@@ -89,7 +89,6 @@ public:
|
||||
int* addrOfDaylight;
|
||||
long* addrOfTimezone;
|
||||
char** addrOfTZName;
|
||||
bool isGlobal;
|
||||
|
||||
TimeConversionDataBridge(bool isGlobal);
|
||||
};
|
||||
@@ -103,7 +102,6 @@ struct LocaleDataBridge {
|
||||
LocaleTimeDataBridge timeDataBridge;
|
||||
TimeConversionDataBridge timeConversionDataBridge;
|
||||
const char** const posixLanginfo;
|
||||
bool isGlobal;
|
||||
|
||||
LocaleDataBridge(bool isGlobal);
|
||||
|
||||
@@ -182,6 +180,7 @@ LocaleBackend* GetCurrentLocaleBackend();
|
||||
extern LocaleBackend* gGlobalLocaleBackend;
|
||||
extern LocaleDataBridge gGlobalLocaleDataBridge;
|
||||
|
||||
|
||||
} // namespace Libroot
|
||||
} // namespace BPrivate
|
||||
|
||||
|
||||
@@ -9,6 +9,15 @@
|
||||
#include <locale.h>
|
||||
|
||||
|
||||
extern "C" {
|
||||
// Global storage (exported for BeOS and older Haiku compatibility)
|
||||
extern const unsigned short int *__ctype_b;
|
||||
extern const int *__ctype_tolower;
|
||||
extern const int *__ctype_toupper;
|
||||
extern unsigned short int __ctype_mb_cur_max;
|
||||
}
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
namespace Libroot {
|
||||
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright 2022, Trung Nguyen, [email protected]
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#ifndef _THREAD_LOCALE_H
|
||||
#define _THREAD_LOCALE_H
|
||||
|
||||
|
||||
#include "LocaleBackend.h"
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
namespace Libroot {
|
||||
|
||||
|
||||
// The pointer in the TLS will point to this struct.
|
||||
struct ThreadLocale {
|
||||
LocaleBackendData* threadLocaleInfo;
|
||||
|
||||
const unsigned short int* ctype_b;
|
||||
const int* ctype_tolower;
|
||||
const int* ctype_toupper;
|
||||
};
|
||||
|
||||
|
||||
ThreadLocale* GetCurrentThreadLocale();
|
||||
|
||||
|
||||
} // namespace Libroot
|
||||
} // namespace BPrivate
|
||||
|
||||
|
||||
#endif // _THREAD_LOCALE_H
|
||||
Reference in New Issue
Block a user