Skip to content

feat(libc): implement __std_free_crt as free - #13828

Merged
adriadam10 merged 2 commits into
boykopovar:mainfrom
zaryabzip:feat/libc-std-free-crt
Nov 8, 2026
Merged

adriadam10 merged 2 commits into
boykopovar:mainfrom
zaryabzip:feat/libc-std-free-crt

Conversation

@zaryabzip

@zaryabzip zaryabzip commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

What

libc gains __std_free_crt (NID y-r+TFZgeUU), which forwards to free. Microsoft STL defines it as void __std_free_crt(void* p) noexcept { _free_crt(p); }, right after __std_calloc_crt, whose memory it releases. The name and NID are in ps5rs's libc list, as __std_calloc_crt's are.

@oneandonlydean noted on #12184 that this pair member isn't on main, so a title importing both would still have an unresolved import. #12184 adds __std_calloc_crt; this adds the other half on its own. It sits just before free in FileAndHeap.cpp and Api.hpp, so it merges cleanly with both #12184 (after calloc) and #11848 (after free). Its debt entry sits next to the application heap entries, where no open pull request changes the file, so it also merges cleanly with #9677 and #12560. I checked all four with git merge-tree. The debt entry says that whether the console's wrapper frees through the application allocator, as free does, isn't measured. libc goes from 1480 of 1496 to 1481 of 1497.

ApplicationHeap.cpp's scripting mode now also checks that __std_free_crt on a block from malloc reaches the application heap's free callback, and that a null pointer doesn't. The test calls the new declaration, so it doesn't build on main.

Tested

Windows 11 (WinLibs MinGW-w64 GCC 15.2.0 UCRT r7, CMake 4.3.1, Ninja 1.13.2) and Ubuntu 24.04 on WSL2 (GCC 13.3.0, CMake 3.28.3, Ninja 1.11.1), both with the head 87b2b88 merged into main e8c25dd.

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 (Claude Code)

__std_free_crt forwards to free, as Microsoft STL defines it next to
__std_calloc_crt, so a title that imports the pair resolves both.
@github-actions

github-actions Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Progress report (809c7fa → 498a8da)

📈 System libraries: 26.87% (+0.01%, +1 implemented functions)

✅ 1 implemented
Library Name
libc __std_free_crt_nid_postfix

Changed libraries (implemented exports)

Library Before After Change
libc 1480/1496 (98.93%) 1481/1497 (98.93%) +0.0007%

@github-actions

github-actions Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

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.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 16418 __std_free_crt

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.

Pull request Shared files not compared
PR 5021 docs/dev/debt/libc.md
PR 7386 docs/dev/debt/libc.md
PR 7447 core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libc.md
PR 7544 docs/dev/debt/libc.md
PR 7715 docs/dev/debt/libc.md
PR 8150 docs/dev/debt/libc.md
PR 8417 core/libs/prx/libc/include/Api.hpp
docs/dev/debt/libc.md
PR 8965 docs/dev/debt/libc.md
PR 9340 docs/dev/debt/libc.md
PR 9371 docs/dev/debt/libc.md
PR 9447 docs/dev/debt/libc.md
PR 9466 docs/dev/debt/libc.md
PR 9526 core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libc.md
PR 9677 docs/dev/debt/libc.md
PR 10274 docs/dev/debt/libc.md
PR 10780 core/libs/prx/libc/include/Api.hpp
docs/dev/debt/libc.md
PR 11109 docs/dev/debt/libc.md
PR 11172 docs/dev/debt/libc.md
PR 11332 docs/dev/debt/libc.md
PR 11726 docs/dev/debt/libc.md
PR 11831 core/libs/prx/libc/include/Api.hpp
core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libc.md
PR 12518 docs/dev/debt/libc.md
PR 12592 docs/dev/debt/libc.md
PR 12627 docs/dev/debt/libc.md
PR 12704 docs/dev/debt/libc.md
PR 12849 docs/dev/debt/libc.md
PR 13449 docs/dev/debt/libc.md
PR 13794 docs/dev/debt/libc.md
PR 13804 docs/dev/debt/libc.md
PR 13809 docs/dev/debt/libc.md
PR 14212 docs/dev/debt/libc.md
PR 14298 docs/dev/debt/libc.md
PR 14796 core/libs/prx/libc/include/Api.hpp
PR 15807 core/libs/prx/libc/include/Api.hpp
docs/dev/debt/libc.md
PR 16004 core/libs/prx/libc/include/Api.hpp
docs/dev/debt/libc.md

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — changes requested

