haskell / c2hs

c2hs is a pre-processor for Haskell FFI bindings to C libraries
http://hackage.haskell.org/package/c2hs
Other
199 stars 50 forks source link

unnamed struct elements and union elements not supported #230

Open dpreed opened 5 years ago

dpreed commented 5 years ago

The following style of struct is relatively common in C interfaces, using the unnamed structure or union as a holder for items without requiring an intermediate qualifier:

struct foo { union { int x; double y; void (*foo) z(void); }; int more; } bar;

The names bar.x, bar.y and bar.z are all valid, and they all refer to the same location within the struct. The name bar.more has an offset from the beginning of the structure calculated as the max of sizes of x, y, and z.

C2HS currently doesn't handle this correctly at all. Note: I have coded up a smallish patch that handles this correctly. Once I'm satisfied that it tests correctly, I will submit a pull request. But I wanted to get the issue on record, if only to be able to give the test for the bug a name in the test-bugs category.

dpreed commented 5 years ago

A pull request (#233) has been submitted for the maintainers' consideration. Works like a charm for me, allowing me to interface to Linux interfaces like the KVM ioctls.