Properly support C99's `_Bool` in libgirepository
Currently we assume that _Bool
can fit into a gboolean
(which is an alias for int
). This is not really the case:
- any
_Bool
value can fit into agboolean
- not all
gboolean
values can fit into a_Bool
(though you should never store anything butTRUE
orFALSE
into agboolean
) -
sizeof _Bool
is not defined in the C standard, except that it must be big enough to storetrue
andfalse
Additionally, there are some issues with how libgirepository deal with _Bool
:
- the introspection scanner will emit
_Bool
as:<type name="gboolean" c:type="_Bool"/>
- the FFI type for
gboolean
isffi_type_uint
, which is not really accurate to the ABI - libgirepository takes anything that is smaller than a
long
and stuffs into along
as the result offfi_call()
—counting on the calling code to read just the interesting bits; of course, this might yield different results depending on optimisations outside of our control
While we can keep the equivalence between _Bool
and gboolean
at the GType level, libgirepository and the GIR data should be more accurate in their representation at the C boundary.