bufferprocs_py37.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // Copyright (C) 2018 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. /*
  4. PSF LICENSE AGREEMENT FOR PYTHON 3.7.0
  5. 1. This LICENSE AGREEMENT is between the Python Software Foundation ("PSF"), and
  6. the Individual or Organization ("Licensee") accessing and otherwise using Python
  7. 3.7.0 software in source or binary form and its associated documentation.
  8. 2. Subject to the terms and conditions of this License Agreement, PSF hereby
  9. grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce,
  10. analyze, test, perform and/or display publicly, prepare derivative works,
  11. distribute, and otherwise use Python 3.7.0 alone or in any derivative
  12. version, provided, however, that PSF's License Agreement and PSF's notice of
  13. copyright, i.e., "Copyright © 2001-2018 Python Software Foundation; All Rights
  14. Reserved" are retained in Python 3.7.0 alone or in any derivative version
  15. prepared by Licensee.
  16. 3. In the event Licensee prepares a derivative work that is based on or
  17. incorporates Python 3.7.0 or any part thereof, and wants to make the
  18. derivative work available to others as provided herein, then Licensee hereby
  19. agrees to include in any such work a brief summary of the changes made to Python
  20. 3.7.0.
  21. 4. PSF is making Python 3.7.0 available to Licensee on an "AS IS" basis.
  22. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF
  23. EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND DISCLAIMS ANY REPRESENTATION OR
  24. WARRANTY OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE
  25. USE OF PYTHON 3.7.0 WILL NOT INFRINGE ANY THIRD PARTY RIGHTS.
  26. 5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON 3.7.0
  27. FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS A RESULT OF
  28. MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON 3.7.0, OR ANY DERIVATIVE
  29. THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
  30. 6. This License Agreement will automatically terminate upon a material breach of
  31. its terms and conditions.
  32. 7. Nothing in this License Agreement shall be deemed to create any relationship
  33. of agency, partnership, or joint venture between PSF and Licensee. This License
  34. Agreement does not grant permission to use PSF trademarks or trade name in a
  35. trademark sense to endorse or promote products or services of Licensee, or any
  36. third party.
  37. 8. By copying, installing or otherwise using Python 3.7.0, Licensee agrees
  38. to be bound by the terms and conditions of this License Agreement.
  39. */
  40. #ifndef BUFFER_REENABLE_H
  41. #define BUFFER_REENABLE_H
  42. #include "sbkpython.h"
  43. #include "shibokenmacros.h"
  44. #ifdef Py_LIMITED_API
  45. // The buffer interface has been added to limited API in 3.11, (abstract.h, PYSIDE-1960,
  46. // except some internal structs).
  47. # if Py_LIMITED_API < 0x030B0000
  48. struct Pep_buffer
  49. {
  50. void *buf;
  51. PyObject *obj; /* owned reference */
  52. Py_ssize_t len;
  53. Py_ssize_t itemsize; /* This is Py_ssize_t so it can be
  54. pointed to by strides in simple case.*/
  55. int readonly;
  56. int ndim;
  57. char *format;
  58. Py_ssize_t *shape;
  59. Py_ssize_t *strides;
  60. Py_ssize_t *suboffsets;
  61. void *internal;
  62. };
  63. using getbufferproc =int (*)(PyObject *, Pep_buffer *, int);
  64. using releasebufferproc = void (*)(PyObject *, Pep_buffer *);
  65. using Py_buffer = Pep_buffer;
  66. # else // < 3.11
  67. using Pep_buffer = Py_buffer;
  68. # endif // >= 3.11
  69. // The structs below are not part of the limited API.
  70. struct PepBufferProcs
  71. {
  72. getbufferproc bf_getbuffer;
  73. releasebufferproc bf_releasebuffer;
  74. };
  75. struct PepBufferType
  76. {
  77. PyVarObject ob_base;
  78. void *skip[17];
  79. PepBufferProcs *tp_as_buffer;
  80. };
  81. # if Py_LIMITED_API < 0x030B0000
  82. /* Maximum number of dimensions */
  83. #define PyBUF_MAX_NDIM 64
  84. /* Flags for getting buffers */
  85. #define PyBUF_SIMPLE 0
  86. #define PyBUF_WRITABLE 0x0001
  87. /* we used to include an E, backwards compatible alias */
  88. #define PyBUF_WRITEABLE PyBUF_WRITABLE
  89. #define PyBUF_FORMAT 0x0004
  90. #define PyBUF_ND 0x0008
  91. #define PyBUF_STRIDES (0x0010 | PyBUF_ND)
  92. #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES)
  93. #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES)
  94. #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES)
  95. #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES)
  96. #define PyBUF_CONTIG (PyBUF_ND | PyBUF_WRITABLE)
  97. #define PyBUF_CONTIG_RO (PyBUF_ND)
  98. #define PyBUF_STRIDED (PyBUF_STRIDES | PyBUF_WRITABLE)
  99. #define PyBUF_STRIDED_RO (PyBUF_STRIDES)
  100. #define PyBUF_RECORDS (PyBUF_STRIDES | PyBUF_WRITABLE | PyBUF_FORMAT)
  101. #define PyBUF_RECORDS_RO (PyBUF_STRIDES | PyBUF_FORMAT)
  102. #define PyBUF_FULL (PyBUF_INDIRECT | PyBUF_WRITABLE | PyBUF_FORMAT)
  103. #define PyBUF_FULL_RO (PyBUF_INDIRECT | PyBUF_FORMAT)
  104. #define PyBUF_READ 0x100
  105. #define PyBUF_WRITE 0x200
  106. /* End buffer interface */
  107. LIBSHIBOKEN_API PyObject *PyMemoryView_FromBuffer(Pep_buffer *info);
  108. #define Py_buffer Pep_buffer
  109. #define PyObject_CheckBuffer(obj) \
  110. ((PepType_AS_BUFFER(Py_TYPE(obj)) != NULL) && \
  111. (PepType_AS_BUFFER(Py_TYPE(obj))->bf_getbuffer != NULL))
  112. LIBSHIBOKEN_API int PyObject_GetBuffer(PyObject *ob, Pep_buffer *view, int flags);
  113. LIBSHIBOKEN_API void PyBuffer_Release(Pep_buffer *view);
  114. # endif // << 3.11
  115. # define PepType_AS_BUFFER(type) \
  116. reinterpret_cast<PepBufferType *>(type)->tp_as_buffer
  117. using PyBufferProcs = PepBufferProcs;
  118. #else // Py_LIMITED_API
  119. using PepBufferProcs = PyBufferProcs;
  120. # define PepType_AS_BUFFER(type) ((type)->tp_as_buffer)
  121. #endif // !Py_LIMITED_API
  122. #endif // BUFFER_REENABLE_H