This fails horribly if called recursively (or from a signal handler). You need something like:
wrapped_qsort(/* array,callback */)
{
auto tmp = CBQ;
CBQ = wrap(callback);
qsort(array.ptr,array.len,cbq_callback);
CBQ = tmp; /* pop old value from stack */
}
It'll fail from a signal handler inside qsort, or inside the callback function.
It won't fail recursively - while the second call is happening, the first will be stored on the stack (see the take and replace in the callback shim function)
Your `fn rust_qsort` takes ownership of the vector, so it frees its memory after sorting and it can't be used after sorting in the caller function.
And generic `impl FnMut` won't work in `extern "C"`, it only accepts function pointers.
Problem solved.