PyGC_Head *gc = _Py_AS_GC(op);
_PyGCHead_SET_FINALIZED(gc);
}
+static inline void _PyGC_CLEAR_FINALIZED(PyObject *op) {
+ PyGC_Head *gc = _Py_AS_GC(op);
+ gc->_gc_prev &= ~_PyGC_PREV_MASK_FINALIZED;
+}
/* GC runtime state */
async def gen():
yield 1
+ # gh-113753: asend objects allocated from a free-list should warn.
+ # Ensure there is a finalized 'asend' object ready to be reused.
+ try:
+ g = gen()
+ g.asend(None).send(None)
+ except StopIteration:
+ pass
+
msg = f"coroutine method 'asend' of '{gen.__qualname__}' was never awaited"
with self.assertWarnsRegex(RuntimeWarning, msg):
g = gen()
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_ceval.h" // _PyEval_EvalFrame()
#include "pycore_frame.h" // _PyInterpreterFrame
+#include "pycore_gc.h" // _PyGC_CLEAR_FINALIZED()
#include "pycore_genobject.h" // struct _Py_async_gen_state
#include "pycore_modsupport.h" // _PyArg_CheckPositional()
#include "pycore_object.h" // _PyObject_GC_UNTRACK()
#endif
if (state->asend_numfree < _PyAsyncGen_MAXFREELIST) {
assert(PyAsyncGenASend_CheckExact(o));
+ _PyGC_CLEAR_FINALIZED((PyObject *)o);
state->asend_freelist[state->asend_numfree++] = o;
}
else