fix(json2): preserve values when type allocation fails #7977

Merged
Ondra97 merged 1 commit from upstream-pr/7977 into main 2026-10-20 04:55:20 +00:00
Ondra97 commented 2026-10-19 16:41:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Ondra97 on 2026-10-19T16:41:46Z.


What

Value::set(ValueType) clears the existing value and publishes the requested type before allocating its empty String, Array or Object storage. If allocation throws, the destination loses its previous contents and retains a type with null storage.

Construct the replacement storage before clearing the destination, then transfer it while preserving the per-value handlers. Extend the existing JsonCopyFailure fixture with the three type setter paths, checking that failures preserve the old type and serialized value and release all tracked allocations.

The author of #7477 confirmed that either merge order works. I verified that its current head 2a1ca278eefad1e84aff2801e44442fdb406d12d leaves SetType and JsonCopyFailure.cpp identical to main and combines cleanly with this patch.

The overlap tool reports #7215 as a shared file it cannot compare because that branch conflicts with main. I compared its diff manually: it changes numeric conversion in RealText and Parser::number, plus includes, and does not change SetType or the allocation failure fixture. There is no dependency on either PR.

Tested

Tested revision: 51e75dec2591d1b884c541f48cdfdd2431bdf0eb, based on d047690c6391577c9add655ae1dc2ed20df177a8. Full native Windows configuration: Windows 11 Pro 10.0.26300, WinLibs MinGW-w64 GCC 15.2.0, Release/O3, BUILD_TESTING=ON.

Hardware: Ryzen 9 7900X, 32 GB RAM, GeForce RTX 4070 Ti SUPER.

  • Full Windows build passed after rebasing.
  • guest_json, guest_json_copy_failure and patched_libraries: 3/3 passed, no skips.
  • The allocation failure fixture completed 20 operations and 312 injected failures with no tracked leaks; 352 patched libraries loaded, 0 failed.
  • The same regression source failed on the original production code at set empty array budget=0: failed setter changed the destination type (base bcdee66d109008334b07c0ff73a27e845708675f). The JSON implementation and original fixture are byte-identical in that base and the rebased base.
  • python3 tools/check_conventions.py --base origin/main passed.
  • python3 tools/pr_overlap.py --branch codex/fix-json2-type-allocation completed; its remaining #7215 warning was reviewed as described above.

Linux, PRAGMATA gameplay and the complete CTest suite were not run.

Reproduction commands, using build as the build directory and the documented toolchain on PATH:

cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++
cmake --build build --parallel 2
ctest --test-dir build -R '^(guest_json|guest_json_copy_failure|patched_libraries)$' -V --output-on-failure --no-tests=error
python3 tools/check_conventions.py --base origin/main

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:4924234959 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7977). Originally posted by [Ondra97](https://github.com/Ondra97) on 2026-10-19T16:41:46Z. --- ### What `Value::set(ValueType)` clears the existing value and publishes the requested type before allocating its empty String, Array or Object storage. If allocation throws, the destination loses its previous contents and retains a type with null storage. Construct the replacement storage before clearing the destination, then transfer it while preserving the per-value handlers. Extend the existing `JsonCopyFailure` fixture with the three type setter paths, checking that failures preserve the old type and serialized value and release all tracked allocations. The author of #7477 [confirmed that either merge order works](https://github.com/boykopovar/AnyPS5/pull/7477#issuecomment-6271599228). I verified that its current head `2a1ca278eefad1e84aff2801e44442fdb406d12d` leaves `SetType` and `JsonCopyFailure.cpp` identical to main and combines cleanly with this patch. The overlap tool reports #7215 as a shared file it cannot compare because that branch conflicts with main. I compared its diff manually: it changes numeric conversion in `RealText` and `Parser::number`, plus includes, and does not change `SetType` or the allocation failure fixture. There is no dependency on either PR. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Tested revision: `51e75dec2591d1b884c541f48cdfdd2431bdf0eb`, based on `d047690c6391577c9add655ae1dc2ed20df177a8`. Full native Windows configuration: Windows 11 Pro 10.0.26300, WinLibs MinGW-w64 GCC 15.2.0, Release/O3, `BUILD_TESTING=ON`. Hardware: Ryzen 9 7900X, 32 GB RAM, GeForce RTX 4070 Ti SUPER. - Full Windows build passed after rebasing. - `guest_json`, `guest_json_copy_failure` and `patched_libraries`: 3/3 passed, no skips. - The allocation failure fixture completed 20 operations and 312 injected failures with no tracked leaks; 352 patched libraries loaded, 0 failed. - The same regression source failed on the original production code at `set empty array budget=0: failed setter changed the destination type` (base `bcdee66d109008334b07c0ff73a27e845708675f`). The JSON implementation and original fixture are byte-identical in that base and the rebased base. - `python3 tools/check_conventions.py --base origin/main` passed. - `python3 tools/pr_overlap.py --branch codex/fix-json2-type-allocation` completed; its remaining #7215 warning was reviewed as described above. Linux, PRAGMATA gameplay and the complete CTest suite were not run. Reproduction commands, using `build` as the build directory and the documented toolchain on PATH: ```sh cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ cmake --build build --parallel 2 ctest --test-dir build -R '^(guest_json|guest_json_copy_failure|patched_libraries)$' -V --output-on-failure --no-tests=error python3 tools/check_conventions.py --base origin/main ``` ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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 <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->
MarcZX10 commented 2026-10-19 16:42:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T16:42:51Z.

Review: COMMENTED


I reviewed the exception-safety path at the current head. SetType now validates before mutation, constructs the replacement payload before clearing the old node, and transfers the existing handlers after Clear preserves them. The new allocation-failure cases check both the previous type and serialized value for string, array, and object setters, which covers the destructive failure mode. I did not independently run the reported Windows build/tests; the PR description identifies the tested revision and notes Linux/gameplay were not run.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5574743221 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7977#pullrequestreview-5574743221). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-19T16:42:51Z. **Review:** COMMENTED --- I reviewed the exception-safety path at the current head. `SetType` now validates before mutation, constructs the replacement payload before clearing the old node, and transfers the existing handlers after `Clear` preserves them. The new allocation-failure cases check both the previous type and serialized value for string, array, and object setters, which covers the destructive failure mode. I did not independently run the reported Windows build/tests; the PR description identifies the tested revision and notes Linux/gameplay were not run.
github-actions[bot] commented 2026-10-19 23:08:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-19T23:08:02Z.


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 7215 core/libs/prx/libSceJson2/Export.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6279332718 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7977#issuecomment-6279332718). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-19T23:08:02Z. --- <!-- pr-overlap --> 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 7215](https://www.github.com/boykopovar/AnyPS5/pull/7215) | `core/libs/prx/libSceJson2/Export.cpp` |
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!7977
No description provided.