src/list.c

changeset 1620
bf5d647f939d
parent 1618
ef7cab6eb131
--- a/src/list.c	Wed Dec 17 20:13:08 2025 +0100
+++ b/src/list.c	Thu Dec 18 12:11:30 2025 +0100
@@ -31,6 +31,12 @@
 #include <string.h>
 #include <assert.h>
 
+// we don't want to include the full array_list.h.
+// therefore, we only forward declare the one function we want to use
+CX_EXPORT void cx_array_qsort_c(void *array, size_t nmemb, size_t size,
+        cx_compare_func2 fn, void *context);
+
+
 int cx_list_compare_wrapper(const void *l, const void *r, void *c) {
     CxList *list = c;
     const void *left;
@@ -283,12 +289,6 @@
     return cx_list_default_insert_sorted_impl(list, sorted_data, n, false);
 }
 
-// TODO: remove this hack once we have a solution for qsort() / qsort_s()
-static _Thread_local CxList *cx_hack_for_qsort_list;
-static int cx_hack_cmp_for_qsort(const void *l, const void *r) {
-    return cx_list_compare_wrapper(l, r, cx_hack_for_qsort_list);
-}
-
 void cx_list_default_sort(struct cx_list_s *list) {
     size_t elem_size = list->collection.elem_size;
     size_t list_size = list->collection.size;
@@ -304,9 +304,7 @@
     }
 
     // qsort
-    // TODO: qsort_s() is not as nice as we thought
-    cx_hack_for_qsort_list = list;
-    qsort(tmp, list_size, elem_size, cx_hack_cmp_for_qsort);
+    cx_array_qsort_c(tmp, list_size, elem_size, cx_list_compare_wrapper, list);
 
     // copy elements back
     loc = tmp;

mercurial