mirror of
https://github.com/hanzoai/datastore.git
synced 2026-09-26 13:55:07 +00:00
The move-based Hoare partition (`partition_hoare_branchy_cyclic`, used by `::sort` for non-trivially-copyable types) saves an in-transit element in a `Uninit<T>` union while shuffling. If the `is_less` comparator throws while the gap is engaged, unwinding runs the union's trivial destructor, which never calls `~T`, leaking the saved element and leaving the range one value short. This is a regression versus the `pdqsort` path it replaces. Add a `GapRestorer` RAII guard (mirroring `GapGuard` used by the trivially-copyable block partition) that, on unwind, moves the saved element back into the hole and destroys it. Add a unit test that throws from the comparator at every comparison index in turn and asserts nothing is leaked. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
C++ port of ipnsort (unstable sort) by Lukas Bergdoll & Orson Peters. Upstream (Rust): https://github.com/Voultapher/sort-research-rs (ipnsort/). Dual-licensed MIT / Apache-2.0. See LICENSE.