shibokenbuffer.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright (C) 2016 The Qt Company Ltd.
  2. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
  3. #ifndef SHIBOKEN_BUFFER_H
  4. #define SHIBOKEN_BUFFER_H
  5. #include "sbkpython.h"
  6. #include "shibokenmacros.h"
  7. namespace Shiboken::Buffer
  8. {
  9. enum Type {
  10. ReadOnly,
  11. WriteOnly,
  12. ReadWrite
  13. };
  14. /**
  15. * Creates a new Python buffer pointing to a contiguous memory block at
  16. * \p memory of size \p size.
  17. */
  18. LIBSHIBOKEN_API PyObject *newObject(void *memory, Py_ssize_t size, Type type);
  19. /**
  20. * Creates a new <b>read only</b> Python buffer pointing to a contiguous memory block at
  21. * \p memory of size \p size.
  22. */
  23. LIBSHIBOKEN_API PyObject *newObject(const void *memory, Py_ssize_t size);
  24. /**
  25. * Check if is ok to use \p pyObj as argument in all function under Shiboken::Buffer namespace.
  26. */
  27. LIBSHIBOKEN_API bool checkType(PyObject *pyObj);
  28. /**
  29. * Returns a pointer to the memory pointed by the buffer \p pyObj, \p size is filled with the buffer
  30. * size if not null.
  31. *
  32. * If the \p pyObj is a non-contiguous buffer a Python error is set.
  33. */
  34. LIBSHIBOKEN_API void *getPointer(PyObject *pyObj, Py_ssize_t *size = nullptr);
  35. /**
  36. * Returns a copy of the buffer data which should be free'd.
  37. *
  38. * If the \p pyObj is a non-contiguous buffer a Python error is set.
  39. * nullptr is returned for empty buffers.
  40. */
  41. LIBSHIBOKEN_API void *copyData(PyObject *pyObj, Py_ssize_t *size = nullptr);
  42. } // namespace Shiboken::Buffer
  43. #endif