@@ -138,8 +138,10 @@ typedef struct {
138
138
/* Counter for autogenerated Task names */
139
139
uint64_t task_name_counter ;
140
140
141
+ #ifndef Py_GIL_DISABLED
141
142
futureiterobject * fi_freelist ;
142
143
Py_ssize_t fi_freelist_len ;
144
+ #endif
143
145
144
146
/* Linked-list of all tasks which are instances of asyncio.Task or subclasses
145
147
of it. Third party tasks implementations which don't inherit from
@@ -1579,14 +1581,14 @@ FutureIter_dealloc(futureiterobject *it)
1579
1581
1580
1582
assert (_PyType_HasFeature (tp , Py_TPFLAGS_HEAPTYPE ));
1581
1583
1582
- PyObject * module = ((PyHeapTypeObject * )tp )-> ht_module ;
1583
- asyncio_state * state = NULL ;
1584
-
1585
1584
PyObject_GC_UnTrack (it );
1586
1585
tp -> tp_clear ((PyObject * )it );
1587
1586
1587
+ #ifndef Py_GIL_DISABLED
1588
1588
// GH-115874: We can't use PyType_GetModuleByDef here as the type might have
1589
1589
// already been cleared, which is also why we must check if ht_module != NULL.
1590
+ PyObject * module = ((PyHeapTypeObject * )tp )-> ht_module ;
1591
+ asyncio_state * state = NULL ;
1590
1592
if (module && _PyModule_GetDef (module ) == & _asynciomodule ) {
1591
1593
state = get_asyncio_state (module );
1592
1594
}
@@ -1597,7 +1599,9 @@ FutureIter_dealloc(futureiterobject *it)
1597
1599
it -> future = (FutureObj * ) state -> fi_freelist ;
1598
1600
state -> fi_freelist = it ;
1599
1601
}
1600
- else {
1602
+ else
1603
+ #endif
1604
+ {
1601
1605
PyObject_GC_Del (it );
1602
1606
Py_DECREF (tp );
1603
1607
}
@@ -1801,14 +1805,17 @@ future_new_iter(PyObject *fut)
1801
1805
asyncio_state * state = get_asyncio_state_by_def ((PyObject * )fut );
1802
1806
ENSURE_FUTURE_ALIVE (state , fut )
1803
1807
1808
+ #ifndef Py_GIL_DISABLED
1804
1809
if (state -> fi_freelist_len ) {
1805
1810
state -> fi_freelist_len -- ;
1806
1811
it = state -> fi_freelist ;
1807
1812
state -> fi_freelist = (futureiterobject * ) it -> future ;
1808
1813
it -> future = NULL ;
1809
1814
_Py_NewReference ((PyObject * ) it );
1810
1815
}
1811
- else {
1816
+ else
1817
+ #endif
1818
+ {
1812
1819
it = PyObject_GC_New (futureiterobject , state -> FutureIterType );
1813
1820
if (it == NULL ) {
1814
1821
return NULL ;
@@ -3679,6 +3686,7 @@ _asyncio_all_tasks_impl(PyObject *module, PyObject *loop)
3679
3686
static void
3680
3687
module_free_freelists (asyncio_state * state )
3681
3688
{
3689
+ #ifndef Py_GIL_DISABLED
3682
3690
PyObject * next ;
3683
3691
PyObject * current ;
3684
3692
@@ -3693,6 +3701,7 @@ module_free_freelists(asyncio_state *state)
3693
3701
}
3694
3702
assert (state -> fi_freelist_len == 0 );
3695
3703
state -> fi_freelist = NULL ;
3704
+ #endif
3696
3705
}
3697
3706
3698
3707
static int
@@ -3723,13 +3732,16 @@ module_traverse(PyObject *mod, visitproc visit, void *arg)
3723
3732
3724
3733
Py_VISIT (state -> context_kwname );
3725
3734
3735
+ #ifndef Py_GIL_DISABLED
3726
3736
// Visit freelist.
3727
3737
PyObject * next = (PyObject * ) state -> fi_freelist ;
3728
3738
while (next != NULL ) {
3729
3739
PyObject * current = next ;
3730
3740
Py_VISIT (current );
3731
3741
next = (PyObject * ) ((futureiterobject * ) current )-> future ;
3732
3742
}
3743
+ #endif
3744
+
3733
3745
return 0 ;
3734
3746
}
3735
3747
0 commit comments