ctypes News - http://starship.python.net/crew/theller/ctypes.html Changes in 0.9.1 ================ ctypes 0.9.1 should be fully compatible again with Gary Bishop's readline module which is also used by IPython. ctypes changes The internal conversions that ctypes does between unicode and strings can now use a specified encoding and error handling. A set_conversion_mode() function allows to set them, it returns the previous values. The inital values are ('mbcs', 'ignore') on Windows, and ('ascii', 'strict') on other systems. When internal processing of an argument for a function call fails, the new ctypes.ArgumentError is raised. CDLL and its subclasses now accept an optional second handle parameter. If this is supplied, it is used instead of calling LoadLibrary() or dlopen() to get one. Sometimes objects have been freed too early when calling functions where argtypes have been set. Fixed the create_unicode_buffer function - it was returning c_char arrays instead of c_wchar arrays. Both create_string_buffer and create_unicode_buffer can now be called with string and unicode instances, they will do the needed conversions themselves. ctypes now allows calling Python C api functions. The 'pythonapi' symbol should be used to access these functions, this will automatically use the correct calling convention and exception handling. The 'py_object' type is the ctypes variant of 'PyObject *'. This feature should also work if you are using a static python build. It is now possible to call cdecl functions with more arguments than the length of the argtypes sequence specifies - this allows to provide functions like sprintf() with a proper prototype. It is now possible to create strings or unicode strings if you have the integer address by calling c_char_p(address) or c_wchar_p(address). Integers can also be assigned to structure fields of type c_char_p and c_wchar_p. c_char_p and c_wchar_p both accept strings and unicode strings - if needed they are encoded or decoded using 'strict' error handling. The _ctypes.call_function function, although private and deprecated, has been put back in - it is used by Gary Bishop's readline module. Array and pointer instances now support slicing, for pointers only getslice is implemented (setslice is too dangerous, probably). Slices are represented as lists of the elements, except for character and unicode character pointer and arrays, where strings resp. unicode strings are used instead. On windows, the include files were missing from the source distribution. The alignment function was not exported by the ctypes module. It returns the alignment requirements in bytes of a type or instance. ctypes.com changes Applied a patch from Bruce Dodson which fixes an infinite loop in readtlb.py if a typelib references types defined in another typelib. readtlb still generates bad code for such cases, but the results could be edited by hand if the dependencies can be sorted out. ctypes now caches the types that WINFUNCTYPE and CFUNCTYPE creates, to avoid unneeeded creation of classes. This makes importing files containing a lot of COM interfaces (like the ones that the readtlb tool generates) a lot (10 x) faster. COM servers now print a short usage message when they are run without the /regserver or /unregserver flag. VARIANT does now handle the COM DATE type (VT_DATE) as Python datetime. VARIANT now handles integers and longs correctly - if longs are too large they are stored as doubles (VT_R8). Integers are now stored as VT_I4 instead of VT_INT. Cache the types that WINFUNCTYPE and CFUNCTYPE creates, to avoid creation of a lot of similar classes. Rearrange the code to use try:except: instead of dict.get(xxx, None), the former is faster if lookup mostly succeeds - as is the case for POINTER imo. This makes importing large COM files created by readtlb a lot faster, since WINFUNCTYPE is called for every COM method. The python wrapper for mshtml.tlb, which contains nearly 600 interfaces, now imports in 3 seconds instead of 40! Array and POINTER instance now support slicing, for POINTER only getslice is implemented (setslice is too dangerous, probably). Slices are accepted or returned as lists of the elements, except for character and unicode character pointer and arrays, where strings resp. unicode strings are used - much more convenient. Changes in 0.9.0 ================ ctypes now requires Python 2.3 or higher, Python 2.2 is no longer supported. The big change is that ctypes now uses the same code base on all platforms, many, many bug should have been fixed this way on non-windows systems. The destribution now contains libffi, no need to find, download, build and install a compatible version. There have been lots of improvements and additions both to ctypes itself, and to the ctypes.com windows framework, too many to remember now and document here. Most prominent additions to ctypes.com are: A ctypes.com.client module supporting dynamic dispatch An internet explorer toolband sample Many improvements to the stoplite sample Other Versions: no news recorded in this file! Please see the CVS commit messages. Version 0.4.0, 2003-02-07: This an intermediate release, there is still a lot to be done. Changes: ctypes works with Python 2.2 and Python 2.3 now. Structure and Union fields have now readonly .size and .offset properties, see the docs. POINTER instances can now be indexed as if they point to arrays of objects instead of only a single object. CFunction instances now have a .from_param class method. (This is the protocol which allows to validate and convert function call arguments from Python to C - in other words, you can now use a CFunction subclass in the argtype attribute for a function from a DLL to specify the type of the callback function. Does anyone understand this?) Argument conversion from Python to C is somewhat faster now. I added a lot of unittests, which not only check for bugs, but also 'describe the current behaviour'. Unittest rocks! Lots and lots of bugs and potential crashes have been fixed: Alignment and sizes of structures and unions is now correct as far as I can see. Assigning Python numbers to mutable integer types (c_short, c_int, c_long and so on) now correctly checks for valid range, you can no longer assign a negative Python number to an unsigned C data type for example. General News: I moved the sources from local CVS to SourceForge CVS repository. Version 0.3.5, 2003-01-14: Runs under linux now, and hopefully also other systems where libffi works. More changes, like enabling the Python garbage collector on CFunction objects. Version 0.2.0, 2002-11-12: Allows to assign callables to functions' restype attribute. Refactored _CallProc, for much clearer and less buggy code. Plugged some gross memory leaks. License is MIT, not BSD.