Skip to content

Commit a1a5154

Browse files
authored
Merge pull request #4312 from Cyan4973/musl_ci
introduce ZSTD_USE_C90_QSORT
2 parents 22b2fd2 + fd5498a commit a1a5154

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

.github/workflows/dev-short-tests.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,17 @@ jobs:
684684
make -C programs zstd-pgo
685685
./programs/zstd -b
686686
687+
musl-build:
688+
runs-on: ubuntu-22.04
689+
steps:
690+
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # tag=v4.1.1
691+
- name: Install musl-tools
692+
run: |
693+
sudo apt install -y musl-tools
694+
- name: Compile the project with musl-gcc
695+
run: |
696+
CC=musl-gcc CPPFLAGS=-DZSTD_USE_C90_QSORT make -j V=1 zstd
697+
687698
intel-cet-compatibility:
688699
runs-on: ubuntu-latest
689700
steps:

lib/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ The file structure is designed to make this selection manually achievable for an
193193
and assembly decoding loops. You may want to use this macro if these loops are
194194
slower on your platform.
195195

196+
- The macro `ZSTD_USE_C90_QSORT` forces usage of C90's `qsort()`,
197+
for situations where the code cannot determine that `qsort_r()` is not supported,
198+
such as, for example, older versions of `musl`.
199+
196200
#### Windows : using MinGW+MSYS to create DLL
197201

198202
DLL can be created using MinGW+MSYS with the `make libzstd` command.

lib/dictBuilder/cover.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
/* qsort_r is an extension. */
2525
#if defined(__linux) || defined(__linux__) || defined(linux) || defined(__gnu_linux__) || \
2626
defined(__CYGWIN__) || defined(__MSYS__)
27-
#if !defined(_GNU_SOURCE) && !defined(__ANDROID__) /* NDK doesn't ship qsort_r(). */
28-
#define _GNU_SOURCE
29-
#endif
27+
# if !defined(_GNU_SOURCE) && !defined(__ANDROID__) /* NDK doesn't ship qsort_r(). */
28+
# define _GNU_SOURCE
29+
# endif
3030
#endif
3131

3232
#include <stdio.h> /* fprintf */
@@ -241,8 +241,9 @@ typedef struct {
241241
unsigned d;
242242
} COVER_ctx_t;
243243

244-
#if !defined(_GNU_SOURCE) && !defined(__APPLE__) && !defined(_MSC_VER)
245-
/* C90 only offers qsort() that needs a global context. */
244+
#if defined(ZSTD_USE_C90_QSORT) \
245+
|| (!defined(_GNU_SOURCE) && !defined(__APPLE__) && !defined(_MSC_VER))
246+
/* Use global context for non-reentrant sort functions */
246247
static COVER_ctx_t *g_coverCtx = NULL;
247248
#endif
248249

@@ -328,7 +329,7 @@ static void stableSort(COVER_ctx_t *ctx) {
328329
qsort_r(ctx->suffix, ctx->suffixSize, sizeof(U32),
329330
ctx,
330331
(ctx->d <= 8 ? &COVER_strict_cmp8 : &COVER_strict_cmp));
331-
#elif defined(_GNU_SOURCE)
332+
#elif defined(_GNU_SOURCE) && !defined(ZSTD_USE_C90_QSORT)
332333
qsort_r(ctx->suffix, ctx->suffixSize, sizeof(U32),
333334
(ctx->d <= 8 ? &COVER_strict_cmp8 : &COVER_strict_cmp),
334335
ctx);
@@ -342,7 +343,7 @@ static void stableSort(COVER_ctx_t *ctx) {
342343
(ctx->d <= 8 ? &COVER_strict_cmp8 : &COVER_strict_cmp));
343344
#else /* C90 fallback.*/
344345
g_coverCtx = ctx;
345-
/* TODO(cavalcanti): implement a reentrant qsort() when is not available. */
346+
/* TODO(cavalcanti): implement a reentrant qsort() when _r is not available. */
346347
qsort(ctx->suffix, ctx->suffixSize, sizeof(U32),
347348
(ctx->d <= 8 ? &COVER_strict_cmp8 : &COVER_strict_cmp));
348349
#endif

0 commit comments

Comments
 (0)