File tree 3 files changed +22
-2
lines changed 3 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,7 @@ typedef struct {
55
55
} _PyListIterObject ;
56
56
57
57
PyAPI_FUNC (PyObject * )_PyList_FromArraySteal (PyObject * const * src , Py_ssize_t n );
58
+ PyObject * _PyList_AsTupleStealItems (PyObject * );
58
59
59
60
#ifdef __cplusplus
60
61
}
Original file line number Diff line number Diff line change @@ -2069,7 +2069,7 @@ PySequence_Tuple(PyObject *v)
2069
2069
if (temp == NULL )
2070
2070
goto Fail ;
2071
2071
2072
- /* Fill the tuple . */
2072
+ /* Fill the temporary list . */
2073
2073
for (;;) {
2074
2074
PyObject * item = PyIter_Next (it );
2075
2075
if (item == NULL ) {
@@ -2085,7 +2085,7 @@ PySequence_Tuple(PyObject *v)
2085
2085
}
2086
2086
}
2087
2087
Py_DECREF (it );
2088
- PyObject * result = PyList_AsTuple (temp );
2088
+ PyObject * result = _PyList_AsTupleStealItems (temp );
2089
2089
Py_DECREF (temp );
2090
2090
return result ;
2091
2091
Original file line number Diff line number Diff line change @@ -3174,6 +3174,25 @@ PyList_AsTuple(PyObject *v)
3174
3174
return ret ;
3175
3175
}
3176
3176
3177
+ PyObject *
3178
+ _PyList_AsTupleStealItems (PyObject * v )
3179
+ {
3180
+ if (v == NULL || !PyList_Check (v )) {
3181
+ PyErr_BadInternalCall ();
3182
+ return NULL ;
3183
+ }
3184
+ PyObject * ret ;
3185
+ PyListObject * self = (PyListObject * )v ;
3186
+ if (Py_SIZE (v ) == 0 ) {
3187
+ return PyTuple_New (0 );
3188
+ }
3189
+ Py_BEGIN_CRITICAL_SECTION (self );
3190
+ ret = _PyTuple_FromNonEmptyArraySteal (self -> ob_item , Py_SIZE (v ));
3191
+ Py_SET_SIZE (v , 0 );
3192
+ Py_END_CRITICAL_SECTION ();
3193
+ return ret ;
3194
+ }
3195
+
3177
3196
PyObject *
3178
3197
_PyList_FromArraySteal (PyObject * const * src , Py_ssize_t n )
3179
3198
{
You can’t perform that action at this time.
0 commit comments