@@ -111,8 +111,8 @@ static PyTypeObject TaskType;
111111static PyTypeObject PyRunningLoopHolder_Type ;
112112
113113
114- #define Future_CheckExact (obj ) (Py_TYPE (obj) == &FutureType)
115- #define Task_CheckExact (obj ) (Py_TYPE (obj) == &TaskType)
114+ #define Future_CheckExact (obj ) (Py_TYPE_IS (obj, &FutureType) )
115+ #define Task_CheckExact (obj ) (Py_TYPE_IS (obj, &TaskType) )
116116
117117#define Future_Check (obj ) PyObject_TypeCheck(obj, &FutureType)
118118#define Task_Check (obj ) PyObject_TypeCheck(obj, &TaskType)
@@ -158,9 +158,12 @@ _is_coroutine(PyObject *coro)
158158 positive types. That shouldn't ever happen, unless
159159 someone stressing the system on purpose.
160160 */
161- if (PySet_Add (iscoroutine_typecache , (PyObject * ) Py_TYPE (coro ))) {
161+ PyTypeObject * type = Py_GetType (coro );
162+ if (PySet_Add (iscoroutine_typecache , (PyObject * )type )) {
163+ Py_DECREF (type );
162164 return -1 ;
163165 }
166+ Py_DECREF (type );
164167 }
165168
166169 return 1 ;
@@ -183,8 +186,9 @@ is_coroutine(PyObject *coro)
183186 This cache allows us to avoid the cost of even calling
184187 a pure-Python function in 99.9% cases.
185188 */
186- int has_it = PySet_Contains (
187- iscoroutine_typecache , (PyObject * ) Py_TYPE (coro ));
189+ PyTypeObject * type = Py_GetType (coro );
190+ int has_it = PySet_Contains (iscoroutine_typecache , (PyObject * ) type );
191+ Py_DECREF (type );
188192 if (has_it == 0 ) {
189193 /* type(coro) is not in iscoroutine_typecache */
190194 return _is_coroutine (coro );
@@ -255,7 +259,7 @@ get_running_loop(PyObject **loop)
255259 cached_running_holder_tsid = ts -> id ;
256260 }
257261
258- assert (Py_TYPE (rl ) == & PyRunningLoopHolder_Type );
262+ assert (Py_TYPE_IS (rl , & PyRunningLoopHolder_Type ) );
259263 PyObject * running_loop = ((PyRunningLoopHolder * )rl )-> rl_loop ;
260264
261265 if (running_loop == Py_None ) {
@@ -577,7 +581,7 @@ future_set_exception(FutureObj *fut, PyObject *exc)
577581 PyErr_SetString (PyExc_TypeError , "invalid exception object" );
578582 return NULL ;
579583 }
580- if (( PyObject * ) Py_TYPE ( exc_val ) == PyExc_StopIteration ) {
584+ if (Py_TYPE_IS ( exc_val , ( PyTypeObject * ) PyExc_StopIteration ) ) {
581585 Py_DECREF (exc_val );
582586 PyErr_SetString (PyExc_TypeError ,
583587 "StopIteration interacts badly with generators "
@@ -1308,8 +1312,10 @@ FutureObj_repr(FutureObj *fut)
13081312 }
13091313
13101314 PyObject * rstr = NULL ;
1311- PyObject * type_name = PyObject_GetAttrString ((PyObject * )Py_TYPE (fut ),
1315+ PyTypeObject * type = Py_GetType (fut );
1316+ PyObject * type_name = PyObject_GetAttrString ((PyObject * )type ,
13121317 "__name__" );
1318+ Py_DECREF (type );
13131319 if (type_name != NULL ) {
13141320 rstr = PyUnicode_FromFormat ("<%S %U>" , type_name , rinfo_s );
13151321 Py_DECREF (type_name );
@@ -1347,7 +1353,9 @@ FutureObj_finalize(FutureObj *fut)
13471353 goto finally ;
13481354 }
13491355
1350- type_name = PyObject_GetAttrString ((PyObject * )Py_TYPE (fut ), "__name__" );
1356+ PyTypeObject * type = Py_GetType (fut );
1357+ type_name = PyObject_GetAttrString ((PyObject * )type , "__name__" );
1358+ Py_DECREF (type );
13511359 if (type_name == NULL ) {
13521360 goto finally ;
13531361 }
@@ -1476,7 +1484,9 @@ FutureObj_dealloc(PyObject *self)
14761484 }
14771485
14781486 (void )FutureObj_clear (fut );
1479- Py_TYPE (fut )-> tp_free (fut );
1487+ PyTypeObject * type = Py_GetType (fut );
1488+ type -> tp_free (fut );
1489+ Py_DECREF (type );
14801490}
14811491
14821492
@@ -1702,7 +1712,9 @@ TaskStepMethWrapper_dealloc(TaskStepMethWrapper *o)
17021712{
17031713 PyObject_GC_UnTrack (o );
17041714 (void )TaskStepMethWrapper_clear (o );
1705- Py_TYPE (o )-> tp_free (o );
1715+ PyTypeObject * type = Py_GetType (o );
1716+ type -> tp_free (o );
1717+ Py_DECREF (type );
17061718}
17071719
17081720static PyObject *
@@ -1816,7 +1828,9 @@ TaskWakeupMethWrapper_dealloc(TaskWakeupMethWrapper *o)
18161828{
18171829 PyObject_GC_UnTrack (o );
18181830 (void )TaskWakeupMethWrapper_clear (o );
1819- Py_TYPE (o )-> tp_free (o );
1831+ PyTypeObject * type = Py_GetType (o );
1832+ type -> tp_free (o );
1833+ Py_DECREF (type );
18201834}
18211835
18221836static PyTypeObject TaskWakeupMethWrapper_Type = {
@@ -2503,7 +2517,9 @@ TaskObj_dealloc(PyObject *self)
25032517 }
25042518
25052519 (void )TaskObj_clear (task );
2506- Py_TYPE (task )-> tp_free (task );
2520+ PyTypeObject * type = Py_GetType (task );
2521+ type -> tp_free (task );
2522+ Py_DECREF (type );
25072523}
25082524
25092525static int
0 commit comments