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 martin.panter
Recipients benrg, martin.panter, meador.inge, santoso.wijaya, theller, vstinner
Date 2014-07-31.11:30:47
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1406806247.79.0.0915292007301.issue11427@psf.upfronthosting.co.za>
In-reply-to
Content
For the record, I have been (ab?)using the “c_char_p” type to get the address of immutable byte strings without copying memory:

>>> from ctypes import *
>>> data = b"123\x00abc"
>>> pubyte = cast(c_char_p(data), POINTER(c_ubyte))
>>> address = addressof(pubyte.contents)
>>> string_at(address, 7)
b'123\x00abc'
>>> # 2nd instance has same address, rather than memory copy:
... cast(c_char_p(data), c_void_p).value == address
True

In to the documentation, “c_char_p” is only defined for zero-terminated strings, but it seems to also work for strings with embedded zero bytes. However it does not work for “bytearray” objects (“from_buffer” should work instead), nor memory views.
History
Date User Action Args
2014-07-31 11:30:47martin.pantersetrecipients: + martin.panter, theller, vstinner, meador.inge, santoso.wijaya, benrg
2014-07-31 11:30:47martin.pantersetmessageid: <1406806247.79.0.0915292007301.issue11427@psf.upfronthosting.co.za>
2014-07-31 11:30:47martin.panterlinkissue11427 messages
2014-07-31 11:30:47martin.pantercreate