rust-GSL icon indicating copy to clipboard operation
rust-GSL copied to clipboard

Incorrect ffi-binding to gsl_multifit_function_fdf

Open hombit opened this issue 4 years ago • 3 comments

GSL header gsl_multifit_nlin.h specifies gsl_multifit_function_fdf as

struct gsl_multifit_function_fdf_struct
{
  int (* f) (const gsl_vector * x, void * params, gsl_vector * f);
  int (* df) (const gsl_vector * x, void * params, gsl_matrix * df);
  int (* fdf) (const gsl_vector * x, void * params, gsl_vector * f, gsl_matrix *df);
  size_t n;       /* number of functions */
  size_t p;       /* number of independent variables */
  void * params;  /* user parameters */
  size_t nevalf;  /* number of function evaluations */
  size_t nevaldf; /* number of Jacobian evaluations */
};

typedef struct gsl_multifit_function_fdf_struct gsl_multifit_function_fdf ;

but Rust ffi binding misses last two fields: https://github.com/GuillaumeGomez/rust-GSL/blob/b06c6732fd1155825141b28844f764cb396907dc/src/ffi/solvers.rs#L150-L168

I noticed this when saw undefined behaviour of my Rust code: some of my variables are changed by MultiFitFSolver::set(), but I didn't passed them there. Probably it also can cause problems described by #67

hombit avatar Aug 24 '20 07:08 hombit

I'm currently writing the script to check that the Rust bindings are correct. I realized that a few types/functions had mismatching definitions compared to the C one.

GuillaumeGomez avatar Aug 24 '20 08:08 GuillaumeGomez

Can the ffi bindings be generated by bindgen?

hombit avatar Aug 25 '20 07:08 hombit

Yes but I don't like the generated code.

GuillaumeGomez avatar Aug 25 '20 08:08 GuillaumeGomez

This issue was fixed when we (finally) switched to automated FFI code generation.

GuillaumeGomez avatar Jul 26 '23 14:07 GuillaumeGomez