MCPcopy Create free account
hub / github.com/numpy/numpy / void_getbuffer

Function void_getbuffer

numpy/core/src/multiarray/buffer.c:847–887  ·  view source on GitHub ↗

* Retrieving buffers for void scalar (which can contain any complex types), * defined in buffer.c since it requires the complex format building logic. */

Source from the content-addressed store, hash-verified

845 * defined in buffer.c since it requires the complex format building logic.
846 */
847NPY_NO_EXPORT int
848void_getbuffer(PyObject *self, Py_buffer *view, int flags)
849{
850 PyVoidScalarObject *scalar = (PyVoidScalarObject *)self;
851
852 if (flags & PyBUF_WRITABLE) {
853 PyErr_SetString(PyExc_BufferError, "scalar buffer is readonly");
854 return -1;
855 }
856
857 view->ndim = 0;
858 view->shape = NULL;
859 view->strides = NULL;
860 view->suboffsets = NULL;
861 view->len = scalar->descr->elsize;
862 view->itemsize = scalar->descr->elsize;
863 view->readonly = 1;
864 view->suboffsets = NULL;
865 Py_INCREF(self);
866 view->obj = self;
867 view->buf = scalar->obval;
868
869 if (((flags & PyBUF_FORMAT) != PyBUF_FORMAT)) {
870 /* It is unnecessary to find the correct format */
871 view->format = NULL;
872 return 0;
873 }
874
875 /*
876 * If a format is being exported, we need to use _buffer_get_info
877 * to find the correct format. This format must also be stored, since
878 * at least in theory it can change (in practice it should never change).
879 */
880 _buffer_info_t *info = _buffer_get_info(&scalar->_buffer_info, self, flags);
881 if (info == NULL) {
882 Py_DECREF(self);
883 return -1;
884 }
885 view->format = info->format;
886 return 0;
887}
888
889
890/*************************************************************************/

Callers

nothing calls this directly

Calls 1

_buffer_get_infoFunction · 0.85

Tested by

no test coverage detected