Skip to content

feat(libc): fill the std::__sce_v2 classic locale with its facets - #17610

Open
Danigamer05 wants to merge 51 commits into
boykopovar:mainfrom
Danigamer05:feat/libc-sce-v2-classic-locale-20261109
Open

Danigamer05 wants to merge 51 commits into
boykopovar:mainfrom
Danigamer05:feat/libc-sce-v2-classic-locale-20261109

Conversation

@Danigamer05

@Danigamer05 Danigamer05 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

What

Builds on #17607: this branch contains its commits, and through them #17578, #17568, #17539, #17331, #17296, #17277, #16975, #16949, #16944, #16924, #16919, #16560, #16516, #16214, #16178 and #15923, with current main. It needs the facets those PRs implement, so it cannot stand alone. Until they merge, only the last commit is this PR's change.

Give std::__sce_v2's classic locale its facets, as the libc.prx bundled with PPSA03671 v01.001.005 (J03848509, SHA-256 483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6) does. Until now the versioned classic locale, global locale, _Locimp::_Clocptr and _sceLibcClassicLocale were all the unversioned classic _Locimp, which holds no std::__sce_v2 facet. use_facet built each facet the first time a stream asked for it, so formatting worked. But has_facet and the facet vector of locale::classic() found nothing, and the facet ids depended on the order in which a title first used each facet.

What the module does, read from the disassembly of locale::_Init (0xCFE60), classic (0xCFE30), _Getgloballocale (0xCFD40), _Setgloballocale (0xCFD50) and the library's static initializer (0xF2940):

  • When the library loads, its static initializer calls _Init(true) and keeps the result in _sceLibcClassicLocale.

  • The first _Init fills a static classic _Locimp, made with the name *, with 25 facets in this order:

    • char: ctype, num_get, num_put, numpunct, codecvt, collate, messages, money_get, money_put, both moneypunct, time_get and time_put;
    • wchar_t: the same, without codecvt.

    So these facets take ids 1 to 25. Each facet holds two references and the vector has 40 slots.

  • It then names the locale C, gives it every category, and retains it twice. It makes it the global locale and stores it as _Clocptr and as the object classic() returns.

This PR builds the same locale on the first locale call or facet id assignment, which every facet use goes through. It then reaches the state the module has after loading: the 25 facets with two references each in ids 1 to 25, codecvt<wchar_t> and the unsigned short facets left to _Makeloc, name C, categories 0x3F, and four references, counting the one _sceLibcClassicLocale keeps. _Clocptr, _sceLibcClassicLocale and classic() point to that object from the start. _Getgloballocale, _Setgloballocale, global and the transparent-locale fallback of use_facet build it before they use the global locale. The unversioned classic locale is unchanged.

The _Makeloc debt entry records that the facets arrive on first use instead of at load.

Tested

