Stefan Krah added the comment: 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). ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue15986> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com