diff --git a/Objects/memoryobject.c b/Objects/memoryobject.c --- a/Objects/memoryobject.c +++ b/Objects/memoryobject.c @@ -1044,6 +1044,11 @@ return -1; } +PyDoc_STRVAR(memory_release_doc, +"M.release() -> None\n\ +\n\ +Release the underlying buffer exposed by the memoryview object."); + static PyObject * memory_release(PyMemoryViewObject *self, PyObject *noargs) { @@ -1304,6 +1309,12 @@ All casts must result in views that will have the exact byte size of the original input. Otherwise, an error is raised. */ + +PyDoc_STRVAR(memory_cast_doc, +"M.cast(format[, shape]) -> memoryview\n\ +\n\ +Cast a memoryview to a new format or shape."); + static PyObject * memory_cast(PyMemoryViewObject *self, PyObject *args, PyObject *kwds) { @@ -2061,6 +2072,11 @@ /* Return a list representation of the memoryview. Currently only buffers with native format strings are supported. */ +PyDoc_STRVAR(memory_tolist_doc, +"M.tobytes() -> list\n\ +\n\ +Return the data in the buffer as a list of elements."); + static PyObject * memory_tolist(PyMemoryViewObject *mv, PyObject *noargs) { @@ -2087,6 +2103,11 @@ } } +PyDoc_STRVAR(memory_tobytes_doc, +"M.tobytes() -> bytes\n\ +\n\ +Return the data in the buffer as a bytestring."); + static PyObject * memory_tobytes(PyMemoryViewObject *self, PyObject *dummy) { @@ -2771,6 +2792,8 @@ return intTuple; } +PyDoc_STRVAR(memory_obj_doc, + "The underlying object of the memoryview."); static PyObject * memory_obj_get(PyMemoryViewObject *self) { @@ -2784,6 +2807,9 @@ return view->obj; } +PyDoc_STRVAR(memory_nbytes_doc, + "The amount of space in bytes that the array would use in\n" + " a contiguous representation."); static PyObject * memory_nbytes_get(PyMemoryViewObject *self) { @@ -2791,6 +2817,9 @@ return PyLong_FromSsize_t(self->view.len); } +PyDoc_STRVAR(memory_format_doc, + "A string containing the format (in struct module style)\n" + " for each element in the view."); static PyObject * memory_format_get(PyMemoryViewObject *self) { @@ -2798,6 +2827,8 @@ return PyUnicode_FromString(self->view.format); } +PyDoc_STRVAR(memory_itemsize_doc, + "The size in bytes of each element of the memoryview."); static PyObject * memory_itemsize_get(PyMemoryViewObject *self) { @@ -2805,6 +2836,9 @@ return PyLong_FromSsize_t(self->view.itemsize); } +PyDoc_STRVAR(memory_shape_doc, + "A tuple of ndim integers giving the shape of the memory\n" + " as a N-dimensional array."); static PyObject * memory_shape_get(PyMemoryViewObject *self) { @@ -2812,6 +2846,10 @@ return _IntTupleFromSsizet(self->view.ndim, self->view.shape); } +PyDoc_STRVAR(memory_strides_doc, + "A tuple of ndim integers giving the size in bytes to access\n" + " each element for each dimension of the array or None for C\n" + " contiguous."); static PyObject * memory_strides_get(PyMemoryViewObject *self) { @@ -2819,6 +2857,10 @@ return _IntTupleFromSsizet(self->view.ndim, self->view.strides); } + +PyDoc_STRVAR(memory_suboffsets_doc, + "A tuple of ndim integers used internally for PIL-style arrays\n" + " or None."); static PyObject * memory_suboffsets_get(PyMemoryViewObject *self) { @@ -2826,6 +2868,9 @@ return _IntTupleFromSsizet(self->view.ndim, self->view.suboffsets); } + +PyDoc_STRVAR(memory_readonly_doc, + "A bool indicating whether the memory is read only."); static PyObject * memory_readonly_get(PyMemoryViewObject *self) { @@ -2833,6 +2878,9 @@ return PyBool_FromLong(self->view.readonly); } +PyDoc_STRVAR(memory_ndim_doc, + "An integer indicating how many dimensions of a multi-dimensional\n" + " array the memory represents."); static PyObject * memory_ndim_get(PyMemoryViewObject *self) { @@ -2840,6 +2888,9 @@ return PyLong_FromLong(self->view.ndim); } + +PyDoc_STRVAR(memory_c_contiguous_doc, + "A bool indicating whether the memory is C contiguous."); static PyObject * memory_c_contiguous(PyMemoryViewObject *self, PyObject *dummy) { @@ -2847,6 +2898,9 @@ return PyBool_FromLong(MV_C_CONTIGUOUS(self->flags)); } + +PyDoc_STRVAR(memory_f_contiguous_doc, + "A bool indicating whether the memory is Fortran contiguous."); static PyObject * memory_f_contiguous(PyMemoryViewObject *self, PyObject *dummy) { @@ -2854,6 +2908,8 @@ return PyBool_FromLong(MV_F_CONTIGUOUS(self->flags)); } +PyDoc_STRVAR(memory_contiguous_doc, + "A bool indicating whether the memory is contiguous."); static PyObject * memory_contiguous(PyMemoryViewObject *self, PyObject *dummy) { @@ -2862,27 +2918,27 @@ } static PyGetSetDef memory_getsetlist[] = { - {"obj", (getter)memory_obj_get, NULL, NULL}, - {"nbytes", (getter)memory_nbytes_get, NULL, NULL}, - {"readonly", (getter)memory_readonly_get, NULL, NULL}, - {"itemsize", (getter)memory_itemsize_get, NULL, NULL}, - {"format", (getter)memory_format_get, NULL, NULL}, - {"ndim", (getter)memory_ndim_get, NULL, NULL}, - {"shape", (getter)memory_shape_get, NULL, NULL}, - {"strides", (getter)memory_strides_get, NULL, NULL}, - {"suboffsets", (getter)memory_suboffsets_get, NULL, NULL}, - {"c_contiguous", (getter)memory_c_contiguous, NULL, NULL}, - {"f_contiguous", (getter)memory_f_contiguous, NULL, NULL}, - {"contiguous", (getter)memory_contiguous, NULL, NULL}, + {"obj", (getter)memory_obj_get, NULL, memory_obj_doc}, + {"nbytes", (getter)memory_nbytes_get, NULL, memory_nbytes_doc}, + {"readonly", (getter)memory_readonly_get, NULL, memory_readonly_doc}, + {"itemsize", (getter)memory_itemsize_get, NULL, memory_itemsize_doc}, + {"format", (getter)memory_format_get, NULL, memory_format_doc}, + {"ndim", (getter)memory_ndim_get, NULL, memory_ndim_doc}, + {"shape", (getter)memory_shape_get, NULL, memory_shape_doc}, + {"strides", (getter)memory_strides_get, NULL, memory_strides_doc}, + {"suboffsets", (getter)memory_suboffsets_get, NULL, memory_suboffsets_doc}, + {"c_contiguous", (getter)memory_c_contiguous, NULL, memory_c_contiguous_doc}, + {"f_contiguous", (getter)memory_f_contiguous, NULL, memory_f_contiguous_doc}, + {"contiguous", (getter)memory_contiguous, NULL, memory_contiguous_doc}, {NULL, NULL, NULL, NULL}, }; static PyMethodDef memory_methods[] = { - {"release", (PyCFunction)memory_release, METH_NOARGS, NULL}, - {"tobytes", (PyCFunction)memory_tobytes, METH_NOARGS, NULL}, - {"tolist", (PyCFunction)memory_tolist, METH_NOARGS, NULL}, - {"cast", (PyCFunction)memory_cast, METH_VARARGS|METH_KEYWORDS, NULL}, + {"release", (PyCFunction)memory_release, METH_NOARGS, memory_release_doc}, + {"tobytes", (PyCFunction)memory_tobytes, METH_NOARGS, memory_tobytes_doc}, + {"tolist", (PyCFunction)memory_tolist, METH_NOARGS, memory_tolist_doc}, + {"cast", (PyCFunction)memory_cast, METH_VARARGS|METH_KEYWORDS, memory_cast_doc}, {"__enter__", memory_enter, METH_NOARGS, NULL}, {"__exit__", memory_exit, METH_VARARGS, NULL}, {NULL, NULL}