2004-09-16 Thomas Heller * (Message): ctypes 0.9.1 released. * (Message): 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', 'strist') on other systems. (source\callproc.c): The Extend_Error_Info() function has been fixed - sometimes is displayed weird error messages like 'TypeError: function takes 5 arguments (1 given)' when an UnicodeEncodingError was raised. When internal processing of an argument for a function call fails, the new ctypes.ArgumentError exception is raised. 2004-09-15 Thomas Heller * ctypes\__init__.py: CDLL and subclasses now accept an optional second handle parameter. If this is supplied, it is used instead of calling LoadLibrary() or dlopen() to get one. * source\callproc.c: Important fix - sometimes pointers to arguments in function call have been free'd too early, especially when argtypes have been specified for functions. 2004-09-07 Thomas Heller * (Message): Fix 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. 2004-09-01 Thomas Heller * (Message): A pythonapi object has been added to the ctypes package. On windows, it is bound to the python dll, on other systems it is bound to the current process. It allows to access C Python api functions. py_object is the ctypes type corresponding to the C 'PyObject *' type. * ctypes: It is now possible to call cdecl functions with more arguments than the length of the argtypes attribute, even if this is set. This allows specify argtypes for functions like sprintf(). 2004-08-27 Thomas Heller * ctypes: Accept integer addresses, uncode strings, and strings in the c_char_p and c_wchar_p constructor and as c_char_p and c_wchar_p fields in Structures. strings are automatically decoded to unicode, and unicode is automatically encoded in strings if needed. Integer addresses are *not* accepted in function parameter lists, they must before be converted to c_char_p or c_wchar_p. 2004-08-26 Thomas Heller * source\callproc.c: Implemented Py_INCREF and Py_DECREF as functions. * ctypes\__init__.py: 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! 2004-08-20 Thomas Heller * (Message): Add the PyDLL class and pydll object to ctypes, they will expose functions using FUNCFLAG_PYTHONAPI allowing to call Python api functions. * source/cfield.c: Add accessors for 'O' typecode (which converts to/from python objects). * (Message): Implement the FUNCFLAG_PYTHONAPI flag which allows to call Python API functions with ctypes. Somewhat tricky - we have to keep the thread state during the call, and we have to make sure to return failure if the Python error flag has been set. 2004-08-19 Thomas Heller * (Message): the alignment function was not exported by the ctypes module. It returns the alignment requirements in bytes of a type or instance. * source/callproc.c: The _ctypes.call_function function, although private and deprecated, has been put back in - it is used by Gary Bishop's readline module. 2004-08-18 Thomas Heller * (Message): 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. * MANIFEST.windows.in: Added the include files which were missing from the source distribution. 2004-07-28 Thomas Heller * (Message): CopyComPointer is no longer a function exported from the _ctypes dll/shared lib, instead it is a normal Python function implemented in the _ctypes extension. This allows to build _ctypes as a builtin module. 2004-07-23 Thomas Heller (Message): ctypes 0.9.0 released. * (Message): c_int, c_uint and other integer variants now use the masked functions when converting Python integers/longs to C integers. This has the effect that the value of the integer is never checked, it is silently truncated. * (Message): ctypes now requires Python 2.3 or better. * (Message): Add some 'hacks' which make ctypes work on big-endian platforms. On platforms with strict alignment rules, there are still some crashes (solaris sparc). 2004-xx-xx Thomas Heller * (Message): Conversion to libffi is now complete. libffi is now used on all platforms. unittests pass, at least on x86 architectures. Tested on Linux, FreeBSD. 2004-05-07 Thomas Heller * (Message): Tag the HEAD with before_libffi_2004_05_07 * ctypes\source\callbacks.c: Callback functions can now return c_char and c_char_p data types. 2004-05-06 Thomas Heller * Finally fixed the sometimes shortened traceback prints when an exception occurrs in a callback function - only the exception class was printed, not the value. 2004-05-03 Thomas Heller * win32\com\client.py: Add a COMError class, compatible to that used in pywin32. If _DispMethod.__call__ fails, a COMError is now raised, with more detailed information. * ctypes\__init__.py: The WinError function does now accept an optional second parameter, this is the textual error description. 2004-04-20 Thomas Heller * ctypes\__init__.py: c_buffer is silently deprecated, and replaced by create_string_buffer. A similar function create_unicode_buffer has been added. * source\callproc.c: Improve the error reporting for access violations - the message now reports the faulting address in charge, and whether reading or writing failed. 2004-02-05 Thomas Heller * source\_ctypes.c: Added c_char_p_from_param and c_void_p_from_param class methods to the _SimpleCData type. These are later used as from_param class methods for the c_void_p, c_char_p, and POINTER(c_char) types. Added unittests for them. * (CFuncPtr_set_argtypes): It is now possible to assign None to a functions argtypes attribute. This clear the argtypes sequence, after that the function can be called with any number and types of arguments. 2004-01-20 Thomas Heller * source\_ctypes.c: Moved the test functions into a seaparate Python extension module _ctypes_test.c. Setup-script and unittests updated. 2003-10-30 Thomas Heller * source\_ctypes.c: Finally added cycle GC support for all the base-types implemented in this module, without breaking the test-suite. 2003-10-24 Thomas Heller * win32\com\__init__.py: Changes to prevent crashes when the interpreter exits, and COM pointers are to be cleaned up. The problem was that CoUninitialize was registered by the atexit module, and this runs *before* all the modules are cleared out and the final Release() call on the COM pointers is done. The solution is to create an object in the com\__init__.py module which will call CoUninitialize when it's refcount reaches zero. Even better would probably be to make this an attribute of the sys module, because sys is cleaned last, only __builtins__ is cleaned later. 2003-07-18 Thomas Heller * ctypes\__init__.py (c_buffer): Accept int as well as long integers as the size argment for c_buffer. 2003-07-09 Thomas Heller * source\_ctypes.c: Prevent crashes on pointer(IUnknown()) call. 2003-07-08 Thomas Heller * source\_ctypes.c: Finally fixed this nasty pointer bug. The incomplete pointer sample from the tutorial now works. 2003-07-03 Thomas Heller * ctypes\__init__.py: Use __getitem__ to load libaries or get functions. gpib = cdll["gpib-32.dll"], and gpib["Function-With-A-Strange_Name@@@"]. Suggested by Chuck Esterbrook. 2003-06-24 Thomas Heller * source\_callbacks.c: Callback functions can now return simple data types like floats, doubles, long long and so on. Before, only integers were returned. 2003-06-12 Thomas Heller * source\*.c: On Windows, structures and unions can now be passed *by value* to function calls. 2003-06-03 Thomas Heller * source\_ctypes.c: Raise AttributeError instead of ValueError when a function is not found in a dll. Suggested by Chuck Esterbrook. 2003-05-16 Thomas Heller * source\_ctypes.c: Fix some (but not all) problems with pointer instance and types. * source\_ctypes.c: Make the restype atribute of functions readable. VisualPython's debugger had problems if it was not. Contributed by Nick Adams. * ctypes\__init__.py: Fix the name of the void pointer type, it's c_void_p not c_voidp (but leave the old name intact) * source\cfield.c: The c_wchar_p.from_param method did not accept None (NULL pointer as parameter). Unittests updated. * source\_ctypes.c: ctypes' types now have a in_dll() class method. It allows to access values exported from dlls. Also added a unittest. Often requested feature. 2003-05-14 Thomas Heller * win32\com\register.py: Register the script with the absolute pathname. 2003-03-11 Thomas Heller * ctypes/source: CFuncPtr changes: The _argtypes_ attribute is now optional (but required if you want to construct callbacks). CFuncPtr now has two contructors: CFuncPtr(callable), and CFuncPtr(funcname, dll). So CFuncPtr can now completely replace both CFunction (for callbacks) and DynFunction (for dll functions). 2003-03-07 Thomas Heller * ctypes: The CFuncPtr type now supports cyclic garbage collection, it is especially useful here, but GC support for other types is not far away. * ctypes: The CFunction subclass _types_ attribute does not accept format characters any more, types like c_int, c_char_p and so on must now be used. The same change has been made for the argtypes and restype attribute of dll functions. A new base type CFuncPtr was added. This will soon make CFunction and DynFunction obsolete. Subclass creation requires an _argtype_ attribute mush must be a sequence of types like c_int or c_charp, a _flags_attribute which must be a bitwise or of FUNCFLAG_CDECL, FUNCFLAG_STDCALL and FUNCFLAG_HRESULT (the latter two only on Windows) to specify the calling convention, and an optional _restype_ attribute which defaults to c_int. The plan is to create some factory functions like STDCALL() and CDECL() which return CFuncPtr subclasses, this is useful to define these subclasses in an expression instead of a class statement, also it probably makes it easier to use. Obscure change: If the CFunction instance uses c_int in the _types_ sequence, it will now receive a standard Python integer and no longer a c_int instance if it is called. (CFuncPtr instances behave in the same way). 2003-03-04 Thomas Heller * ctypes.py (cdll): Changed the __getattr__ implementations for all *DLL classes to raise an attribute error if the requested name both starts and ends with a double underscore. Thanks to Wolfgang Strobl for pointing at this. 2003-02-26 Thomas Heller * source\_ctypes.c: Removed the unused from_bytes stuff. * source\_ctypes.c (CString_new): The buffer is only initialized to the bytes from the string is passed in, if any. The terminating NUL byte is always set. This allows large c_string instances to be created with minimum overhead. * source: Moved code from _ctypes.c into the new files cfield.c (field accessors) and stgdict.c (storage info dict). 2003-02-25 Thomas Heller * source\callproc.c: Added call_cdeclfunction. * source\_ctypes.c: addressof() now accepts CFunction instances. 2003-02-24 Thomas Heller * source\_ctypes.c: c_string() and c_wstring() signatures changed. If the first parameter is a string, an optional positive integer can be used as second parameter to specify the size of the internal buffer. This size does NOT include the terminating NUL byte. Since sizeof() does now support c_string and c_wstring, len() is no longer supported (c_string and c_wstring have never really been sequences). * source\_ctypes.c: Made sizeof() and addressof() work with c_string and c_wstring objects. * source\callproc.c: PyCArgObjects now have a readonly _obj attribute, this is the object passed to the byref() call. Useful for implmenting custom argument type checking in Python. 2003-02-20 Thomas Heller * unittests\test_strings.py (StringTestCase.test_sized_strings): Added tests for the new c_string constructor. * source\_ctypes.c (CString_new): The c_string constructor can now be called with a positive integer, this will create an empty string buffer of the specified length (+ 1 for a terminating NUL character). * source\_ctypes.c (CString_new): It's no longer possible to call c_string with None as argument. It created a string of zero size, but this doesn't seem to make sense. 2003-02-19 Thomas Heller * source/_ctypes.c, ctypes.py: Add a c_voidp data type, which represents (void) pointers to memory locations. The value attribute is a Python integer (or a long). 2003-02-18 Thomas Heller * (Repository): Added a packages directory, and created a ctcom package. See separate changelog. 2003-02-11 Thomas Heller * source/_ctypes.c: The .from_parameter method of POINTER classes now accept Array instances containing elements of exactly the same type. * source/callproc.c: Make sure call_comproc checks for valid number of arguments before calling _CallProc. 2003-02-07 Thomas Heller * Version 0.4.0 released and uploaded. * source/_ctypes.c: PointerType_new, ArrayType_new, SimpleType_new, and CFunctionType_new did not check for NULL result from PyType_Type.tp_new() call. This call will fail in Python 2.3 when 'object' is listed as the first base class with a TypeError: MRO conflict among bases. Spotted by Greg Chapman. 2003-02-05 Thomas Heller * The 'raw' and 'value' properties of c_wstring are back, also fixed some severe bugs (it seems c_wstring never worked correctly). Added unittests. * Fixed a problem in c_string: The NUL byte at the buffer end could be overwritten. Added unittests for c_strings. Per suggestion from Niki Spahiev, CFieldObjects now have a readonly size and offset property. Added short docs for them. 2003-01-31 Thomas Heller * Item deletion on Array or Pointer instances did crash with a NULL pointer access. Added unittest for this, and also for Arrays. 2003-01-28 Thomas Heller * source\_ctypes.c: Dangerous code checked in. Pointer instances can point to a single data item, or they can point to an array of values. Back in the distant past ;-), I had a SetSize() method, which would enable indexes != 0. Don't know when and why I removed it, but I need it again. Should it have to be enabled explicitely? Would be better, it seems. Note that there's no corresponding ass_item implementation with indexes != 0. This means, we can get and change the items the pointer points to, if they are mutable, but not replace the items by different ones. 2003-01-24 Thomas Heller * (several): Fixed the alignment and size of the compound datatypes Structure, Union, and hopefully also Array. 2003-01-23 Thomas Heller * source/_ctypes.c: Raise a TypeError if a SimpleCData type or a CDataType is specified as a CFunction's restype. * source/_ctypes.c: CFunction now has a from_param class method. This means that CFunction subclasses can now be used in the argtypes attribute, and so typechecking is done. * unittests: Rewrote the tests from doctest to pyunit. 2003-01-21 Thomas Heller * source/: Merged in these changes from the C_FAST_CARGS branch: ConvParam returns PyCArgObject instances now. Fixed the _as_parameter_ properties of Array, CString, and CFunction so that they 'return' PyCArgObject instances instead of magic tuples. Added a public 'P' fielddescriptor, which is mostly for internal use. The 's' rettype value for functions is probably useless, because functions return *pointers* to strings (char *), not strings. Adapted all the unittests to work, and also changed the samples. 2003-01-20 Thomas Heller * source/*.[ch]: Introduced PyCArgObject objects, which contain a Python object itself and also the data converted to C. This replaces the magic 3-tuples, and should be somewhat faster because no two conversions take place. This is now used by SimpleType_from_param(), byref(), and Pointer_as_parameter(), and is understood by ConvParam(). In the long run this should be the only thing (besides primitive Python data types with trivial conversions) used by ConvParam(). Also ConvParam should probably *return* these things. 2003-01-17 Thomas Heller * source/_ctypes.c: Rewrite of SimpleType_from_param complete. unittests/test_parameters.py shows that it does the right things in most cases. * (Repository): Moved everything from local CVS to the SF repository, and restructured the directories.