Added
Link Here
|
1 |
--- CMakeLists.txt.orig 2023-02-15 10:03:30 UTC |
2 |
+++ CMakeLists.txt |
3 |
@@ -96,7 +96,7 @@ include(CheckStructHasMember) |
4 |
include(CheckFunctionExists) |
5 |
include(CheckSymbolExists) |
6 |
include(CheckStructHasMember) |
7 |
-include(CheckPrototypeDefinition) |
8 |
+include(CheckPrototypeDefinitionSafe) |
9 |
include(AddCFlagIfSupported) |
10 |
include(FindPkgLibraries) |
11 |
include(FindThreads) |
12 |
--- cmake/CheckPrototypeDefinitionSafe.cmake.orig 2023-05-14 12:22:20 UTC |
13 |
+++ cmake/CheckPrototypeDefinitionSafe.cmake |
14 |
@@ -0,0 +1,16 @@ |
15 |
+include(CheckPrototypeDefinition) |
16 |
+ |
17 |
+function(check_prototype_definition_safe function prototype return header variable) |
18 |
+ # temporarily save CMAKE_C_FLAGS and disable warnings about unused |
19 |
+ # unused functions and parameters, otherwise they will always fail |
20 |
+ # if ENABLE_WERROR is on |
21 |
+ set(SAVED_CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") |
22 |
+ |
23 |
+ disable_warnings(unused-function) |
24 |
+ disable_warnings(unused-parameter) |
25 |
+ |
26 |
+ check_prototype_definition("${function}" "${prototype}" "${return}" "${header}" "${variable}") |
27 |
+ |
28 |
+ # restore CMAKE_C_FLAGS |
29 |
+ set(CMAKE_C_FLAGS "${SAVED_CMAKE_C_FLAGS}") |
30 |
+endfunction() |
31 |
--- src/CMakeLists.txt.orig 2023-02-15 10:03:30 UTC |
32 |
+++ src/CMakeLists.txt |
33 |
@@ -58,15 +58,29 @@ add_feature_info(futimens GIT_USE_FUTIMENS "futimens s |
34 |
|
35 |
# qsort |
36 |
|
37 |
-check_prototype_definition(qsort_r |
38 |
- "void qsort_r(void *base, size_t nmemb, size_t size, void *thunk, int (*compar)(void *, const void *, const void *))" |
39 |
- "" "stdlib.h" GIT_QSORT_R_BSD) |
40 |
+# old-style FreeBSD qsort_r() has the 'context' parameter as the first argument |
41 |
+# of the comparison function: |
42 |
+check_prototype_definition_safe(qsort_r |
43 |
+ "void (qsort_r)(void *base, size_t nmemb, size_t size, void *context, int (*compar)(void *, const void *, const void *))" |
44 |
+ "" "stdlib.h" GIT_QSORT_BSD) |
45 |
|
46 |
-check_prototype_definition(qsort_r |
47 |
- "void qsort_r(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *, void *), void *arg)" |
48 |
- "" "stdlib.h" GIT_QSORT_R_GNU) |
49 |
+# GNU or POSIX qsort_r() has the 'context' parameter as the last argument of the |
50 |
+# comparison function: |
51 |
+check_prototype_definition_safe(qsort_r |
52 |
+ "void (qsort_r)(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *, void *), void *context)" |
53 |
+ "" "stdlib.h" GIT_QSORT_GNU) |
54 |
|
55 |
-check_function_exists(qsort_s GIT_QSORT_S) |
56 |
+# C11 qsort_s() has the 'context' parameter as the last argument of the |
57 |
+# comparison function, and returns an error status: |
58 |
+check_prototype_definition_safe(qsort_s |
59 |
+ "errno_t (qsort_s)(void *base, rsize_t nmemb, rsize_t size, int (*compar)(const void *, const void *, void *), void *context)" |
60 |
+ "0" "stdlib.h" GIT_QSORT_C11) |
61 |
+ |
62 |
+# MSC qsort_s() has the 'context' parameter as the first argument of the |
63 |
+# comparison function, and as the last argument of qsort_s(): |
64 |
+check_prototype_definition_safe(qsort_s |
65 |
+ "void (qsort_s)(void *base, size_t num, size_t width, int (*compare )(void *, const void *, const void *), void *context)" |
66 |
+ "" "stdlib.h" GIT_QSORT_MSC) |
67 |
|
68 |
# random / entropy data |
69 |
|
70 |
--- src/features.h.in.orig 2023-02-15 10:03:30 UTC |
71 |
+++ src/features.h.in |
72 |
@@ -24,9 +24,10 @@ |
73 |
#cmakedefine GIT_REGEX_PCRE2 |
74 |
#cmakedefine GIT_REGEX_BUILTIN 1 |
75 |
|
76 |
-#cmakedefine GIT_QSORT_R_BSD |
77 |
-#cmakedefine GIT_QSORT_R_GNU |
78 |
-#cmakedefine GIT_QSORT_S |
79 |
+#cmakedefine GIT_QSORT_BSD |
80 |
+#cmakedefine GIT_QSORT_GNU |
81 |
+#cmakedefine GIT_QSORT_C11 |
82 |
+#cmakedefine GIT_QSORT_MSC |
83 |
|
84 |
#cmakedefine GIT_SSH 1 |
85 |
#cmakedefine GIT_SSH_MEMORY_CREDENTIALS 1 |
86 |
--- src/util/util.c.orig 2023-02-15 10:03:30 UTC |
87 |
+++ src/util/util.c |
88 |
@@ -18,7 +18,7 @@ |
89 |
# endif |
90 |
# include <windows.h> |
91 |
|
92 |
-# ifdef GIT_QSORT_S |
93 |
+# ifdef GIT_QSORT_MSC |
94 |
# include <search.h> |
95 |
# endif |
96 |
#endif |
97 |
@@ -673,7 +673,7 @@ size_t git__unescape(char *str) |
98 |
return (pos - str); |
99 |
} |
100 |
|
101 |
-#if defined(GIT_QSORT_S) || defined(GIT_QSORT_R_BSD) |
102 |
+#if defined(GIT_QSORT_MSC) || defined(GIT_QSORT_BSD) |
103 |
typedef struct { |
104 |
git__sort_r_cmp cmp; |
105 |
void *payload; |
106 |
@@ -688,9 +688,11 @@ static int GIT_LIBGIT2_CALL git__qsort_r_glue_cmp( |
107 |
#endif |
108 |
|
109 |
|
110 |
-#if !defined(GIT_QSORT_R_BSD) && \ |
111 |
- !defined(GIT_QSORT_R_GNU) && \ |
112 |
- !defined(GIT_QSORT_S) |
113 |
+#if !defined(GIT_QSORT_BSD) && \ |
114 |
+ !defined(GIT_QSORT_GNU) && \ |
115 |
+ !defined(GIT_QSORT_C11) && \ |
116 |
+ !defined(GIT_QSORT_MSC) |
117 |
+ |
118 |
static void swap(uint8_t *a, uint8_t *b, size_t elsize) |
119 |
{ |
120 |
char tmp[256]; |
121 |
@@ -716,17 +718,20 @@ static void insertsort( |
122 |
for (j = i; j > base && cmp(j, j - elsize, payload) < 0; j -= elsize) |
123 |
swap(j, j - elsize, elsize); |
124 |
} |
125 |
+ |
126 |
#endif |
127 |
|
128 |
void git__qsort_r( |
129 |
void *els, size_t nel, size_t elsize, git__sort_r_cmp cmp, void *payload) |
130 |
{ |
131 |
-#if defined(GIT_QSORT_R_BSD) |
132 |
+#if defined(GIT_QSORT_GNU) |
133 |
+ qsort_r(els, nel, elsize, cmp, payload); |
134 |
+#elif defined(GIT_QSORT_C11) |
135 |
+ qsort_s(els, nel, elsize, cmp, payload); |
136 |
+#elif defined(GIT_QSORT_BSD) |
137 |
git__qsort_r_glue glue = { cmp, payload }; |
138 |
qsort_r(els, nel, elsize, &glue, git__qsort_r_glue_cmp); |
139 |
-#elif defined(GIT_QSORT_R_GNU) |
140 |
- qsort_r(els, nel, elsize, cmp, payload); |
141 |
-#elif defined(GIT_QSORT_S) |
142 |
+#elif defined(GIT_QSORT_MSC) |
143 |
git__qsort_r_glue glue = { cmp, payload }; |
144 |
qsort_s(els, nel, elsize, git__qsort_r_glue_cmp, &glue); |
145 |
#else |