gtamba / spice_rub

Ruby wrapper for the NASA-JPL CSPICE library via SciRuby
Other
9 stars 3 forks source link

Error handling from within C #12

Open gtamba opened 8 years ago

gtamba commented 8 years ago

As of now, any SPICE exception causes rb_raise() from within C to signal the error. This isn't a very good practice due to the call bypassing any memory cleanup code subsequent to the rb_raise() statement, as pointed out by Will Levine here.

SpiceRub uses NMatrix very frequently to represent Cartesian vectors and state/position arrays, so this could be a potential cause of memory problems in the future. I would like to switch to an error code system where the C function returns an error code which is parsed in Ruby as suggested in the above thread. There might possibly be a better way to this.

gtamba commented 8 years ago

As far as possible I have tried to call xfree() before checking if a SPICE Error has occurred.

v0dro commented 8 years ago

Good thought. I think we can use the design of your system in other Ruby gems using C extensions.