fix(json2): keep numeric conversion independent of host locale #7215
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7215"
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 simonbronk on 2026-10-17T17:08:46Z.
What
With a decimal-comma host
LC_NUMERIC, Json2 emits invalid JSON (1.5becomes1,5) and silently reads JSON1.5as1. In the regression,{"value":1.5,"list":[2.5,-0.125]}becomes{"value":1,"list":[2,-0]}after parsing and serializing.Use
to_charswith the existing 17 significant digits for output andfrom_charsfor input. On an out-of-range input only, use a stream explicitly imbued with the classic locale to retain the prior underflow-to-signed-zero behavior and overflow exception. Do not change the process locale. The numeric grammar still rejects a decimal comma.RFC 8259 section 6 requires
.as the decimal point. The C++ numeric conversion specification specifies C-locale formatting. Console rounding and formatting remain unmeasured and are recorded in Json2 debt. No title unblock, percentage increase or performance gain is claimed.Tested
Windows, WinLibs MinGW-w64 GCC 15.2.0r7 UCRT, Release, actual shared
libSceJson2.prxand its CMake test executable; base66702f1cffd3646f2d674ed093fde0a85a70761f:guest_jsonpasses, newguest_json_numeric_localefails. The output records invalid decimal commas, truncated input values, and the corrupted nested document above.aa92ad8072ff2efc82851c64fc6c95c6af31bded: both CTests pass, no skips (2/2, 0.43 s). The comma locale selected isde_DE.UTF-8.check_conventions.pyagainst the pinned base andgit diff --checkpass for the final committed change.pr_overlap.pycannot execute becauseghis unavailable; live connector searches found no open Json2 numeric-locale fix. #6126 adds callbacks (including special-float handling), #6593 handles allocation failures, and #6447 is a broader compatibility batch; those address different behavior but may require textual reconciliation.AI assistance: OpenAI Codex. Evidence is attached below.
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)json-numeric-locale-evidence-20261017.zip
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T17:23:58Z.
Full CI on 8706b8258 (run 39052899521): every test passes on both lanes, and
guest_json_numeric_localeruns and passes on Windows. The Linux job still fails attools/check_skips.py:The Linux runner has no decimal-comma locale, so the test exits 77 with "No decimal-comma numeric locale is installed". On Linux, the guard only accepts skips that report a device limitation. Could you make the test cover Linux without an installed locale? For example, build the numeric facet in the test, or set
LC_NUMERICfrom a locale the test generates. If that is not practical, only register the case where it can run. We will re-run full CI on the new head.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T17:36:29Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)docs/dev/debt/libSceJson2.mdL4Some 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.
docs/dev/debt/libSceJson2.mdcore/libs/prx/libSceJson2/CMakeLists.txtcore/libs/tests/GuestJson.cppImported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T18:37:47Z.
I checked the Linux skip path in
NumericLocale(): it needs an installed comma-decimal locale only to change the processLC_NUMERIC, which makes the serializer/parser regression locale-sensitive. A portable fix is to expose the conversion logic through a small internal helper that takes an explicit locale (or use a test-only locale facet for the legacy host conversion), then assert the JSON path always uses.while the host locale remains unchanged. If the goal is specifically exercisingsetlocale, the Linux test can generate/install a locale in CI, but that adds runner setup; conditionally unregistering the test would lose Linux coverage. I have not modified this PR. Thecheck_skips.pyreport on the current head is a real required-CI failure, so please update the test and request a fresh full CI run.Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-17T23:33:38Z.
Review: COMMENTED
Linux run of
guest_json_numeric_localewith a decimal-comma locale, since the Linux CI job skips it (no such locale installed) and the description has no Linux run.Machine: Linux x86_64, i7-8700, Ubuntu 26.04, GCC 15.2, Release,
BUILD_TESTING=ON, full build.Head
8706b8258merged ontomain5de7a46e0(clean merge).The host has only
C,C.utf8anden_US.utf8. I generatedde_DE.UTF-8into a user directory without root (localedef -i de_DE -f UTF-8 <dir>/de_DE.UTF-8) and pointed glibc at it withLOCPATH=<dir>.LOCPATHset:guest_jsonandguest_json_numeric_localepass, 5 of 5 runs. The test reportsJSON numeric locale: de_DE.UTF-8.LOCPATH:guest_json_numeric_localeexits 77 and CTest shows it as skipped, as in CI.main, withLOCPATHset:guest_json_numeric_localefails with the bug described above, e.g.Decimal-point serialization failed: 1,5,Decimal-point parsing failed: 1.5andNested numeric serialization failed: {"value":1,"list":[2,-0]}. So the test covers the change on Linux too.ctest -E "^agc|gpu|vulkan|video_out", noLOCPATH): 698/698, the 697 tests ofmainplusguest_json_numeric_localecounted as passed with its skip.On the CI skip: on glibc a test-local locale works without installing one system-wide, as long as
localedefand the locale sources (/usr/share/i18n/locales) are present. I did not check whether the GitHub runner image has them.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T23:50:41Z.
Thanks for running this with a generated
de_DE.UTF-8locale and checking the negative control on main. That confirms the regression on Linux when the locale is available, while the current CI skip is the expected no-locale path. I’ve updated my earlier review concern; the current required checks are green.Imported from boykopovar/AnyPS5. Originally posted by TheTerr4 on 2026-10-18T14:59:39Z.
Windows runtime check. Windows 11 Pro 10.0.26200, Ryzen 7 7800X3D, WinLibs GCC 15.2.0 r7 (UCRT), Release.
This PR's head
8706b8258merged cleanly intomain385ed71f2; the full build andlibsboth exit 0.guest_jsonandguest_json_numeric_locale(the locale test ran underde_DE.UTF-8, so it was not skipped) pass, three repeated-j1runs.libSceJson2/Export.cpprestored tomain's version,guest_json_numeric_localefails;guest_jsonstill passes.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T15:18:03Z.
Thanks for the Linux locale run and negative control. Generating
de_DE.UTF-8in a user directory confirms the test can exercise decimal-comma behavior without a system-wide locale install, and the restored-main failure shows it catches the bug. The Linux full-build subset also passed; platform limits are clear in your report.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T07:17:30Z.
Full CI on our merge-main head
0b51b5b482(run 39383582595): every test passes, but the Linux job still fails attools/check_skips.py, as it did on 17 Oct:The check is deliberate. A skip there means Linux CI never runs the case, and we won't add a "no locale" category to the guard. The Linux runner has no decimal-comma locale and we can't install one on it, so the test has to bring its own.
This works without root and without any system locale sources. Ship two small data files next to the test:
comma.charmap(ASCII only):comma.locale:Then build the locale in the build tree as a CTest fixture (Linux only), point the test at it with
LOCPATH, and addxx_COMMAto the namesNumericLocale()tries:localedef -cexits 1 here because the other categories are missing, even though it writes the locale. That's why the fixture checks for theLC_NUMERICfile instead of the exit status.localedefcomes with glibc (libc-bin on Ubuntu), and pointingI18NPATHat an empty directory proves nothing comes from/usr/share/i18n.Checked on glibc with every system i18n path hidden:
setlocale(LC_NUMERIC, "xx_COMMA")withLOCPATHset succeeds,decimal_pointis,,printf("%.2f", 1.5)prints1,50andstrtod("1.5")returns 1. So the oldsnprintf/strtodcode fails the test under this locale and theto_chars/from_charscode passes. Windows keeps its existingde-DE/German_Germany.1252path, which ran and passed in CI.Please also keep
return 77for hosts where the fixture can't run, and leave the rest of the test as it is. We'll rerun full CI on the new head.Imported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-22T09:07:15Z.
@oneandonlydean done as you described, with
mainmerged in (one conflict in the libSceJson2 debt file; I keptmain's entries and this PR's one line).core/libs/tests/numeric-locale/comma.charmap(ASCII 0x00-0x7F) andcomma.locale(LC_NUMERIConly,,as the decimal point).guest_json_numeric_locale_setupbuildsxx_COMMAinto the build tree withlocaledef -candI18NPATHpointing at an empty directory, and checks for theLC_NUMERICfile. It is the fixture ofguest_json_numeric_locale, which runs withLOCPATHset.NumericLocale()triesxx_COMMAfirst, andreturn 77stays.CMAKE_SYSTEM_NAME STREQUAL "Linux"rather thanNOT WIN32. macOS has no glibclocaledef, and itsde_DE.UTF-8is already found.Tested: Linux, Ubuntu 24.04 x86-64 container (Colima/Rosetta), GCC 13, RelWithDebInfo with ASan, merged onto
maind6eafa54d:guest_json_numeric_locale_setupandguest_json_numeric_localeboth report Passed, not skipped.guest_json,guest_json_copy_failure,param_json_parserandparam_json_utf8pass too.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-22T09:19:36Z.
@simonbronk thanks, the locale fixture does what I hoped. With the shipped charmap and LC_NUMERIC source,
localedef -cbuildsxx_COMMAeven with an emptyI18NPATH, and underLOCPATHit gives,as the decimal point, so the test now runs on Linux instead of skipping.One problem from the merge:
core/libs/prx/libSceJson2/Export.cppstill has the conflict markers at lines 13-17, so the file doesn't compile:Both includes are needed (
<sstream>for the classic-locale fallback,<memory>frommain). With the markers removed and both lines kept, it compiles cleanly here. Could you push that fix? I'll run the full CI on the new head.Imported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-22T09:47:55Z.
@oneandonlydean thank you for catching it, and sorry. My earlier Tested line was wrong. The merge left those markers in
Export.cpp, the library failed to compile in my run, and ctest ran a binary left from an older build. I put the non-zero build exit down to an unrelated link failure and didn't check further. That's on me.Fixed on the new head:
2f579e0ebremoves the markers and keeps both<memory>and<sstream>, as you said.a07d5a507updates the locale test tomain's parser, which the merge brought in and which I hadn't run against before.mainkeeps object keys sorted, so the nested document now lists them in order,{"list":[2.5,-0.125],"value":1.5}.mainalso stops after the first value (parse("{} trailing") == 0is in its tests), so"1,5"now has to parse as the unsigned integer 1 instead of failing.Tested again, this time building the targets explicitly and checking the exit code: Linux, Ubuntu 24.04 x86-64 container (Colima/Rosetta), GCC 13, ASan, merged onto
main7e2ba73e4.cmake --build --target libSceJson2 guest_json_testsexits 0.guest_json_numeric_localeruns underxx_COMMAand passes, and so doguest_json,guest_json_numeric_locale_setup,guest_json_copy_failure,param_json_parserandparam_json_utf8.Negative control, with
main'slibSceJson2/Export.cppswapped in:guest_json_numeric_localefails. Serialization writes1,5,-0,125,1,25e+30and so on, parsing1.5doesn't round-trip, and the nested document serializes as{"list":[2,-0],"value":1}.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-22T10:06:01Z.
@simonbronk, merged, thanks. Full CI on
a07d5a5was green on Linux and Windows, andguest_json_numeric_localenow runs on Linux under the comma-decimal test locale instead of skipping.