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 skrah
Recipients amaury.forgeotdarc, belopolsky, dabeaz, josh.r, martin.panter, meador.inge, pitrou, skrah
Date 2014-09-27.12:51:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1411822314.86.0.471388420322.issue15986@psf.upfronthosting.co.za>
In-reply-to
Content
Sometimes I've used memoryview slices to model pointers in C code.

memoryview could have limited number methods for pointer arithmetic on the
buf pointer. Arithmetic would return new slices, so in fact everything would
be safe with respect to bounds checking and life-cycle management.


Not completely safe of course once you pass the pointer to ctypes, but
the following is less likely to happen:

m = memoryview(b"123")
ptr = m.buf
del m
my_ctypes_func(ptr)


This is safer, since the view itself is the pointer:

m = memoryview(b"123")
my_ctypes_func(m)


Of course you could still subvert the second idiom by using ptr = int(m).
History
Date User Action Args
2014-09-27 12:51:55skrahsetrecipients: + skrah, amaury.forgeotdarc, belopolsky, pitrou, meador.inge, dabeaz, martin.panter, josh.r
2014-09-27 12:51:54skrahsetmessageid: <1411822314.86.0.471388420322.issue15986@psf.upfronthosting.co.za>
2014-09-27 12:51:54skrahlinkissue15986 messages
2014-09-27 12:51:54skrahcreate