Serhiy Storchaka added the comment: Here are things which support bytes instances only:
1. Constructor and setter of the "value" attribute of NUL terminated char buffer. >>> p = create_string_buffer(b"Hello") >>> p.value b'Hello' >>> p.raw b'Hello\x00' >>> p.value = b'Bye' >>> p.value b'Bye' >>> p.raw b'Bye\x00o\x00' >>> create_string_buffer(bytearray(b"Hello")) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/serhiy/py/cpython-3.4/Lib/ctypes/__init__.py", line 63, in create_string_buffer raise TypeError(init) TypeError: bytearray(b'Hello') >>> p.value = bytearray(b'Hi') Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: bytes expected instead of bytearray instance But setter of the "raw" attribute accepts arbitrary bytes-like objects. >>> p.raw = bytearray(b'Hi') >>> p.raw b'Hie\x00o\x00' The patch adds support of bytearray here. It would be not so easy to add support for arbitrary bytes-like objects, and due to NUL-terminating it can be confused. I even not sure that support of bytearray is needed here. 2. Constructor of NUL terminated wchar buffer (create_unicode_buffer). Actually this doesn't work. Bytes argument is accepted, but then rejected in internal setting function. This is a bug, bytes should be removed here. 3. c_wchar_p.from_param() accepts bytes argument, but then reject it in internal function. This is a bug, bytes should be removed here. 4. c_void_p.from_param() accepts bytes and bytearray arguments, but then reject bytearray in internal function. This is a bug, either bytearray should be rejected here, or support of bytearray should be added in internal function (very easy, the patch does this). Adding support of arbitrary bytes-like objects is more complicated. 5. c_char_p.from_param() accepts bytes argument. Adding support for bytearray or arbitrary bytes-like objects has same complexity as in c_void_p.from_param(). 6. Bytes arguments of call_function(), call_cdeclfunction() and CopyComPointer() are implicitly converted to pointers. It is easy to add support of bytearray, and more complicated for arbitrary bytes-like objects. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue10803> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com