Skip to content

Wrong type size on packed enum #3195

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

Open
lemleyautomation opened this issue Apr 16, 2025 · 0 comments
Open

Wrong type size on packed enum #3195

lemleyautomation opened this issue Apr 16, 2025 · 0 comments

Comments

@lemleyautomation
Copy link

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

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

No branches or pull requests

1 participant