feat(libSceJson2): implement Value::setTypeMismatchHandler and store the element access failure and special float handlers #6126
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6126"
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 fdfawef324 on 2026-10-14T22:51:07Z.
What
sce::Json::Value::setTypeMismatchHandler,setElementAccessFailureHandlerandsetSpecialFloatHandlerwereNotImplementedstubs. PPSA07411 calls all three right aftersetNullAccessCallBack, so its boot stopped on the first one.This PR implements the type mismatch handler. The element access failure and special float handlers are stored but not called yet: their use sites throw, because what the console passes them is unknown (details below).
How the title calls them (its
eboot.elfwas read, not run):Value, not static functions. The title calls each one on the rootValueof its document wrapper withthisinrdi, the handler inrsiand the context inrdx. It calls them before it parses into thatValue.Valueargument.getValue,getStringon child values), it reads that error from the root's context. So handlers registered on the root before parsing have to reach the values the parse creates.The PS Vita
sce::Jsonlibrary also declares aValuehandler setter,setNullAccessCallback, as a member that returns int (vitasdk json.h L638).The change (
core/libs/prx/libSceJson2/Export.cpp):(Value* this, handler, context), store the handler and context on thatValueand on the values it holds, and return 0. A null handler clears it.Valuekeeps its handlers when its content changes (set,set(const Value&),clear,operator=,Parser::parse).Parser::parsegives the values it creates the handlers of theValueit parses into. A copy-constructedValue,push_backandObject::operator[]do not carry them.getBoolean,getInteger,getUInteger,getReal,getString,getArray,getObject) on a non-null value of another type calls the handler with(requested type, the value, null, context). It returns the handler's value if that value has the requested type, else the getter's default, as the null-access path does. A null-typed value still goes to the null-access callback, and a value without the handler behaves as before. The null secondValueand the order of the twoValuearguments are inferred, not known.operator[]orgetValueon a value carrying this handler throws instead of calling it with an invented code. The title registers this handler on its root before parsing, so every failed lookup in its parsed documents now throws; if it looks up optional keys, its boot stops there with that error. Without the handler, the access still reaches the null-access callback.FunctionTypevalues and the meaning of thebool*output are unknown, and the title's handler returns a different replacement for each of its two types, so picking a numbering would silently change the output. Serializing a non-finite real already threw without the handler. With it, the only change is the exception message, which names the unknownFunctionType; the setter has no other observable effect.docs/dev/debt/libSceJson2.mdrecords what is inferred and what is unknown: how the console finds an accessed value's handler, the secondValueargument and the argument order, the error code and theFunctionTypevalues. The three members are removed from the PPSA07411 list of declarations with unknown signatures indocs/dev/debt/libSceSsl.md, which now names onlyoperator bool.operator boolis a separate topic and is untouched.Not in this PR:
Value::setNullAccessCallBack. The title calls it the same way as the three handlers (a member,thisfirst), but onmainit is a static(callback, context)function, so it stores the title'sValuepointer as the global null-access callback and the handler as its context. Onmainthe title stops with a cleanNotImplementedatsetTypeMismatchHandler. With this PR it gets past that stop, and its next null access (a typed getter on a JSONnull, or a failed lookup or type mismatch on a value that does not carry the handlers) calls into data and faults instead of throwing. That needs its own fix (setNullAccessCallBackas a member that stores the callback perValue), so this PR alone does not unblock the title.Tested
Documentation-only follow-up
edf6717cd: two debt lines changed on top of maintainer-rebased head7e4b1b7c3. The two touched entries no longer name the title, and the null third callback argument (the secondValuepointer) and pointer order are explicitly unverified against the console. Implementation and tests are byte-for-byte unchanged from the maintainer head. Conventions passed; no new runtime or title test was needed for these two prose edits. The runtime results below are historical evidence on their stated original base.Windows Server 2025 (10.0.26100), WinLibs MinGW-w64 GCC 15.2.0, Ninja, Release,
BUILD_TESTING=ON, onmaineea428ca8. No title run.core/libs/tests/GuestJson.cpp(guest_json) gains three cases:ValueTypeMismatchHandler: with the handler set on the root before parsing,getIntegeron a parsed string member returns the handler's integer, and the handler receives(TypeInteger, &member, null, &context).getBooleangets the getter's default when the handler returns another type. A matching getter does not call it. Mismatches on the root and on a nested array element call it with that value. A null member goes to the null-access path. A document parsed without the handler gets it when it is set afterwards. Afterroot = other,root.set(const Value&), andValue::clearfollowed byset(const char*), a mismatch on the root still calls the handler; the assigned-fromValuedoes not get it, and a copy-constructedValuedoes not carry it. Clearing the handler restores the default.ValueElementAccessFailureHandler: successful accesses work. A missing key throughoperator[]andgetValue(String), an index into an object and an out-of-rangegetValue(size_t)on a child all throw "unverified", and the handler is not called. After clearing, they return null values.ValueSpecialFloatHandler: serializing NaN and infinity with the handler set throws "unverified" without calling it. The handler survivesset(double), and a finite value serializes as2.5.Results:
main'sExport.cpp:guest_jsonaborts (0xc0000409) with..._ZN3sce4Json5Value22setTypeMismatchHandler... not implemented. With each of the other two cases moved first, it aborts withsetElementAccessFailureHandler ... not implementedandsetSpecialFloatHandler ... not implemented.copy.handlers = destination.handlers;fromAssignNode(handlers lost onoperator=andset(const Value&)) fails at the newoperator=assertion. Removing the handler restore fromClearfails as well.ctest -R guest_json --repeat until-fail:3passes (0.09 to 0.24 s per run). guest_json is the library's only test.tools/check_conventions.pyfrommain,--base upstream/main --head HEADwith this title and body: passed.git merge-tree: this branch merges cleanly with #5439, which also changes the Json2Export.cppandGuestJson.cpp. It conflicts with #5911 and #6039 only on the PPSA07411 line ofdocs/dev/debt/libSceSsl.md, which all three rewrite. Whichever merges later resolves that one line.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)setTypeMismatchHandler; its next stop issetNullAccessCallBack(see What). No Game bring-up discussion yet🤖 Generated with Claude Code
Co-Authored-By: Codex [email protected]
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T22:51:46Z.
Progress report (
fc62332→edf6717)📈 System libraries: 90.86% (+0.07%, +3 implemented functions)
✅ 3 implemented
_ZN3sce4Json5Value22setSpecialFloatHandlerEPFKS1_NS0_12FunctionTypeEdPS2_PvPbES5__ZN3sce4Json5Value22setTypeMismatchHandlerEPFRKS1_NS0_9ValueTypeEPS2_S5_PvES6__ZN3sce4Json5Value30setElementAccessFailureHandlerEPFviPKNS0_6StringEPKmPKS1_S8_PvES9_Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T23:16:24Z.
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)core/libs/tests/GuestJson.cppL769-770core/libs/prx/libSceJson2/Export.cppL96-98, L137-144, L195-196, L229-231, L403-404, L430-431core/libs/tests/GuestJson.cppL769docs/dev/debt/libSceJson2.mdL8-9, L13-14core/libs/prx/libSceJson2/Export.cppL904-906, L909-911, L914-916core/libs/tests/GuestJson.cppL23, L32, L769, L781docs/dev/debt/libSceJson2.mdL13_ZN3sce4Json5Value22setSpecialFloatHandlerEPFKS1_NS0_12FunctionTypeEdPS2_PvPbES5__ZN3sce4Json5Value22setTypeMismatchHandlerEPFRKS1_NS0_9ValueTypeEPS2_S5_PvES6__ZN3sce4Json5Value30setElementAccessFailureHandlerEPFviPKNS0_6StringEPKmPKS1_S8_PvES9_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.
docs/dev/debt/libSceJson2.mdcore/libs/tests/GuestJson.cppdocs/dev/debt/libSceJson2.mdImported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-15T00:41:05Z.
Resident Evil 4 (PPSA07411) on plain
main0ae1deb85(Windows Server 2025, RTX 3060, driver 591.86; app.exe relinked 2026-10-13, imports identical to a relink withmain's relinker) stops 9.9 s into boot on:So this PR addresses the title's current first stop on
main. A run with this PR'slibSceJson2follows, to show where it stops next.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by coltken95 on 2026-10-15T00:42:22Z.
Tested on Linux x86-64 (Release build), with 5dd4c4e7e merged into main
ab9a47684:guest_jsonpasses.libSceJson2/Export.cpp:guest_jsonaborts withwhat(): _ZN3sce4Json5Value22setTypeMismatchHandlerEPFRKS1_NS0_9ValueTypeEPS2_S5_PvES6_ not implemented.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-15T01:05:05Z.
Follow-up run with this PR's
libSceJson2(head5dd4c4e7e, onmaineea428ca8; same machine and app.exe as above):setTypeMismatchHandlerstop and runs for 739 s: 25,570 frames, title barFPS: 42.73at the end.The run never reached the per-
Valuenull-access path that the PR body mentions as a follow-up, so I'm not opening that change until a run shows it.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T23:42:05Z.
Rebased onto current
main(only conflict: the PPSA07411 debt line, which moved todocs/dev/debt/libSceJson2.md; it now lists justValue::operator boolthere). Rebuilt and ran the Json2 scope: 35 tests pass. Code unchanged since the earlier check (guest_jsonfails without the change; stored-only handlers throw instead of inventing the error code /FunctionType); merging once the full Build is green.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-18T17:52:25Z.
The handler plumbing reads right, and keeping the two unverified handlers throwing is good. Two small doc points: the debt entries name the title (PPSA07411); could they drop it, as it's in the PR body already? And could the type-mismatch entry note that the third argument is passed as null, which isn't verified against the console?
Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-18T23:04:12Z.
Removed PPSA07411 from both debt entries touched by this PR. The type-mismatch entry now explicitly says that passing null as the third handler argument (the second
Valuepointer), and the order of the twoValuepointers, remain unverified against the console.This follow-up changes documentation only; the implementation and tests are unchanged. Conventions passed.
AI-assisted: yes