[Python-3000] py3k-struni: proposition to fix ctypes bug, ctypes c_char creates bytes

Guido van Rossum guido at python.org
Wed Aug 8 18:45:38 CEST 2007


Thanks! Would you mind submitting to SF and assigning to Thomas Heller
(theller I think)?

And update the wiki (http://wiki.python.org/moin/Py3kStrUniTests)

On 8/8/07, Victor Stinner <victor.stinner at haypocalc.com> wrote:
> 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/
>
> _______________________________________________
> Python-3000 mailing list
> Python-3000 at python.org
> http://mail.python.org/mailman/listinfo/python-3000
> Unsubscribe: http://mail.python.org/mailman/options/python-3000/guido%40python.org
>
>
>


-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list