@@ -71,8 +71,10 @@ typedef struct {
71
71
/* Counter for autogenerated Task names */
72
72
uint64_t task_name_counter ;
73
73
74
+ #ifndef Py_GIL_DISABLED
74
75
futureiterobject * fi_freelist ;
75
76
Py_ssize_t fi_freelist_len ;
77
+ #endif
76
78
} asyncio_state ;
77
79
78
80
static inline asyncio_state *
@@ -1520,14 +1522,14 @@ FutureIter_dealloc(futureiterobject *it)
1520
1522
1521
1523
assert (_PyType_HasFeature (tp , Py_TPFLAGS_HEAPTYPE ));
1522
1524
1523
- PyObject * module = ((PyHeapTypeObject * )tp )-> ht_module ;
1524
- asyncio_state * state = NULL ;
1525
-
1526
1525
PyObject_GC_UnTrack (it );
1527
1526
tp -> tp_clear ((PyObject * )it );
1528
1527
1528
+ #ifndef Py_GIL_DISABLED
1529
1529
// GH-115874: We can't use PyType_GetModuleByDef here as the type might have
1530
1530
// already been cleared, which is also why we must check if ht_module != NULL.
1531
+ PyObject * module = ((PyHeapTypeObject * )tp )-> ht_module ;
1532
+ asyncio_state * state = NULL ;
1531
1533
if (module && _PyModule_GetDef (module ) == & _asynciomodule ) {
1532
1534
state = get_asyncio_state (module );
1533
1535
}
@@ -1538,7 +1540,9 @@ FutureIter_dealloc(futureiterobject *it)
1538
1540
it -> future = (FutureObj * ) state -> fi_freelist ;
1539
1541
state -> fi_freelist = it ;
1540
1542
}
1541
- else {
1543
+ else
1544
+ #endif
1545
+ {
1542
1546
PyObject_GC_Del (it );
1543
1547
Py_DECREF (tp );
1544
1548
}
@@ -1742,14 +1746,17 @@ future_new_iter(PyObject *fut)
1742
1746
asyncio_state * state = get_asyncio_state_by_def ((PyObject * )fut );
1743
1747
ENSURE_FUTURE_ALIVE (state , fut )
1744
1748
1749
+ #ifndef Py_GIL_DISABLED
1745
1750
if (state -> fi_freelist_len ) {
1746
1751
state -> fi_freelist_len -- ;
1747
1752
it = state -> fi_freelist ;
1748
1753
state -> fi_freelist = (futureiterobject * ) it -> future ;
1749
1754
it -> future = NULL ;
1750
1755
_Py_NewReference ((PyObject * ) it );
1751
1756
}
1752
- else {
1757
+ else
1758
+ #endif
1759
+ {
1753
1760
it = PyObject_GC_New (futureiterobject , state -> FutureIterType );
1754
1761
if (it == NULL ) {
1755
1762
return NULL ;
@@ -3463,6 +3470,7 @@ _asyncio_current_task_impl(PyObject *module, PyObject *loop)
3463
3470
static void
3464
3471
module_free_freelists (asyncio_state * state )
3465
3472
{
3473
+ #ifndef Py_GIL_DISABLED
3466
3474
PyObject * next ;
3467
3475
PyObject * current ;
3468
3476
@@ -3477,6 +3485,7 @@ module_free_freelists(asyncio_state *state)
3477
3485
}
3478
3486
assert (state -> fi_freelist_len == 0 );
3479
3487
state -> fi_freelist = NULL ;
3488
+ #endif
3480
3489
}
3481
3490
3482
3491
static int
@@ -3507,13 +3516,16 @@ module_traverse(PyObject *mod, visitproc visit, void *arg)
3507
3516
3508
3517
Py_VISIT (state -> context_kwname );
3509
3518
3519
+ #ifndef Py_GIL_DISABLED
3510
3520
// Visit freelist.
3511
3521
PyObject * next = (PyObject * ) state -> fi_freelist ;
3512
3522
while (next != NULL ) {
3513
3523
PyObject * current = next ;
3514
3524
Py_VISIT (current );
3515
3525
next = (PyObject * ) ((futureiterobject * ) current )-> future ;
3516
3526
}
3527
+ #endif
3528
+
3517
3529
return 0 ;
3518
3530
}
3519
3531
0 commit comments