From: Travis O. <oli...@ie...> - 2006-10-12 06:37:33
|
I made some fixes to the "asbuffer" code which let me feel better about exposing it in NumPy (where it is now named int_asbuffer). This code takes a Python integer and a size and returns a buffer object that points to that memory. A little test is performed by trying to read (and possibly write if a writeable buffer is requested) to the first and last elements of the buffer. Any segfault is trapped and used to raise a Python error indicating you can't use that area of memory. It doesn't guarantee you won't shoot yourself, but it does make it more difficult to segfault Python. Previously a simple int_asbuffer(3423423, 5) would have segfaulted (unless by chance you the memory area 3423423 happens to be owned by Python). I have not tested the code on other platforms to make sure it works as expected, so please try and compiled it. -Travis |