PageRenderTime 61ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/pypy/module/cpyext/memoryobject.py

https://bitbucket.org/pypy/pypy/
Python | 40 lines | 34 code | 4 blank | 2 comment | 1 complexity | 290e406a02cab79a93b633cd11bff146 MD5 | raw file
Possible License(s): AGPL-3.0, BSD-3-Clause, Apache-2.0
  1. from pypy.module.cpyext.api import (cpython_api, Py_buffer, CANNOT_FAIL,
  2. build_type_checkers)
  3. from pypy.module.cpyext.pyobject import PyObject
  4. from rpython.rtyper.lltypesystem import lltype
  5. PyMemoryView_Check, PyMemoryView_CheckExact = build_type_checkers("MemoryView", "w_memoryview")
  6. @cpython_api([PyObject], PyObject)
  7. def PyMemoryView_FromObject(space, w_obj):
  8. return space.call_method(space.builtin, "memoryview", w_obj)
  9. @cpython_api([PyObject], PyObject)
  10. def PyMemoryView_GET_BASE(space, w_obj):
  11. # return the obj field of the Py_buffer created by PyMemoryView_GET_BUFFER
  12. raise NotImplementedError
  13. @cpython_api([PyObject], lltype.Ptr(Py_buffer), error=CANNOT_FAIL)
  14. def PyMemoryView_GET_BUFFER(space, w_obj):
  15. """Return a pointer to the buffer-info structure wrapped by the given
  16. object. The object must be a memoryview instance; this macro doesn't
  17. check its type, you must do it yourself or you will risk crashes."""
  18. view = lltype.malloc(Py_buffer, flavor='raw', zero=True)
  19. # TODO - fill in fields
  20. '''
  21. view.c_buf = buf
  22. view.c_len = length
  23. view.c_obj = obj
  24. Py_IncRef(space, obj)
  25. view.c_itemsize = 1
  26. rffi.setintfield(view, 'c_readonly', readonly)
  27. rffi.setintfield(view, 'c_ndim', 0)
  28. view.c_format = lltype.nullptr(rffi.CCHARP.TO)
  29. view.c_shape = lltype.nullptr(Py_ssize_tP.TO)
  30. view.c_strides = lltype.nullptr(Py_ssize_tP.TO)
  31. view.c_suboffsets = lltype.nullptr(Py_ssize_tP.TO)
  32. view.c_internal = lltype.nullptr(rffi.VOIDP.TO)
  33. '''
  34. return view