diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2023-05-12 22:24:49 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-12 22:24:49 +0100 |
commit | 213d35ea6d69598693b7f4b5b737aa98c91ba98e (patch) | |
tree | c0b39dd4da242f4907a13b172d42194570f66dc1 /src | |
parent | 2bbcdee6b666f34e83d1cf9ca9badc66258202d6 (diff) | |
parent | 333573857960fa7260f01f38a2003bafa2313a87 (diff) | |
download | libgit2-213d35ea6d69598693b7f4b5b737aa98c91ba98e.tar.gz |
Merge pull request #6558 from DimitryAndric/fix-qsort-variants-2
Work around -Werror problems when detecting qsort variants
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 16 | ||||
-rw-r--r-- | src/util/git2_features.h.in | 8 | ||||
-rw-r--r-- | src/util/util.c | 22 |
3 files changed, 24 insertions, 22 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index de591e4e4..88d616cec 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -60,27 +60,27 @@ add_feature_info(futimens GIT_USE_FUTIMENS "futimens support") # old-style FreeBSD qsort_r() has the 'context' parameter as the first argument # of the comparison function: -check_prototype_definition(qsort_r +check_prototype_definition_safe(qsort_r "void (qsort_r)(void *base, size_t nmemb, size_t size, void *context, int (*compar)(void *, const void *, const void *))" - "" "stdlib.h" GIT_QSORT_R_BSD) + "" "stdlib.h" GIT_QSORT_BSD) # GNU or POSIX qsort_r() has the 'context' parameter as the last argument of the # comparison function: -check_prototype_definition(qsort_r +check_prototype_definition_safe(qsort_r "void (qsort_r)(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *, void *), void *context)" - "" "stdlib.h" GIT_QSORT_R_GNU) + "" "stdlib.h" GIT_QSORT_GNU) # C11 qsort_s() has the 'context' parameter as the last argument of the # comparison function, and returns an error status: -check_prototype_definition(qsort_s +check_prototype_definition_safe(qsort_s "errno_t (qsort_s)(void *base, rsize_t nmemb, rsize_t size, int (*compar)(const void *, const void *, void *), void *context)" - "0" "stdlib.h" GIT_QSORT_S_C11) + "0" "stdlib.h" GIT_QSORT_C11) # MSC qsort_s() has the 'context' parameter as the first argument of the # comparison function, and as the last argument of qsort_s(): -check_prototype_definition(qsort_s +check_prototype_definition_safe(qsort_s "void (qsort_s)(void *base, size_t num, size_t width, int (*compare )(void *, const void *, const void *), void *context)" - "" "stdlib.h" GIT_QSORT_S_MSC) + "" "stdlib.h" GIT_QSORT_MSC) # random / entropy data diff --git a/src/util/git2_features.h.in b/src/util/git2_features.h.in index 5f606df84..18644c3cc 100644 --- a/src/util/git2_features.h.in +++ b/src/util/git2_features.h.in @@ -24,10 +24,10 @@ #cmakedefine GIT_REGEX_PCRE2 #cmakedefine GIT_REGEX_BUILTIN 1 -#cmakedefine GIT_QSORT_R_BSD -#cmakedefine GIT_QSORT_R_GNU -#cmakedefine GIT_QSORT_S_C11 -#cmakedefine GIT_QSORT_S_MSC +#cmakedefine GIT_QSORT_BSD +#cmakedefine GIT_QSORT_GNU +#cmakedefine GIT_QSORT_C11 +#cmakedefine GIT_QSORT_MSC #cmakedefine GIT_SSH 1 #cmakedefine GIT_SSH_MEMORY_CREDENTIALS 1 diff --git a/src/util/util.c b/src/util/util.c index f4eaf5835..c8e8303af 100644 --- a/src/util/util.c +++ b/src/util/util.c @@ -18,7 +18,7 @@ # endif # include <windows.h> -# ifdef GIT_QSORT_S_MSC +# ifdef GIT_QSORT_MSC # include <search.h> # endif #endif @@ -673,7 +673,7 @@ size_t git__unescape(char *str) return (pos - str); } -#if defined(GIT_QSORT_S_MSC) || defined(GIT_QSORT_R_BSD) +#if defined(GIT_QSORT_MSC) || defined(GIT_QSORT_BSD) typedef struct { git__sort_r_cmp cmp; void *payload; @@ -688,10 +688,11 @@ static int GIT_LIBGIT2_CALL git__qsort_r_glue_cmp( #endif -#if !defined(GIT_QSORT_R_BSD) && \ - !defined(GIT_QSORT_R_GNU) && \ - !defined(GIT_QSORT_S_C11) && \ - !defined(GIT_QSORT_S_MSC) +#if !defined(GIT_QSORT_BSD) && \ + !defined(GIT_QSORT_GNU) && \ + !defined(GIT_QSORT_C11) && \ + !defined(GIT_QSORT_MSC) + static void swap(uint8_t *a, uint8_t *b, size_t elsize) { char tmp[256]; @@ -717,19 +718,20 @@ static void insertsort( for (j = i; j > base && cmp(j, j - elsize, payload) < 0; j -= elsize) swap(j, j - elsize, elsize); } + #endif void git__qsort_r( void *els, size_t nel, size_t elsize, git__sort_r_cmp cmp, void *payload) { -#if defined(GIT_QSORT_R_GNU) +#if defined(GIT_QSORT_GNU) qsort_r(els, nel, elsize, cmp, payload); -#elif defined(GIT_QSORT_S_C11) +#elif defined(GIT_QSORT_C11) qsort_s(els, nel, elsize, cmp, payload); -#elif defined(GIT_QSORT_R_BSD) +#elif defined(GIT_QSORT_BSD) git__qsort_r_glue glue = { cmp, payload }; qsort_r(els, nel, elsize, &glue, git__qsort_r_glue_cmp); -#elif defined(GIT_QSORT_S_MSC) +#elif defined(GIT_QSORT_MSC) git__qsort_r_glue glue = { cmp, payload }; qsort_s(els, nel, elsize, git__qsort_r_glue_cmp, &glue); #else |