diff options
| author | Junio C Hamano <gitster@pobox.com> | 2017-01-31 13:15:00 -0800 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2017-01-31 13:15:00 -0800 |
| commit | 6ad8b8e98faa5a301a98a2997da162dea060672e (patch) | |
| tree | 99ca685d15df287c1f686c033157756d439c119c /git-compat-util.h | |
| parent | 4e170adc8ad654bddb9421a4bf51bb4802656262 (diff) | |
| parent | 83fc4d64fec779d73b18494461613ef911236daf (diff) | |
| download | git-6ad8b8e98faa5a301a98a2997da162dea060672e.tar.gz | |
Merge branch 'rs/qsort-s'
A few codepaths had to rely on a global variable when sorting
elements of an array because sort(3) API does not allow extra data
to be passed to the comparison function. Use qsort_s() when
natively available, and a fallback implementation of it when not,
to eliminate the need, which is a prerequisite for making the
codepath reentrant.
* rs/qsort-s:
ref-filter: use QSORT_S in ref_array_sort()
string-list: use QSORT_S in string_list_sort()
perf: add basic sort performance test
add QSORT_S
compat: add qsort_s()
Diffstat (limited to 'git-compat-util.h')
| -rw-r--r-- | git-compat-util.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/git-compat-util.h b/git-compat-util.h index 87237b092b..f46d40e4a4 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -988,6 +988,17 @@ static inline void sane_qsort(void *base, size_t nmemb, size_t size, qsort(base, nmemb, size, compar); } +#ifndef HAVE_ISO_QSORT_S +int git_qsort_s(void *base, size_t nmemb, size_t size, + int (*compar)(const void *, const void *, void *), void *ctx); +#define qsort_s git_qsort_s +#endif + +#define QSORT_S(base, n, compar, ctx) do { \ + if (qsort_s((base), (n), sizeof(*(base)), compar, ctx)) \ + die("BUG: qsort_s() failed"); \ +} while (0) + #ifndef REG_STARTEND #error "Git requires REG_STARTEND support. Compile with NO_REGEX=NeedsStartEnd" #endif |
