GSoC/GCI Archive
Google Code-in 2013 BRL-CAD

Implement a platform independent re-entrant sort function

completed by: Johannes Schulte

mentors: Daniel Rossberg

The classic C library qsort() does not support a context parameter.  A work around is to store the context information in a static variable.  However, this solution is not thread save and may result in unpredictable behavior.

There are platform specific sort functions qsort_r() in incompatible versions for BSD and GNU and qsort_s() for MSVC.  Your task is to implement a bu_sort() function for BRL-CAD which is platform independent.

Code:

  • src/libbu/sort.c

The new sort function could look like this:
void bu_sort(genptr_t array, size_t nummemb, size_t sizememb,
   int (*compare)(const_genptr_t, const_genptr_t, genptr_t),
   genptr_t context);