Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect ffi-binding to gsl_multifit_function_fdf #82

Closed
hombit opened this issue Aug 24, 2020 · 4 comments
Closed

Incorrect ffi-binding to gsl_multifit_function_fdf #82

hombit opened this issue Aug 24, 2020 · 4 comments

Comments

@hombit
Copy link

hombit commented Aug 24, 2020

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:

rust-GSL/src/ffi/solvers.rs

Lines 150 to 168 in b06c673

#[repr(C)]
pub struct gsl_multifit_function_fdf {
pub f:
Option<extern "C" fn(x: *mut gsl_vector, params: *mut c_void, f: *mut gsl_vector) -> c_int>,
pub df: Option<
extern "C" fn(x: *mut gsl_vector, params: *mut c_void, df: *mut gsl_matrix) -> c_int,
>,
pub fdf: Option<
extern "C" fn(
x: *mut gsl_vector,
params: *mut c_void,
f: *mut gsl_vector,
df: *mut gsl_matrix,
) -> c_int,
>,
pub n: size_t,
pub p: size_t,
pub params: *mut c_void,
}

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

@GuillaumeGomez
Copy link
Owner

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.

@hombit
Copy link
Author

hombit commented Aug 25, 2020

Can the ffi bindings be generated by bindgen?

@GuillaumeGomez
Copy link
Owner

Yes but I don't like the generated code.

@GuillaumeGomez
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants