By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,974 Members | 1,913 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,974 IT Pros & Developers. It's quick & easy.

ctypes 0.9.1 released

P: n/a
ctypes 0.9.1 released - Sept 14, 2004
=====================================

Overview

ctypes is a ffi (Foreign Function Interface) package for Python
2.3 and higher.

ctypes allows to call functions exposed from dlls/shared libraries
and has extensive facilities to create, access and manipulate
simple and complicated C data types in Python - in other words:
wrap libraries in pure Python. It is even possible to implement C
callback functions in pure Python.

ctypes runs on Windows, MacOS X, Linux, Solaris, FreeBSD. It may
also run on other systems, provided that libffi supports this
platform.

On windows, ctypes contains a ctypes.com package which allows to
call and implement custom COM interfaces.
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.

Detailed changelogs are in CVS:

<http://cvs.sourceforge.net/viewcvs.py/ctypes/ctypes/ChangeLog?rev=HEAD>

<http://cvs.sourceforge.net/viewcvs.py/ctypes/ctypes/win32/com/ChangeLog?rev=HEAD>
Future plans

The ultimate purpose of the 0.9 release series is to shake out the
remaining bugs, especially on platforms I have no access to, and
to target a rock stable ctypes 1.0 release.

When ctypes 1.0 is released, the com framework will be split off
into a separate framework named 'comtypes'.
Download

Downloads are available in the sourceforge files section
<http://sourceforge.net/project/showfiles.php?group_id=71702>

Separate source distributions are available for windows and non-windows systems.
Please use the .zip file for Windows (it contains the ctypes.com framework),
and use the .tar.gz file for non-Windows systems (it contains the
complete cross-platform libffi sources).

Binary windows installers, which contain compiled extension
modules, are also available, be sure to download the correct one
for the Python version you are using.
Homepage

<http://starship.python.net/crew/theller/ctypes/>

Enjoy,

Thomas

Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Thomas Heller wrote:
ctypes 0.9.1 released - Sept 14, 2004
===================================== [...] The _ctypes.call_function function, although private and
deprecated, has been put back in - it is used by Gary Bishop's
readline module.


IPython uses heavily Gary's readline and had been bitten by this. Windows
users of ipython have already confirmed that ctypes 0.9.1 fixes the problem.
I'd just like to send you a quick thank you note for accomodating us :)

Cheers,

f
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.