Skip to content

Commit 5a2e4f1

Browse files
committed
fix compilation with musl < 1.2.3
1 parent 8ff47f3 commit 5a2e4f1

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

lib/dictBuilder/cover.c

+10-8
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,9 +241,10 @@ 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. */
246-
static COVER_ctx_t *g_coverCtx = NULL;
244+
#if (!defined(_GNU_SOURCE) && !defined(__APPLE__) && !defined(_MSC_VER)) \
245+
|| (defined(__MUSL__) && __MUSL__ < 0x01020300)
246+
/* global context needed for non-reentrant sorting functions */
247+
static COVER_ctx_t* g_coverCtx = NULL;
247248
#endif
248249

249250
/*-*************************************
@@ -328,7 +329,8 @@ 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) \
333+
&& !(defined(__MUSL__) && __MUSL__ < 0x01020300) /* musl only provides qsort_r starting v1.2.3 */
332334
qsort_r(ctx->suffix, ctx->suffixSize, sizeof(U32),
333335
(ctx->d <= 8 ? &COVER_strict_cmp8 : &COVER_strict_cmp),
334336
ctx);
@@ -342,7 +344,7 @@ static void stableSort(COVER_ctx_t *ctx) {
342344
(ctx->d <= 8 ? &COVER_strict_cmp8 : &COVER_strict_cmp));
343345
#else /* C90 fallback.*/
344346
g_coverCtx = ctx;
345-
/* TODO(cavalcanti): implement a reentrant qsort() when is not available. */
347+
/* TODO(cavalcanti): implement a reentrant qsort() when _r is not available. */
346348
qsort(ctx->suffix, ctx->suffixSize, sizeof(U32),
347349
(ctx->d <= 8 ? &COVER_strict_cmp8 : &COVER_strict_cmp));
348350
#endif

0 commit comments

Comments
 (0)