File tree 4 files changed +16
-0
lines changed
Misc/NEWS.d/next/Core and Builtins
4 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -122,6 +122,10 @@ static inline void _PyGC_SET_FINALIZED(PyObject *op) {
122
122
PyGC_Head * gc = _Py_AS_GC (op );
123
123
_PyGCHead_SET_FINALIZED (gc );
124
124
}
125
+ static inline void _PyGC_CLEAR_FINALIZED (PyObject * op ) {
126
+ PyGC_Head * gc = _Py_AS_GC (op );
127
+ gc -> _gc_prev &= ~_PyGC_PREV_MASK_FINALIZED ;
128
+ }
125
129
126
130
127
131
/* GC runtime state */
Original file line number Diff line number Diff line change @@ -1701,6 +1701,14 @@ def test_asend(self):
1701
1701
async def gen ():
1702
1702
yield 1
1703
1703
1704
+ # gh-113753: asend objects allocated from a free-list should warn.
1705
+ # Ensure there is a finalized 'asend' object ready to be reused.
1706
+ try :
1707
+ g = gen ()
1708
+ g .asend (None ).send (None )
1709
+ except StopIteration :
1710
+ pass
1711
+
1704
1712
msg = f"coroutine method 'asend' of '{ gen .__qualname__ } ' was never awaited"
1705
1713
with self .assertWarnsRegex (RuntimeWarning , msg ):
1706
1714
g = gen ()
Original file line number Diff line number Diff line change
1
+ Fix an issue where the finalizer of ``PyAsyncGenASend `` objects might not be
2
+ called if they were allocated from a free list.
Original file line number Diff line number Diff line change 6
6
#include "pycore_call.h" // _PyObject_CallNoArgs()
7
7
#include "pycore_ceval.h" // _PyEval_EvalFrame()
8
8
#include "pycore_frame.h" // _PyInterpreterFrame
9
+ #include "pycore_gc.h" // _PyGC_CLEAR_FINALIZED()
9
10
#include "pycore_genobject.h" // struct _Py_async_gen_state
10
11
#include "pycore_modsupport.h" // _PyArg_CheckPositional()
11
12
#include "pycore_object.h" // _PyObject_GC_UNTRACK()
@@ -1739,6 +1740,7 @@ async_gen_asend_dealloc(PyAsyncGenASend *o)
1739
1740
#endif
1740
1741
if (state -> asend_numfree < _PyAsyncGen_MAXFREELIST ) {
1741
1742
assert (PyAsyncGenASend_CheckExact (o ));
1743
+ _PyGC_CLEAR_FINALIZED ((PyObject * )o );
1742
1744
state -> asend_freelist [state -> asend_numfree ++ ] = o ;
1743
1745
}
1744
1746
else
You can’t perform that action at this time.
0 commit comments