Update qsort() calls to bu_sort() #7BRL-CAD
Status: ClosedTime to complete: 72 hrs Mentors: HarmanpreetTags: 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
remove_qsort.diff3.7 KBDecember 20 2013 06:53 UTC
remove_qsort.diff4.6 KBDecember 20 2013 07:18 UTC
remove_qsort.diff5.0 KBDecember 20 2013 12:39 UTC
remove_qsort.diff5.0 KBDecember 20 2013 15:19 UTC
remove_qsort.diff5.2 KBDecember 20 2013 15:35 UTC
Comments
Peter Amidonon December 20 2013 05:11 UTCTask Claimed

I would like to work on this task.

Sean on December 20 2013 06:49 UTCTask Assigned

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

Peter Amidonon December 20 2013 06:53 UTCReady for review

The work on this task is ready to be reviewed.

Peter Amidonon December 20 2013 07:06 UTC1 problem

I just realized that there is a problem with the qsort functions not taking the 3rd argument, I will post an updated diff in a minute


 

Sean on December 20 2013 07:10 UTCTask Needs More Work

One of the mentors has sent this task back for more work. Talk to the mentor(s) assigned to this task to satisfy the requirements needed to complete this task, submit your work again and mark the task as complete once you re-submit your work.

Sean on December 20 2013 07:11 UTCyes, quite wrong

Yes, this patch is quite wrong in a variety of ways.  The callback functions still need to be updated. The old code also had function pointer casts, which need to be removed.

Peter Amidonon December 20 2013 07:17 UTCWrong diff

Sorry, I realized that right after I submitted it, I am about to submit a corrected diff.


 

Peter Amidonon December 20 2013 07:18 UTCReady for review

The work on this task is ready to be reviewed.

Sean on December 20 2013 07:45 UTCTask Needs More Work

One of the mentors has sent this task back for more work. Talk to the mentor(s) assigned to this task to satisfy the requirements needed to complete this task, submit your work again and mark the task as complete once you re-submit your work.

Sean on December 20 2013 07:46 UTCmissed a couple callbacks

Looks like you missed updating a few callbacks.  I'm surprised your compiler isn't warning about type mismatch on the function pointers.


pnt_compare_2d is an example, may be others.


 

Peter Amidonon December 20 2013 12:41 UTCReady for review

The work on this task is ready to be reviewed.

Daniel Rossberg on December 20 2013 14:02 UTCCompile errors

I'm getting errors like this:


/home/rossberg/Devel/brlcad/src/libged/wdb_obj.c: In function ‘wdb_vls_col_pr4v’:
/home/rossberg/Devel/brlcad/src/libged/wdb_obj.c:276:6: error: passing argument 4 of ‘bu_sort’ from incompatible pointer type [-Werror]
In file included from /home/rossberg/Devel/brlcad/src/libged/wdb_obj.c:44:0:
/home/rossberg/Devel/brlcad/include/bu.h:6347:23: note: expected ‘int (*)(const void *, const void *, void *)’ but argument is of type ‘int (*)(void * const,  void * const,  void *)’

Daniel Rossberg on December 20 2013 14:02 UTCTask Needs More Work

One of the mentors has sent this task back for more work. Talk to the mentor(s) assigned to this task to satisfy the requirements needed to complete this task, submit your work again and mark the task as complete once you re-submit your work.

Peter Amidonon December 20 2013 15:20 UTCReady for review

The work on this task is ready to be reviewed.

Daniel Rossberg on December 20 2013 15:24 UTCthere is still a qsort left

Look at the comments ;)

Daniel Rossberg on December 20 2013 15:25 UTCTask Needs More Work

One of the mentors has sent this task back for more work. Talk to the mentor(s) assigned to this task to satisfy the requirements needed to complete this task, submit your work again and mark the task as complete once you re-submit your work.

Peter Amidonon December 20 2013 15:38 UTCReady for review

The work on this task is ready to be reviewed.

Daniel Rossberg on December 20 2013 15:48 UTCTask Closed

Congratulations, this task has been completed successfully.