This is an archive of the discontinued LLVM Phabricator instance.

[libc] Add qsort_r
ClosedPublic

Authored by michaelrj on Jun 8 2023, 2:09 PM.

Details

Summary

This patch adds the reentrent qsort entrypoint, qsort_r. This is done by
extending the qsort functionality and moving it to a shared utility
header. For this reason the qsort_r tests focus mostly on the places
where it differs from qsort, since they share the same sorting code.

Diff Detail

Event Timeline

michaelrj created this revision.Jun 8 2023, 2:09 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJun 8 2023, 2:09 PM
michaelrj requested review of this revision.Jun 8 2023, 2:09 PM
lntue accepted this revision.Jun 8 2023, 3:42 PM
This revision is now accepted and ready to land.Jun 8 2023, 3:42 PM
michaelrj updated this revision to Diff 529764.Jun 8 2023, 4:11 PM

add a comment explaining which variety of qsort_r this is, and why.

sivachandra accepted this revision.Jun 9 2023, 4:18 PM
sivachandra added inline comments.
libc/src/stdlib/qsort_util.h
20–39

May be Compare and CompareWithState.

21

Nit: Since you are touching this anyway, you can change it to:

using Compare = int(const void *, const void *);
using CompareWithState = int(const void *, const void *, void *);
24

All caps. Also, if you make it an enum class, then you can get scoped names like COMPARE and COMPARE_WITH_STATE.

michaelrj updated this revision to Diff 530124.Jun 9 2023, 6:01 PM
michaelrj marked 3 inline comments as done.

address comments. I will land this next business day.

This revision was landed with ongoing or failed builds.Jun 12 2023, 11:12 AM
Closed by commit rGd3074f16a6f6: [libc] Add qsort_r (authored by michaelrj). · Explain Why
This revision was automatically updated to reflect the committed changes.