Ok, I have the following C interfaces:
struct TagStruct {
char strTag[80];
double val1 = 0.0;
double val2 = 0.0;
double val3 = 0.0;
};
void* config_data(Type t, const char* xml,
int nCi, const TagStruct* ci,
int nIn, const TagStruct* in
int nOut, const TagStruct* out)
which is called once for every Model. This code is called exactly once per Model and returns a void* handler for it's internal data structures. It also memcpy the TagStruct arrays internally.
It's correspondent code in rust is:
#[derive(Debug)]
#[repr(C)]
pub struct TagStruct {
pub str_tag: *mut c_char,
pub val1: c_double,
pub val2: c_double,
pub val3: c_double,
}
extern "C" {
pub fn adicionar_modelo(
t: Type,
xml: *const c_char,
nCi: c_int,
ci: *const TagStruct,
nIn: c_int,
in: *const TagStruct,
nOut: c_int,
out: *const TagStruct
) -> *mut c_void;
}
The following functions are called continually, where set updates the internal data structures, step runs a step of the number crunching and get copies the internal data structures to it's inputs:
void step(void* ptr);
void set (void* ptr, const TagStruct* in);
void get(void* ptr, TagStruct* in, TagStruct* out);
And the corresponding rust code:
extern "C" {
pub fn set(
ptr: *mut c_void,
in: *const TagStruct
);
pub fn get(
ptr: *mut c_void,
in: *mut TagStruct,
out: *mut TagStruct
);
pub fn step(ptr: *mut c_void);
}
I should also say that I'm used to working with this code through java's JNA/JNI and directly through C++ and these errors never happened.