1
"""Run-time calculation of offset into Python Numeric (old) structures
3
Numeric Python, by fortuitous chance, puts the one thing
4
we need precisely as the first value in the structure beyond the
5
PyObject * header, so that it's exactly that many bytes from the
6
pointer value for the object...
10
def dataPointerFunction( ):
11
"""Calculate the data-pointer offset in the Numeric object header"""
12
offset = object.__basicsize__
13
from_address = ctypes.c_void_p.from_address
14
def dataPointer( data):
15
"""Return pointer-to-data + offset"""
16
return from_address( id( data ) + offset ).value
19
dataPointer = dataPointerFunction()
21
if __name__ == "__main__":
23
test = Numeric.arange( 0,200, 1,'i' )
24
aType = ctypes.c_int * 200
25
test2 = aType.from_address( dataPointer( test ) )
26
assert test == test2, (test,test2)
b'\\ No newline at end of file'