feat(libSceIcu): implement uloc_getLCID and uloc_getLocaleForLCID #20034
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/20034"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by rudranshcoolhai-boop on 2026-11-14T12:42:29Z.
What
Implements
uloc_getLCID(NIDsijsfM-blKs) anduloc_getLocaleForLCID(NIDqqDpxJnCHyo) in libSceIcu, the ICU 68 names inLegacyExports.cpp. Both were parameterless placeholders that threw throughNotImplemented_nid_no_patch. Signatures are ICU's:uint32_t uloc_getLCID(const char* localeID)andint32_t uloc_getLocaleForLCID(uint32_t hostID, char* locale, int32_t capacity, UErrorCode* status).Reference: ICU 78.1, the
3rdparty/icusubmodule at049e0d6a,uloc.cppL2279-L2330:uloc_getLCIDreturns 0 for a null or shorter-than-2 ID. Then it asksuprv_convertToLCIDPlatform, which returns 0 here (built withUCONFIG_USE_WINDOWS_LCID_MAPPING_API=0, as the mergeduprv_*exports are). Next it takes the language withulocimp_getLanguage, which also turns 3-letter codes into 2-letter ones. If the ID has keywords, it keeps onlycollation. Last, it callsuprv_convertToLCIDfromlocmap.cpp.uloc_getLocaleForLCIDis ICU's one-line forward touprv_convertToPosix.uprv_convertToPosix/uprv_convertToLCIDexports already use.uloc_getLocaleForLCIDcalls this library'suprv_convertToPosixexport, so the guards stay the same: a null status throwsstd::invalid_argument, a negative capacity throws, and a null buffer is accepted only for a zero-capacity preflight.Version note: the NIDs are ICU 68 names. ICU 68.2
uloc.cppL1985-L2054 has the same steps. The difference is that it builds the language and the "base name + collation keyword" in 157-byte (ULOC_FULLNAME_CAPACITY) stack buffers, so a longer locale ID can take a different path there. Itslocmap.cpptable also differs in entries added since 68. I used 78.1 because the submodule is 78.1 and the mergeduprv_convertTo*exports already use its table. Both gaps are written in the debt entry.Changes:
core/libs/prx/libSceIcu/LocaleMap.cpp,LocaleMap.hpp: the two exports with their real signatures, next to theuprv_convertTo*exports. The placeholders are removed fromLegacyExports.cppandinclude/LegacyExports.hpp.cmake/Icu.cmake:uloc.cppand the sources it reaches (locid.cpp,loclikely*.cpp,uloc_tag.cpp,uresbund.cpp, …) were compiled intoicu_commononly on Windows. They are now compiled on every platform, and onlywintz.cppstays Windows-only. This is the same move #18344 makes (that PR has conflicted withmainsince before #18331).core/libs/prx/libSceIcu/tests/LocaleMap.cpp(guest_icu_locale_map):uloc_getLCID, 37 IDs plus 3 long ones:""andegive 0en,en_US,en_ZZ,zh_Hans_CN,zh_Hant_TW,sr_Latn_RS,sr_Cyrl_RS,ckb_Arab_IQ,en_US_POSIX,de__POSIXen-US,EN_us,en_US.UTF-8,xx_YY,eng_USA,root,und_US,prs_AF,in_IDquz_PE/qu_PE,iw_ILes_ES@collation=traditional,de_DE@collation=phonebook,de@collation=phonebook,zh_CN@collation=strokePhoneBook(case),pinyin,currency,calendar, an empty value, a bare@, andcollationafter another keyworduloc_getLocaleForLCID:0x10407givesde_DE@collation=phonebook(25),0x0004giveszh_Hans, and0givesroot/usr/lib/libicuuc.so.78.3). Itsuloc.cpp,locmap.cpp,locid.cppanduloc_tag.cppare byte-identical to the 78.1 submodule.docs/dev/debt/libSceIcu.md: the LCID mapping entry now covers the two exports and the ICU 68 buffer difference. The "Older callable exports" line names them among the implemented exports; its counts are unchanged, since names are not counts of stubs.Tested
Arch Linux x86-64, Linux 7.2.15-arch1-1, GCC 16.2.1 20260810, Ninja Release,
BUILD_TESTING=ON, headf939a0bf58onmain0f4538fa02.cmake --build build --target libSceIcu libharfbuzzplus everyguest_icu_*_testsandguest_harfbuzz_*_teststarget. libharfbuzz is included because it also linksicu_common, which now has more sources on Linux.ctest --test-dir build -R 'guest_icu|guest_harfbuzz|^public_headers|^conventions_|^debt_split|^tools_nid' -j8 --output-on-failure --no-tests=error: 217 of 217 passed. That covers all libSceIcu and libharfbuzz guest tests plus the public-header, convention, debt and NID checker tests.ctest --test-dir build -R '^guest_icu_locale_map$'run 3 times: passed each time.libSceIcu. It called the two exports and compared their output with a host program that calls the system ICU 78.3uloc_getLCID/uloc_getLocaleForLCID:gPosixIDmapname, its 3-letter, hyphen, upper-case,.codesetand keyword variants, and 1,950 IDs with@keywords. 4,079 map to a nonzero LCID. All 7,094 match exactly.0-0x10000, then 145,457 sampled values up to0xFFFFFFFF), comparing the returned length, the status and the string. 28,691 succeed. All 211,001 match exactly.LocaleMap.cpp, rebuilt and reverted. Every one failedguest_icu_locale_map:en-US: got 0x409)de_DE@currency=EUR;collation=phonebook: got 0x407)capacity - 1touprv_convertToPosix(exact capacity case)en_US: got 9)After reverting, the test passes.
python3 tools/check_conventions.py --base origin/main: "All conventions checks passed."git diff --check origin/main: clean.python3 tools/pr_overlap.py --names uloc_getLCID uloc_getLocaleForLCID: main stubs both, no open PR adds them.python3 tools/pr_overlap.py --branch feat/icu-uloc-lcidfailed closed, because several open libSceIcu PRs no longer merge intomain. I also fetched the heads of all 1,535 open PRs and searched each diff against its merge base foruloc_getLCID,uloc_getLocaleForLCID,sijsfM-blKsandqqDpxJnCHyo: no match.stubdata.cppline ofcmake/Icu.cmake, the context line right above this PR's hunk.if(WIN32)group move. #18208, #18210 and #19435 also touchcmake/Icu.cmake.LegacyExports.cpp/.hppand the "Older callable exports" debt line: #14144, #14340, #14443, #17297, #18208, #18344.Not run: console, any title, Windows, macOS.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)— @rudranshcoolhai-boop
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-14T13:18:04Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
f939a0bf58:tools/check_conventions.pypassed;git diff --checkclean.guest_icu_locale_map_testsbuilt cleanly.guest_icu_locale_map):core/libs/prx/libSceIcu/LegacyExports.cpp,core/libs/prx/libSceIcu/LocaleMap.cpp,core/libs/prx/libSceIcu/LocaleMap.hpp,core/libs/prx/libSceIcu/include/LegacyExports.hppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T13:49:46Z.
Review: APPROVED
Reviewed — looks good
The changed wrappers forward to ICU’s locale mapping routines, and the added tests cover key input, buffer-capacity, and status cases; I did not run the checks reported by the author.
What I ran
Reviewed head
f939a0bf5848b6e83f77440f277df1d755795967. No build or tests were run in this review session. The PR description reports Linux build and test results; those are author-reported, not independently verified.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The changed files shown in
review/manifest.jsonwerecmake/Icu.cmake,core/libs/prx/libSceIcu/LegacyExports.cpp,core/libs/prx/libSceIcu/LocaleMap.cpp,core/libs/prx/libSceIcu/LocaleMap.hpp,core/libs/prx/libSceIcu/include/LegacyExports.hpp,core/libs/prx/libSceIcu/tests/LocaleMap.cpp, anddocs/dev/debt/libSceIcu.md. I read the diff and the head contents ofcmake/Icu.cmake,core/libs/prx/libSceIcu/LocaleMap.cpp,core/libs/prx/libSceIcu/LocaleMap.hpp,core/libs/prx/libSceIcu/CMakeLists.txt, andcore/libs/prx/libSceIcu/tests/LocaleMap.cpp. I did not read the full contents ofLegacyExports.cpp,include/LegacyExports.hpp, ordocs/dev/debt/libSceIcu.md; their changes are visible in the diff. The review bundle did not exposereview/files/through the available reader. Console, Windows, and macOS behavior were not verified.To get this to a good state
Nothing is required.