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 benrg
Recipients benrg, theller
Date 2011-03-07.07:49:00
SpamBayes Score 1.195255e-11
Marked as misclassified No
Message-id <1299484141.33.0.394671210882.issue11429@psf.upfronthosting.co.za>
In-reply-to
Content
ctypes accepts bytes objects as arguments to C functions, but not bytearray objects. It has its own array types but seems to be unaware of array.array. It doesn't even understand memoryview objects. I think that all of these types should be passable to C code.

Additionally, while passing a pointer to a bytes value to a C function is easy, it's remarkably difficult to pass that same pointer with an offset added to it. I first tried byref(buf, offset), but byref wouldn't accept bytes. Then I tried addressof(buf), but that didn't work either, even though ctypes is clearly able to obtain this address when it has to. After banging my head against the wall for longer than I care to think about, I finally came up with something like byref((c_char*length).from_buffer(buf), offset). But that broke in 3.2. After wasting even more time, I came up with addressof(cast(buf, POINTER(c_char)).contents) + offset. This is nuts. There should be a simple and documented way to do this. My first preference would be for the byref method, since it was the first thing I tried, and would have saved me the most time. Ideally both byref and addressof should work for bytes objects as they do for ctypes arrays (and also for bytearray, memoryview, etc.)
History
Date User Action Args
2011-03-07 07:49:01benrgsetrecipients: + benrg, theller
2011-03-07 07:49:01benrgsetmessageid: <1299484141.33.0.394671210882.issue11429@psf.upfronthosting.co.za>
2011-03-07 07:49:00benrglinkissue11429 messages
2011-03-07 07:49:00benrgcreate