GH-128682: Change a couple of functions to only steal references on success. (GH-129132)

Change PyTuple_FromStackRefSteal and PyList_FromStackRefSteal to only steal on success to avoid escaping
This commit is contained in:
Mark Shannon 2025-01-22 10:51:37 +00:00 committed by GitHub
parent a65f802692
commit 470a0a68eb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 34 additions and 32 deletions

View file

@ -3190,7 +3190,7 @@ _PyList_AsTupleAndClear(PyListObject *self)
}
PyObject *
_PyList_FromStackRefSteal(const _PyStackRef *src, Py_ssize_t n)
_PyList_FromStackRefStealOnSuccess(const _PyStackRef *src, Py_ssize_t n)
{
if (n == 0) {
return PyList_New(0);
@ -3198,9 +3198,6 @@ _PyList_FromStackRefSteal(const _PyStackRef *src, Py_ssize_t n)
PyListObject *list = (PyListObject *)PyList_New(n);
if (list == NULL) {
for (Py_ssize_t i = 0; i < n; i++) {
PyStackRef_CLOSE(src[i]);
}
return NULL;
}