Description
I am working on a rust wrapper for a c library and there is one place I have to go and manually edit the bindgen file after generation. The problem is a packed enum that is then used in a struct. Bindgen is tagging the enum with #[repr(i32)]
, but because it is a packed enum, it should be #[repr(u8)]
or similar. This causes the struct which uses the enum to be too large on the rust side and cause a segfault when attempting to access the enum member of the struct.
compiling on windows
a simplified version of the c file:
typedef __pragma(pack(push, 1)) enum __pragma(pack(pop)) {
a,
b,
c,
} aaa;
typedef struct {
/* other fields */
aaa field;
} bbb;
I'm using rustified enums which work really well for my use case. after generation, I have to manually change the bindgen output file enum tag from repr(i32) to repr(u8) and I have to change the size of the struct from 88usize
to 80usize
and change the offset of the field from 80usize
to 78usize