2008-08-19 15:22:14 -03:00
|
|
|
/* Memory view object. In Python this is available as "memoryview". */
|
2007-08-18 08:21:56 -03:00
|
|
|
|
|
|
|
#ifndef Py_MEMORYOBJECT_H
|
|
|
|
#define Py_MEMORYOBJECT_H
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2012-02-25 07:24:21 -04:00
|
|
|
#ifndef Py_LIMITED_API
|
|
|
|
PyAPI_DATA(PyTypeObject) _PyManagedBuffer_Type;
|
|
|
|
#endif
|
2007-08-18 08:21:56 -03:00
|
|
|
PyAPI_DATA(PyTypeObject) PyMemoryView_Type;
|
|
|
|
|
2020-02-13 13:37:17 -04:00
|
|
|
#define PyMemoryView_Check(op) Py_IS_TYPE(op, &PyMemoryView_Type)
|
2008-08-19 15:22:14 -03:00
|
|
|
|
2010-12-03 16:14:31 -04:00
|
|
|
#ifndef Py_LIMITED_API
|
2012-02-25 07:24:21 -04:00
|
|
|
/* Get a pointer to the memoryview's private copy of the exporter's buffer. */
|
2008-08-19 15:22:14 -03:00
|
|
|
#define PyMemoryView_GET_BUFFER(op) (&((PyMemoryViewObject *)(op))->view)
|
2012-02-25 07:24:21 -04:00
|
|
|
/* Get a pointer to the exporting object (this may be NULL!). */
|
2008-08-19 15:22:14 -03:00
|
|
|
#define PyMemoryView_GET_BASE(op) (((PyMemoryViewObject *)(op))->view.obj)
|
2010-12-03 16:14:31 -04:00
|
|
|
#endif
|
2007-08-18 08:21:56 -03:00
|
|
|
|
|
|
|
PyAPI_FUNC(PyObject *) PyMemoryView_FromObject(PyObject *base);
|
2016-12-27 08:57:39 -04:00
|
|
|
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
|
2012-02-25 07:24:21 -04:00
|
|
|
PyAPI_FUNC(PyObject *) PyMemoryView_FromMemory(char *mem, Py_ssize_t size,
|
|
|
|
int flags);
|
2016-12-27 08:57:39 -04:00
|
|
|
#endif
|
2011-01-06 15:15:47 -04:00
|
|
|
#ifndef Py_LIMITED_API
|
2021-12-22 09:07:46 -04:00
|
|
|
PyAPI_FUNC(PyObject *) PyMemoryView_FromBuffer(const Py_buffer *info);
|
2011-01-06 15:15:47 -04:00
|
|
|
#endif
|
2012-02-25 07:24:21 -04:00
|
|
|
PyAPI_FUNC(PyObject *) PyMemoryView_GetContiguous(PyObject *base,
|
|
|
|
int buffertype,
|
|
|
|
char order);
|
2009-01-03 15:20:36 -04:00
|
|
|
|
2007-08-18 08:21:56 -03:00
|
|
|
|
2012-02-25 07:24:21 -04:00
|
|
|
/* 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
|
2008-08-19 15:22:14 -03:00
|
|
|
and functions instead! */
|
2010-12-03 16:14:31 -04:00
|
|
|
#ifndef Py_LIMITED_API
|
2012-02-25 07:24:21 -04:00
|
|
|
#define _Py_MANAGED_BUFFER_RELEASED 0x001 /* access to exporter blocked */
|
|
|
|
#define _Py_MANAGED_BUFFER_FREE_FORMAT 0x002 /* free format */
|
2008-08-19 15:22:14 -03:00
|
|
|
typedef struct {
|
2009-01-03 15:20:36 -04:00
|
|
|
PyObject_HEAD
|
2012-02-25 07:24:21 -04:00
|
|
|
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 */
|
2012-05-28 17:35:09 -03:00
|
|
|
PyObject *weakreflist;
|
2012-02-25 07:24:21 -04:00
|
|
|
Py_ssize_t ob_array[1]; /* shape, strides, suboffsets */
|
2008-08-19 15:22:14 -03:00
|
|
|
} PyMemoryViewObject;
|
2010-12-03 16:14:31 -04:00
|
|
|
#endif
|
2008-08-19 15:22:14 -03:00
|
|
|
|
2007-08-18 08:21:56 -03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif /* !Py_MEMORYOBJECT_H */
|