feat(libSceLibcInternal): construct the moneypunct facet and answer its members #18135

Closed
QW1CKS wants to merge 1 commit from upstream-pr/18135 into main
QW1CKS commented 2026-11-10 15:22:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by QW1CKS on 2026-11-10T15:22:46Z.


What

The thirty-seven moneypunct and _Mpunct exports threw: both moneypunct<char, bool> specialisations, _Mpunct<char> and _Mpunct<wchar_t>. Titles that format or parse a monetary value reach them through money_put and money_get, so any currency formatting aborted.

Each constructor now writes the facet libc models, with the classic C locale's values, and each do_ member reads a field of that facet. The libc side is new: GuestLocale::MoneyPunctFacet and WideMoneyPunctFacet are declared in GuestLocale.hpp and answered in LocaleSupport.cpp behind descriptive _nid_postfix names, and the guest exports forward to them, which is how numpunct already works. The classic C locale values come from the C standard: '.' and ',' separators, an empty grouping string, an empty currency symbol and sign, CHAR_MAX frac digits, and symbol sign none value / sign symbol none value patterns.

This does not implement money_get or money_put, which read and write the fields this PR provides, and it does not read the values from an installed locale: a constructor given a name other than "C" throws std::invalid_argument rather than silently reporting classic values for a locale that asks for something else. Those names are recorded in the debt file.

37 exports, all bound by their NID. libSceLibcInternal 347/1128 to 384/1128 (30.76% to 34.04%), libc 1755/1763 to 1792/1800, overall 37.06% to 37.21%. Stubs in libSceLibcInternal 789 to 752.

Tested

Linux, x86-64, GCC 13 (build-gcc, Release), AMD EPYC 7763.

  • ctest --test-dir build-gcc -R guest_libc_internal_moneypunct passes.
  • The new test fails when the change is reverted: sceLibcInternalMoneyPunctDoDecimalPointChar_nid_no_patch throwing instead of reading the field aborts it with what(): sceLibcInternalMoneyPunctDoDecimalPointChar_nid_no_patch not implemented. Restored, it passes.
  • ctest --test-dir build-gcc -R guest_libc_internal passes, 37 of 37.
  • python3 tools/check_conventions.py --base upstream/main reports all checks passed.

The new test covers every constructor and every do_ member on both specialisations, the reference count taken from the argument, the _Locinfo constructors, destruction of a heap facet, the non-classic name throw, and a derived vtable to prove the do_ members are read through the facet rather than from a fixed table.

