oldbuffer.pxd 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # Legacy Python 2 buffer interface.
  2. #
  3. # These functions are no longer available in Python 3, use the new
  4. # buffer interface instead.
  5. cdef extern from "Python.h":
  6. cdef enum _:
  7. Py_END_OF_BUFFER
  8. # This constant may be passed as the size parameter to
  9. # PyBuffer_FromObject() or PyBuffer_FromReadWriteObject(). It
  10. # indicates that the new PyBufferObject should refer to base object
  11. # from the specified offset to the end of its exported
  12. # buffer. Using this enables the caller to avoid querying the base
  13. # object for its length.
  14. bint PyBuffer_Check(object p)
  15. # Return true if the argument has type PyBuffer_Type.
  16. object PyBuffer_FromObject(object base, Py_ssize_t offset, Py_ssize_t size)
  17. # Return value: New reference.
  18. #
  19. # Return a new read-only buffer object. This raises TypeError if
  20. # base doesn't support the read-only buffer protocol or doesn't
  21. # provide exactly one buffer segment, or it raises ValueError if
  22. # offset is less than zero. The buffer will hold a reference to the
  23. # base object, and the buffer's contents will refer to the base
  24. # object's buffer interface, starting as position offset and
  25. # extending for size bytes. If size is Py_END_OF_BUFFER, then the
  26. # new buffer's contents extend to the length of the base object's
  27. # exported buffer data.
  28. object PyBuffer_FromReadWriteObject(object base, Py_ssize_t offset, Py_ssize_t size)
  29. # Return value: New reference.
  30. #
  31. # Return a new writable buffer object. Parameters and exceptions
  32. # are similar to those for PyBuffer_FromObject(). If the base
  33. # object does not export the writeable buffer protocol, then
  34. # TypeError is raised.
  35. object PyBuffer_FromMemory(void *ptr, Py_ssize_t size)
  36. # Return value: New reference.
  37. #
  38. # Return a new read-only buffer object that reads from a specified
  39. # location in memory, with a specified size. The caller is
  40. # responsible for ensuring that the memory buffer, passed in as
  41. # ptr, is not deallocated while the returned buffer object
  42. # exists. Raises ValueError if size is less than zero. Note that
  43. # Py_END_OF_BUFFER may not be passed for the size parameter;
  44. # ValueError will be raised in that case.
  45. object PyBuffer_FromReadWriteMemory(void *ptr, Py_ssize_t size)
  46. # Return value: New reference.
  47. #
  48. # Similar to PyBuffer_FromMemory(), but the returned buffer is
  49. # writable.
  50. object PyBuffer_New(Py_ssize_t size)
  51. # Return value: New reference.
  52. #
  53. # Return a new writable buffer object that maintains its own memory
  54. # buffer of size bytes. ValueError is returned if size is not zero
  55. # or positive. Note that the memory buffer (as returned by
  56. # PyObject_AsWriteBuffer()) is not specifically aligned.