The implementation and reported tests look sound, but an open PR overlap creates a real debt-file conflict and its landing order is not recorded.

What I ran

Reviewed head 87b2b8895c5ee30ebafd7f141d254602a08b1225 against PR base e8c25dd3baa6e78531d5eee067fec5cbe8af3dcf. I also checked a merge preview against current main 45e39c7ad16c93871809eee8c81c3865596e883f; it merged cleanly. Environment: Debian 12 Linux, Python 3.11.2, GCC 12.2.0. I did not build the project or run C++ tests locally.

python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 13828 --output-dir /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13828
python3 tools/pr_abi_audit.py --repo /marc/AnyPS5 --base e8c25dd3baa6e78531d5eee067fec5cbe8af3dcf --head 87b2b8895c5ee30ebafd7f141d254602a08b1225 --json
python3 /marc/AnyPS5/tools/pr_test_quality.py --root /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13828/head-87b2b8895c5e-c8e3bdfc --json core/libs/tests/ApplicationHeap.cpp
python3 tools/pr_stack_check.py 13828 --repo boykopovar/AnyPS5 --output-dir /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13828/stack
python3 tools/pr_overlap.py --branch 87b2b8895c5ee30ebafd7f141d254602a08b1225
git merge-tree 87b2b8895c5ee30ebafd7f141d254602a08b1225 6ac7ce9e401899294b07fd56eea0ec72a6fb0980
git merge-tree 87b2b8895c5ee30ebafd7f141d254602a08b1225 e52854d1b6ecef00ae86bf9b86c90333000dbadf
git merge-tree 87b2b8895c5ee30ebafd7f141d254602a08b1225 c272bbe1b3d1fa9cdd9e56d7e9c56d01ef04df15

Results

Check Result
Diff and conventions Passed.
Current-main merge preview Passed against 45e39c7ad16c93871809eee8c81c3865596e883f.
Export ABI audit Passed with 3 unrelated existing explicit-alias warnings; no finding for __std_free_crt. The precheck’s isolated copy lacked the local-only audit helper, so I ran the audit directly against the exact base and head.
Test-quality check Heuristic flagged possible test-registration trouble; source inspection confirms ApplicationHeap.cpp is built into application_heap_tests and the scripting test is registered.
PR overlap The current overlap report identifies open #9677 in docs/dev/debt/libc.md at current-main line 68. Pairwise merge preview with #9677 reports a content conflict in that file. Pairwise previews with #12184 and #11848 are clean.
Hosted CI at final refresh Windows, Ubuntu and Windows relinker, ASan, Ubuntu register-context, conventions, intake, eligibility, labels, report, and library-portability passed. Linux product tests were skipped. macOS relinker, register-context and write-watch jobs were queued.
Unedited check output

Precheck command output:

/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13828/report.md
/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13828/report.json
Conclusion: checks failed

The precheck’s conventions output:

All conventions checks passed.

Direct ABI-audit summary:

status: passed_with_warnings
findings: 3
target findings: []

Test-quality output:

{
  "findings": [
    {
      "path": "core/libs/tests/ApplicationHeap.cpp",
      "line": 1,
      "kind": "possible-unregistered-cpp-test",
      "message": "Changed C++ test source path was not found literally in CMake files; inspect registration, generated source lists, and workflow coverage."
    }
  ],
  "negative_control_candidates": [],
  "limits": [
    "Heuristics can miss weak assertions and can flag valid tests; inspect every finding.",
    "A test that passes against base is not by itself proof that the PR test is inadequate.",
    "Negative controls are only candidates until the test actually runs against base and fails by assertion rather than import/setup error."
  ]
}

Relevant overlap-report row:

