~matobet/pyopengl/Python3

« back to all changes in this revision

Viewing changes to arrays/_numeric.py.bak

  • Committer: matobet at gmail
  • Date: 2010-06-26 14:11:04 UTC
  • Revision ID: matobet@gmail.com-20100626141104-k011ofmltgiiu60g
Initial

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""Run-time calculation of offset into Python Numeric (old) structures
 
2
 
 
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...
 
7
"""
 
8
import ctypes
 
9
 
 
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
 
17
    return dataPointer
 
18
 
 
19
dataPointer = dataPointerFunction()
 
20
 
 
21
if __name__ == "__main__":
 
22
    import Numeric 
 
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'