def test_ctypes_pointers(): # TODO: unifiy with test_llvm_pointers # Test pointer conversion for typename in typenames: ty = getattr(ts, tyname(typename)) cty = getattr(cts, tyname(typename)) assert ct(ts.pointer(ty)) == cts.pointer(cty) p = ts.pointer(ts.pointer(ts.int_)) cp = cts.pointer(cts.pointer(cts.int_)) # See if the conversion works assert ct(p) == cp
def test_llvm_pointers(): # Test pointer conversion for typename in typenames: ty = getattr(ts, tyname(typename)) lty = getattr(lts, tyname(typename)) assert llvmt(ts.pointer(ty)) == lts.pointer(lty) p = ts.pointer(ts.pointer(ts.int_)) lp = lts.pointer(lts.pointer(lts.int_)) # See if the conversion works assert llvmt(p) == lp
ts.void: None, ts.string_: ctypes.c_char_p, } def cint(name): ty = getattr(ts, name) cname = "c_int" if ty.signed else "c_uint" nb2ctypes[ty] = getattr(ctypes, cname + str(ty.itemsize * 8)) for name in map(tyname, universe.int_typenames): cint(name) globals().update( (tyname(ty.typename), cty) for ty, cty in nb2ctypes.iteritems()) float_, double, longdouble = float32, float64, float128 ctypes_map = dict((cty, ty) for ty, cty in nb2ctypes.iteritems()) # ______________________________________________________________________ @consing def struct_(fields, name=None, readonly=False, packed=False): class Struct(ctypes.Structure): _fields_ = fields if packed: _pack_ = 1 return Struct
ts.float64: ctypes.c_double, # ts.float128: ctypes.c_longdouble, ts.object_: ctypes.py_object, ts.void: None, ts.string_: ctypes.c_char_p, } def cint(name): ty = getattr(ts, name) cname = "c_int" if ty.signed else "c_uint" nb2ctypes[ty] = getattr(ctypes, cname + str(ty.itemsize * 8)) for name in map(tyname, universe.int_typenames): cint(name) globals().update((tyname(ty.typename), cty) for ty, cty in nb2ctypes.iteritems()) # float_, double, longdouble = float32, float64, float128 float_, double = float32, float64 ctypes_map = dict((cty, ty) for ty, cty in nb2ctypes.iteritems()) if ctypes.c_double == ctypes.c_longdouble: # Ctypes and numpy can disagree on longdouble. If ctypes assume # double == longdouble, make sure we don't assume longdouble, and then # later use the numpy representation ctypes_map[ctypes.c_double] = ts.float64 # ______________________________________________________________________
def convert(ts1, ts2, conversion_type, typenames): for typename in typenames: t1 = getattr(ts1, tyname(typename)) t2 = getattr(ts2, tyname(typename)) assert ts.convert(conversion_type, t1) == t2, (t1, t2)
def convert(ts1, ts2, conversion_type, typenames): for typename in typenames: t1 = getattr(ts1, tyname(typename)) t2 = getattr(ts2, tyname(typename)) converted = ts1.convert(conversion_type, t1) assert converted == t2, (str(t1), str(converted), str(t2))
ts.float64: ctypes.c_double, ts.float128: ctypes.c_longdouble, ts.object_: ctypes.py_object, ts.void: None, ts.string_: ctypes.c_char_p, } def cint(name): ty = getattr(ts, name) cname = "c_int" if ty.signed else "c_uint" nb2ctypes[ty] = getattr(ctypes, cname + str(ty.itemsize * 8)) for name in map(tyname, universe.int_typenames): cint(name) globals().update((tyname(ty.typename), cty) for ty, cty in nb2ctypes.iteritems()) float_, double, longdouble = float32, float64, float128 ctypes_map = dict((cty, ty) for ty, cty in nb2ctypes.iteritems()) # ______________________________________________________________________ @consing def struct_(fields, name=None, readonly=False, packed=False): class Struct(ctypes.Structure): _fields_ = fields if packed: _pack_ = 1 return Struct
return llvm.core.Type.float() elif itemsize == 8: return llvm.core.Type.double() else: return l_longdouble size = universe.default_type_sizes.__getitem__ unittypes = {} for typename in universe.int_typenames: unittypes[typename] = lint(typename, size(typename)) for typename in universe.float_typenames: unittypes[typename] = lfloat(typename, size(typename)) unittypes["void"] = llvm.core.Type.void() globals().update((tyname(name), ty) for name, ty in unittypes.iteritems()) #------------------------------------------------------------------------ # Exposed types #------------------------------------------------------------------------ # @consing # llvm types don't hash in python 3 in llvmpy 0.11.2 def struct_(fields, name=None, readonly=False, packed=False): if packed: struct = llvm.core.Type.packed_struct else: struct = llvm.core.Type.struct return struct([field_type for field_name, field_type in fields]) # @consing