fix(libSceNpCppWebApi): match Common::String layout and copy semantics #12801

Merged
edubox merged 2 commits from upstream-pr/12801 into main 2026-11-02 16:12:59 +00:00
edubox commented 2026-10-29 09:55:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by edubox on 2026-10-29T09:55:55Z.


What

Common::String now follows the module bundled with PPSA21564/PPSA23732 (builds J03093737/J03341606) instead of treating +0x10 as a growing capacity:

  • +0x10 is the used size including the terminator, as the module's append and copyFrom compute it.
  • append(char const*) reallocates exactly oldLength + textLength + 1, keeps the previous buffer when allocation fails and returns 0x80553503 for a null string and 0x80553504 when out of memory.
  • Implemented copyFrom(char const*), copyFrom(String const&), clear, size, length, operator==(String const&), setContext, the default constructor and the intrusive reference operations.
  • copyFrom(String const&) adopts the source LibContext when the destination has none, and keeps it for the empty-source path, as the module does.
  • copyFrom(char const*) was imported by 13 dumps and was not exported before.

Evidence, from sce_module/libSceNpCppWebApi.prx in the dumps (same bytes in both builds):

Export Module address Behaviour
String::append(char const*) 0x121b0 [+0x10] - 1 old length; exact reallocation; 0x80553503/0x80553504
String::copyFrom(char const*) 0x11ee0 exact strlen + 1; same error codes
String::copyFrom(String const&) 0x11e60 empty source clears; adopts source context when destination has none
String::clear / size / length 0x11e20 / 0x11ff0 / 0x12000 frees and zeroes; strlen
String::operator==(String const&) 0x12100 strncmp bounded by the left length
String::intrusive_ptr_add_ref / sub_ref 0x11df0 / 0x11e00 returns the new / previous count

Tested

Linux x86-64, GCC 16.2.1, ctest --test-dir build -R '^guest_np_cpp_web_api': 7/7 passed, including guest_np_cpp_web_api_alias_append, guest_np_cpp_web_api_alias_string_vector and guest_np_cpp_web_api_alias_intrusive_vector. tools/check_conventions.py --base origin/main passes. No console or title runtime test.

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: #10925
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5065907375 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12801). Originally posted by [edubox](https://github.com/edubox) on 2026-10-29T09:55:55Z. --- ### What `Common::String` now follows the module bundled with PPSA21564/PPSA23732 (builds `J03093737`/`J03341606`) instead of treating `+0x10` as a growing capacity: - `+0x10` is the used size including the terminator, as the module's `append` and `copyFrom` compute it. - `append(char const*)` reallocates exactly `oldLength + textLength + 1`, keeps the previous buffer when allocation fails and returns `0x80553503` for a null string and `0x80553504` when out of memory. - Implemented `copyFrom(char const*)`, `copyFrom(String const&)`, `clear`, `size`, `length`, `operator==(String const&)`, `setContext`, the default constructor and the intrusive reference operations. - `copyFrom(String const&)` adopts the source `LibContext` when the destination has none, and keeps it for the empty-source path, as the module does. - `copyFrom(char const*)` was imported by 13 dumps and was not exported before. Evidence, from `sce_module/libSceNpCppWebApi.prx` in the dumps (same bytes in both builds): | Export | Module address | Behaviour | |---|---|---| | `String::append(char const*)` | `0x121b0` | `[+0x10] - 1` old length; exact reallocation; `0x80553503`/`0x80553504` | | `String::copyFrom(char const*)` | `0x11ee0` | exact `strlen + 1`; same error codes | | `String::copyFrom(String const&)` | `0x11e60` | empty source clears; adopts source context when destination has none | | `String::clear` / `size` / `length` | `0x11e20` / `0x11ff0` / `0x12000` | frees and zeroes; `strlen` | | `String::operator==(String const&)` | `0x12100` | `strncmp` bounded by the left length | | `String::intrusive_ptr_add_ref` / `sub_ref` | `0x11df0` / `0x11e00` | returns the new / previous count | ### Tested Linux x86-64, GCC 16.2.1, `ctest --test-dir build -R '^guest_np_cpp_web_api'`: **7/7 passed**, including `guest_np_cpp_web_api_alias_append`, `guest_np_cpp_web_api_alias_string_vector` and `guest_np_cpp_web_api_alias_intrusive_vector`. `tools/check_conventions.py --base origin/main` passes. No console or title runtime test. ### 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 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: #10925 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
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!12801
No description provided.