Skip to content

feat(libSceJson2): implement allocator-backed values and recovery - #10378

Merged
oneandonlydean merged 120 commits into
boykopovar:mainfrom
kyon-eth:fix/json2-special-float-modes
Nov 2, 2026
Merged

oneandonlydean merged 120 commits into
boykopovar:mainfrom
kyon-eth:fix/json2-special-float-modes

Conversation

@kyon-eth

@kyon-eth kyon-eth commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

What

Implement allocator-backed Json2 values, object trees and iterators, auxiliary callback records, recovery fallbacks, and initialization resources. Preserve allocation ordering, partial failure states, ownership, callback precedence and retry behavior instead of using host-only storage or fabricated success results.

Implement 73 of the 74 inventory exports introduced by #9517. The remaining base allocator deleting destructor deliberately traps and stays explicitly unsupported. Correct member/callback signatures, setter return declarations, special-float settings and SDK-dependent storage behavior. Document remaining unsupported cases in the library debt file.

Expose the four read-only Boolean, signed-integer, unsigned-integer and real fallback objects and the three writable String, Array and Object fallback pointers. The pointers are published after construction, used by getters and initialization admission, and consumed and cleared during cleanup. When a getter reaches its default path, it returns the corresponding exported object's address; successful callback replacements retain their own addresses. These data NIDs also occur in libSceJson; this branch defines them in libSceJson2, and independently loaded provider resolution remains separate.

Original prerequisites #10212, #10353 and #8530 have merged into main. This branch retains their String/Array assignment and parser-cleanup regressions. There is no remaining landing dependency on those PRs.

Preserved the String overload cases from #10212 and the deep-copy/source-independence/self-assignment regression from #10353. Two String expectations are deliberately corrected: out-of-range at returns zero, and a null C-string needle is empty. Existing String boundary regressions cover those contracts. Array assignment keeps the SDK-dependent allocator ordering and partial-failure behavior covered by the allocator tests. The current debt file retains applicable limitations instead of restoring obsolete pending-export declarations.

Integrated #8530 in the agreed order. Array parsing continues to admit an owned placeholder through AppendArray before parsing its payload. Its expanded buffer/callback, malformed/nested, long-key and missing-key checks are retained, with expectations reconciled to the implemented ABI and measured partial-parser states. Host-allocation counts from the former list storage are not treated as guest-allocation coverage.

Other overlap review: #8658 decimal conversion, #9826 placeholder bodies, #6039 debt documentation and #6044 test organization. Same-name matches in #9470 belong to libSceJson, a different module. These are not prerequisites.

Tested

  • Current head: after merging main 50843f4, a fresh macOS x86-64 production-source fixture passed all 202 supported JSON tests, including scalar fallback addresses, writable pointer identity and replacement, allocator-callback publication and initialization rollback. A separate historical callback baseline timed out and is excluded from that supported suite. The four scalar objects were present at distinct read-only addresses and the three pointer symbols were exported as writable data in the linked fixture. No patched guest-import, Linux or Windows execution was performed on this head.
  • The refreshed open-PR scan checked 1,610 other PRs and found no overlapping changes.

Current-main refresh: merged 556547da71 in 3a9241afe5, retaining both the existing test links and the new C++23 requirement. The macOS x86-64 production-source fixture passes 202/202 registered guest_json cases; the public-header audit, conventions and whitespace checks pass. The fixture adapts unrelated libc/kernel boundaries; no full product build or new Linux/Windows run is claimed.

Current-main validation (2026-10-28): merged main 6a28efaa27 in da1fb929ea and reconciled its decimal-underflow fix with this PR's reference-backed ParseDecimal, allocator admission and AssignReal path. The registered decimal-range tests cover signed underflow to zero, subnormals and overflow settings. Rebuilt macOS x86-64 production-source fixture: 202/202 guest_json checks pass. Header audit, conventions, whitespace and privacy checks pass. This is a focused fixture with unrelated libc/kernel boundaries adapted, not a full product build.

Current-main validation (2026-10-27): integrated main 9ae2f7d22a in 34632912cf. All 202/202 supported Json2 CTest cases pass in the rebuilt macOS x86-64 production-source fixture. The fixture now also compiles the production macOS guest-image lookup required by main; unrelated libc/kernel boundaries remain substituted. Conventions, whitespace and privacy checks pass. The reviewer independently reports both focused Linux ownership/callback-thread cases passing, including a later QEMU TCG run. No complete Linux-suite or Windows runtime pass is claimed; Windows guest_json remains outstanding.

