feat(libc): convert wide strings with _WStoull, _WStoll, _WStod, _WStof and _WStold as the console's libc does #11733
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11733"
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 verusferro on 2026-10-27T06:21:57Z.
What
libc did not export the wide Dinkumware conversions
_WStoull,_WStoll,_WStod,_WStofand_WStold, which the console'slibc.prxexports. They now follow the SDK 7.00libc.prxthat PPSA06416 ships insce_module/(0x3c8b0, 0x3c730, 0x7d3d0, 0x7d6f0 and 0x725c0), read from its disassembly (REVERSE_ENGINEERING, source 2) and run:_WStoullis Dinkumware'sxwstoul.c. It skips characters for which_Iswctype(c, 9)(space) is true and takes one sign. A base below 0, equal to 1 or above 36 converts nothing (*endptris the string, result 0). Base 0 and 16 strip a0xor0X. Leading zeros are skipped, and each digit is looked up with_Towctrans(c, 1)andwmemchrin0123456789abcdefghijklmnopqrstuvwxyz. Text with no digits after the prefix, a bare0xincluded, converts nothing. Overflow is found from the per-base digit counts the module keeps at 0xfc790 (65 for base 2, 20 for base 10) and returnsULLONG_MAXwithERANGEwhatever the sign. Otherwise a-negates the result._WStollskips the same spaces, takes one sign and calls_WStoullon the rest, so--1reaches_WStoullas-1and overflows. It returnsLLONG_MAXorLLONG_MINwithERANGEwhen the value does not fit, and the original string as*endptrwhen nothing converts._WStod,_WStofand_WStoldcall the module's internal_WStodx-style parsers with a null error pointer, as the narrow_Stodcalls_Stodx. Here they run this library's_Stodx,_Stofxand_Stoldxon the leading ASCII characters, through the helperwcstoduses. The new debt entry records where that differs.The console's
_WStoul(0x7a8f0) is the same code as_WStoull. This library's_WStoulstill runswcstouland throws for a bad base, as its existing debt entry says; that entry is on a line that #9087, #9863 and #10453 also change, so this PR leaves it.Tested
Ubuntu 24.04 (WSL2) x86-64, GCC 13.3, Release, full build with
BUILD_TESTING=ON, onmain2227f13661:libc.prx, converted by the relinker and loaded in a host process, against this library's unpatchedlibc.prx, comparing the result, the characters consumed anderrno. The inputs are 30,000 random wide strings built as in JJenkx's differential: a leading space, tab or U+3000, then+,-,--or no sign,0x,0Xor no prefix, then up to 27 characters from0-9a-fA-F zZ . e + - p P x nand space._WStoulland_WStoll, with bases 0, 2, 8, 10, 16, 36, 1, 37 and -1. All match. On the earlier basefe2b52c7e4, 175,560 hand-picked calls also matched: every base from -1 to 37 and 100; no-break, ideographic and NEL spaces;0bprefixes; Latin-1, fullwidth and Arabic-Indic digits; and values at, below and above the overflow limit in every base._WStod,_WStofand_WStold, with a scale of 0 and, for text without anx, one more scale from -400 to 400. 8,818 differ, none of them from_WStold. Every one of the 8,818 is a text whose narrow form gives the same two results from the module's_Stodor_Stofand from this library's: the difference is in_Stodxand_Stofx, which the wide functions call. There are three kinds: 8,732 zeros whose sign differs after a-with nothing convertible, 42 hexadecimal overflows where this library setsERANGE, and 44 long hexadecimal mantissas that end one unit apart.-nanand the 1e-30 subnormal with a scale of -10, checked separately, differ in the narrow functions the same way. The debt entry lists all of them.guest_wide_conversiongains cases for each function, taken from the module's results: overflow on either side of the limit, a sign before a second sign or a space, base detection, an empty string, a bare0x, leading zeros past the digit count, and scaling. Making_WStollaccept 2^63 with a+fails it.ctest -R '^(guest_wide_conversion|guest_dinkumware_internals|patched_libraries|conventions_unknown_nids|public_headers)$': 5/5 pass.tools/progress.py: +5 implemented. libc goes from 1419/1436 to 1424/1441.python3 tools/check_conventions.py --base origin/main: passed.python3 tools/pr_overlap.py --branch feat/libc-wide-string-to-number: no conflicting lines and no same exports. The debt entry is placed after thejrand48entry, between lines no open PR changes; next to the_Stodentry, and where it first was, open PRs (#11270, #12291, #12397) change the neighbouring lines.Not tested: Windows, macOS, a title that calls these functions, a console 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)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-27T06:33:29Z.
Review: APPROVED
Reviewed exact head
14cd697dd201cfb6a2c0dd85cd1a08d1b77ba8c2. The integer conversions consistently handle whitespace/sign/prefix before digit counting, leaveendptrat the original string when no conversion occurs, and distinguish unsigned overflow from the signed range checks. The floating wrappers reuse the existing ASCII-prefix path and narrow_Stodxfamily, with the observed differences explicitly recorded in technical debt. The focused cases cover the main boundary behaviors and are not export-only tests.The author reports direct result/end-pointer/
errnocomparisons against the shipped module over 175,560 integer calls and 1,038 floating calls; the documented two_WStofdiscrepancies are retained as debt. Hosted conventions, intake, Linux/Windows relinker, ASan and Ubuntu register-context checks pass; product Linux/Windows jobs are skipped, and several macOS jobs remain queued. I did not independently run the full build or module comparison in this workspace.