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
11 changed files with 34 additions and 32 deletions

View File

@@ -391,16 +391,13 @@ _PyTuple_FromArray(PyObject *const *src, Py_ssize_t n)
}
PyObject *
_PyTuple_FromStackRefSteal(const _PyStackRef *src, Py_ssize_t n)
_PyTuple_FromStackRefStealOnSuccess(const _PyStackRef *src, Py_ssize_t n)
{
if (n == 0) {
return tuple_get_empty();
}
PyTupleObject *tuple = tuple_alloc(n);
if (tuple == NULL) {
for (Py_ssize_t i = 0; i < n; i++) {
PyStackRef_CLOSE(src[i]);
}
return NULL;
}
PyObject **dst = tuple->ob_item;