Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
251408cf
Unverified
Commit
251408cf
authored
May 09, 2023
by
Edward Thomson
Committed by
GitHub
May 09, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6555 from DimitryAndric/fix-qsort-variants-1
util: detect all possible qsort_r and qsort_s variants
parents
fc4c00b2
d873966f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
11 deletions
+29
-11
src/CMakeLists.txt
+17
-3
src/util/git2_features.h.in
+2
-1
src/util/util.c
+10
-7
No files found.
src/CMakeLists.txt
View file @
251408cf
...
...
@@ -58,15 +58,29 @@ add_feature_info(futimens GIT_USE_FUTIMENS "futimens support")
# qsort
# old-style FreeBSD qsort_r() has the 'context' parameter as the first argument
# of the comparison function:
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 *))"
"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
)
# GNU or POSIX qsort_r() has the 'context' parameter as the last argument of the
# comparison function:
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
)"
"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
)
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
(
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
)
# 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
"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
)
# random / entropy data
...
...
src/util/git2_features.h.in
View file @
251408cf
...
...
@@ -26,7 +26,8 @@
#cmakedefine GIT_QSORT_R_BSD
#cmakedefine GIT_QSORT_R_GNU
#cmakedefine GIT_QSORT_S
#cmakedefine GIT_QSORT_S_C11
#cmakedefine GIT_QSORT_S_MSC
#cmakedefine GIT_SSH 1
#cmakedefine GIT_SSH_MEMORY_CREDENTIALS 1
...
...
src/util/util.c
View file @
251408cf
...
...
@@ -18,7 +18,7 @@
# endif
# include <windows.h>
# ifdef GIT_QSORT_S
# ifdef GIT_QSORT_S
_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_S
_MSC
) || defined(GIT_QSORT_R_BSD)
typedef
struct
{
git__sort_r_cmp
cmp
;
void
*
payload
;
...
...
@@ -690,7 +690,8 @@ static int GIT_LIBGIT2_CALL git__qsort_r_glue_cmp(
#if !defined(GIT_QSORT_R_BSD) && \
!defined(GIT_QSORT_R_GNU) && \
!defined(GIT_QSORT_S)
!defined(GIT_QSORT_S_C11) && \
!defined(GIT_QSORT_S_MSC)
static
void
swap
(
uint8_t
*
a
,
uint8_t
*
b
,
size_t
elsize
)
{
char
tmp
[
256
];
...
...
@@ -721,12 +722,14 @@ static void insertsort(
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_R_GNU)
qsort_r
(
els
,
nel
,
elsize
,
cmp
,
payload
);
#elif defined(GIT_QSORT_S_C11)
qsort_s
(
els
,
nel
,
elsize
,
cmp
,
payload
);
#elif defined(GIT_QSORT_R_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_S_MSC)
git__qsort_r_glue
glue
=
{
cmp
,
payload
};
qsort_s
(
els
,
nel
,
elsize
,
git__qsort_r_glue_cmp
,
&
glue
);
#else
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment