libgpiod: rust bindings and bindgen issue with C enums

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi!

The rust bindings are now in the master branch and I started working
on some additional changes for v2. Among other: using C enum types
explicitly in the core library as suggested by Kent as even though the
C standard says:

---
The expression that defines the value of an enumeration constant shall
be an integer constant expression that has a value representable as an
int.
---

and virtually all compilers store enum variables as signed integers,
modern compilers can spot some errors when using explicit types and it
also benefits IDEs which can interpret them better than ints.

That however led to a problem I'm seeing with rust bindings: bindgen
seems to set the type of an enum constant to ::std::os::raw::c_uint
unless that enum has at least one value explicitly set to a negative
number, in which case the type is ::std::os::raw::c_int.

In order to allow gpiod_line_request_get_value() to still return an
error, I added an additional value to enum gpiod_line_value:
GPIOD_LINE_VALUE_INVALID = -1. Now this one enum in bindgen generated
code has become c_int while all others are still c_uint which - as you
can imagine - leads to all kinds of build-time errors due to strong
typing.

As enums are naturally signed integers in the C world - can we somehow
make bindgen default to c_int for all enum types?

Bartosz



[Index of Archives]     [Linux SPI]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux