feat(libc): implement qsort_r #12845
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12845"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by heditrigui on 2026-10-29T12:28:29Z.
What
Implement FreeBSD \qsort_r\ (NID \VLM2LMcMT5I) in \libc, sorting elements with caller-provided \ hunk\ context passed as the comparator's first argument. Cover forward and reverse sorting with thunk context on distinct keys as well as argument validation in \GuestQsort.
Tested
Checklist
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T12:32:43Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The new reverse-order test expects equal-key elements to reverse their relative order, but the existing insertion-sort path preserves them, so the test expectation conflicts with the implementation.
What I ran
Reviewed PR head
3f086c312a26200a1872a7c27d55083d13c67ef8againstmainat5454cd2e455994d992aca39335ce60507eeda1eb. The merge preview is clean (50eb657dc0fccfe3ec973bc2b59bab37d75ac622). Environment: Debian Linux, GCC 12.2.0, CMake 3.25.1.Results
git diff --check50eb657dc0fccfe3ec973bc2b59bab37d75ac622guest_qsortbuild/testUnedited command output
python3 tools/check_conventions.py --base upstream/main:git diff --check upstream/main...refs/remotes/upstream/pr/12845-reviewproduced no output and exited successfully.git merge-tree --write-tree upstream/main refs/remotes/upstream/pr/12845-review:The first configure attempt reported:
After initializing SDL2 and Vulkan-Headers, the bundled-dependency configure reported missing submodules including
ffmpeg-core,freetype,libusb-cmake,zstd,opus,glslangandLibAtrac9, and ended withConfiguring incomplete, errors occurred!.Hosted checks at review time:
Negative control
Findings
Blocking
ExpectOrderRsorts{1, 0, 1, 0}and checks that the descending result is the exact reverse of the ascending tag list. For the four-element insertion-sort path, equal elements are not swapped because the loop moves an element only when the comparator returns> 0. After ascending order{1, 3, 0, 2}, descending order therefore retains tie order as{0, 2, 1, 3}, while the test expects{2, 0, 3, 1}. This will make the new focused test fail. Please check descending key order and thunk direction without requiring equal-key elements to reverse their relative order, or use distinct keys for the exact-order assertion.Non-blocking
The
qsort_rcallback signature and forwarding order match FreeBSD'sqsort_rimplementation shape. This was checked by reading source; no console behavior was tested.Sources
3f086c312a26200a1872a7c27d55083d13c67ef83f086c312a26200a1872a7c27d55083d13c67ef8qsort.c, pinned commit5ed7eb0d97ba4436218e810f61bd059acba984c2Not verified
I did not build or run
guest_qsort, run a negative control, or test other platforms, GPUs, or consoles. Hosted build and test jobs were still pending.To get this to a good state
Adjust the reverse-order test so equal-key order is not assumed, then rerun the convention check and
ctest --test-dir build -R '^guest_qsort$' --output-on-failureon the new head. I will re-run the same commands on that head.