aboutsummaryrefslogtreecommitdiff
path: root/Objects/clinic/memoryobject.c.h
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2020-07-18 11:12:05 +0300
committerGitHub <noreply@github.com>2020-07-18 11:12:05 +0300
commit80a50368c0e4dc9d56af0ce748dea35c9d96d23f (patch)
tree5baa0c1dc16a57228f151f3601812f9234b93e43 /Objects/clinic/memoryobject.c.h
parentb4c98ed41e6c959e95b2a6f65c1b728e94039dfd (diff)
downloadcpython3-80a50368c0e4dc9d56af0ce748dea35c9d96d23f.tar.gz
bpo-41262: Convert memoryview to Argument Clinic. (GH-21421)
Diffstat (limited to 'Objects/clinic/memoryobject.c.h')
-rw-r--r--Objects/clinic/memoryobject.c.h194
1 files changed, 193 insertions, 1 deletions
diff --git a/Objects/clinic/memoryobject.c.h b/Objects/clinic/memoryobject.c.h
index 8227f0edfb..4a682f69d6 100644
--- a/Objects/clinic/memoryobject.c.h
+++ b/Objects/clinic/memoryobject.c.h
@@ -2,6 +2,198 @@
preserve
[clinic start generated code]*/
+PyDoc_STRVAR(memoryview__doc__,
+"memoryview(object)\n"
+"--\n"
+"\n"
+"Create a new memoryview object which references the given object.");
+
+static PyObject *
+memoryview_impl(PyTypeObject *type, PyObject *object);
+
+static PyObject *
+memoryview(PyTypeObject *type, PyObject *args, PyObject *kwargs)
+{
+ PyObject *return_value = NULL;
+ static const char * const _keywords[] = {"object", NULL};
+ static _PyArg_Parser _parser = {NULL, _keywords, "memoryview", 0};
+ PyObject *argsbuf[1];
+ PyObject * const *fastargs;
+ Py_ssize_t nargs = PyTuple_GET_SIZE(args);
+ PyObject *object;
+
+ fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 1, 0, argsbuf);
+ if (!fastargs) {
+ goto exit;
+ }
+ object = fastargs[0];
+ return_value = memoryview_impl(type, object);
+
+exit:
+ return return_value;
+}
+
+PyDoc_STRVAR(memoryview_release__doc__,
+"release($self, /)\n"
+"--\n"
+"\n"
+"Release the underlying buffer exposed by the memoryview object.");
+
+#define MEMORYVIEW_RELEASE_METHODDEF \
+ {"release", (PyCFunction)memoryview_release, METH_NOARGS, memoryview_release__doc__},
+
+static PyObject *
+memoryview_release_impl(PyMemoryViewObject *self);
+
+static PyObject *
+memoryview_release(PyMemoryViewObject *self, PyObject *Py_UNUSED(ignored))
+{
+ return memoryview_release_impl(self);
+}
+
+PyDoc_STRVAR(memoryview_cast__doc__,
+"cast($self, /, format, shape=<unrepresentable>)\n"
+"--\n"
+"\n"
+"Cast a memoryview to a new format or shape.");
+
+#define MEMORYVIEW_CAST_METHODDEF \
+ {"cast", (PyCFunction)(void(*)(void))memoryview_cast, METH_FASTCALL|METH_KEYWORDS, memoryview_cast__doc__},
+
+static PyObject *
+memoryview_cast_impl(PyMemoryViewObject *self, PyObject *format,
+ PyObject *shape);
+
+static PyObject *
+memoryview_cast(PyMemoryViewObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+{
+ PyObject *return_value = NULL;
+ static const char * const _keywords[] = {"format", "shape", NULL};
+ static _PyArg_Parser _parser = {NULL, _keywords, "cast", 0};
+ PyObject *argsbuf[2];
+ Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
+ PyObject *format;
+ PyObject *shape = NULL;
+
+ args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
+ if (!args) {
+ goto exit;
+ }
+ if (!PyUnicode_Check(args[0])) {
+ _PyArg_BadArgument("cast", "argument 'format'", "str", args[0]);
+ goto exit;
+ }
+ if (PyUnicode_READY(args[0]) == -1) {
+ goto exit;
+ }
+ format = args[0];
+ if (!noptargs) {
+ goto skip_optional_pos;
+ }
+ shape = args[1];
+skip_optional_pos:
+ return_value = memoryview_cast_impl(self, format, shape);
+
+exit:
+ return return_value;
+}
+
+PyDoc_STRVAR(memoryview_toreadonly__doc__,
+"toreadonly($self, /)\n"
+"--\n"
+"\n"
+"Return a readonly version of the memoryview.");
+
+#define MEMORYVIEW_TOREADONLY_METHODDEF \
+ {"toreadonly", (PyCFunction)memoryview_toreadonly, METH_NOARGS, memoryview_toreadonly__doc__},
+
+static PyObject *
+memoryview_toreadonly_impl(PyMemoryViewObject *self);
+
+static PyObject *
+memoryview_toreadonly(PyMemoryViewObject *self, PyObject *Py_UNUSED(ignored))
+{
+ return memoryview_toreadonly_impl(self);
+}
+
+PyDoc_STRVAR(memoryview_tolist__doc__,
+"tolist($self, /)\n"
+"--\n"
+"\n"
+"Return the data in the buffer as a list of elements.");
+
+#define MEMORYVIEW_TOLIST_METHODDEF \
+ {"tolist", (PyCFunction)memoryview_tolist, METH_NOARGS, memoryview_tolist__doc__},
+
+static PyObject *
+memoryview_tolist_impl(PyMemoryViewObject *self);
+
+static PyObject *
+memoryview_tolist(PyMemoryViewObject *self, PyObject *Py_UNUSED(ignored))
+{
+ return memoryview_tolist_impl(self);
+}
+
+PyDoc_STRVAR(memoryview_tobytes__doc__,
+"tobytes($self, /, order=\'C\')\n"
+"--\n"
+"\n"
+"Return the data in the buffer as a byte string.\n"
+"\n"
+"Order can be {\'C\', \'F\', \'A\'}. When order is \'C\' or \'F\', the data of the\n"
+"original array is converted to C or Fortran order. For contiguous views,\n"
+"\'A\' returns an exact copy of the physical memory. In particular, in-memory\n"
+"Fortran order is preserved. For non-contiguous views, the data is converted\n"
+"to C first. order=None is the same as order=\'C\'.");
+
+#define MEMORYVIEW_TOBYTES_METHODDEF \
+ {"tobytes", (PyCFunction)(void(*)(void))memoryview_tobytes, METH_FASTCALL|METH_KEYWORDS, memoryview_tobytes__doc__},
+
+static PyObject *
+memoryview_tobytes_impl(PyMemoryViewObject *self, const char *order);
+
+static PyObject *
+memoryview_tobytes(PyMemoryViewObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+{
+ PyObject *return_value = NULL;
+ static const char * const _keywords[] = {"order", NULL};
+ static _PyArg_Parser _parser = {NULL, _keywords, "tobytes", 0};
+ PyObject *argsbuf[1];
+ Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
+ const char *order = NULL;
+
+ args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
+ if (!args) {
+ goto exit;
+ }
+ if (!noptargs) {
+ goto skip_optional_pos;
+ }
+ if (args[0] == Py_None) {
+ order = NULL;
+ }
+ else if (PyUnicode_Check(args[0])) {
+ Py_ssize_t order_length;
+ order = PyUnicode_AsUTF8AndSize(args[0], &order_length);
+ if (order == NULL) {
+ goto exit;
+ }
+ if (strlen(order) != (size_t)order_length) {
+ PyErr_SetString(PyExc_ValueError, "embedded null character");
+ goto exit;
+ }
+ }
+ else {
+ _PyArg_BadArgument("tobytes", "argument 'order'", "str or None", args[0]);
+ goto exit;
+ }
+skip_optional_pos:
+ return_value = memoryview_tobytes_impl(self, order);
+
+exit:
+ return return_value;
+}
+
PyDoc_STRVAR(memoryview_hex__doc__,
"hex($self, /, sep=<unrepresentable>, bytes_per_sep=1)\n"
"--\n"
@@ -66,4 +258,4 @@ skip_optional_pos:
exit:
return return_value;
}
-/*[clinic end generated code: output=91106ef704134b19 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=1b879bb934d18c66 input=a9049054013a1b77]*/