summaryrefslogtreecommitdiff
path: root/Modules/_testcapimodule.c
diff options
context:
space:
mode:
authorYury Selivanov <yselivanov@sprymix.com>2015-05-11 22:57:16 -0400
committerYury Selivanov <yselivanov@sprymix.com>2015-05-11 22:57:16 -0400
commitea639832c36905ecb07caba111f614c4bbf9bdd6 (patch)
treeb1e24bb312d8c2cd302e49282707b5bd952714c8 /Modules/_testcapimodule.c
parent94240635a6a981ddbb60010bf7472bbbb5e52e2e (diff)
downloadcpython-ea639832c36905ecb07caba111f614c4bbf9bdd6.tar.gz
PEP 0492 -- Coroutines with async and await syntax. Issue #24017.
Diffstat (limited to 'Modules/_testcapimodule.c')
-rw-r--r--Modules/_testcapimodule.c97
1 files changed, 97 insertions, 0 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index d77d1dbcd9..77167b2c1e 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -3944,6 +3944,98 @@ static PyTypeObject matmulType = {
};
+typedef struct {
+ PyObject_HEAD
+ PyObject *ao_iterator;
+} awaitObject;
+
+
+static PyObject *
+awaitObject_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+ PyObject *v;
+ awaitObject *ao;
+
+ if (!PyArg_UnpackTuple(args, "awaitObject", 1, 1, &v))
+ return NULL;
+
+ ao = (awaitObject *)type->tp_alloc(type, 0);
+ if (ao == NULL) {
+ return NULL;
+ }
+
+ Py_INCREF(v);
+ ao->ao_iterator = v;
+
+ return (PyObject *)ao;
+}
+
+
+static void
+awaitObject_dealloc(awaitObject *ao)
+{
+ Py_CLEAR(ao->ao_iterator);
+ Py_TYPE(ao)->tp_free(ao);
+}
+
+
+static PyObject *
+awaitObject_await(awaitObject *ao)
+{
+ Py_INCREF(ao->ao_iterator);
+ return ao->ao_iterator;
+}
+
+static PyAsyncMethods awaitType_as_async = {
+ (getawaitablefunc)awaitObject_await, /* am_await */
+ 0, /* am_aiter */
+ 0 /* am_anext */
+};
+
+
+static PyTypeObject awaitType = {
+ PyVarObject_HEAD_INIT(NULL, 0)
+ "awaitType",
+ sizeof(awaitObject), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ (destructor)awaitObject_dealloc, /* destructor tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ &awaitType_as_async, /* tp_as_async */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ PyObject_GenericGetAttr, /* tp_getattro */
+ PyObject_GenericSetAttr, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ 0, /* tp_flags */
+ "C level type with tp_as_async",
+ 0, /* traverseproc tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ 0, /* tp_methods */
+ 0, /* tp_members */
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ awaitObject_new, /* tp_new */
+ PyObject_Del, /* tp_free */
+};
+
+
static struct PyModuleDef _testcapimodule = {
PyModuleDef_HEAD_INIT,
"_testcapi",
@@ -3977,6 +4069,11 @@ PyInit__testcapi(void)
Py_INCREF(&matmulType);
PyModule_AddObject(m, "matmulType", (PyObject *)&matmulType);
+ if (PyType_Ready(&awaitType) < 0)
+ return NULL;
+ Py_INCREF(&awaitType);
+ PyModule_AddObject(m, "awaitType", (PyObject *)&awaitType);
+
PyModule_AddObject(m, "CHAR_MAX", PyLong_FromLong(CHAR_MAX));
PyModule_AddObject(m, "CHAR_MIN", PyLong_FromLong(CHAR_MIN));
PyModule_AddObject(m, "UCHAR_MAX", PyLong_FromLong(UCHAR_MAX));