Skip to content

Structs with bitfields are incorrectly generated #70

@yduf

Description

@yduf

Hello,

I was just bitten by the fact that when translating structs, bitfields are not interpreted properly.
(I am using the libgen wrapper but I don't think it matters in this case).

For eg fuse_file_info

struct fuse_file_info {
	int flags;
	unsigned int writepage : 1;
	unsigned int direct_io : 1;
...
}

is translated to

struct fuse_file_info {
    flags : LibC::Int
    writepage : LibC::UInt
    direct_io : LibC::UInt
...
}

And as such, assignment like fi.writepage = 0 may have a lot of side effect, ranging from incorrect value to stack smashing, due to the misalignment of the resulting structure compared to original definition.

I saw that there was a closed discussion on the matter on crystal side #3898.

Currently I am not sure how to address that on my code.

I don't know if it is possible,
but it would be nice at least, if crystal_lib would be able to issue warning or error message when bitfields are encoutered, so that the discovery is not delayed too much...

Or ideally, even if there is no bitfield support in crystal, that a placeholder is put into the structure, so that resulting translation is compatible in term of memory layout.

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