Eliminate any library global variable #6BRL-CAD
Status: ClosedTime to complete: 100 hrs Mentors: Mihai Neacsu, IshwerdasTags: C, global, cleanup, code refactoring, reduction

BRL-CAD is a very large mature code base and as with such body of code, issues creep in over time that are undesirable. One such issue is the introduction of global variables. They are often a short-term crutch that allows some feature to be implemented quickly, but they become a long-term burden.

All you need to do is eliminate any one of them that is declared in a header and accessed in more than one file. That means static globals don't count and variables declared global in one file but not used anywhere else also don't count. That said, we try to make it clear where our shared globals are at by putting their definitions in one place (see references below).

You also must preserve the behavior and capabilities of code that was using the global and remove the variable cleanly. That is to say, for example, that if there was a global variable storing a date string that is printed, you can't just eliminate the variable and remove the line that printed the variable -- you'd probably replace the code printing the date with a function or pass the date in from calling code.

This task is to eliminate just ONE global variable in any of our libraries. If you're quick and clever, you'll notice that some globals are VERY simple to eliminate while others can be complicated with thousands of lines of code needing to get updated.

Submit a patch file

References:
  • src/libbu/globals.c
  • src/libbn/globals.c
  • src/librt/globals.c
  • http://brlcad.org/wiki/Patches
Modify:
  • What you'll have to modify completely depends on how you're going to remove the global.
Uploaded Work
File name/URLFile sizeDate submitted
gci_remove_globals.patch2.6 KBJanuary 17 2015 09:42 UTC
gci_remove_globals_v2.patch2.6 KBJanuary 17 2015 22:43 UTC
Comments
Jacob Lon January 16 2015 10:11 UTCTask Claimed

I would like to work on this task.

Daniel_R on January 16 2015 10:15 UTCTask Assigned

This task has been assigned to Jacob L. You have 78 hours to complete this task, good luck!

Jacob Lon January 16 2015 11:11 UTCClaim Removed

The claim on this task has been removed, someone else can claim it now.

Jacob Lon January 16 2015 21:12 UTCTask Claimed

I would like to work on this task.

Mihai Neacsu on January 16 2015 21:13 UTCTask Assigned

This task has been assigned to Jacob L. You have 67 hours to complete this task, good luck!

Jacob Lon January 17 2015 09:42 UTCReady for review

The work on this task is ready to be reviewed.

Sean on January 17 2015 12:59 UTCstatic

Jacob, this looks good, but you only moved the bu_n_malloc global.  To eliminate it, you must at least mark it static in malloc.c and you'll need to protect it from multithreaded access (bu_semaphore_acquire/bu_semaphore_release) when adding to it.


That said, anytime a function or global variable are not global scope, they should not have the bu_ prefix, so malloc_add() would be a better name.  Also suggest renaming to bu_malloc_get() so that it matches the convention in our HACKING file of LIB_GROUP_VERB() on function names.

Sean on January 17 2015 12:59 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.

Jacob Lon January 17 2015 22:43 UTCReady for review

The work on this task is ready to be reviewed.

Sean on January 18 2015 02:51 UTCTask Closed

Congratulations, this task has been completed successfully.