[Python-3000] py3k-struni: proposition to fix ctypes bug, ctypes c_char creates bytes
Victor Stinner
victor.stinner at haypocalc.com
Wed Aug 8 18:14:05 CEST 2007
Hi,
I hear Guido's request to fix last py3k-struni bugs. I downloaded subversion
trunk and started to work on ctypes tests.
The problem is that ctypes c_char (and c_char_p) creates unicode string
instead of byte string. I attached a proposition (patch) to change this
behaviour (use bytes for c_char).
So in next example, it will display 'bytes' and not 'str':
from ctypes import c_buffer, c_char
buf = c_buffer("abcdef")
print (type(buf[0]))
Other behaviour changes:
- repr(c_char) adds a "b"
eg. repr(c_char('x')) is "c_char(b'x')" instead of "c_char('x')"
- bytes is mutable whereas str is not:
this may break some modules based on ctypes
Victor Stinner aka haypo
http://hachoir.org/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: py3k-struni-ctypes.diff
Type: text/x-diff
Size: 4992 bytes
Desc: not available
Url : http://mail.python.org/pipermail/python-3000/attachments/20070808/d4bfd476/attachment.bin
More information about the Python-3000
mailing list