Windows 11, MinGW GCC 15.2, Release, head on top of #17607. Not run on Linux or macOS. Not run in a title: PPSA03671 ships its own libc.prx, which AnyPS5 converts and looks up before this library, so its std::__sce_v2 calls never reach this code.

  • guest_sce_v2_locale_basics now checks the classic locale's facets, references, name, categories and ids. guest_sce_v2_locimp_references now takes the classic locale's own vtable for copies, and keeps its borrowed-vector case on the unversioned classic locale, the only one that still has that static vector.
  • Differential harness against the module's own code, loaded and relocated, with the module's static initializer run first.
    • Before and after _Init(true), it compares the classic locale's references, slot count, category, name, the facets present with their references, and the ids of ctype<char>, ctype<wchar_t>, codecvt<wchar_t>, num_put<char> and time_put<wchar_t>. It also checks _Init, _Getgloballocale, classic(), _Clocptr and _sceLibcClassicLocale, which all give the same object.
    • It changes the classic numpunct<char>'s decimal point and prints a double through a stream on the classic locale and on a transparent empty() locale. It then moves the global locale to a copy and back with global, compares the references of the classic locale, the copy and the facet, and prints again after the switch.
    • Both libraries give identical output.
  • The facet harnesses of feat(libc): implement the std::__sce_v2 num_put virtuals for char #16516 to feat(libc): implement the std::__sce_v2 unsigned short facet virtuals #17607, 20,000 calls each for char and wchar_t and again for unsigned short: 0 differences.
  • The libc tests built from this head, without the tests that drive the GPU, audio, video or controllers (208): all pass, with guest_fopen_errors skipped.
  • check_conventions, git diff --check: clean. Merges cleanly with main.
  • pr_overlap reports no open PR with the same functions or conflicting code. It could not compare 48 PRs that conflict with main on shared files. None of the 4 that touch LocaleSupport.cpp (feat(libc): add std::__sce_v2::_Random_device, _Fiopen and setw #9526, feat(libc): wire the codecvt<wchar_t,char> facet vtable #11172, feat(libc): export the money_put facet vtable as data #12518 and feat(libc): export the wide time_put facet vtable as data #12704) touches the versioned classic or global locale.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: feat(libc): implement the std::__sce_v2 unsigned short facet virtuals #17607
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

Danigamer05 and others added 26 commits November 5, 2026 21:33
…irtuals for char

The facets built by _Makeloc threw NotImplemented from every virtual
except the lifecycle slots. The char ctype, numpunct and codecvt facets
now answer as the console's libc.prx does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…irtuals for wchar_t

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Main removed GuestStringInlineCapacity, GuestStringCapacityMask and
GuestStringLargeAllocation from LocaleSupport.cpp, so the versioned
facets' strings use GuestLocale::StringInlineCapacity,
GuestLocale::StringCapacityMask and GuestStringStorage::Deallocate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…egers, bool and pointers

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Main removed GuestStringInlineCapacity and GuestStringCapacityMask from
LocaleSupport.cpp, so AssignSceV2String uses
GuestLocale::StringInlineCapacity and GuestLocale::StringCapacityMask.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Main removed GuestStringInlineCapacity and GuestStringLargeAllocation
from LocaleSupport.cpp, so TakeSceV2String tests
GuestLocale::StringInlineCapacity and frees through
GuestStringStorage::Deallocate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…sce-v2-num-put-wide-20261107

Brings in current main through boykopovar#16516. The templated TakeSceV2String
frees through GuestStringStorage::Deallocate, since main removed
GuestStringLargeAllocation from LocaleSupport.cpp.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…integers, bool and pointers

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ating point

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…sce-v2-num-get-wide-floating-20261108

# Conflicts:
#	docs/dev/debt/libc.md
…floating point

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implement do_compare, do_transform and do_hash of collate<char> and
collate<wchar_t>, and the nine virtuals of moneypunct<char, Intl> and
moneypunct<wchar_t, Intl>, following the libc.prx of PPSA03671.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implement do_open, do_get and do_close of messages<char> and
messages<wchar_t>, following the libc.prx of PPSA03671: no catalog
opens, and do_get returns a copy of the default string.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implement do_put of a long double and of a digit string for
money_put<char> and money_put<wchar_t>, following the libc.prx of
PPSA03671: Dinkumware's field writer with this module's character
pattern encoding.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implement do_get for long double and for digit strings in
money_get<char> and money_get<wchar_t>, following the PPSA03671
libc.prx: _Getmfld reads the negative pattern of the moneypunct facet
byte by byte, matches the symbol, sign, grouped value with its fraction
and spaces, and do_get converts the digits with _Stod or widens them
into the string.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implement date_order, get_time, get_date, get_weekday, get_monthname,
get_year and the single-field do_get of time_get<char> and
time_get<wchar_t>, following the PPSA03671 libc.prx: its integer reader
counts spaces as digits and converts with the v2 _Stolx, names match
without case through the global locale's ctype, %x reads day first and
%% never fails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implement do_put of time_put<char> and time_put<wchar_t>, following the
PPSA03671 libc.prx: it formats "!%<modifier><specifier>" with strftime
or wcsftime into a buffer grown by 16, 32, 64 units until the call
succeeds, keeps errno, and writes the text after the leading mark.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Give the thirteen unsigned short facets that _Makeushloc builds the
virtuals of their wchar_t twins, as the PPSA03671 libc.prx instantiates
the same code for both, looking up the unsigned short ctype, numpunct
and moneypunct. collate<unsigned short>::do_compare walks the ranges
unit by unit, as the module's does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Give std::__sce_v2's classic _Locimp the 25 char and wchar_t facets
that the PPSA03671 libc.prx's locale::_Init adds when the library
loads, name it C with every category, and make it the global locale,
_Locimp::_Clocptr, _sceLibcClassicLocale and classic(), instead of the
unversioned classic locale. It is built on the first locale call or
facet id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JJenkx

JJenkx commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Windows check of head 1e976773e3, merged onto main ff2b85fa27 (7dcdc7f391, clean merge).

Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.

  • guest_sce_v2_char_facet_virtuals, guest_sce_v2_codecvt_wide, guest_sce_v2_collate_moneypunct, guest_sce_v2_facet_ids, guest_sce_v2_locale_basics, guest_sce_v2_locimp_references, guest_sce_v2_makeloc, guest_sce_v2_messages, guest_sce_v2_money_get, guest_sce_v2_money_put, guest_sce_v2_num_get_char, guest_sce_v2_num_get_wide, guest_sce_v2_num_put_char, guest_sce_v2_num_put_wide, guest_sce_v2_time_get, guest_sce_v2_time_put, guest_sce_v2_ushort_facets pass in 3 of 3 runs, none skipped.

AI-assisted: yes.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — looks good

The changed locale initialization and facet registration are consistent with the described classic-locale state; no blocking defect was verified in the source and tests reviewed.

What I ran

No commands or tests were run. Inspected the prepared diff at head 7a47c466550322502e069127e765449611048d77 and targeted source context with the PR reader. The description reports Windows 11/MinGW testing and differential harness results; these were not independently run.

Results

Check Result Note
Source review passed Initialization and locale callers inspected
Tests in this session not run Author-reported results only
Console behavior not verified Description says no title run

Findings

Blocking

None.

Non-blocking

None.

Not verified

I read the complete diff and all 18 changed files listed as included in the manifest: core/libs/prx/libc/CMakeLists.txt, core/libs/prx/libc/include/GuestLocale.hpp, core/libs/prx/libc/src/LocaleSupport.cpp, the 14 changed core/libs/tests/GuestSceV2*.cpp files, and docs/dev/debt/libc.md. The manifest marked all changed files included; no changed file was excluded. Targeted source ranges were additionally read for locale initialization, facet ID assignment, installation, global switching, and the modified locale tests. No build, test suite, Linux/macOS run, or console run was performed here.

To get this to a good state

Nothing is required.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 20, 2026
Danigamer05 and others added 9 commits November 20, 2026 18:00
A review asked whether a field whose first 768 or more digits are zeros
could reach the lost-digit rounding with no kept digit, and bump the
leading zero or the decimal point. It cannot: leading zeros in the
integer part are not counted, and leading fraction zeros only lower the
power, so the first nonzero digit is always kept. Pin that down with 800
integer zeros, 769 fraction zeros before a 1 scaled back by e770, and
both together. Counting leading zeros as significant fails two of them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A review asked for a test of a moneypunct facet whose currency symbol is
empty, since the optional-symbol checks compare the next character with
symbol[0]. On a std::basic_string that is the terminating null, so the
comparison is defined and an empty symbol simply matches nothing. Check
it at the front and at the end of the pattern, with and without
showbase, including input left after the value. Failing every empty
symbol breaks these cases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A review asked whether do_in should keep the caller's conversion state
and for a test that splits a multibyte sequence across calls. As in the
module, do_in starts each call from a clean state and does not consume
an incomplete sequence, so the caller passes those bytes again with the
rest. Check that the first call returns partial without reading the two
bytes or touching the state, and that the second converts the euro sign
and the character after it. Consuming the incomplete bytes fails both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — comments

The review is incomplete because only selected changed lines and source ranges were read; the remaining changed behavior was not verified.

What I ran

Reviewed head dc68baffe91c2c3b85d3317c89b6f8386f283c9b from the prepared bundle. No commands or tests were run.

Results

Check Result Note
Bundle and change summary passed Description, commits and diff inspected
Targeted source review passed Locale initialization and facet lookup inspected
Full changed-line review not run Not every changed line was read
Tests not run Author-reported results were not independently run

Findings

Blocking

None identified in the inspected lines.

Non-blocking

None.

Not verified

The bundle lists 19 changed files; I read the description, commits, review README, manifest, selected diff ranges, and targeted ranges in core/libs/prx/libc/src/LocaleSupport.cpp. I did not read every changed line or the full contents of the changed test files, core/libs/prx/libc/CMakeLists.txt, core/libs/prx/libc/include/GuestLocale.hpp, or docs/dev/debt/libc.md. Their behavior is not verified. No tests or build checks were run.

To get this to a good state

Complete the changed-line review and run the applicable checks before making a formal review decision.

@ycbuzi

ycbuzi commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Tested dc68baffe9 merged into main, with the whole ctest suite on each machine below. Nothing fails that does not also fail on main on the same machine.

  • Windows Server 2022 (GitHub-hosted runner), full build, WinLibs GCC 15.2.0: 99% tests passed, 3 tests failed out of 7495; 99% tests passed, 3 tests failed out of 7495. 3 of the failing tests fail on main too. run
  • Windows Server 2025 (GitHub-hosted runner), full build, WinLibs GCC 15.2.0: 100% tests passed, 0 tests failed out of 7495; 100% tests passed, 0 tests failed out of 7495. run

AI-assisted: yes (Claude Code); the runs are automated, this summary was written from their reports.

@ligmaSec ligmaSec left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Built the branch’s locale implementation and matching headers against the existing Linux runtime, with the branch’s SceV2 exception assembly linked into the fixture. The focused locale-basics test passed.

AI-assisted: yes.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants