]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-79315: Add Include/cpython/memoryobject.h header (#99723)
authorVictor Stinner <vstinner@python.org>
Wed, 23 Nov 2022 14:44:42 +0000 (15:44 +0100)
committerGitHub <noreply@github.com>
Wed, 23 Nov 2022 14:44:42 +0000 (15:44 +0100)
Move non-limited C API from Include/memoryobject.h to a new
Include/cpython/memoryobject.h header file.

Include/cpython/memoryobject.h [new file with mode: 0644]
Include/memoryobject.h
Makefile.pre.in
PCbuild/pythoncore.vcxproj
PCbuild/pythoncore.vcxproj.filters

diff --git a/Include/cpython/memoryobject.h b/Include/cpython/memoryobject.h
new file mode 100644 (file)
index 0000000..e2a1e16
--- /dev/null
@@ -0,0 +1,42 @@
+#ifndef Py_CPYTHON_MEMORYOBJECT_H
+#  error "this header file must not be included directly"
+#endif
+
+PyAPI_DATA(PyTypeObject) _PyManagedBuffer_Type;
+
+/* The structs are declared here so that macros can work, but they shouldn't
+   be considered public. Don't access their fields directly, use the macros
+   and functions instead! */
+#define _Py_MANAGED_BUFFER_RELEASED    0x001  /* access to exporter blocked */
+#define _Py_MANAGED_BUFFER_FREE_FORMAT 0x002  /* free format */
+
+typedef struct {
+    PyObject_HEAD
+    int flags;          /* state flags */
+    Py_ssize_t exports; /* number of direct memoryview exports */
+    Py_buffer master; /* snapshot buffer obtained from the original exporter */
+} _PyManagedBufferObject;
+
+
+/* memoryview state flags */
+#define _Py_MEMORYVIEW_RELEASED    0x001  /* access to master buffer blocked */
+#define _Py_MEMORYVIEW_C           0x002  /* C-contiguous layout */
+#define _Py_MEMORYVIEW_FORTRAN     0x004  /* Fortran contiguous layout */
+#define _Py_MEMORYVIEW_SCALAR      0x008  /* scalar: ndim = 0 */
+#define _Py_MEMORYVIEW_PIL         0x010  /* PIL-style layout */
+
+typedef struct {
+    PyObject_VAR_HEAD
+    _PyManagedBufferObject *mbuf; /* managed buffer */
+    Py_hash_t hash;               /* hash value for read-only views */
+    int flags;                    /* state flags */
+    Py_ssize_t exports;           /* number of buffer re-exports */
+    Py_buffer view;               /* private copy of the exporter's view */
+    PyObject *weakreflist;
+    Py_ssize_t ob_array[1];       /* shape, strides, suboffsets */
+} PyMemoryViewObject;
+
+/* Get a pointer to the memoryview's private copy of the exporter's buffer. */
+#define PyMemoryView_GET_BUFFER(op) (&((PyMemoryViewObject *)(op))->view)
+/* Get a pointer to the exporting object (this may be NULL!). */
+#define PyMemoryView_GET_BASE(op) (((PyMemoryViewObject *)(op))->view.obj)
index 19aec679a5fad16c5b9a8e21b3b9e56bd630b2f0..2c9146aa2b5b06ee2e5c54ec03f180a970e33a72 100644 (file)
@@ -6,20 +6,10 @@
 extern "C" {
 #endif
 
-#ifndef Py_LIMITED_API
-PyAPI_DATA(PyTypeObject) _PyManagedBuffer_Type;
-#endif
 PyAPI_DATA(PyTypeObject) PyMemoryView_Type;
 
 #define PyMemoryView_Check(op) Py_IS_TYPE((op), &PyMemoryView_Type)
 
-#ifndef Py_LIMITED_API
-/* Get a pointer to the memoryview's private copy of the exporter's buffer. */
-#define PyMemoryView_GET_BUFFER(op) (&((PyMemoryViewObject *)(op))->view)
-/* Get a pointer to the exporting object (this may be NULL!). */
-#define PyMemoryView_GET_BASE(op) (((PyMemoryViewObject *)(op))->view.obj)
-#endif
-
 PyAPI_FUNC(PyObject *) PyMemoryView_FromObject(PyObject *base);
 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
 PyAPI_FUNC(PyObject *) PyMemoryView_FromMemory(char *mem, Py_ssize_t size,
@@ -32,38 +22,10 @@ PyAPI_FUNC(PyObject *) PyMemoryView_GetContiguous(PyObject *base,
                                                   int buffertype,
                                                   char order);
 
-
-/* The structs are declared here so that macros can work, but they shouldn't
-   be considered public. Don't access their fields directly, use the macros
-   and functions instead! */
 #ifndef Py_LIMITED_API
-#define _Py_MANAGED_BUFFER_RELEASED    0x001  /* access to exporter blocked */
-#define _Py_MANAGED_BUFFER_FREE_FORMAT 0x002  /* free format */
-typedef struct {
-    PyObject_HEAD
-    int flags;          /* state flags */
-    Py_ssize_t exports; /* number of direct memoryview exports */
-    Py_buffer master; /* snapshot buffer obtained from the original exporter */
-} _PyManagedBufferObject;
-
-
-/* memoryview state flags */
-#define _Py_MEMORYVIEW_RELEASED    0x001  /* access to master buffer blocked */
-#define _Py_MEMORYVIEW_C           0x002  /* C-contiguous layout */
-#define _Py_MEMORYVIEW_FORTRAN     0x004  /* Fortran contiguous layout */
-#define _Py_MEMORYVIEW_SCALAR      0x008  /* scalar: ndim = 0 */
-#define _Py_MEMORYVIEW_PIL         0x010  /* PIL-style layout */
-
-typedef struct {
-    PyObject_VAR_HEAD
-    _PyManagedBufferObject *mbuf; /* managed buffer */
-    Py_hash_t hash;               /* hash value for read-only views */
-    int flags;                    /* state flags */
-    Py_ssize_t exports;           /* number of buffer re-exports */
-    Py_buffer view;               /* private copy of the exporter's view */
-    PyObject *weakreflist;
-    Py_ssize_t ob_array[1];       /* shape, strides, suboffsets */
-} PyMemoryViewObject;
+#  define Py_CPYTHON_MEMORYOBJECT_H
+#  include "cpython/memoryobject.h"
+#  undef Py_CPYTHON_MEMORYOBJECT_H
 #endif
 
 #ifdef __cplusplus
index 209a9b376a08c9e34701d0acc84a1a4872be70b4..5c49af36d86736913a66caeea15013e79159698e 100644 (file)
@@ -1585,6 +1585,7 @@ PYTHON_HEADERS= \
                $(srcdir)/Include/cpython/listobject.h \
                $(srcdir)/Include/cpython/longintrepr.h \
                $(srcdir)/Include/cpython/longobject.h \
+               $(srcdir)/Include/cpython/memoryobject.h \
                $(srcdir)/Include/cpython/methodobject.h \
                $(srcdir)/Include/cpython/modsupport.h \
                $(srcdir)/Include/cpython/object.h \
index 3c3ff406bdf0aed601ad25dc1c1d34364eff9c48..f62434370cfdf7294141fa2d8f2af534a153c6f8 100644 (file)
     <ClInclude Include="..\Include\cpython\listobject.h" />
     <ClInclude Include="..\Include\cpython\longintrepr.h" />
     <ClInclude Include="..\Include\cpython\longobject.h" />
+    <ClInclude Include="..\Include\cpython\memoryobject.h" />
     <ClInclude Include="..\Include\cpython\methodobject.h" />
     <ClInclude Include="..\Include\cpython\modsupport.h" />
     <ClInclude Include="..\Include\cpython\object.h" />
index 3ab7f31dff43f362607caf1ba8796731d84b3fd1..f44a1ad8550a382da7e748b1e4dcbbc385addfb1 100644 (file)
     <ClInclude Include="..\Include\cpython\longobject.h">
       <Filter>Include</Filter>
     </ClInclude>
+    <ClInclude Include="..\Include\cpython\memoryobject.h">
+      <Filter>Include</Filter>
+    </ClInclude>
     <ClInclude Include="..\Include\cpython\odictobject.h">
       <Filter>Include</Filter>
     </ClInclude>