Repository navigation
feat(libSceIcu): implement uloc_toLanguageTag - #20189
Conversation
Follow ICU 68.2 uloc_tag.cpp to write a BCP 47 tag from a locale ID over this module's canonicalize and component getters: deprecated language and region replacement, sorted variants, the POSIX variant as -u-va-posix, attributes, one-letter extensions, private use and the x-lvariant form, in lenient and strict mode. Keywords that need the keyTypeData mapping throw. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — changes requested
Changes are required before merge: correct the 157-byte BCP 47 input handling so valid longer tags are not reported as illegal arguments.
What I ran
Reviewed head 04c28dd3cb7dac1ee27745211bddd69dbe920b94. I inspected the prepared description, commit list, manifest and diff, plus the changed implementation, its declarations, tests and debt entry. I did not run commands or tests; reported test results below are from the PR description.
Results
| Check | Result | Note |
|---|---|---|
| Source review | failed | Long valid BCP 47 input is rejected |
| Linux tests | not run | 44/44 reported by author |
| Other platforms and console | not run | Windows, macOS and console execution unverified |
Findings
Blocking
core/libs/prx/libSceIcu/LanguageTag.cpp:1064: The BCP 47 pre-conversion uses a fixed 157-byte buffer, then treatsIcu::NotTerminatedlike a conversion error at lines 1065–1067. A valid input tag whose locale representation needs 157 bytes or more therefore returnsU_ILLEGAL_ARGUMENT_ERROR, rather than converting the tag. This is reachable for long private-use subtags: the existing parser accepts a sequence of 1–8 character subtags without a total-length limit (LanguageTag.cpp:199–200,392–415). Use a capacity retry or otherwise handle buffer overflow separately from invalid input.
Non-blocking
None.
Not verified
- No tests or build commands were run during this review. The PR description reports Linux tests and checks; those results were not independently verified.
- Windows, macOS, console behavior, and the exact console ICU implementation were not verified.
- Files read:
core/libs/prx/libSceIcu/LanguageTag.cpp,core/libs/prx/libSceIcu/Export.cpp,core/libs/prx/libSceIcu/include/InventoryExports.hpp,core/libs/prx/libSceIcu/Identified.hpp,core/libs/prx/libSceIcu/tests/LanguageTag.cpp,docs/dev/debt/libSceIcu.md, and prepared review materialsdescription.md,commits.md,manifest.json, anddiff.patch. No exclusions were listed in the manifest;files.jsonwas unavailable through the reader.
To get this to a good state
Handle overflow from uloc_forLanguageTag by retrying with sufficient capacity, and add a regression case for a valid BCP 47 input whose locale representation exceeds 156 bytes. Re-run the reported Linux build and ICU tests on the updated head.
The BCP 47 pre-conversion read uloc_forLanguageTag into a fixed 157-byte buffer and reported a longer result as an illegal argument, so a valid tag with a long private-use sequence failed. Retry with the length the conversion reports, keeping rejected tags as errors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@MarcZX10 thanks, fixed in What changed. New test.
It fails on the previous head Run. Linux, Docker
|
|
@fogydes, a note on ordering with #18344. This PR removes the I'm happy for #18344 to go first. If it merges before this one, I'll rebase this branch on it and resolve the conflict here. If this one merges first, the fix on your side is keeping both removals. Does that work for you? |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Moved the debt changes to |
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
Windows check of head Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.
AI-assisted: yes. |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
Implements the typed uloc_toLanguageTag export to convert ICU locale IDs into BCP 47 tags, and updates its debt documentation. Adds tests for conversion behavior and edge cases.
What I ran
No commands were run. The review read 6 of 6 changed files, 824 of 824 added lines, through the repository reader at head be5332b33067bbde65a948d28e3b0f8b7627c06a, in 2 parts.
Results
| Check | Result | Note |
|---|---|---|
| Change review | passed | Every added line was read. |
| Automated checks | not run | Author-reported results were not independently run. |
Findings
Blocking
None.
Non-blocking
None.
Sources
AnyPS5/core/libs/prx/libSceIcu/LanguageTag.cpp
Line 1171 in be5332b
AnyPS5/core/libs/prx/libSceIcu/LanguageTag.cpp
Line 1124 in be5332b
AnyPS5/core/libs/prx/libSceIcu/LanguageTag.cpp
Line 1059 in be5332b
AnyPS5/core/libs/prx/libSceIcu/LanguageTag.cpp
Line 1173 in be5332b
Not verified
- Console behavior: BCP 47 output, keyword mapping, and differences inherited from locale getters have not been compared against console behavior.
To get this to a good state
Nothing is required.
…uage-tag Resolve the adjacent stub removals with boykopovar#18344 by keeping both: the uloc_setKeywordValue and uloc_toLanguageTag stubs are both gone from Export.cpp and InventoryExports.hpp, and uloc_toLanguageTag keeps its typed declaration. The boykopovar#18344 debt fragment no longer lists uloc_toLanguageTag as throwing. The locale getters now shorten three-letter codes as ICU 68.2 does, so the uloc_toLanguageTag debt entry drops that difference and the test pins it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
#18344 merged first, so as promised I resolved the conflict here: merged
New head |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — no blocking findings
The implementation and its added test cases were reviewed at head 61b8caed8aa558de3f737f8528bf5211345e78e1; no independent checks were run, so a formal approval is not justified.
What I ran
Read the prepared description, commits, manifest and diff, then inspected the changed implementation, declarations, tests and debt entries through repo_read.py. No build or tests were run in this review.
Results
| Check | Result | Note |
|---|---|---|
| Source review | passed | Changed code and declarations inspected |
| Build and tests | not run | Author reports successful Linux checks |
| Console behavior | not run | Also listed as unverified in the debt entry |
Negative control
Not run; no test environment was available in this review.
Findings
Blocking
None.
Non-blocking
None.
Sources
Reviewed core/libs/prx/libSceIcu/LanguageTag.cpp, core/libs/prx/libSceIcu/Export.cpp, core/libs/prx/libSceIcu/include/InventoryExports.hpp, core/libs/prx/libSceIcu/tests/LanguageTag.cpp, docs/dev/debt/changes/feat-icu-uloc-to-language-tag.md, docs/dev/debt/changes/libSceIcu-locale-syntax.md, and docs/dev/debt/libSceIcu.md at the pinned head. The prepared bundle listed all seven changed files as included; files.json was unavailable through the reader.
Not verified
I did not independently reproduce the reported build, test, mutation, or audit results. Windows, macOS, console execution, and title behavior were not verified.
To get this to a good state
Nothing is required. The reported test results and remaining console verification are optional review context.
|
Tested
AI-assisted: yes (Claude Code); the runs are automated, this summary was written from their reports. |
…uage-tag Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Merged The conflict came from #20642 (default locale). It typed the Rebuilt |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
The reviewed implementation and its added regression coverage support merging at head cdcb24749012ce8b395545e94d1a5ded9be1c124; the author reports passing build, tests, and convention checks, which I did not run.
What I ran
No commands were run. I read the prepared review bundle and the changed implementation, API declaration, tests, and debt documentation at the pinned head. The author reports Linux Docker build and test checks in description.md; these were not independently run. No merged-preview check was run.
Results
| Check | Result | Note |
|---|---|---|
| Source review | passed | Implementation and tests read |
| Build and test checks | not run | Reported by author only |
| Console behavior | not run | Not verified on hardware |
Findings
Blocking
None.
Non-blocking
None.
Not verified
Build and test output, convention checks, merged-preview behavior, Windows and macOS behavior, and console behavior were not independently verified. All seven changed files marked included in the manifest were read: Export.cpp, LanguageTag.cpp, InventoryExports.hpp, tests/LanguageTag.cpp, the new feature debt fragment, the locale syntax debt fragment, and libSceIcu.md. No changed file was excluded in the manifest.
To get this to a good state
Nothing is required.
What
uloc_toLanguageTag(zmMWRKwedmw) is a parameterless stub inlibSceIcuthat throws. The debt file says so in the BCP 47 entry. This PR gives it the ICU signature,int32_t (const char* localeID, char* langtag, int32_t capacity, UBool strict, UErrorCode* status). It writes a BCP 47 tag from an ICU locale ID, the reverse ofuloc_forLanguageTag(#16872, onmain). It follows ICU 68.2, the version the debt file already assigns to the 3.20 module and touloc_forLanguageTag:ulocimp_toLanguageTagand its helpers inuloc_tag.cpp. The code goes intoLanguageTag.cpp, which already carries the ICU licence notice; I added aDerived fromline above it. The PR removes the stub and types the inventory declaration. Its fragmentdocs/dev/debt/changes/feat-icu-uloc-to-language-tag.md(#17217) removes the debt table row; the throwing count in the debt file goes from main's 50 to 49.uloc_canonicalize,uloc_getLanguage,uloc_getScriptanduloc_getCountry, with ICU's buffer sizes (12, 6, 4). The variant and the keyword list have no export onmain. They follow ICU 68.2'suloc_getVariantandulocimp_getKeywords/ulocimp_getKeywordValue(code).iwtohe, …) and regions (DDtoDE, …) use ICU 68.2's tables. Variants are lower-cased and sorted. A wholePOSIXvariant becomes-u-va-posix. A variant that is not a BCP 47 variant moves to-x-lvariant-.attributekeywords become sorted-u-attributes, and one-letter keywords become extensions, ordered as ICU's_addExtensionToListorders them. The private-use-only ID@x=…givesx-…. Strict mode fails withU_ILLEGAL_ARGUMENT_ERRORwhere ICU's does, and leaves the partial tag ICU leaves.@whose shortest subtag has one character is first read withuloc_forLanguageTag, into a buffer sized from the length it reports (code), soen-x-elmergivesen-x-elmer.attributeor a one-letter extension (calendar,va, …) throws throughNotImplemented_nid_no_patchbefore any output is written. ICU maps those through thekeyTypeDataresource, whichuloc_forLanguageTagalready throws for. A null locale and a null buffer with a positive capacity throw an invalid-argument exception, asuloc_forLanguageTagdoes; a null status throws.Reachability. Every argument is a plain value a title builds: a C string locale ID such as
"en_US", a buffer, its size and a flag. A locale ID can also come fromuloc_forLanguageTag,uloc_canonicalizeoruloc_getBaseName, all onmain, and the test round-trips tags throughuloc_forLanguageTag.uloc_toLanguageTagis how ICU callers turn a locale into the tag that HTTPAccept-Language, JavaScriptIntland web APIs use. For example, JavaScriptCore'slanguageTagForLocaleIDcalls it withstrictfalse for everyIntllocale and for the default locale.The fragment adds a debt entry for the remaining gaps:
eng_USAgivesen-US).uloc_forLanguageTagrejects returnsU_ILLEGAL_ARGUMENT_ERROR.Overlap:
tools/pr_overlap.py --names uloc_toLanguageTagchecked 1,519 open PRs: none adds it. I also grepped the diffs of every open PR that matchesIcu,ulocorlanguage tag. feat(libSceIcu): implement 481 data-free ICU 68 exports #14144, feat(libSceIcu): implement 458 more data-free ICU 68 exports #14340 and feat(libSceIcu): implement the string trie builders, data swappers and the ICU service cache #14443 touchulocimp_toLanguageTagandLocale::toLanguageTag, which are other exports. The rest only show it as unchanged context.uloc_setKeywordValuestub removal inExport.cppandInventoryExports.hppconflicted with this one and was resolved here as agreed, keeping both removals. Its debt fragment no longer listsuloc_toLanguageTagas throwing.main: feat(libSceIcu): implement UTF-8 and UTF-16 conversion #10965, feat(icu): implement ten resource bundle accessors #14123, feat(libSceIcu): implement 481 data-free ICU 68 exports #14144, feat(libSceIcu): implement 458 more data-free ICU 68 exports #14340, feat(libSceIcu): implement the string trie builders, data swappers and the ICU service cache #14443, feat(libSceIcu): implement Unicode decimal digit classification #16250, feat(libSceIcu): build ICU data from source and implement C break iteration #16971, refactor(prx): name the Icu legacy export aliases the NID databases resolve #17297, feat(libSceIcu): implement the character name exports over ICU data #18208, feat(libSceIcu): implement u_strToTitle over the ICU break data #18210, feat(libSceIcu): implement uprv_isASCIILetter from ICU 68.2 #19951, feat(libSceIcu): implement uprv_stableBinarySearch #19972, feat(libSceIcu): implement uprv_sortArray #19985, feat(libSceIcu): implement uprv_isInvariantString and uprv_isInvariantUString #19998. I trial-merged each intomainand into this branch: each conflicts in exactly the same files both ways, so this branch adds no new conflict.Tested
Linux only, in Docker
ubuntu:24.04(GCC 13.3.0, CMake 3.28.3, Ninja 1.11.1), Release,-DBUILD_TESTING=ON; based onmaindcb5aabff0db8f625ec6007bbcd9db304ae6cca8, tested head8149e5b774d080375da9329fe8520862fca64f3f. Headbe5332b33067bbde65a948d28e3b0f8b7627c06aonly adds a clean merge ofmain6a86d4d1a9cand moves the debt changes to the fragment;tools/debt_fold.py --checkpasses on it. Head61b8caed8aa558de3f737f8528bf5211345e78e1mergesmain1bd3e160c60(including #18344 and #20148), resolves the #18344 conflict and adds two three-letter-code vectors; the build, thenm -Dcheck and the ctest run below were repeated on it. Headcdcb24749012ce8b395545e94d1a5ded9be1c124mergesmaine4caa07950f862269fbe664e3502b15544161e1f(including #20642 and #21242) and resolves theInventoryExports.hppconflict with #20642, keeping itsuloc_setDefault_nid_postfixdeclaration next to the typeduloc_toLanguageTagone; the build, thenm -Dcheck, the ctest run,tools/debt_fold.py --checkand the convention checks were repeated on it.libSceIcu.prxand everyguest_icu_*test.nm -Don the patchedlibSceIcu.prxshowszmMWRKwedmw, which matchestools/nid_names.pycompute_nid("uloc_toLanguageTag").ctest -R '^guest_icu|^public_headers': 122/122 passed (57 ICU, 65 public headers) on headcdcb247490, includingguest_icu_language_tag, which now also coversuloc_toLanguageTag(tests):locale_to_langtagcases that need nokeyTypeDatamapping, with ICU's expected tags and strict failures, plus deprecated regions, duplicate attributes,POSIXwith attributes and private use, and BCP 47 input.uloc_forLanguageTag.en-x-ab-…-abwith 80 private-use subtags, whose locale formen@x=ab-…is also 244 bytes, so well over the 157-byte buffer the pre-conversion first tries. Given either the tag or the locale form, it comes back unchanged with length 244 in lenient and strict mode. A preflight, an exact buffer and a 156-byte buffer give overflow, not-terminated and overflow with the 156-byte prefix. The case fails on04c28dd3cb7dac1ee27745211bddd69dbe920b94(unexpected status) and passes on this head.en-USof a strict failure;U_INVALID_FORMAT_ERRORfor a keyword without a value; the null-argument throws.-x-lvariant-, the private-use-only branch or the BCP 47 pre-conversion; strict-mode variant failures off; private-use order andattributeorder (right side) flipped. The survivor flips theattributeorder whenattributeis the key being inserted. That case only happens after an earlier multi-letter key, and every such key throws, so it cannot be reached here.python3 core/libs/tests/test_public_headers.py --audit-only(413 libraries, 34,557 exports) passes.python3 tools/check_conventions.py --base origin/mainandgit diff --checkpass.Windows, macOS and console or title execution were not run.
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)