Victor Stinner schrieb:
> Le Friday 31 October 2008 14:13:01 Christian Heimes, vous avez écrit :
>> ctypes is also missing utilities to write code that works on 32 and
>> 64bit platforms. Without a tool like
>> http://pypi.python.org/pypi/ctypes_configure it's very hard and tedious
>> to avoid and fix segfaults.
> 
> I wrote some ctypes binding and some ctypes tools are missing. The most 
> important lacks are:
>  - get_errno()
>  - size_t and <stdint.h> types
> 
> You may be interrested by my modules:

Some of the problems you list here have already been fixed in Python 2.6:

> 
> get errno value:
> http://python-ptrace.hachoir.org/trac/browser/trunk/ptrace/ctypes_errno.py
> (ctypes_support has a get_errno function)

A new calling convention has been added for *safe* access to errno.

> open the C library:
> http://python-ptrace.hachoir.org/trac/browser/trunk/ptrace/ctypes_libc.py
> (ok, code is trivial, it's not critical to integrate it to ctypes)

This code is not in ctypes, but with Python2.6 it will also work on windows.

> *size_t* and <stdint.h> types!
> http://python-ptrace.hachoir.org/trac/browser/trunk/ptrace/ctypes_stdint.py
> (my module is incomplete, some types are missing)

Well, the signed types are named c_int8, c_uint8, and so on.
size_t is named c_size_t, please look into Lib/ctypes/__init__.py.
IIRC, these types are present event longer.

> Some functions to ease ctypes development:
> http://python-ptrace.hachoir.org/trac/browser/trunk/ptrace/ctypes_tools.py
>  - bytes2type() and bytes2array() are useful to convert a bytes array
>    to a ctypes object

There are also new ctypes methods in Python 2.6 .from_buffer() and 
.from_buffer_copy()
which should cover this use case.

An example from your module:

> 124   def bytes2type(bytes, type):
> 125       """
> 126       Cast a bytes string to an objet of the specified type.
> 127       """
> 128       return cast(bytes, POINTER(type))[0]
> 129   

Personally I would prefer to spell out 'cast(bytes, POINTER(type))[0]' instead 
of
documenting and learning what bytes2type() does.

> Should I open issues?
> 

Please decide yourself.

Thanks,
Thomas

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to