homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients benrg, meador.inge, santoso.wijaya, theller, vstinner
Date 2011年11月29日.17:57:48
SpamBayes Score 3.5836987e-08
Marked as misclassified No
Message-id <1322589469.34.0.265240935939.issue11427@psf.upfronthosting.co.za>
In-reply-to
Content
> 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.
History
Date User Action Args
2011年11月29日 17:57:49vstinnersetrecipients: + vstinner, theller, meador.inge, santoso.wijaya, benrg
2011年11月29日 17:57:49vstinnersetmessageid: <1322589469.34.0.265240935939.issue11427@psf.upfronthosting.co.za>
2011年11月29日 17:57:48vstinnerlinkissue11427 messages
2011年11月29日 17:57:48vstinnercreate

AltStyle によって変換されたページ (->オリジナル) /