Skip to content

Wrong type size on packed enum #3195

Open
@lemleyautomation

Description

@lemleyautomation

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions