bpo-40887: Don't use finalized free lists (GH-20700) · python/cpython@bcb1983

@@ -1430,6 +1430,11 @@ void

14301430

_PyAsyncGen_Fini(PyThreadState *tstate)

14311431

{

14321432

_PyAsyncGen_ClearFreeLists(tstate);

1433+

#ifdef Py_DEBUG

1434+

struct _Py_async_gen_state *state = &tstate->interp->async_gen;

1435+

state->value_numfree = -1;

1436+

state->asend_numfree = -1;

1437+

#endif

14331438

}

1434143914351440

@@ -1474,6 +1479,10 @@ async_gen_asend_dealloc(PyAsyncGenASend *o)

14741479

Py_CLEAR(o->ags_sendval);

14751480

PyInterpreterState *interp = _PyInterpreterState_GET();

14761481

struct _Py_async_gen_state *state = &interp->async_gen;

1482+

#ifdef Py_DEBUG

1483+

// async_gen_asend_dealloc() must not be called after _PyAsyncGen_Fini()

1484+

assert(state->asend_numfree != -1);

1485+

#endif

14771486

if (state->asend_numfree < _PyAsyncGen_MAXFREELIST) {

14781487

assert(PyAsyncGenASend_CheckExact(o));

14791488

state->asend_freelist[state->asend_numfree++] = o;

@@ -1632,6 +1641,10 @@ async_gen_asend_new(PyAsyncGenObject *gen, PyObject *sendval)

16321641

PyAsyncGenASend *o;

16331642

PyInterpreterState *interp = _PyInterpreterState_GET();

16341643

struct _Py_async_gen_state *state = &interp->async_gen;

1644+

#ifdef Py_DEBUG

1645+

// async_gen_asend_new() must not be called after _PyAsyncGen_Fini()

1646+

assert(state->asend_numfree != -1);

1647+

#endif

16351648

if (state->asend_numfree) {

16361649

state->asend_numfree--;

16371650

o = state->asend_freelist[state->asend_numfree];

@@ -1667,6 +1680,10 @@ async_gen_wrapped_val_dealloc(_PyAsyncGenWrappedValue *o)

16671680

Py_CLEAR(o->agw_val);

16681681

PyInterpreterState *interp = _PyInterpreterState_GET();

16691682

struct _Py_async_gen_state *state = &interp->async_gen;

1683+

#ifdef Py_DEBUG

1684+

// async_gen_wrapped_val_dealloc() must not be called after _PyAsyncGen_Fini()

1685+

assert(state->value_numfree != -1);

1686+

#endif

16701687

if (state->value_numfree < _PyAsyncGen_MAXFREELIST) {

16711688

assert(_PyAsyncGenWrappedValue_CheckExact(o));

16721689

state->value_freelist[state->value_numfree++] = o;

@@ -1737,6 +1754,10 @@ _PyAsyncGenValueWrapperNew(PyObject *val)

1737175417381755

PyInterpreterState *interp = _PyInterpreterState_GET();

17391756

struct _Py_async_gen_state *state = &interp->async_gen;

1757+

#ifdef Py_DEBUG

1758+

// _PyAsyncGenValueWrapperNew() must not be called after _PyAsyncGen_Fini()

1759+

assert(state->value_numfree != -1);

1760+

#endif

17401761

if (state->value_numfree) {

17411762

state->value_numfree--;

17421763

o = state->value_freelist[state->value_numfree];