@@ -132,13 +132,25 @@ future_schedule_callbacks(FutureObj *fut)
132132 return 0 ;
133133}
134134
135+
135136static int
136137future_init (FutureObj * fut , PyObject * loop )
137138{
138139 PyObject * res ;
139140 int is_true ;
140141 _Py_IDENTIFIER (get_debug );
141142
143+ // Same to FutureObj_clear() but not clearing fut->dict
144+ Py_CLEAR (fut -> fut_loop );
145+ Py_CLEAR (fut -> fut_callbacks );
146+ Py_CLEAR (fut -> fut_result );
147+ Py_CLEAR (fut -> fut_exception );
148+ Py_CLEAR (fut -> fut_source_tb );
149+
150+ fut -> fut_state = STATE_PENDING ;
151+ fut -> fut_log_tb = 0 ;
152+ fut -> fut_blocking = 0 ;
153+
142154 if (loop == Py_None ) {
143155 loop = _PyObject_CallNoArg (asyncio_get_event_loop );
144156 if (loop == NULL ) {
@@ -148,7 +160,7 @@ future_init(FutureObj *fut, PyObject *loop)
148160 else {
149161 Py_INCREF (loop );
150162 }
151- Py_XSETREF ( fut -> fut_loop , loop ) ;
163+ fut -> fut_loop = loop ;
152164
153165 res = _PyObject_CallMethodId (fut -> fut_loop , & PyId_get_debug , NULL );
154166 if (res == NULL ) {
@@ -160,13 +172,13 @@ future_init(FutureObj *fut, PyObject *loop)
160172 return -1 ;
161173 }
162174 if (is_true ) {
163- Py_XSETREF ( fut -> fut_source_tb , _PyObject_CallNoArg (traceback_extract_stack ) );
175+ fut -> fut_source_tb = _PyObject_CallNoArg (traceback_extract_stack );
164176 if (fut -> fut_source_tb == NULL ) {
165177 return -1 ;
166178 }
167179 }
168180
169- Py_XSETREF ( fut -> fut_callbacks , PyList_New (0 ) );
181+ fut -> fut_callbacks = PyList_New (0 );
170182 if (fut -> fut_callbacks == NULL ) {
171183 return -1 ;
172184 }
@@ -1336,12 +1348,12 @@ _asyncio_Task___init___impl(TaskObj *self, PyObject *coro, PyObject *loop)
13361348 return -1 ;
13371349 }
13381350
1339- self -> task_fut_waiter = NULL ;
1351+ Py_CLEAR ( self -> task_fut_waiter ) ;
13401352 self -> task_must_cancel = 0 ;
13411353 self -> task_log_destroy_pending = 1 ;
13421354
13431355 Py_INCREF (coro );
1344- self -> task_coro = coro ;
1356+ Py_XSETREF ( self -> task_coro , coro ) ;
13451357
13461358 if (task_call_step_soon (self , NULL )) {
13471359 return -1 ;
0 commit comments