diff options
author | Alex Grönholm <alex.gronholm@nextday.fi> | 2018-08-09 20:49:49 (GMT) |
---|---|---|
committer | Yury Selivanov <yury@magic.io> | 2018-08-09 20:49:49 (GMT) |
commit | a7548230ff6db5008c76e97f2597ebfdb41da19d (patch) | |
tree | b5fb3e212b1e146891a395755e0f5c7344e1dc8a | |
parent | 22d131a7f9e4e64486da1d1cddbfed2379517791 (diff) | |
download | cpython-a7548230ff6db5008c76e97f2597ebfdb41da19d.zip cpython-a7548230ff6db5008c76e97f2597ebfdb41da19d.tar.gz cpython-a7548230ff6db5008c76e97f2597ebfdb41da19d.tar.bz2 |
Fixed inconsistency in string handling in the Task C implementation (GH-8717)
-rw-r--r-- | Modules/_asynciomodule.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c index 3c94848..3d7ce01 100644 --- a/Modules/_asynciomodule.c +++ b/Modules/_asynciomodule.c @@ -1976,7 +1976,7 @@ _asyncio_Task___init___impl(TaskObj *self, PyObject *coro, PyObject *loop, if (name == Py_None) { name = PyUnicode_FromFormat("Task-%" PRIu64, ++task_name_counter); - } else if (!PyUnicode_Check(name)) { + } else if (!PyUnicode_CheckExact(name)) { name = PyObject_Str(name); } else { Py_INCREF(name); @@ -2343,12 +2343,16 @@ static PyObject * _asyncio_Task_set_name(TaskObj *self, PyObject *value) /*[clinic end generated code: output=138a8d51e32057d6 input=a8359b6e65f8fd31]*/ { - PyObject *name = PyObject_Str(value); - if (name == NULL) { - return NULL; + if (!PyUnicode_CheckExact(value)) { + value = PyObject_Str(value); + if (value == NULL) { + return NULL; + } + } else { + Py_INCREF(value); } - Py_XSETREF(self->task_name, name); + Py_XSETREF(self->task_name, value); Py_RETURN_NONE; } |