Not tested: a title formatting a monetary value, and a locale other than "C", which this PR does not support. Not run on Windows or macOS.

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: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5243873764 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18135). Originally posted by [QW1CKS](https://github.com/QW1CKS) on 2026-11-10T15:22:46Z. --- ### What The thirty-seven `moneypunct` and `_Mpunct` exports threw: both `moneypunct<char, bool>` specialisations, `_Mpunct<char>` and `_Mpunct<wchar_t>`. Titles that format or parse a monetary value reach them through `money_put` and `money_get`, so any currency formatting aborted. Each constructor now writes the facet libc models, with the classic C locale's values, and each `do_` member reads a field of that facet. The libc side is new: `GuestLocale::MoneyPunctFacet` and `WideMoneyPunctFacet` are declared in `GuestLocale.hpp` and answered in `LocaleSupport.cpp` behind descriptive `_nid_postfix` names, and the guest exports forward to them, which is how `numpunct` already works. The classic C locale values come from the C standard: `'.'` and `','` separators, an empty grouping string, an empty currency symbol and sign, `CHAR_MAX` frac digits, and `symbol sign none value` / `sign symbol none value` patterns. This does not implement `money_get` or `money_put`, which read and write the fields this PR provides, and it does not read the values from an installed locale: a constructor given a name other than `"C"` throws `std::invalid_argument` rather than silently reporting classic values for a locale that asks for something else. Those names are recorded in the debt file. 37 exports, all bound by their NID. `libSceLibcInternal` 347/1128 to 384/1128 (30.76% to 34.04%), `libc` 1755/1763 to 1792/1800, overall 37.06% to 37.21%. Stubs in `libSceLibcInternal` 789 to 752. ### Tested Linux, x86-64, GCC 13 (`build-gcc`, Release), AMD EPYC 7763. - `ctest --test-dir build-gcc -R guest_libc_internal_moneypunct` passes. - The new test fails when the change is reverted: `sceLibcInternalMoneyPunctDoDecimalPointChar_nid_no_patch` throwing instead of reading the field aborts it with `what(): sceLibcInternalMoneyPunctDoDecimalPointChar_nid_no_patch not implemented`. Restored, it passes. - `ctest --test-dir build-gcc -R guest_libc_internal` passes, 37 of 37. - `python3 tools/check_conventions.py --base upstream/main` reports all checks passed. The new test covers every constructor and every `do_` member on both specialisations, the reference count taken from the argument, the `_Locinfo` constructors, destruction of a heap facet, the non-classic name throw, and a derived vtable to prove the `do_` members are read through the facet rather than from a fixed table. Not tested: a title formatting a monetary value, and a locale other than `"C"`, which this PR does not support. Not run on Windows or macOS. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
PrivacyOnion commented 2026-11-11 17:01:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-11T17:01:39Z.

Review: CHANGES_REQUESTED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against e36012df66:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • GitHub CI: failing check(s): windows.
  • Build: guest_libc_internal_moneypunct_tests built cleanly.
  • CTest (guest_libc_internal_moneypunct):
    1/1 Test #3463: guest_libc_internal_moneypunct ...   Passed    0.12 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceLibcInternal/Err.cpp, core/libs/prx/libSceLibcInternal/Export.cpp, core/libs/prx/libSceLibcInternal/InventoryExports2.cpp, core/libs/prx/libSceLibcInternal/InventoryExports6.cpp, core/libs/prx/libSceLibcInternal/include/Api.hpp, core/libs/prx/libSceLibcInternal/include/ErrExports.hpp, core/libs/prx/libSceLibcInternal/include/InventoryExports2.hpp, core/libs/prx/libSceLibcInternal/include/InventoryExports6.hpp, core/libs/prx/libSceLibcInternal/include/PendingExports.hpp, core/libs/prx/libc/include/Api.hpp, core/libs/prx/libc/include/GuestLocale.hpp, core/libs/prx/libc/src/LocaleSupport.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • core/libs/prx/libc/include/Api.hpp, core/libs/prx/libc/include/GuestLocale.hpp, core/libs/prx/libc/src/LocaleSupport.cpp, and core/libs/prx/libSceLibcInternal/include/Api.hpp: verified virtual do_frac_digits return types against standard C++ moneypunct and Dinkumware PS5 ABI specifications.
    • core/libs/prx/libSceLibcInternal/Moneypunct.cpp: verified all 37 NID exports, parameter lists, calling conventions, and sret pointer forwarding against libc counterparts.
    • core/libs/prx/libc/src/LocaleSupport.cpp: verified RequireMoneyPunct and RequireWideMoneyPunct null checks, classic locale validation, and pointer safety.
    • core/libs/prx/libc/include/GuestLocale.hpp: checked struct layouts, alignment, and member offsets of MoneyPunctFacet and WideMoneyPunctFacet across LP64 and LLP64 architectures.
  • Concerns:
    • core/libs/prx/libc/include/Api.hpp:1809, core/libs/prx/libc/include/GuestLocale.hpp:168, core/libs/prx/libc/src/LocaleSupport.cpp:1301: _ZNKSt7_MpunctIcE14do_frac_digitsEv_nid_postfix (and the MoneyPunctVtable::fracDigits function pointer) is declared and implemented returning char instead of int. In ISO C++ (std::moneypunct<charT>::do_frac_digits() const) and the PS5 Dinkumware runtime ABI (as previously defined in InventoryExports2.hpp), do_frac_digits() returns int. Returning char in %al instead of int in %eax leaves the upper 24 bits of %eax unextended/uninitialized under the System V AMD64 ABI, causing guest callers expecting int to read corrupted frac digit counts.
    • core/libs/prx/libc/include/Api.hpp:1818, core/libs/prx/libc/include/GuestLocale.hpp:193, core/libs/prx/libc/src/LocaleSupport.cpp:1337: _ZNKSt7_MpunctIwE14do_frac_digitsEv_nid_postfix (and the WideMoneyPunctVtable::fracDigits function pointer) is declared and implemented returning char instead of int. In ISO C++ and the PS5 Dinkumware runtime ABI (as previously defined in ErrExports.hpp), moneypunct<wchar_t>::do_frac_digits() returns int. Returning char violates the ABI and produces garbage in high register bits on caller side.
    • core/libs/prx/libSceLibcInternal/include/Api.hpp:235, core/libs/prx/libSceLibcInternal/Moneypunct.cpp:38: sceLibcInternalMoneyPunctDoFracDigitsChar_nid_no_patch is declared and implemented returning char instead of int. PS5's libSceLibcInternal wrapper for moneypunct<char>::do_frac_digits returns a 32-bit int.
    • core/libs/prx/libSceLibcInternal/include/Api.hpp:240, core/libs/prx/libSceLibcInternal/Moneypunct.cpp:81: sceLibcInternalMoneyPunctDoFracDigitsWide_nid_no_patch is declared and implemented returning char instead of int. PS5's libSceLibcInternal wrapper for moneypunct<wchar_t>::do_frac_digits returns a 32-bit int.
  • Note: the AI-assisted checkbox can stay.

Requesting changes for the points above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5862438455 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18135#pullrequestreview-5862438455). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-11T17:01:39Z. **Review:** CHANGES_REQUESTED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `e36012df66`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **GitHub CI**: failing check(s): `windows`. - **Build**: `guest_libc_internal_moneypunct_tests` built cleanly. - **CTest** (`guest_libc_internal_moneypunct`): ``` 1/1 Test #3463: guest_libc_internal_moneypunct ... Passed 0.12 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceLibcInternal/Err.cpp`, `core/libs/prx/libSceLibcInternal/Export.cpp`, `core/libs/prx/libSceLibcInternal/InventoryExports2.cpp`, `core/libs/prx/libSceLibcInternal/InventoryExports6.cpp`, `core/libs/prx/libSceLibcInternal/include/Api.hpp`, `core/libs/prx/libSceLibcInternal/include/ErrExports.hpp`, `core/libs/prx/libSceLibcInternal/include/InventoryExports2.hpp`, `core/libs/prx/libSceLibcInternal/include/InventoryExports6.hpp`, `core/libs/prx/libSceLibcInternal/include/PendingExports.hpp`, `core/libs/prx/libc/include/Api.hpp`, `core/libs/prx/libc/include/GuestLocale.hpp`, `core/libs/prx/libc/src/LocaleSupport.cpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - core/libs/prx/libc/include/Api.hpp, core/libs/prx/libc/include/GuestLocale.hpp, core/libs/prx/libc/src/LocaleSupport.cpp, and core/libs/prx/libSceLibcInternal/include/Api.hpp: verified virtual do_frac_digits return types against standard C++ moneypunct and Dinkumware PS5 ABI specifications. - core/libs/prx/libSceLibcInternal/Moneypunct.cpp: verified all 37 NID exports, parameter lists, calling conventions, and sret pointer forwarding against libc counterparts. - core/libs/prx/libc/src/LocaleSupport.cpp: verified RequireMoneyPunct and RequireWideMoneyPunct null checks, classic locale validation, and pointer safety. - core/libs/prx/libc/include/GuestLocale.hpp: checked struct layouts, alignment, and member offsets of MoneyPunctFacet and WideMoneyPunctFacet across LP64 and LLP64 architectures. - **Concerns**: - core/libs/prx/libc/include/Api.hpp:1809, core/libs/prx/libc/include/GuestLocale.hpp:168, core/libs/prx/libc/src/LocaleSupport.cpp:1301: `_ZNKSt7_MpunctIcE14do_frac_digitsEv_nid_postfix` (and the `MoneyPunctVtable::fracDigits` function pointer) is declared and implemented returning `char` instead of `int`. In ISO C++ (`std::moneypunct<charT>::do_frac_digits() const`) and the PS5 Dinkumware runtime ABI (as previously defined in `InventoryExports2.hpp`), `do_frac_digits()` returns `int`. Returning `char` in `%al` instead of `int` in `%eax` leaves the upper 24 bits of `%eax` unextended/uninitialized under the System V AMD64 ABI, causing guest callers expecting `int` to read corrupted frac digit counts. - core/libs/prx/libc/include/Api.hpp:1818, core/libs/prx/libc/include/GuestLocale.hpp:193, core/libs/prx/libc/src/LocaleSupport.cpp:1337: `_ZNKSt7_MpunctIwE14do_frac_digitsEv_nid_postfix` (and the `WideMoneyPunctVtable::fracDigits` function pointer) is declared and implemented returning `char` instead of `int`. In ISO C++ and the PS5 Dinkumware runtime ABI (as previously defined in `ErrExports.hpp`), `moneypunct<wchar_t>::do_frac_digits()` returns `int`. Returning `char` violates the ABI and produces garbage in high register bits on caller side. - core/libs/prx/libSceLibcInternal/include/Api.hpp:235, core/libs/prx/libSceLibcInternal/Moneypunct.cpp:38: `sceLibcInternalMoneyPunctDoFracDigitsChar_nid_no_patch` is declared and implemented returning `char` instead of `int`. PS5's `libSceLibcInternal` wrapper for `moneypunct<char>::do_frac_digits` returns a 32-bit `int`. - core/libs/prx/libSceLibcInternal/include/Api.hpp:240, core/libs/prx/libSceLibcInternal/Moneypunct.cpp:81: `sceLibcInternalMoneyPunctDoFracDigitsWide_nid_no_patch` is declared and implemented returning `char` instead of `int`. PS5's `libSceLibcInternal` wrapper for `moneypunct<wchar_t>::do_frac_digits` returns a 32-bit `int`. - Note: the AI-assisted checkbox can stay. Requesting changes for the points above.
MarcZX10 commented 2026-11-19 03:02:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T03:02:13Z.

Review: CHANGES_REQUESTED


Reviewed — changes requested

Changes are required before merge: make the _Locinfo constructors reject or correctly handle unsupported non-C locale data instead of silently installing C-locale values.

What I ran

Reviewed head e36012df661dd7268b2d3f93dd5356589a29b5f4 from the prepared diff and repository reader. No commands or tests were run.

Results

Check Result Note
Diff and changed code review passed Inspected the prepared diff and relevant code.
Tests not run Test results in the PR description were author-reported.
Negative control not run No test execution was available.

Findings

Blocking

  • core/libs/prx/libc/src/LocaleSupport.cpp:976-978: The _Locinfo constructor discards info and always initializes the facet with C-locale values. Unlike the named constructor, it does not reject unsupported locale data, so constructing a facet from a non-C locale silently returns incorrect punctuation and monetary fields. Validate the locale represented by info and reject unsupported data, or populate the facet from it.

Non-blocking

None.

Sources

Not verified

No tests, build, console behavior, or non-C locale behavior were run. Read the prepared description, commits, manifest, and diff; reviewed the changed money-punctuation implementation, locale facet declarations, export declarations, CMake test registration, and debt entry. The other changed export inventory and declaration files were inspected through their diff hunks. The excluded-file list was not available in the review folder.

To get this to a good state

Reject unsupported locale data in each _Locinfo constructor or implement loading those values. Then rerun the focused guest_libc_internal_moneypunct test and review the updated head.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5968704933 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18135#pullrequestreview-5968704933). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-19T03:02:13Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested Changes are required before merge: make the `_Locinfo` constructors reject or correctly handle unsupported non-C locale data instead of silently installing C-locale values. ## What I ran Reviewed head `e36012df661dd7268b2d3f93dd5356589a29b5f4` from the prepared diff and repository reader. No commands or tests were run. ## Results | Check | Result | Note | |---|---|---| | Diff and changed code review | passed | Inspected the prepared diff and relevant code. | | Tests | not run | Test results in the PR description were author-reported. | | Negative control | not run | No test execution was available. | ## Findings ### Blocking - `core/libs/prx/libc/src/LocaleSupport.cpp:976-978`: The `_Locinfo` constructor discards `info` and always initializes the facet with C-locale values. Unlike the named constructor, it does not reject unsupported locale data, so constructing a facet from a non-C locale silently returns incorrect punctuation and monetary fields. Validate the locale represented by `info` and reject unsupported data, or populate the facet from it. ### Non-blocking None. ## Sources - [LocaleSupport.cpp at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/e36012df661dd7268b2d3f93dd5356589a29b5f4/core/libs/prx/libc/src/LocaleSupport.cpp#L974-L978) - [MoneyPunctFacet declarations at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/e36012df661dd7268b2d3f93dd5356589a29b5f4/core/libs/prx/libc/include/GuestLocale.hpp#L147-L184) ## Not verified No tests, build, console behavior, or non-C locale behavior were run. Read the prepared description, commits, manifest, and diff; reviewed the changed money-punctuation implementation, locale facet declarations, export declarations, CMake test registration, and debt entry. The other changed export inventory and declaration files were inspected through their diff hunks. The excluded-file list was not available in the review folder. ## To get this to a good state Reject unsupported locale data in each `_Locinfo` constructor or implement loading those values. Then rerun the focused `guest_libc_internal_moneypunct` test and review the updated head.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!18135
No description provided.