home *** CD-ROM | disk | FTP | other *** search
/ Hackers Magazine 57 / CdHackersMagazineNr57.iso / Software / Multimedia / k3d-setup-0.7.11.0.exe / lib / site-packages / OpenGL / arrays / _numeric.py < prev    next >
Encoding:
Python Source  |  2008-12-07  |  856 b   |  27 lines

  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)
  27.