Skip to content

Commit

Permalink
fix compilation with musl < 1.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyan4973 committed Feb 21, 2025
1 parent 8ff47f3 commit 5a2e4f1
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions lib/dictBuilder/cover.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
/* qsort_r is an extension. */
#if defined(__linux) || defined(__linux__) || defined(linux) || defined(__gnu_linux__) || \
defined(__CYGWIN__) || defined(__MSYS__)
#if !defined(_GNU_SOURCE) && !defined(__ANDROID__) /* NDK doesn't ship qsort_r(). */
#define _GNU_SOURCE
#endif
# if !defined(_GNU_SOURCE) && !defined(__ANDROID__) /* NDK doesn't ship qsort_r(). */
# define _GNU_SOURCE
# endif
#endif

#include <stdio.h> /* fprintf */
Expand Down Expand Up @@ -241,9 +241,10 @@ typedef struct {
unsigned d;
} COVER_ctx_t;

#if !defined(_GNU_SOURCE) && !defined(__APPLE__) && !defined(_MSC_VER)
/* C90 only offers qsort() that needs a global context. */
static COVER_ctx_t *g_coverCtx = NULL;
#if (!defined(_GNU_SOURCE) && !defined(__APPLE__) && !defined(_MSC_VER)) \
|| (defined(__MUSL__) && __MUSL__ < 0x01020300)
/* global context needed for non-reentrant sorting functions */
static COVER_ctx_t* g_coverCtx = NULL;
#endif

/*-*************************************
Expand Down Expand Up @@ -328,7 +329,8 @@ static void stableSort(COVER_ctx_t *ctx) {
qsort_r(ctx->suffix, ctx->suffixSize, sizeof(U32),
ctx,
(ctx->d <= 8 ? &COVER_strict_cmp8 : &COVER_strict_cmp));
#elif defined(_GNU_SOURCE)
#elif defined(_GNU_SOURCE) \
&& !(defined(__MUSL__) && __MUSL__ < 0x01020300) /* musl only provides qsort_r starting v1.2.3 */
qsort_r(ctx->suffix, ctx->suffixSize, sizeof(U32),
(ctx->d <= 8 ? &COVER_strict_cmp8 : &COVER_strict_cmp),
ctx);
Expand All @@ -342,7 +344,7 @@ static void stableSort(COVER_ctx_t *ctx) {
(ctx->d <= 8 ? &COVER_strict_cmp8 : &COVER_strict_cmp));
#else /* C90 fallback.*/
g_coverCtx = ctx;
/* TODO(cavalcanti): implement a reentrant qsort() when is not available. */
/* TODO(cavalcanti): implement a reentrant qsort() when _r is not available. */
qsort(ctx->suffix, ctx->suffixSize, sizeof(U32),
(ctx->d <= 8 ? &COVER_strict_cmp8 : &COVER_strict_cmp));
#endif
Expand Down

0 comments on commit 5a2e4f1

Please sign in to comment.