summaryrefslogtreecommitdiff
path: root/src/libgit2/oidarray.h
diff options
context:
space:
mode:
authorDimitry Andric <dimitry@andric.com>2023-05-03 22:47:12 +0200
committerDimitry Andric <dimitry@andric.com>2023-05-08 20:29:26 +0200
commitd873966fdeae7f0ac974318ce21772af555f1660 (patch)
treef41e294f70c296286c3d7a249482ae4134101691 /src/libgit2/oidarray.h
parentfc4c00b21983ddbe7a5e67e240c40fece4fea285 (diff)
downloadlibgit2-d873966fdeae7f0ac974318ce21772af555f1660.tar.gz
util: detect all possible qsort_r and qsort_s variants
As reported in https://bugs.freebsd.org/271234, recent versions of FreeBSD have adjusted the prototype for qsort_r() to match the POSIX interface. This causes libgit2's CMake configuration check to fail to detect qsort_r(), making it fall back to qsort_s(), which in libgit2 also has an incompatible interface. With recent versions of clang this results in a "incompatible function pointer types" compile error. Summarizing, there are four variations of 'qsort-with-context': * old style BSD qsort_r(), used in FreeBSD 13 and earlier, where the comparison function has the context parameter first * GNU or POSIX qsort_r(), also used in FreeBSD 14 and later, where the comparison function has the context parameter last * C11 qsort_s(), where the comparison function has the context parameter last * Microsoft qsort_s(), where the comparison function has the context parameter first Add explicit detections for all these variants, so they get detected as (in the same order as above): * `GIT_QSORT_R_BSD` * `GIT_QSORT_R_GNU` * `GIT_QSORT_S_C11` * `GIT_QSORT_S_MSC` An additional complication is that on FreeBSD 14 and later, <stdlib.h> uses the C11 _Generic() macro mechanism to automatically select the correct qsort_r() prototype, depending on the caller's comparison function argument. This breaks CMake's check_prototype_definition() functionality, since it tries to redefine the function, and _Generic macro is expanded inline causing a compile error. Work around that problem by putting the function names in parentheses, to prevent the preprocessor from using a macro to replace the function name. Also, in `git__qsort_r()`, change the `#if` order so the variants that do not have to use glue are preferred.
Diffstat (limited to 'src/libgit2/oidarray.h')
0 files changed, 0 insertions, 0 deletions