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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user