mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-11-07 13:39:55 +00:00
Release the process-wide state this module keeps, following ICU 78.1 ucln_cmn.cpp: the functions stored by u_setMemoryFunctions are cleared and the data and time zone files directories return to their empty defaults. Calling it repeatedly or with nothing set is harmless, and the module can be configured again afterwards. The sceIcuUnknown stub with this NID is removed.
89 lines
2.4 KiB
C++
89 lines
2.4 KiB
C++
#include "prx/libSceIcu/libSceIcu.hpp"
|
|
#include "prx/libSceIcu/Status.hpp"
|
|
#include <cstdint>
|
|
#include <mutex>
|
|
#include <string>
|
|
#include <utility>
|
|
|
|
namespace {
|
|
|
|
struct MemoryFunctions {
|
|
const void* context = nullptr;
|
|
Icu::MemoryAllocate allocate = nullptr;
|
|
Icu::MemoryReallocate reallocate = nullptr;
|
|
Icu::MemoryFree release = nullptr;
|
|
};
|
|
|
|
std::mutex MemoryLock;
|
|
MemoryFunctions Memory;
|
|
std::mutex DirectoryLock;
|
|
std::string DataDirectory;
|
|
std::string TimeZoneDirectory;
|
|
|
|
}
|
|
|
|
extern "C" {
|
|
|
|
void APS5_VABI u_setMutexFunctions_nid_postfix(const void*, const void*, const void*, const void*, const void*, std::int32_t* status) {
|
|
if (!Icu::Failure(status)) *status = Icu::UnsupportedError;
|
|
}
|
|
|
|
void APS5_VABI u_setAtomicIncDecFunctions_nid_postfix(const void*, const void*, const void*, std::int32_t* status) {
|
|
if (!Icu::Failure(status)) *status = Icu::UnsupportedError;
|
|
}
|
|
|
|
|
|
void APS5_VABI u_setMemoryFunctions_nid_postfix(const void* context, Icu::MemoryAllocate allocate, Icu::MemoryReallocate reallocate,
|
|
Icu::MemoryFree release, std::int32_t* status) {
|
|
if (Icu::Failure(status)) return;
|
|
if (!allocate || !reallocate || !release) {
|
|
*status = Icu::IllegalArgument;
|
|
return;
|
|
}
|
|
const std::lock_guard lock(MemoryLock);
|
|
Memory = {context, allocate, reallocate, release};
|
|
}
|
|
|
|
|
|
const char* APS5_VABI u_getDataDirectory_nid_postfix() {
|
|
const std::lock_guard lock(DirectoryLock);
|
|
return DataDirectory.c_str();
|
|
}
|
|
|
|
void APS5_VABI u_setDataDirectory_nid_postfix(const char* directory) {
|
|
std::string copy = directory ? directory : "";
|
|
const std::lock_guard lock(DirectoryLock);
|
|
DataDirectory = std::move(copy);
|
|
}
|
|
|
|
|
|
const char* APS5_VABI u_getTimeZoneFilesDirectory_nid_postfix(std::int32_t* status) {
|
|
if (Icu::Failure(status)) return "";
|
|
const std::lock_guard lock(DirectoryLock);
|
|
return TimeZoneDirectory.c_str();
|
|
}
|
|
|
|
void APS5_VABI u_setTimeZoneFilesDirectory_nid_postfix(const char* path, std::int32_t* status) {
|
|
if (Icu::Failure(status)) return;
|
|
const std::lock_guard lock(DirectoryLock);
|
|
TimeZoneDirectory.clear();
|
|
if (!path) {
|
|
*status = Icu::IllegalArgument;
|
|
return;
|
|
}
|
|
TimeZoneDirectory = path;
|
|
}
|
|
|
|
|
|
void APS5_VABI u_cleanup_nid_postfix() {
|
|
{
|
|
const std::lock_guard lock(MemoryLock);
|
|
Memory = {};
|
|
}
|
|
const std::lock_guard lock(DirectoryLock);
|
|
DataDirectory.clear();
|
|
TimeZoneDirectory.clear();
|
|
}
|
|
|
|
}
|