[3.7] bpo-34762: Update PyContext* refs to PyObject* in asyncio and decimal (GH-9610)

This commit is contained in:
Yury Selivanov 2018-09-27 15:33:23 -04:00 committed by GitHub
parent 273fc220b2
commit 24cb7de15d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 12 deletions

View File

@ -59,7 +59,7 @@ typedef enum {
PyObject_HEAD \ PyObject_HEAD \
PyObject *prefix##_loop; \ PyObject *prefix##_loop; \
PyObject *prefix##_callback0; \ PyObject *prefix##_callback0; \
PyContext *prefix##_context0; \ PyObject *prefix##_context0; \
PyObject *prefix##_callbacks; \ PyObject *prefix##_callbacks; \
PyObject *prefix##_exception; \ PyObject *prefix##_exception; \
PyObject *prefix##_result; \ PyObject *prefix##_result; \
@ -78,7 +78,7 @@ typedef struct {
FutureObj_HEAD(task) FutureObj_HEAD(task)
PyObject *task_fut_waiter; PyObject *task_fut_waiter;
PyObject *task_coro; PyObject *task_coro;
PyContext *task_context; PyObject *task_context;
int task_must_cancel; int task_must_cancel;
int task_log_destroy_pending; int task_log_destroy_pending;
} TaskObj; } TaskObj;
@ -337,7 +337,7 @@ get_event_loop(void)
static int static int
call_soon(PyObject *loop, PyObject *func, PyObject *arg, PyContext *ctx) call_soon(PyObject *loop, PyObject *func, PyObject *arg, PyObject *ctx)
{ {
PyObject *handle; PyObject *handle;
PyObject *stack[3]; PyObject *stack[3];
@ -448,7 +448,7 @@ future_schedule_callbacks(FutureObj *fut)
PyObject *cb = PyTuple_GET_ITEM(cb_tup, 0); PyObject *cb = PyTuple_GET_ITEM(cb_tup, 0);
PyObject *ctx = PyTuple_GET_ITEM(cb_tup, 1); PyObject *ctx = PyTuple_GET_ITEM(cb_tup, 1);
if (call_soon(fut->fut_loop, cb, (PyObject *)fut, (PyContext *)ctx)) { if (call_soon(fut->fut_loop, cb, (PyObject *)fut, ctx)) {
/* If an error occurs in pure-Python implementation, /* If an error occurs in pure-Python implementation,
all callbacks are cleared. */ all callbacks are cleared. */
Py_CLEAR(fut->fut_callbacks); Py_CLEAR(fut->fut_callbacks);
@ -616,7 +616,7 @@ future_get_result(FutureObj *fut, PyObject **result)
} }
static PyObject * static PyObject *
future_add_done_callback(FutureObj *fut, PyObject *arg, PyContext *ctx) future_add_done_callback(FutureObj *fut, PyObject *arg, PyObject *ctx)
{ {
if (!future_is_alive(fut)) { if (!future_is_alive(fut)) {
PyErr_SetString(PyExc_RuntimeError, "uninitialized Future object"); PyErr_SetString(PyExc_RuntimeError, "uninitialized Future object");
@ -903,16 +903,15 @@ _asyncio_Future_add_done_callback_impl(FutureObj *self, PyObject *fn,
/*[clinic end generated code: output=7ce635bbc9554c1e input=15ab0693a96e9533]*/ /*[clinic end generated code: output=7ce635bbc9554c1e input=15ab0693a96e9533]*/
{ {
if (context == NULL) { if (context == NULL) {
context = (PyObject *)PyContext_CopyCurrent(); context = PyContext_CopyCurrent();
if (context == NULL) { if (context == NULL) {
return NULL; return NULL;
} }
PyObject *res = future_add_done_callback( PyObject *res = future_add_done_callback(self, fn, context);
self, fn, (PyContext *)context);
Py_DECREF(context); Py_DECREF(context);
return res; return res;
} }
return future_add_done_callback(self, fn, (PyContext *)context); return future_add_done_callback(self, fn, context);
} }
/*[clinic input] /*[clinic input]

View File

@ -122,7 +122,7 @@ incr_false(void)
} }
static PyContextVar *current_context_var; static PyObject *current_context_var;
/* Template for creating new thread contexts, calling Context() without /* Template for creating new thread contexts, calling Context() without
* arguments and initializing the module_context on first access. */ * arguments and initializing the module_context on first access. */
@ -1500,7 +1500,7 @@ init_current_context(void)
} }
CTX(tl_context)->status = 0; CTX(tl_context)->status = 0;
PyContextToken *tok = PyContextVar_Set(current_context_var, tl_context); PyObject *tok = PyContextVar_Set(current_context_var, tl_context);
if (tok == NULL) { if (tok == NULL) {
Py_DECREF(tl_context); Py_DECREF(tl_context);
return NULL; return NULL;
@ -1561,7 +1561,7 @@ PyDec_SetCurrentContext(PyObject *self UNUSED, PyObject *v)
Py_INCREF(v); Py_INCREF(v);
} }
PyContextToken *tok = PyContextVar_Set(current_context_var, v); PyObject *tok = PyContextVar_Set(current_context_var, v);
Py_DECREF(v); Py_DECREF(v);
if (tok == NULL) { if (tok == NULL) {
return NULL; return NULL;