Skip to content

Add C23 free_sized/free_aligned_sized support#1

Merged
emeryberger merged 6 commits intomainfrom
feature/free-sized-support
Mar 3, 2026
Merged

Add C23 free_sized/free_aligned_sized support#1
emeryberger merged 6 commits intomainfrom
feature/free-sized-support

Conversation

@emeryberger
Copy link
Owner

Summary

  • Thread size/alignment info from C23 free_sized, C++14 sized operator delete, and macOS malloc_zone_free_definite_size through to allocators that can exploit it
  • Allocators opt in by providing free_sized() and/or free_aligned_sized() methods, detected via if constexpr — existing allocators are fully unchanged
  • Fallback chain: free_aligned_sizedfree_sizedfree

What gets routed through the new functions

Call site Routes to
C23 free_sized(ptr, sz) xxfree_sized(ptr, sz)
C23 free_aligned_sized(ptr, align, sz) xxfree_aligned_sized(ptr, align, sz)
C++14 operator delete(void*, size_t) xxfree_sized(ptr, sz)
C++14+17 operator delete(void*, size_t, align_val_t) xxfree_aligned_sized(ptr, align, sz)
macOS malloc_zone_free_definite_size(zone, ptr, sz) xxfree_sized(ptr, sz)
Plain free(ptr) / aligned-only delete xxfree(ptr) (unchanged)

Files changed (15 files, +242/-27)

  • Core: allocator_traits.h, alloc8.h, new_delete.inc, new_delete.cpp
  • Linux: gnu_wrapper.cpp, gnu_wrapper.h, version_script.map.in
  • macOS: mac_wrapper.cpp, mac_zones.cpp
  • Windows: win_wrapper_detours.cpp
  • Examples: DieHard and Hoard *_alloc8.cpp and *_redirect_win.cpp
  • Docs: CLAUDE.md

Test plan

  • Build with tests and examples on macOS (cmake --build succeeds)
  • ctest passes (1/1 tests)
  • Interposition works: DYLD_INSERT_LIBRARIES=libsimple_heap.dylib ./test_basic_alloc — all 13 tests pass
  • New symbols exported: nm -gU shows _xxfree_sized and _xxfree_aligned_sized
  • C++ sized delete interpose entries correctly use xxfree_sized (verified via nm)
  • Linux build verification
  • Windows build verification

🤖 Generated with Claude Code

emeryberger and others added 6 commits December 27, 2025 11:54
Thread size/alignment info from C23 free_sized, C++14 sized delete, and
macOS malloc_zone_free_definite_size through to allocators that can
exploit it. Allocators opt in by providing free_sized() and/or
free_aligned_sized() methods, detected via if constexpr. Existing
allocators are unchanged — the fallback chain is:
free_aligned_sized → free_sized → free.

- HeapRedirect: new free_sized/free_aligned_sized with if constexpr detection
- ALLOC8_REDIRECT: generates xxfree_sized and xxfree_aligned_sized
- C++ sized delete operators now route through xxfree_sized/xxfree_aligned_sized
- All platform wrappers updated (Linux, macOS, Windows)
- gnu_wrapper.h: inline helpers with heap type detection for zero-overhead path
- Version script: exports new symbols and C++14+17 sized+aligned delete manglings
- DieHard/Hoard examples: add xxfree_sized/xxfree_aligned_sized stubs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
GitHub Actions workflow that builds with tests and examples, runs ctest,
verifies symbol exports, and tests LD_PRELOAD/DYLD_INSERT_LIBRARIES
interposition on both platforms.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@emeryberger emeryberger merged commit 586138d into main Mar 3, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant