feat(libs): implement NpCppWebApi Common::String constructor, destructor and c_str #630

Merged
DotDebian merged 1 commit from upstream-pr/630 into main 2026-10-05 13:33:33 +00:00
DotDebian commented 2026-10-05 09:13:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DotDebian on 2026-10-05T09:13:37Z.


What

sce::Np::CppWebApi::Common::String in libSceNpCppWebApi. On main the constructor is a silent stub that leaves the guest object uninitialised, and c_str() throws.

  • String(LibContext*) initialises the object: reference count 0, null buffer, buffer size 0, the context pointer.
  • c_str() returns the buffer, or an empty string when the buffer is null. It never returns null.
  • ~String() writes nothing for a null buffer. A non-null buffer has to be released through the LibContext allocator, which this library does not implement, so that path throws instead of dropping the buffer silently. No export of this library can fill a String today, so only strings left empty reach the destructor.

Source of the layout: disassembly of the retail libSceNpCppWebApi.prx bundled with one title (Astro Bot, PPSA21564 01.007.000). Functions were located by hashing their mangled names to NIDs. No other build of the module was checked; this is recorded in TechnicalDebt.

Observed in that module:

  • sizeof(String) is 0x20: a 32-bit field at 0x00 written by the RefObject base constructor, char* at 0x08, a 64-bit field at 0x10, LibContext* at 0x18. No vtable.
  • Constructor: 32-bit 0 at 0x00, zero at 0x08 and 0x10, context stored at 0x18.
  • c_str(): the pointer at 0x08 when non-null, otherwise the address of a static empty string.
  • Destructor: when the pointer at 0x08 is non-null, frees it through the context and zeroes 0x08 and 0x10; otherwise writes nothing.

Inferred, and not relied on here: the field at 0x00 is an intrusive reference count, and 0x10 holds the allocated byte count including the terminator (from String::append, which this library does not export).

Not included: Binary, Vector, the iterators and IntrusivePtr. The library gets a CMakeLists.txt only to register the test.

Tested

  • Windows 11, MinGW-w64 GCC 15.2.0, Release, -DBUILD_TESTING=ON: full build, ctest 280/282.
  • New test guest_np_cpp_web_api_string: constructor on pre-filled storage (field values, nothing written past 0x20), c_str() on an empty string and on a string with a buffer, destructor on an empty string (storage unchanged) and on a string with a buffer (throws). It fails on main and passes with this change.
  • The two failures are agc_driver_f32_output_modifier and agc_driver_scalar_sop1, shader tests that run on the GPU (RTX 5080) and do not depend on any file changed here. The first also fails on unmodified main on this machine; the second was not re-run on a clean main.
  • No title was run. Linux: not tested.

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 in TechnicalDebt
  • 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
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4742685717 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/630). Originally posted by [DotDebian](https://github.com/DotDebian) on 2026-10-05T09:13:37Z. --- ### What `sce::Np::CppWebApi::Common::String` in libSceNpCppWebApi. On `main` the constructor is a silent stub that leaves the guest object uninitialised, and `c_str()` throws. - `String(LibContext*)` initialises the object: reference count 0, null buffer, buffer size 0, the context pointer. - `c_str()` returns the buffer, or an empty string when the buffer is null. It never returns null. - `~String()` writes nothing for a null buffer. A non-null buffer has to be released through the `LibContext` allocator, which this library does not implement, so that path throws instead of dropping the buffer silently. No export of this library can fill a `String` today, so only strings left empty reach the destructor. Source of the layout: disassembly of the retail `libSceNpCppWebApi.prx` bundled with one title (Astro Bot, PPSA21564 01.007.000). Functions were located by hashing their mangled names to NIDs. No other build of the module was checked; this is recorded in TechnicalDebt. Observed in that module: - `sizeof(String)` is 0x20: a 32-bit field at 0x00 written by the `RefObject` base constructor, `char*` at 0x08, a 64-bit field at 0x10, `LibContext*` at 0x18. No vtable. - Constructor: 32-bit 0 at 0x00, zero at 0x08 and 0x10, context stored at 0x18. - `c_str()`: the pointer at 0x08 when non-null, otherwise the address of a static empty string. - Destructor: when the pointer at 0x08 is non-null, frees it through the context and zeroes 0x08 and 0x10; otherwise writes nothing. Inferred, and not relied on here: the field at 0x00 is an intrusive reference count, and 0x10 holds the allocated byte count including the terminator (from `String::append`, which this library does not export). Not included: `Binary`, `Vector`, the iterators and `IntrusivePtr`. The library gets a `CMakeLists.txt` only to register the test. ### Tested - Windows 11, MinGW-w64 GCC 15.2.0, Release, `-DBUILD_TESTING=ON`: full build, `ctest` 280/282. - New test `guest_np_cpp_web_api_string`: constructor on pre-filled storage (field values, nothing written past 0x20), `c_str()` on an empty string and on a string with a buffer, destructor on an empty string (storage unchanged) and on a string with a buffer (throws). It fails on `main` and passes with this change. - The two failures are `agc_driver_f32_output_modifier` and `agc_driver_scalar_sop1`, shader tests that run on the GPU (RTX 5080) and do not depend on any file changed here. The first also fails on unmodified `main` on this machine; the second was not re-run on a clean `main`. - No title was run. Linux: not tested. ### Checklist - [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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-05 09:14:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-05T09:14:01Z.


Progress report (8c906ca → 6a20036)

➖ System libraries: 79.14% (+0.0%, +1 implemented, -1 reverted functions)

✅ 1 implemented
Library Name
libSceNpCppWebApi _ZNK3sce2Np9CppWebApi6Common6String5c_strEv
⚠️ 1 went back to stubs
Library Name
libSceNpCppWebApi _ZN3sce2Np9CppWebApi6Common6StringD1Ev
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5991529808 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/630#issuecomment-5991529808). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-05T09:14:01Z. --- <!-- progress-report --> ### Progress report (8c906ca → 6a20036) ➖ **System libraries**: 79.14% (+0.0%, +1 implemented, -1 reverted functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libSceNpCppWebApi | `_ZNK3sce2Np9CppWebApi6Common6String5c_strEv` | </details> <details> <summary>⚠️ 1 went back to stubs</summary> | Library | Name | | - | - | | libSceNpCppWebApi | `_ZN3sce2Np9CppWebApi6Common6StringD1Ev` | </details>
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!630
No description provided.