feat(libSceFreeType): implement FT_Done_Library and FT_Reference_Library #10606

Closed
MarcZX10 wants to merge 0 commits from upstream-pr/10606 into main
MarcZX10 commented 2026-10-24 12:24:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T12:24:18Z.


What

Adds FT_Done_Library and FT_Reference_Library to libSceFreeType, following the bundled FreeType 2.13.3 (ftobjs.c). The guest library wrapper now carries a reference count that mirrors the native one: FT_Reference_Library raises both, and FT_Done_Library lowers both and releases the wrapper together with the native library on the last reference. FT_Done_FreeType is unchanged: as natively, it drops one reference through FT_Done_Library and then discards the memory manager whatever the count (ftinit.c), so a library that still has references is not usable afterwards and the guest wrapper is released at once. Like the native call, FT_Done_Library does not free the memory manager that FT_Init_FreeType created. FT_New_Library is not included because it takes guest memory callbacks. Console signatures and errors are unverified; the debt entries say so.

Commits: for each function in turn (FT_Done_Library, then FT_Reference_Library), the implementation, its test and its debt entry.

Tested

Linux x86-64, GCC, full CMake build (Ninja, Release). guest_freetype_library_references compares each call with the native one: dropping the only reference with open faces, a null library, and three extra references released one at a time with a face opened and closed between each step on both libraries. It also runs the existing guest_freetype suite, which still passes. While building the test I found that native FT_Done_FreeType frees the memory manager even when references remain, so the test pairs FT_Reference_Library with FT_Done_Library. The host CPU (Xeon E5-1620 v2) fails the startup CPU-feature gate, so I ran the tests with that check disabled in a local, uncommitted edit; both exit 0. Windows was not run. tools/check_conventions.py and git diff --check pass. No title or GPU involved.

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:4995355874 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10606). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T12:24:18Z. --- ### What Adds `FT_Done_Library` and `FT_Reference_Library` to libSceFreeType, following the bundled FreeType 2.13.3 ([ftobjs.c](https://github.com/freetype/freetype/blob/42608f77f20749dd6ddc9e0536788eaad70ea4b5/src/base/ftobjs.c)). The guest library wrapper now carries a reference count that mirrors the native one: `FT_Reference_Library` raises both, and `FT_Done_Library` lowers both and releases the wrapper together with the native library on the last reference. `FT_Done_FreeType` is unchanged: as natively, it drops one reference through `FT_Done_Library` and then discards the memory manager whatever the count ([ftinit.c](https://github.com/freetype/freetype/blob/42608f77f20749dd6ddc9e0536788eaad70ea4b5/src/base/ftinit.c)), so a library that still has references is not usable afterwards and the guest wrapper is released at once. Like the native call, `FT_Done_Library` does not free the memory manager that `FT_Init_FreeType` created. `FT_New_Library` is not included because it takes guest memory callbacks. Console signatures and errors are unverified; the debt entries say so. Commits: for each function in turn (`FT_Done_Library`, then `FT_Reference_Library`), the implementation, its test and its debt entry. ### Tested Linux x86-64, GCC, full CMake build (Ninja, Release). `guest_freetype_library_references` compares each call with the native one: dropping the only reference with open faces, a null library, and three extra references released one at a time with a face opened and closed between each step on both libraries. It also runs the existing `guest_freetype` suite, which still passes. While building the test I found that native `FT_Done_FreeType` frees the memory manager even when references remain, so the test pairs `FT_Reference_Library` with `FT_Done_Library`. The host CPU (Xeon E5-1620 v2) fails the startup CPU-feature gate, so I ran the tests with that check disabled in a local, uncommitted edit; both exit 0. Windows was not run. `tools/check_conventions.py` and `git diff --check` pass. No title or GPU involved. ### 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: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
harisibrar1 commented 2026-10-24 15:46:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T15:46:10Z.

Review: COMMENTED


Checked against main c9b75825f3 and FreeType 2.13.3 (42608f77) src/base/ftobjs.c and src/base/ftinit.c:

  • NIDs 1XCz6Gk0Lt4 / qAPXM5DN62Q match the names, and the branch still merges cleanly into current main. The two wrappers mirror native refcounting correctly, and on the last reference native FT_Done_Face runs the existing finalizer hooks before the wrapper is deleted, in the same order as the existing FT_Done_FreeType path.
  • The FT_Reference_Library debt line (and the PR text) says native FT_Done_FreeType ignores the count and releases the library at once. In 2.13.3 it calls FT_Done_Library, which only decrements while references remain (ftobjs.c:5567-5568), and then frees the memory manager (ftinit.c). So natively the library and its faces stay allocated (leaked, with a freed memory manager), not released. Main's FT_Done_FreeType_nid_postfix (Export.cpp:107-111) still deletes the wrapper and all its GuestFace objects in that case, so after FT_Reference_Library then FT_Done_FreeType, a guest face pointer is already freed on our side while natively it's only leaked. It's an edge case natively too, but could the debt wording be corrected, and possibly FT_Done_FreeType throw when references > 1 rather than silently diverging?
  • Heads-up: #10593 adds an include on the same Export.cpp line as FT_MODULE_H here, so one of them will need a trivial rebase.

Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638834663 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10606#pullrequestreview-5638834663). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-24T15:46:10Z. **Review:** COMMENTED --- Checked against main c9b75825f3 and FreeType 2.13.3 (42608f77) `src/base/ftobjs.c` and `src/base/ftinit.c`: - NIDs `1XCz6Gk0Lt4` / `qAPXM5DN62Q` match the names, and the branch still merges cleanly into current main. The two wrappers mirror native refcounting correctly, and on the last reference native `FT_Done_Face` runs the existing finalizer hooks before the wrapper is deleted, in the same order as the existing `FT_Done_FreeType` path. - The `FT_Reference_Library` debt line (and the PR text) says native `FT_Done_FreeType` ignores the count and releases the library at once. In 2.13.3 it calls `FT_Done_Library`, which only decrements while references remain (`ftobjs.c:5567-5568`), and then frees the memory manager (`ftinit.c`). So natively the library and its faces stay allocated (leaked, with a freed memory manager), not released. Main's `FT_Done_FreeType_nid_postfix` (`Export.cpp:107-111`) still deletes the wrapper and all its `GuestFace` objects in that case, so after `FT_Reference_Library` then `FT_Done_FreeType`, a guest face pointer is already freed on our side while natively it's only leaked. It's an edge case natively too, but could the debt wording be corrected, and possibly `FT_Done_FreeType` throw when `references > 1` rather than silently diverging? - Heads-up: #10593 adds an include on the same `Export.cpp` line as `FT_MODULE_H` here, so one of them will need a trivial rebase. Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.

Pull request closed

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!10606
No description provided.