Update qsort() calls to bu_sort() #6BRL-CAD
Status: ClosedTime to complete: 72 hrs Mentors: H S RaiTags: C, refactoring, portability

This task is a follow-on to http://www.google-melange.com/gci/task/view/google/gci2013/5876128501727232

We call qsort() in about 40 places throughout BRL-CAD.  You can run this to find most of them:

grep -r 'qsort(' src/* | grep -v other | grep -v svn

We have a new function in our LIBBU portable utility library, bu_sort(), that provides functionality nearly identical to qsort_s() on Windows or qsort_r() on Linux.  The difference between sort() and those functions is that you have to put data into global variables with sort() but you pass data as an argument with the others.  

This task involves updating five or more instances of qsort (you must at least update all occurrences in a given file) to bu_sort.

Basically, you'll take any parameter that was being accessed as a global and pass it as an argument.  If the variable can be moved from global into a local scope during the transition, even better, but the important step is to update the callback function to take an additional parameter and to access data through that parameter, not via the global.  If multiple globals are accessed, you'll need to create a struct that combines them together.

Submit your work as a patch file.

There are multiple tasks like this one in order to see all occurrences get fixed.  If you run into any qsort() call that takes more than an hour to convert, for whatever reason, let us know.

Uploaded Work
File name/URLFile sizeDate submitted
http://sourceforge.net/p/brlcad/code/59107/n/aDecember 21 2013 11:03 UTC
Comments
Johannes Schulteon December 20 2013 18:18 UTCTask Claimed

I would like to work on this task.

Gauravjeet Singh on December 21 2013 02:12 UTCTask Assigned

This task has been assigned to Johannes Schulte. You have 72 hours to complete this task, good luck!

Johannes Schulteon December 21 2013 11:03 UTCReady for review

The work on this task is ready to be reviewed.

Johannes Schulteon December 21 2013 11:31 UTC

taking andromeda's work in account, this should be the last uses.

Sean on December 22 2013 06:44 UTCFunction cast necessary?

It would seem to me that the function casts are no longer necessary, yes?  No?


Otherwise, looks great.

Sean on December 22 2013 06:45 UTCTask Closed

Congratulations, this task has been completed successfully.

Johannes Schulteon December 22 2013 13:48 UTC

I also wasn't sure about the cast. Effectively you need to cast at one point during the sort, either the function, which then can take a normal type(in this case char) or you cast the void* parameters to the appropriate type. In this the original function header expected chars not voids, so I kept to that. c