Closed
Description
Bug report
Bug description:
It is unsafe to borrow a PyObject *
reference from a _PyStackRef
and Py_DECREF
the PyObject *
reference and not close the _PyStackRef
. This is quite a common pattern in bytecodes.c, and prevents any optimizations based on reference lifetimes as the inferred lifetime is incorrect.
The fix for this is to change the incorrect pattern:
PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
use(left_o);
Py_DECREF(left_o);
to the correct pattern:
PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
use(left_o);
PyStackRef_CLOSE(left);
This is causing problems, as optimizations to exploit stack refs don't work: https://github.com/python/cpython/compare/main...faster-cpython:cpython:use-stackrefs-opt-experiment?expand=1
CPython versions tested on:
CPython main branch
Operating systems tested on:
Other