Repository navigation
feat(libSceJson2): implement Value, Object, Array, and String methods - #7477
Conversation
|
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.
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.
|
6915b0c to
cbf325a
Compare
jotitadev
left a comment
There was a problem hiding this comment.
Linux/GCC run of the current head, since the description lists only macOS with AppleClang and the last two commits add the iterator/erase methods and rework the parser and serialiser.
Machine: Linux x86_64, i7-8700, Ubuntu 26.04, GCC 15.2 (libstdc++), Release, BUILD_TESTING=ON, full build.
Head 266fcdb79 merged onto main 6efb7261b (clean merge).
- Builds without errors.
guest_json,param_json_parserandparam_json_utf8pass. GuestJson.cpponly, onmain: does not link (undefined reference to sce::Json::Object::iterator::iterator()and the other new methods), as expected for exportsmaindoes not have yet.- Non-GPU suite (
ctest -E "^agc|gpu|vulkan|video_out"): 714/714.
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
|
Thanks @jotitadev for running the full build and test suite on Linux/GCC 15.2! I've updated the PR description with the Linux test results. |
|
Resolved conflicts with latest |
adriadam10
left a comment
There was a problem hiding this comment.
Thanks for the work. A few things before this can go in:
- Conflicts with
mainincore/libs/prx/libSceJson2/Export.cpp(AssignNode) anddocs/dev/debt/libSceJson2.md. #6593 wrapped the string/array/object copies intry { ... } catch (...) { Clear(copy); throw; }; theswitchrewrite drops that cleanup. Please rebase and keep the cleanup. - One topic per PR: the parser/serialiser changes (
AppendEscapedrun-scanning,snprintfinSerialize, stack buffer for numbers,reserve(256), theliteraltemplate) are performance work unrelated to the new members. Perf changes need before/after numbers from the same machine and scene; please move them to a separate PR with measurements or drop them. Value::operator bool,Object::insert(updating an existing key) anderase's return type have no cited source. Please say where each behaviour comes from (KytyPS5, shadPS4, SharpProspero, or the title's disassembly). If none exists, keep them as unverified in the debt file and don't pin the guesses in tests as facts (intZero, empty string,[]evaluating to true).
|
I have a focused fix for This touches the same The patch below was tested on main AI-assisted: yes. Proposed focused patchdiff --git a/core/libs/prx/libSceJson2/Export.cpp b/core/libs/prx/libSceJson2/Export.cpp
index 745771a3b4ba1fc0ae1f60b5a4d8d7369b84c527..286b7d8fd0d3d4f964b5e4bd4d88cd30d5055c9b 100644
--- a/core/libs/prx/libSceJson2/Export.cpp
+++ b/core/libs/prx/libSceJson2/Export.cpp
@@ -196,12 +196,15 @@ void CopyInto(Value& destination, const Value& source) {
}
void SetType(Node& n, ValueType type) {
- Clear(n);
- n.type = type;
- if (type == TypeString) Construct(n.string, std::string());
- if (type == TypeArray) Construct(n.array);
- if (type == TypeObject) Construct(n.object);
if (type < TypeNull || type > TypeObject) throw std::invalid_argument("sce::Json::Value::set: invalid value type");
+ Node pending{};
+ pending.type = type;
+ if (type == TypeString) Construct(pending.string, std::string());
+ if (type == TypeArray) Construct(pending.array);
+ if (type == TypeObject) Construct(pending.object);
+ Clear(n);
+ pending.handlers = n.handlers;
+ n = pending;
}
const Value& Defaults(ValueType type) {
diff --git a/core/libs/tests/JsonCopyFailure.cpp b/core/libs/tests/JsonCopyFailure.cpp
index a3c64622f277a4085e88564e30ba65ad0cdd395f..0fa28bad9874008f747f1cf6a44c58e036d7f3e6 100644
--- a/core/libs/tests/JsonCopyFailure.cpp
+++ b/core/libs/tests/JsonCopyFailure.cpp
@@ -24,6 +24,8 @@ void APS5_VABI _ZN3sce4Json5ValueD1Ev(Value*);
Value* APS5_VABI _ZN3sce4Json5ValueaSERKS1_(Value*, const Value*);
int APS5_VABI _ZN3sce4Json5Value3setERKNS0_5ArrayE(Value*, const Array*);
int APS5_VABI _ZN3sce4Json5Value3setERKNS0_6ObjectE(Value*, const Object*);
+int APS5_VABI _ZN3sce4Json5Value3setENS0_9ValueTypeE(Value*, std::int32_t);
+std::int32_t APS5_VABI _ZNK3sce4Json5Value7getTypeEv(const Value*);
const Array* APS5_VABI _ZNK3sce4Json5Value8getArrayEv(const Value*);
const Object* APS5_VABI _ZNK3sce4Json5Value9getObjectEv(const Value*);
int APS5_VABI _ZN3sce4Json5Value9serializeERNS0_6StringE(Value*, String*);
@@ -92,7 +94,7 @@ static void CheckValue(const Value& value, const char* expected) {
enum class Operation {
ValueCopy, ArrayCopy, ObjectCopy, ValueAssign, ObjectAssign, ArrayAppend,
ValueArray, ValueObject, ValueString, ValueText, ValueTypeString, ValueTypeArray,
- ValueTypeObject, SetArray, SetObject, PairCopy
+ ValueTypeObject, SetArray, SetObject, SetTypeArray, SetTypeObject, SetTypeString, PairCopy
};
static bool Run(Operation operation, const Value& source, const char* expected, const Array& array, const Object& object, const String& text) {
@@ -101,7 +103,8 @@ static bool Run(Operation operation, const Value& source, const char* expected,
Object objectResult{};
Pair pair{};
bool valueReady = false, arrayReady = false, objectReady = false, pairReady = false;
- if (operation == Operation::ValueAssign || operation == Operation::SetArray || operation == Operation::SetObject) {
+ const bool typeSetter = operation == Operation::SetTypeArray || operation == Operation::SetTypeObject || operation == Operation::SetTypeString;
+ if (operation == Operation::ValueAssign || operation == Operation::SetArray || operation == Operation::SetObject || typeSetter) {
_ZN3sce4Json5ValueC1EPKc(&result, "previous");
valueReady = true;
}
@@ -126,6 +129,9 @@ static bool Run(Operation operation, const Value& source, const char* expected,
case Operation::ValueTypeObject: _ZN3sce4Json5ValueC1ENS0_9ValueTypeE(&result, 7); valueReady = true; break;
case Operation::SetArray: _ZN3sce4Json5Value3setERKNS0_5ArrayE(&result, &array); break;
case Operation::SetObject: _ZN3sce4Json5Value3setERKNS0_6ObjectE(&result, &object); break;
+ case Operation::SetTypeArray: _ZN3sce4Json5Value3setENS0_9ValueTypeE(&result, 6); break;
+ case Operation::SetTypeObject: _ZN3sce4Json5Value3setENS0_9ValueTypeE(&result, 7); break;
+ case Operation::SetTypeString: _ZN3sce4Json5Value3setENS0_9ValueTypeE(&result, 5); break;
case Operation::PairCopy: _ZN3sce4Json6Object4PairC1ERKNS0_6StringERKNS0_5ValueE(&pair, &text, &source); pairReady = true; break;
}
succeeded = true;
@@ -134,7 +140,10 @@ static bool Run(Operation operation, const Value& source, const char* expected,
allocationBudget = -1;
if (valueReady) {
if (succeeded) CheckValue(result, expected);
- else CheckValue(result, "\"previous\"");
+ else {
+ Require(_ZNK3sce4Json5Value7getTypeEv(&result) == 5, "failed setter changed the destination type");
+ CheckValue(result, "\"previous\"");
+ }
_ZN3sce4Json5ValueD1Ev(&result);
}
if (arrayReady) {
@@ -183,6 +192,9 @@ int main() {
{"empty object value", Operation::ValueTypeObject, &objectValue, "{}"},
{"set array", Operation::SetArray, &arrayValue, arrayJson},
{"set object", Operation::SetObject, &objectValue, objectJson},
+ {"set empty array", Operation::SetTypeArray, &objectValue, "[]"},
+ {"set empty object", Operation::SetTypeObject, &objectValue, "{}"},
+ {"set empty string", Operation::SetTypeString, &objectValue, "\"\""},
{"pair copy", Operation::PairCopy, &objectValue, objectJson},
};
unsigned failures = 0; |
becd087 to
97a0cec
Compare
|
Thanks for the review @adriadam10! I have addressed all points:
All unit tests ( |
97a0cec to
2a1ca27
Compare
|
Thanks for checking and preparing the fix, @Ondra97! In our latest rebase addressing @adriadam10's review, we dropped our earlier changes to Because #7477 no longer touches |
|
Local cross-check report for CI checks and test suite on the latest head ( Machine: macOS arm64, AppleClang 21.0.0, Release Required Checks (4/4 Passed):
Skipped CI Jobs Cross-Verification (6/6 Verified as Expected):
Unit Tests:
Written with AI assistance. I ran the builds and tests above on my machine. |
Progress report (32004df → 2a1ca27)📈 System libraries: 79.88% (+0.11%, +21 implemented functions) ✅ 21 implemented
|
|
Local cross-check report for the 4 required CI checks and PR status on the latest head ( Machine: Windows 11 Home 64-bit, AMD Ryzen 9 7900X (12 cores / 24 threads), NVIDIA GeForce RTX 4070 SUPER, 32 GB RAM Required Checks (4/4 Passed):
Skipped CI Jobs Cross-Verification (6/6 Verified as Expected):
Review & Verification Summary:
Written with AI assistance. |
|
Checked the new head against the previous review:
Merged. |
What
Implements missing
libSceJson2functions:sce::Json::Value::operator bool() const(_ZNK3sce4Json5ValuecvbEv): returnsfalseforTypeNulland booleanfalse, andtruefor booleantrueand other initialized value types.sce::Json::Object::insert(const Pair&)(_ZN3sce4Json6Object6insertERKNS1_4PairE): updates existing keys or appends a deep copy, returning an iterator via hidden result pointer.sce::Json::Object::iteratorandObject::Pairmethods:operator==(const iterator&) const(_ZNK3sce4Json6Object8iteratoreqERKS2_)operator++(int)(_ZN3sce4Json6Object8iteratorppEi) via result pointeroperator=(const iterator&)(_ZN3sce4Json6Object8iteratoraSERKS2_)iterator()(_ZN3sce4Json6Object8iteratorC1Ev)iterator(const iterator&)(_ZN3sce4Json6Object8iteratorC1ERKS2_)advance(size_t)(_ZN3sce4Json6Object8iterator7advanceEm)Pair()(_ZN3sce4Json6Object4PairC1Ev)sce::Json::Object::erase(const String&)(_ZN3sce4Json6Object5eraseERKNS0_6StringE): removes matching entry, destroying key and value.sce::Json::Array::iteratorcopy constructor (_ZN3sce4Json5Array8iteratorC1ERKS2_) andadvance(size_t)(_ZN3sce4Json5Array8iterator7advanceEm).sce::Json::Value::swap(Value&)(_ZN3sce4Json5Value4swapERS1_): swaps node pointers without reallocations.sce::Json::Stringmethods:size() const(_ZNK3sce4Json6String4sizeEv)capacity() const(_ZNK3sce4Json6String8capacityEv)operator==(const String&) const(_ZNK3sce4Json6StringeqERKS1_)compare(const String&) const(_ZNK3sce4Json6String7compareERKS1_)resize(size_t)(_ZN3sce4Json6String6resizeEm)append(const char*, size_t)(_ZN3sce4Json6String6appendEPKcm)operator+=(const char*)(_ZN3sce4Json6StringpLEPKc)operator+=(unsigned char)(_ZN3sce4Json6StringpLEh)docs/dev/debt/libSceJson2.mdto document the new members and unverified behaviors.Tested
core/libs/tests/GuestJson.cppunit tests:ValueOperatorBool()ObjectInsert()ObjectPair()ArrayIteratorCopies()ObjectIteratorCopies()StringMethods()ValueSwap()ArrayIteratorAdvance()ObjectOperations()StreamParse()core/libs/tests/JsonCopyFailure.cppunit tests:python3 tools/check_conventions.py --base upstream/main: passed with 0 errors.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)