@@ -56,9 +56,7 @@ find_state_by_type(PyTypeObject *tp)
5656 return get_thread_state (mod );
5757}
5858
59- #define clinic_state () (find_state_by_type(type))
6059#include "clinic/_threadmodule.c.h"
61- #undef clinic_state
6260
6361#ifdef MS_WINDOWS
6462typedef HRESULT (WINAPI * PF_GET_THREAD_DESCRIPTION )(HANDLE , PCWSTR * );
@@ -70,10 +68,10 @@ static PF_SET_THREAD_DESCRIPTION pSetThreadDescription = NULL;
7068
7169/*[clinic input]
7270module _thread
73- class _thread.iter_locked "iter_locked_object *" "clinic_state( )->iter_locked_type"
71+ class _thread.iter_locked "iter_locked_object *" "find_state_by_type(type )->iter_locked_type"
7472
7573[clinic start generated code]*/
76- /*[clinic end generated code: output=da39a3ee5e6b4b0d input=6c78d729dec7bf7e ]*/
74+ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=cc495aee1743488d ]*/
7775
7876
7977// _ThreadHandle type
@@ -770,20 +768,24 @@ _thread_iter_locked_impl(PyTypeObject *type, PyObject *iterable)
770768 if (it == NULL )
771769 return NULL ;
772770
773- iter_locked_object * lz = (iter_locked_object * )type -> tp_alloc (type , 0 );
774- lz -> it = it ;
771+ iter_locked_object * il = (iter_locked_object * )type -> tp_alloc (type , 0 );
772+ if (il == NULL ) {
773+ Py_DECREF (it );
774+ return NULL ;
775+ }
776+ il -> it = it ;
775777
776- return (PyObject * )lz ;
778+ return (PyObject * )il ;
777779}
778780
779781static void
780782iter_locked_dealloc (PyObject * op )
781783{
782- iter_locked_object * lz = iter_locked_object_CAST (op );
783- PyTypeObject * tp = Py_TYPE (lz );
784- PyObject_GC_UnTrack (lz );
785- Py_XDECREF ( lz -> it );
786- tp -> tp_free (lz );
784+ iter_locked_object * il = iter_locked_object_CAST (op );
785+ PyTypeObject * tp = Py_TYPE (il );
786+ PyObject_GC_UnTrack (il );
787+ Py_DECREF ( il -> it );
788+ tp -> tp_free (il );
787789 Py_DECREF (tp );
788790}
789791
@@ -802,16 +804,12 @@ iter_locked_next(PyObject *op)
802804 iter_locked_object * lz = iter_locked_object_CAST (op );
803805 PyObject * result = NULL ;
804806
805- Py_BEGIN_CRITICAL_SECTION (lz -> it ); // or lock on op?
807+ Py_BEGIN_CRITICAL_SECTION (op ); // lock on op or lz->it ?
806808 PyObject * it = lz -> it ;
807- if (it != NULL ) {
808- result = PyIter_Next (lz -> it );
809- if (result == NULL ) {
810- /* Note: StopIteration is already cleared by PyIter_Next() */
811- if (PyErr_Occurred ())
812- return NULL ;
813- Py_CLEAR (lz -> it );
814- }
809+ result = PyIter_Next (it );
810+ if (result == NULL ) {
811+ /* Note: StopIteration is already cleared by PyIter_Next() */
812+ /* If PyErr_Occurred() we will also return NULL*/
815813 }
816814 Py_END_CRITICAL_SECTION ();
817815 return result ;
@@ -2854,7 +2852,7 @@ thread_module_traverse(PyObject *module, visitproc visit, void *arg)
28542852{
28552853 thread_module_state * state = get_thread_state (module );
28562854 Py_VISIT (state -> excepthook_type );
2857- Py_CLEAR (state -> iter_locked_type );
2855+ Py_VISIT (state -> iter_locked_type );
28582856 Py_VISIT (state -> lock_type );
28592857 Py_VISIT (state -> local_type );
28602858 Py_VISIT (state -> local_dummy_type );
0 commit comments