Message148588
> I just want to call my C function.
You can use something else than ctypes_array.from_buffer(buffer). ctypes_array.from_buffer() creates a read-write object which can be used to modify the buffer. You cannot pass a read-only object to ctypes_array.from_buffer().
> I'm pretty sure that I verified that this code worked in 3.1.3 before
> opening this bug, but it's been a while.
If it was possible, it was a bug. You cannot modify a read-only object, like bytes, because it would lead to inconsistent object and may lead your program to a crash, even if you don't call C functions.
Example in pure Python:
>>> import ctypes
>>> T=(ctypes.c_uint8*4)
>>> B=bytearray(4)
>>> x=T.from_buffer(B)
>>> B
bytearray(b'\x00\x00\x00\x00')
>>> x[0]=9
>>> x[2]=100
>>> B
bytearray(b'\t\x00d\x00')
>>> list(x)
[9, 0, 100, 0]
B is modified when x[index] is modified.
--
A bug tracker is not the right place to ask help with ctypes. |
|
Date |
User |
Action |
Args |
2011-11-29 17:57:49 | vstinner | set | recipients:
+ vstinner, theller, meador.inge, santoso.wijaya, benrg |
2011-11-29 17:57:49 | vstinner | set | messageid: <1322589469.34.0.265240935939.issue11427@psf.upfronthosting.co.za> |
2011-11-29 17:57:48 | vstinner | link | issue11427 messages |
2011-11-29 17:57:48 | vstinner | create | |
|