Hi, I'm trying to build complete FFI bindings for Hyperic Sigar.
It does some memory management on it's own for certain cases, such as lists of CPUs and so on, and unfortunately there are no examples of doing similar things / working with more compelx FFI structures are available (or at least I could find those).
Look more carefully at the example code you linked. They define a sigar_cpu_list_t on the stack, then pass a pointer to that. &cpulist in Rust would be &mut cpulist. They do not define a pointer to sigar_cpu_list_t.
Yes, sorry, I indeed mixed up two procedures while copying the code... Both of them actually are very similar other than that are for different types.
I've switched to default implementation as @DanielKeep suggested in order to keep the implementation as in the given example.
thank you lot for suggestion, extremely helpful!
Although I'm still struggling with the nested C structures, is there any documented way to reference a C array or maybe work with offsets?
If you meant C structs(that's what I understood), you might want to look into repr(C).
Edit: I realized that might not help you if you didn't see the repr(C) being used before, here is an example.
thanks! Yes, I'm aware of repr(C), so far I've translated:
from
typedef struct {
char vendor[128];
char model[128];
int mhz;
int mhz_max;
int mhz_min;
sigar_uint64_t cache_size;
int total_sockets;
int total_cores;
int cores_per_socket;
} sigar_cpu_info_t;
typedef struct {
unsigned long number;
unsigned long size;
sigar_cpu_info_t *data;
} sigar_cpu_info_list_t;
I'm reading through the offset docs, so far the int fields (number and size) are working fine, although data is always 0x8 so I can't seem to deref. Will read the C code, might give a hint.