| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.GI.CodeGen.StructLayout
Description
Fix the memory layout of structs and unions.
When compiling the typelib, the typelib compiler (both
gi-compile-repository in GLib and g-ir-compiler in
gobject-introspection) makes two simplifications when computing
the layout of structs and unions:
- It ignores the width of bitfields: each bitfield is laid out as if it was a full member of its declared type.
- It ignores unions and structs declared inline (such as
union { ... } u;, or anonymous unions).
This leads to wrong struct sizes, and wrong offsets for the fields following the affected members. This affects the struct itself, and any struct or union embedding it. See https://github.com/haskell-gi/haskell-gi/issues/485.
The GIR files do contain the required information, so here we recompute the layout ourselves, following the rules of the C ABI. To make sure that we are not missing any information (fields that we could not parse, types of unknown size, ...), we first check that by laying out the struct in the same way that the typelib compiler does we reproduce the typelib data exactly. If this is not the case we keep the data from the typelib.
Documentation
The information about a named type that we need in order to compute layouts.
fixupStructLayouts :: Map Name Aggregate -> Map Name Aggregate Source #
Given the structs, unions, and other named types in scope,
return the structs and unions whose layout has been
corrected. Bitfields in the corrected structs and unions will
also have their fieldBitShift set.