[pygobject/benzea/tmp: 1/2] fixup! async: Add a new async type that is an awaitable for a _finish call
- From: Benjamin Berg <bberg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject/benzea/tmp: 1/2] fixup! async: Add a new async type that is an awaitable for a _finish call
- Date: Tue, 28 Dec 2021 15:27:08 +0000 (UTC)
commit 89a57ab41fcc6ac178d4859981ed534bbb460fba
Author: Benjamin Berg <bberg redhat com>
Date: Tue Dec 28 16:25:15 2021 +0100
fixup! async: Add a new async type that is an awaitable for a _finish call
gi/pygi-async.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
---
diff --git a/gi/pygi-async.c b/gi/pygi-async.c
index becf6fbd..a6d4a5a3 100644
--- a/gi/pygi-async.c
+++ b/gi/pygi-async.c
@@ -30,6 +30,9 @@
static PyObject *asyncio_InvalidStateError;
static PyObject *asyncio_get_running_loop;
+#if PY_VERSION_HEX >= 0x03070000 && defined(PYPY_VERSION)
+static PyObject *contextvars_copy_context;
+#endif
static PyObject *cancellable_info;
/* This is never instantiated. */
@@ -153,7 +156,11 @@ async_add_done_callback (PyGIAsync *self, PyObject *args, PyObject *kwargs)
Py_INCREF(callback.func);
if (callback.context == NULL)
+#ifndef PYPY_VERSION
callback.context = PyContext_CopyCurrent ();
+#else
+ callback.context = PyObject_CallObject (contextvars_copy_context, NULL);;
+#endif
else
Py_INCREF(callback.context);
#else
@@ -583,6 +590,9 @@ static struct PyMemberDef async_members[] = {
*/
int pygi_async_register_types(PyObject *module) {
PyObject *asyncio = NULL;
+#if PY_VERSION_HEX >= 0x03070000 && defined(PYPY_VERSION)
+ PyObject *contextvars = NULL;
+#endif
PyGIAsync_Type.tp_finalize = (destructor)async_finalize;
PyGIAsync_Type.tp_dealloc = (destructor)async_dealloc;
@@ -617,6 +627,17 @@ int pygi_async_register_types(PyObject *module) {
if (asyncio_get_running_loop == NULL)
goto fail;
+#if PY_VERSION_HEX >= 0x03070000 && defined(PYPY_VERSION)
+ contextvars = PyImport_ImportModule("contextvars");
+ if (asyncio == NULL) {
+ goto fail;
+ }
+
+ contextvars_copy_context = PyObject_GetAttrString(asyncio, "copy_context");
+ if (contextvars_copy_context == NULL)
+ goto fail;
+#endif
+
/* Only initialized when really needed! */
cancellable_info = NULL;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]