| [PR 9677](https://www.github.com/boykopovar/AnyPS5/pull/9677) | `docs/dev/debt/libc.md` [L68](https://github.com/boykopovar/AnyPS5/blob/45e39c7ad16c93871809eee8c81c3865596e883f/docs/dev/debt/libc.md#L68) |  |  |

Pairwise merge output with #9677:

9a8378c1e68c49c4cb99af789d4095288
100644 568e1931c1abf7cdfc763a4e8d7e8c0c5cebefb6 1	docs/dev/debt/libc.md
100644 e463077515d88ae6063cace01c374095eee7260c 2	docs/dev/debt/libc.md
100644 90228bbb4bdc6574e8e1aff000bde82daa0c8854 3	docs/dev/debt/libc.md
Auto-merging core/libs/prx/libc/src/Time.cpp
Auto-merging core/libs/prx/libkernel/Time/Time.cpp
Auto-merging core/libs/tests/GuestProcessTime.cpp
Auto-merging docs/dev/debt/libc.md
CONFLICT (content): Merge conflict in docs/dev/debt/libc.md
EXIT:1

Current hosted check snapshot:

linux	completed	skipped
register-context (macos-15-intel, Release)	queued	
relinker (macos-latest, clang++, x86_64)	queued	
relinker (macos-latest, clang++)	queued	
relinker-asan	completed	success
relinker (ubuntu-latest, g++)	completed	success
windows	completed	success
write-watch (macos-15)	queued	
register-context (ubuntu-latest, Release)	completed	success
write-watch (macos-15-intel)	queued	
relinker (windows-latest, g++)	completed	success
register-context (ubuntu-latest, Debug)	completed	success
labels	completed	success
conventions	completed	success
intake	completed	success
eligibility	completed	success
report	completed	success
library-portability	completed	success

Findings

Blocking

  • Unresolved landing order with #9677. The live overlap report identifies a shared edit in docs/dev/debt/libc.md, and a pairwise merge preview of these exact heads confirms a content conflict. The repository requires agreeing with the other PR author on which lands first and recording that order with Depends on; this PR still says Depends on: none, and no agreement with #9677’s author is recorded. Please coordinate the order and update the relevant checklist entry or entries, then recheck the pairwise merge.

Non-blocking

  • The scripting test currently allocates with malloc_nid_postfix before calling __std_free_crt. A direct __std_calloc_crt to __std_free_crt case would exercise the exact allocation/free pair motivating this PR; the existing callback test still gives useful evidence for the shared heap path.

Sources

Not verified

  • No local build, C++ tests or negative control. The PR description reports exact-head builds and focused CTest runs on WSL2 and Windows, but those runs were not independently reproduced here.
  • No console measurement. macOS CI jobs were still queued; Linux product tests were skipped.

To get this to a good state

Please agree and record the landing order with #9677’s author. I will rerun the overlap and merge checks, then reassess the new exact head.

… and boykopovar#12560

The entry now sits next to the application heap entries, where no open
pull request changes the file.
@zaryabzip
zaryabzip force-pushed the feat/libc-std-free-crt branch from c5e9d6e to 498a8da Compare October 31, 2026 09:01
@zaryabzip

Copy link
Copy Markdown
Contributor Author

@MarcZX10 Thanks. Instead of ordering it against #9677, I moved the debt entry in 498a8da to sit with the application heap entries. The spot at the end of the section collided with #12560, so I checked every entry boundary against all open pull requests that change libc.md and picked one none of them touch. git merge-tree now merges this cleanly with #9677, #12560, #12184 and #11848, and tools/pr_overlap.py lists no conflicting pull request. Only the debt line moved; the code and test are the tested 87b2b88. Body updated.

@adriadam10 adriadam10 self-assigned this Nov 1, 2026
@zaryabzip

Copy link
Copy Markdown
Contributor Author

@MarcZX10 could you take another look when you have a moment? Your Oct 31 review asked for the landing order against #9677. I moved the debt entry instead in 498a8dadc3, and it now sits with the application heap entries. It merges cleanly with #9677, #12560, #12184 and #11848, and the review still shows "changes requested".

The two red checks are write-watch on macOS, from Nov 1. They fail at CMake configure (CMakeLists.txt:42 (add_test)) in the write-watch test setup, which this PR doesn't touch.

AI-assisted: yes (Claude Code)

@adriadam10
adriadam10 merged commit 7d71912 into boykopovar:main Nov 8, 2026
114 of 133 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked the signature and forwarding against Microsoft STL, the NID against ps5rs, the test (calls the new declaration, covers the null case) and the debt entry placement; Windows and Conventions green; merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants