New submission from benrg <benrud...@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 <rep...@bugs.python.org>
<http://bugs.python.org/issue11427>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to