Hi Bruce,
On 30 July 2015 at 09:36, <
bme...@ska.ac.za> wrote:
> I've partially written a solution, but it's a bit ugly because I'm not sure
> how to introspect a primitive type to determine whether it is signed,
> unsigned, float etc. Does cffi contain this sort of introspection
> information? At the moment I'm just making a list of all primitives of each
> type based on reading the cffi source.
Yes, even if not very cleanly, you can know:
tp = ffi.typeof(T)
assert tp.kind == "primitive" # either some int or some float
if tp.cname in ('float', 'double', 'long double'):
print 'it is a float of size', ffi.sizeof(tp)
else:
print 'it is an integer of size', ffi.sizeof(tp)
x = int(ffi.cast(tp, -1))
if x == -1:
print 'it is signed'
elif x == 1:
print 'it is Bool'
else:
assert x > 1
print 'it is unsigned'
A bientôt,
Armin.