diff options
author | Victor Stinner <vstinner@python.org> | 2022-11-23 14:44:42 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-23 14:44:42 (GMT) |
commit | 55bad199cf89f5488bcfd50b897d798afd57976e (patch) | |
tree | 13f145a35f4c3ebf8517fdc1e9909a8ab157a2c3 /Include/cpython | |
parent | 81f7359f67a7166d57a10a3d5366406d9c85f1de (diff) | |
download | cpython-55bad199cf89f5488bcfd50b897d798afd57976e.zip cpython-55bad199cf89f5488bcfd50b897d798afd57976e.tar.gz cpython-55bad199cf89f5488bcfd50b897d798afd57976e.tar.bz2 |
gh-79315: Add Include/cpython/memoryobject.h header (#99723)
Move non-limited C API from Include/memoryobject.h to a new
Include/cpython/memoryobject.h header file.
Diffstat (limited to 'Include/cpython')
-rw-r--r-- | Include/cpython/memoryobject.h | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/Include/cpython/memoryobject.h b/Include/cpython/memoryobject.h new file mode 100644 index 0000000..e2a1e16 --- /dev/null +++ b/Include/cpython/memoryobject.h @@ -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) |