Historical integration: 18f7696bd6 includes main 941ace5f34 and merged #8530. The production-source macOS x86-64/Rosetta fixture rebuilt and passed 219/219 registered JSON checks, using production process-metadata lookup. File/mutex and unrelated libc boundaries remain substituted; the unsupported-export adapter uses the production diagnostic format. No full product, Linux/Windows or game run is claimed.

  • Retained fix(json2): release partial entries on allocation failure #8530's expanded copy/parser/insertion checks and the existing iterator-copy and swap regressions. Setters use the canonical void ABI; malformed documents retain their measured partial trees instead of restoring the previous destination.
  • A guest-allocator sweep across 11 documents and both buffer/callback readers exercises 578 allocation failures, checks reachable payload ownership, retained trees, destruction and retry, and leaves no tracked guest allocations after cleanup. It separately observes 26 existing missing-sentinel refusals; these are explicitly unsupported, not successful native-compatible OOM handling. Exact reference-backed partial-state and callback regressions remain unchanged.
  • Negative control: temporarily parsing array payloads in detached values before list admission causes the new cleanup check to fail at allocation budget 11 with unreachable guest allocations. Restored the original ownership-first implementation, forced its object to rebuild, then reran the full 219-check suite successfully.
  • Public-header audit, standalone Json2 umbrella compilation, current-main conventions, strict main-sync and whitespace checks pass. No private names/paths or unrelated library work added.

Previous public-header integration (7f0fe1d09b, main 2e22b67032): reconciled #10706's public-header migration with the implemented ABI layouts and signatures. All Json2 callers/tests use the canonical declarations; raw parameter/layout fixtures retain explicit ABI casts. Private storage helpers remain outside the exported API through a header-derived linker export list, including the existing String::npos data symbol.

  • The production-source macOS x86-64/Rosetta fixture rebuilds and all 219/219 registered module checks pass, using production process-metadata lookup. This is not a full application or Linux/Windows run.
  • All 214 existing Export.cpp function bodies are unchanged by this integration. The built module exports exactly the 216 declared API function/data symbols, with no extra private storage helpers.
  • Repository-wide public-header audit, standalone Json2 umbrella compilation, current-main conventions and whitespace checks pass. Earlier ARM64 results below predate this integration.
  • That earlier run preceded fix(json2): release partial entries on allocation failure #8530; the combined validation is recorded above.

