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