[New-bugs-announce] [issue11427] ctypes from_buffer no longer accepts bytes

benrg report at bugs.python.org
Mon Mar 7 08:11:25 CET 2011


New submission from benrg <benrudiak at gmail.com>:

In Python 3.1.3, (c_char*5).from_buffer(b'abcde') worked. In 3.2 it fails with "TypeError: expected an object with a writable buffer interface".

This seems to represent a significant decrease in the functionality of ctypes, since, if I understand correctly, it has no notion of a const array or a const char. I used from_buffer with a bytes argument in 3.1 and it was far from obvious how to port to 3.2 without introducing expensive copying. I understand the motivation behind requiring a writable buffer, but I think it's a bad idea. If you take this to its logical conclusion, it should not be possible to pass bytes or str values directly to C functions, since there's no way to be sure they won't write through the pointer.

----------
assignee: theller
components: ctypes
messages: 130229
nosy: benrg, theller
priority: normal
severity: normal
status: open
title: ctypes from_buffer no longer accepts bytes
type: behavior
versions: Python 3.2

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11427>
_______________________________________


More information about the New-bugs-announce mailing list