Overlap follow-up: added a bounded guest-allocation sweep for [1] and malformed [1, parsed into an already owned empty array, through buffer and callback readers. It checks public error propagation, admitted entry ownership, cleanup and retry of the same destination. Existing measured partial-array and nested-parser expectations remain intact. Seven focused parser/allocator/callback checks pass per macOS architecture. This earlier check preceded the combined #8530 validation above. The missing-sentinel refusal remains documented and unsupported.

Allocation-failure follow-up on main c9b2660d56: reproduced the two reported macOS failures with the production ApplicationProcessParameters.cpp lookup instead of the earlier null-returning metadata adapter. A missing process-metadata lookup throws std::runtime_error; repeatedly constructing that exception can allocate from the host heap while the tests deliberately disable host allocations. Json2 now remembers a failed lookup with an atomic flag and keeps the existing unknown-SDK fallback. Successful metadata queries remain unchanged, preserving SDK-dependent behavior. Main-executable metadata cannot appear later without relinking/restarting the process.

  • On the updated source, all 219 module CTest cases pass on macOS x86-64/Rosetta, including both reported failures and the SDK 5/6 initialization regression, using the real production metadata-lookup implementation. File/mutex and other unrelated libc boundaries remain substituted; this is not a full application or complete libc/kernel integration build.
  • All 219 module cases also pass on macOS ARM64 with the original boundary fixture; the two affected cases additionally pass on ARM64 with the real metadata-lookup implementation.
  • No assertions were removed or weakened. No Linux/Windows execution or full 222-case application-suite result is claimed for this follow-up.

Latest review check: the reported PS4 Pro 10.71 measurements corroborate the measured iterator ABI, allocator slots, constructor footprints and Array assignment results. Added the exact {"a":} case to the existing parser-state regression: parsing returns 0x80848101, public getType() returns object (7), a later parse succeeds and teardown reclaims the admitted storage. This behavior already worked on this branch; no parser implementation change was needed. These PS4 observations do not establish PS5 console or cross-firmware compatibility.

  • Existing cases check object-tree invariants, iterator identity, nested copies, allocation failures, callback ABI/precedence, metadata ownership, initialization rollback, exception state and retry. No new export-only tests.
  • Checked Windows CTest DLL-search-path metadata for 69 lifecycle cases. Linux and Windows binaries/runtime execution were not tested.
  • Local conventions checks, including this PR template, pass. The full open-PR overlap check and branch privacy/export checks were performed; declared overlaps are listed above. No demonstrated game unblock or performance claim.

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

Review follow-up: descendant assignment now snapshots aliased payloads before releasing the owning tree; allocation bookkeeping no longer nests the legacy shared recovery mutex under the host state mutex. Public-entry ownership regressions reproduce the old failure. A coordinated legacy mismatch/parser test times out on the old implementation and completes on the fix. Supported Json2 tests pass 202/202 in the rebuilt macOS production-source fixture. Explicitly unsupported throw-pinning tests were removed, while supported rollback, callback exceptions and returning retries remain.

Windows export generation now marks String::npos DATA and retains function exports normally. The real CMake generator produces 216 entries with exactly that one DATA export. This is generation validation, not a Windows runtime rerun. File mocks include the kernel API header and use int descriptors. The vector insertion behind the reported GCC warning was rewritten as equivalent element appends; the independent Linux ASan/LSan report on the prior code found no overflow. No Linux/Windows execution by the author is claimed for this update. Overlapping ancestor/descendant swaps are explicitly unsupported before mutation pending a verified reference contract; partial object-allocation and null-callback-cycle gaps remain documented.

The callback-thread test substitutes the application-heap allocation entry points and kernel mutex primitives; it exercises the real Json2 state locks, mismatch callback and parser. Its five-word SDK fixture supplies only the compatibility SDK query and is not presented as real application-heap metadata. The substitution now also checks that every legacy application-heap allocation is released. The prior implementation still times out with that corrected fixture and the fixed implementation completes. The raw Object descendant setter also has a public-entry regression alongside Array/String/Value assignment.

The Windows CI failure on the previous head reported ambiguous fallback-data references. The seven definitions now use the namespace of their declarations while retaining C linkage. The macOS production-source fixture rebuilds and all 202 registered tests pass; Windows CI passed on head 881f168de66d.

Independent platform evidence

Native supported-CPU Windows report validates prior exact head 34632912cf: 202 registered groups, three runs each (606 successes), including the String::npos DATA import. It closes the previously missing Windows evidence for that head. It predates this main merge; no current-head Windows rerun is claimed. The Linux report on that head also predates this merge and documents an unsupported-CPU guard bypass, so it is not a supported-CPU Linux result.

@benjaminmathias

Copy link
Copy Markdown
Contributor

Native Windows test report for exact PR head 34632912cfb6d6861443eb73be13ad6538582575.

Windows 11 Pro build 26300, AMD Ryzen 7 5700X3D, WinLibs GCC 15.2.0 r7 (x86_64-ucrt-posix-seh), Ninja, Release, BUILD_TESTING=ON. Used a clean dedicated worktree, initialized pinned submodules and a fresh build directory. Built all 50 guest_json*_tests targets from this PR's CMake registrations, including their production libc/libkernel/Json2 dependencies; no source changes or CPU-feature bypass.

ctest --test-dir C:/tmp/a5json-20261027 -R "^guest_json" --no-tests=error --interactive-debug-mode 0 -V --repeat until-fail:3 --output-log json-ctest.log --output-junit json-ctest.xml

202 registered groups passed three times each: 606 successful executions, zero failures, zero skips. Checked both verbose execution output and JUnit results. This includes guest_json, the numeric-locale case (selected de_DE.UTF-8), recovery/allocation cases and callback-thread tests. The generated Windows definition file contains _ZN3sce4Json6String4nposE DATA; guest_json runs successfully with the resulting import library.

Tested the PR head directly, without merging current main (14332cd8d03269dc74ae7037cbf2ddf69c06dca6); merge base is 9ae2f7d22a11bcb8e640f70dccf48ea0bb7520cc. Rechecked the remote PR head before posting: unchanged. No negative control, full-project test suite, title or GPU test was run. This is test evidence, not a code-review approval.

AI-assisted: yes. Builds and tests were executed locally.

…at-modes

# Conflicts:
#	core/libs/prx/libSceJson2/Export.cpp
@kyon-eth

Copy link
Copy Markdown
Contributor Author

Merged current main 6a28efaa27 in da1fb929ea and resolved the decimal-underflow conflict by retaining the reference-backed conversion plus allocator admission and real-setting behavior. Rebuilt the production-source macOS x86-64 fixture and reran all registered guest_json checks: 202/202 pass, including signed underflow, subnormals, overflow settings and callback ownership. Public-header, conventions, whitespace and privacy checks pass. The fixture adapts unrelated libc/kernel boundaries; no full product or current-head Linux/Windows run is claimed.

The description now records the independent native Windows 606-execution report for prior head 34632912cf separately, rather than continuing to describe that historical platform check as missing. Thank you for that verification.

@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.

Re-reviewed — approved

Reviewed exact PR head da1fb929eabd09573783570048a07438fad59f8d against current main edf6804cf52c62eacafc592dd6142cb4efe5bd05.

What I checked

  • Re-read the latest source/test delta and the decimal-underflow integration. Since the prior Windows-tested head 34632912cfb6d6861443eb73be13ad6538582575, every PR-touched file is byte-identical at the current head; the intervening update merges current main.
  • Current merge base is 6a28efaa277ca38291ba263aa2774859858161a0. Current main has changed 358 paths since then, with no overlap with the PR's 51 changed paths.
  • git merge-tree --write-tree upstream/main refs/review/upstream-10378: clean tree b041b021928f387c1cd070aad408e02e8c380828.
  • git diff --check upstream/main...refs/review/upstream-10378: pass.
  • python3 tools/check_conventions.py --base upstream/main: pass.

Results

Check Result
Current-main merge preview Clean
Diff check and conventions Pass
Linux Json2 tests I previously ran 203/203 on head 34632912cfb6d6861443eb73be13ad6538582575 under QEMU after bypassing only this host's unsupported-CPU guard; not rerun on this merge head
macOS Json2 tests Author reports 202/202 on exact current head da1fb929 in a production-source fixture
Windows Json2 tests Author reports 606/606 executions on 34632912cfb6d6861443eb73be13ad6538582575; the PR-touched files are unchanged at the current head
Hosted Windows job Passes, but product test execution is skipped by the path filter
Full project suite/title/GPU Not reported as run

Negative control

The author reports the callback-thread regression times out with the previous implementation and completes with the fix. No full negative-control run was reported for the current merged tree.

Findings

Blocking

None. The Windows-specific String::npos data export, callback ownership changes, and decimal-range behavior were covered by the reported platform tests. The current-head macOS suite exercises the merged integration; source and test files for this PR are unchanged from the extensive Windows run.

Non-blocking

  • No Windows runtime suite was rerun after the main merge. The Windows run is on the prior head, but the PR's 51 touched files are identical at the reviewed head; current main has no overlapping path changes.
  • The Linux runtime result required QEMU and a temporary host CPU guard bypass because this machine lacks the required CPU features. It is not a native supported-CPU run.
  • The 202-test macOS result is author-reported; I did not reproduce it in this environment.

Sources

Not verified

I did not rerun the Linux or Windows suites on the merged head, nor the macOS fixture. Platform results are attributed above to my earlier run or the authors' reports.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 30, 2026
…61030

# Conflicts:
#	core/libs/prx/libSceJson2/CMakeLists.txt
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 30, 2026
@github-actions

github-actions Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

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.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 14448 Read

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.

Pull request Shared files not compared
PR 14212 docs/dev/debt/libSceJson2.md

@oneandonlydean
oneandonlydean merged commit f1bbcff into boykopovar:main Nov 2, 2026
14 of 15 checks passed
oneandonlydean pushed a commit that referenced this pull request Nov 4, 2026
…ured on a PS5

The system libSceJson2.sprx of a retail PS5 (13.60) returns from
sce::Json::Array::pop_front on an empty array and the size stays 0
(orezraey on #10378); the host threw std::out_of_range.
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.