typedef (type alias) and ctypes

Yosifov Pavel aquagnu at gmail.com
Sat Feb 7 08:50:18 EST 2009


I try to create type aliases, like typedef in C (a specially aliases
to ctypes objects). This case:

>>> some_type = c_ulong
>>> oth_type = c_ulong

works in all cases but not with type qualification:

>>> t1 = c_ulong # reference to c_ulong, nothing else :(
>>> t2 = c_ulong
>>> x = t1()
>>> y = t2()
>>> type(x)==type(y)
True

This trivial way for typedef doesn't allow to determine real type and
it's absolutely right :)

>>> t1 = type('t1',(c_ulong,),{})
>>> t2 = type('t2',(c_ulong,),{})
>>> x = t1()
>>> y = t2()
>>> type(x)==type(y)
False

The problem:
1st way work in complex using of ctypes (interfacing with some DLLs),
but doesn't allow to determine real type!
2st way allows to determine real type, but "access violation reading
0x0000000C'" occurs in some DLL calls!

Question: what "warts", errors are in 2nd way (may be reason of access
violation)?

--
Pavel



More information about the Python-list mailing list