Skip to content
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

Structs with bitfields are incorrectly generated #70

Open
yduf opened this issue Aug 29, 2020 · 1 comment
Open

Structs with bitfields are incorrectly generated #70

yduf opened this issue Aug 29, 2020 · 1 comment

Comments

@yduf
Copy link

yduf commented Aug 29, 2020

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.

@kojix2
Copy link

kojix2 commented Jun 30, 2021

Same problem.

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

2 participants