| 368 static int cx_array_qsort_wrapper(const void *l, const void *r) { |
368 static int cx_array_qsort_wrapper(const void *l, const void *r) { |
| 369 return cx_array_fn_for_qsort(l, r, cx_array_context_for_qsort); |
369 return cx_array_fn_for_qsort(l, r, cx_array_context_for_qsort); |
| 370 } |
370 } |
| 371 #endif |
371 #endif |
| 372 |
372 |
| |
373 #if defined(WITH_QSORT_R) && defined(__APPLE__) |
| |
374 // macOS uses a different comparefunc signature for qsort_r |
| |
375 typedef struct QsortCmpFuncWrapper { |
| |
376 cx_compare_func2 fn; |
| |
377 void *context; |
| |
378 } QsortCmpFuncWrapper; |
| |
379 |
| |
380 static int sort_comparefunc(void *context, const void *left, const void *right){ |
| |
381 QsortCmpFuncWrapper *w = context; |
| |
382 return w->fn(left, right, w->context); |
| |
383 } |
| |
384 #endif |
| |
385 |
| 373 void cx_array_qsort_c(void *array, size_t nmemb, size_t size, |
386 void cx_array_qsort_c(void *array, size_t nmemb, size_t size, |
| 374 cx_compare_func2 fn, void *context) { |
387 cx_compare_func2 fn, void *context) { |
| 375 #ifdef WITH_QSORT_R |
388 #ifdef WITH_QSORT_R |
| |
389 #ifndef __APPLE__ |
| 376 qsort_r(array, nmemb, size, fn, context); |
390 qsort_r(array, nmemb, size, fn, context); |
| |
391 #else |
| |
392 QsortCmpFuncWrapper wrapper; |
| |
393 wrapper.fn = fn; |
| |
394 wrapper.context = context; |
| |
395 qsort_r(array, nmemb, size, &wrapper, sort_comparefunc); |
| |
396 #endif |
| 377 #else |
397 #else |
| 378 cx_array_fn_for_qsort = fn; |
398 cx_array_fn_for_qsort = fn; |
| 379 cx_array_context_for_qsort = context; |
399 cx_array_context_for_qsort = context; |
| 380 qsort(array, nmemb, size, cx_array_qsort_wrapper); |
400 qsort(array, nmemb, size, cx_array_qsort_wrapper); |
| 381 #endif |
401 #endif |