Add support for unknown integer types. #652
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Aims and background
This PR adds support for using integer types of unknown properties (size, alignment requirements, signedness).
For example, POSIX specifies that
off_t
is a signed integer type, but does not specify its size. And it specifies thatdev_t
is an integer type, but does not specify its size or signedness. This PR makes it possible to bind and use both types nonetheless.Similarly, the C standard allows implementations to choose the properties of
enum
types. Implementations sometimes also include extensions (such as GCC's-fshort-enums
) that allow users to vary those properties. That implementation freedom can make it difficult to use enums from ctypes (cf. #650). This PR makes it easier to bind and use such types in ctypes code.Design
This PR adds two new functions,
signed
andunsigned
, to theCtypes.TYPE
signature:Users can apply these functions in type-binding functions to bind integer types of unknown properties:
and unpack the bindings to build modules with information about those types:
The signatures for
Dev_t
andFlags
include all the standard integer operations (fromSigned.S
orUnsigned.S
) as well as atyp
value that makes it possible to use the new types to create values, bind functions, etc.Limitations
Since the type binding interface currently requires that functors such as
Types
above are applicative, it is not possible to unpackDev_t
andFlags
inside the functor.