Renamed from rgslffi
Posted by colby

fig 1 - Testing of Ruby FFI wrappers for GSL against results from direct C calls

Wrapping FFI based ruby calls to GSL requires handling 1000+ functions with their various features of calling arguments and returns. That's an error prone business and I wanted to have tests that would automatically check that my wrappers results match up with results from calling GSL functions within a C program.[1]

This made me depressed.

I was looking at having to hand code C programs to generate answers from functions like, "gsl_complex_sqrt_real(2.0)" (which is (1.4142135623731,0.0) by the by). And then another set of Ruby programs that would cross check those answers against my FFI wrappered calls to GSL. That's a lot of extra coding (see fig 1 for an individual test).

I chewed on this for several days, and when I had time to work on GSL4r again, I decided to add a GSL4r::Harness module, which would include the following methods:

  • write_c_tests
  • compile_c_tests
  • run_c_tests
Posted by colby

I was stumped for a few hours on passing FFI::Structs into external routines, luckily, this post, 'Functions returning structures' (groups/google/ruby-ffi), tipped me off by showing how to return a struct by value:

From the C code:

    typedef struct
        int r, g, b, a;