@@ -1628,12 +1628,12 @@ PyTypeObject PyAsyncGen_Type = {
1628
1628
};
1629
1629
1630
1630
1631
- #if _PyAsyncGen_MAXFREELIST > 0
1631
+ #ifdef WITH_FREELISTS
1632
1632
static struct _Py_async_gen_state *
1633
1633
get_async_gen_state (void )
1634
1634
{
1635
- PyInterpreterState * interp = _PyInterpreterState_GET ();
1636
- return & interp -> async_gen ;
1635
+ _PyFreeListState * state = _PyFreeListState_GET ();
1636
+ return & state -> async_gen_state ;
1637
1637
}
1638
1638
#endif
1639
1639
@@ -1656,36 +1656,36 @@ PyAsyncGen_New(PyFrameObject *f, PyObject *name, PyObject *qualname)
1656
1656
1657
1657
1658
1658
void
1659
- _PyAsyncGen_ClearFreeLists (PyInterpreterState * interp )
1659
+ _PyAsyncGen_ClearFreeLists (_PyFreeListState * freelist_state , int is_finalization )
1660
1660
{
1661
- #if _PyAsyncGen_MAXFREELIST > 0
1662
- struct _Py_async_gen_state * state = & interp -> async_gen ;
1661
+ #ifdef WITH_FREELISTS
1662
+ struct _Py_async_gen_state * state = & freelist_state -> async_gen_state ;
1663
1663
1664
- while (state -> value_numfree ) {
1664
+ while (state -> value_numfree > 0 ) {
1665
1665
_PyAsyncGenWrappedValue * o ;
1666
1666
o = state -> value_freelist [-- state -> value_numfree ];
1667
1667
assert (_PyAsyncGenWrappedValue_CheckExact (o ));
1668
1668
PyObject_GC_Del (o );
1669
1669
}
1670
1670
1671
- while (state -> asend_numfree ) {
1671
+ while (state -> asend_numfree > 0 ) {
1672
1672
PyAsyncGenASend * o ;
1673
1673
o = state -> asend_freelist [-- state -> asend_numfree ];
1674
1674
assert (Py_IS_TYPE (o , & _PyAsyncGenASend_Type ));
1675
1675
PyObject_GC_Del (o );
1676
1676
}
1677
+
1678
+ if (is_finalization ) {
1679
+ state -> value_numfree = -1 ;
1680
+ state -> asend_numfree = -1 ;
1681
+ }
1677
1682
#endif
1678
1683
}
1679
1684
1680
1685
void
1681
- _PyAsyncGen_Fini (PyInterpreterState * interp )
1686
+ _PyAsyncGen_Fini (_PyFreeListState * state )
1682
1687
{
1683
- _PyAsyncGen_ClearFreeLists (interp );
1684
- #if defined(Py_DEBUG ) && _PyAsyncGen_MAXFREELIST > 0
1685
- struct _Py_async_gen_state * state = & interp -> async_gen ;
1686
- state -> value_numfree = -1 ;
1687
- state -> asend_numfree = -1 ;
1688
- #endif
1688
+ _PyAsyncGen_ClearFreeLists (state , 1 );
1689
1689
}
1690
1690
1691
1691
@@ -1732,13 +1732,9 @@ async_gen_asend_dealloc(PyAsyncGenASend *o)
1732
1732
_PyObject_GC_UNTRACK ((PyObject * )o );
1733
1733
Py_CLEAR (o -> ags_gen );
1734
1734
Py_CLEAR (o -> ags_sendval );
1735
- #if _PyAsyncGen_MAXFREELIST > 0
1735
+ #ifdef WITH_FREELISTS
1736
1736
struct _Py_async_gen_state * state = get_async_gen_state ();
1737
- #ifdef Py_DEBUG
1738
- // async_gen_asend_dealloc() must not be called after _PyAsyncGen_Fini()
1739
- assert (state -> asend_numfree != -1 );
1740
- #endif
1741
- if (state -> asend_numfree < _PyAsyncGen_MAXFREELIST ) {
1737
+ if (state -> asend_numfree >= 0 && state -> asend_numfree < _PyAsyncGen_MAXFREELIST ) {
1742
1738
assert (PyAsyncGenASend_CheckExact (o ));
1743
1739
_PyGC_CLEAR_FINALIZED ((PyObject * )o );
1744
1740
state -> asend_freelist [state -> asend_numfree ++ ] = o ;
@@ -1906,13 +1902,9 @@ static PyObject *
1906
1902
async_gen_asend_new (PyAsyncGenObject * gen , PyObject * sendval )
1907
1903
{
1908
1904
PyAsyncGenASend * o ;
1909
- #if _PyAsyncGen_MAXFREELIST > 0
1905
+ #ifdef WITH_FREELISTS
1910
1906
struct _Py_async_gen_state * state = get_async_gen_state ();
1911
- #ifdef Py_DEBUG
1912
- // async_gen_asend_new() must not be called after _PyAsyncGen_Fini()
1913
- assert (state -> asend_numfree != -1 );
1914
- #endif
1915
- if (state -> asend_numfree ) {
1907
+ if (state -> asend_numfree > 0 ) {
1916
1908
state -> asend_numfree -- ;
1917
1909
o = state -> asend_freelist [state -> asend_numfree ];
1918
1910
_Py_NewReference ((PyObject * )o );
@@ -1945,13 +1937,9 @@ async_gen_wrapped_val_dealloc(_PyAsyncGenWrappedValue *o)
1945
1937
{
1946
1938
_PyObject_GC_UNTRACK ((PyObject * )o );
1947
1939
Py_CLEAR (o -> agw_val );
1948
- #if _PyAsyncGen_MAXFREELIST > 0
1940
+ #ifdef WITH_FREELISTS
1949
1941
struct _Py_async_gen_state * state = get_async_gen_state ();
1950
- #ifdef Py_DEBUG
1951
- // async_gen_wrapped_val_dealloc() must not be called after _PyAsyncGen_Fini()
1952
- assert (state -> value_numfree != -1 );
1953
- #endif
1954
- if (state -> value_numfree < _PyAsyncGen_MAXFREELIST ) {
1942
+ if (state -> value_numfree >= 0 && state -> value_numfree < _PyAsyncGen_MAXFREELIST ) {
1955
1943
assert (_PyAsyncGenWrappedValue_CheckExact (o ));
1956
1944
state -> value_freelist [state -> value_numfree ++ ] = o ;
1957
1945
OBJECT_STAT_INC (to_freelist );
@@ -2022,13 +2010,9 @@ _PyAsyncGenValueWrapperNew(PyThreadState *tstate, PyObject *val)
2022
2010
_PyAsyncGenWrappedValue * o ;
2023
2011
assert (val );
2024
2012
2025
- #if _PyAsyncGen_MAXFREELIST > 0
2026
- struct _Py_async_gen_state * state = & tstate -> interp -> async_gen ;
2027
- #ifdef Py_DEBUG
2028
- // _PyAsyncGenValueWrapperNew() must not be called after _PyAsyncGen_Fini()
2029
- assert (state -> value_numfree != -1 );
2030
- #endif
2031
- if (state -> value_numfree ) {
2013
+ #ifdef WITH_FREELISTS
2014
+ struct _Py_async_gen_state * state = get_async_gen_state ();
2015
+ if (state -> value_numfree > 0 ) {
2032
2016
state -> value_numfree -- ;
2033
2017
o = state -> value_freelist [state -> value_numfree ];
2034
2018
OBJECT_STAT_INC (from_freelist );
0 commit comments