File tree Expand file tree Collapse file tree 1 file changed +13
-9
lines changed Expand file tree Collapse file tree 1 file changed +13
-9
lines changed Original file line number Diff line number Diff line change @@ -920,14 +920,22 @@ _PyTuple_Resize(PyObject **pv, Py_ssize_t newsize)
920
920
PyErr_BadInternalCall ();
921
921
return -1 ;
922
922
}
923
+
923
924
oldsize = Py_SIZE (v );
924
- if (oldsize == newsize )
925
+ if (oldsize == newsize ) {
925
926
return 0 ;
926
-
927
+ }
928
+ if (newsize == 0 ) {
929
+ Py_DECREF (v );
930
+ * pv = tuple_get_empty ();
931
+ return 0 ;
932
+ }
927
933
if (oldsize == 0 ) {
928
- /* Empty tuples are often shared, so we should never
929
- resize them in-place even if we do own the only
930
- (current) reference */
934
+ #ifdef Py_DEBUG
935
+ assert (v == & _Py_SINGLETON (tuple_empty ));
936
+ #endif
937
+ /* The empty tuple is statically allocated so we never
938
+ resize it in-place. */
931
939
Py_DECREF (v );
932
940
* pv = PyTuple_New (newsize );
933
941
return * pv == NULL ? -1 : 0 ;
@@ -947,10 +955,6 @@ _PyTuple_Resize(PyObject **pv, Py_ssize_t newsize)
947
955
for (i = newsize ; i < oldsize ; i ++ ) {
948
956
Py_CLEAR (v -> ob_item [i ]);
949
957
}
950
- if (newsize == 0 ) {
951
- * pv = tuple_get_empty ();
952
- return 0 ;
953
- }
954
958
sv = PyObject_GC_Resize (PyTupleObject , v , newsize );
955
959
if (sv == NULL ) {
956
960
* pv = NULL ;
You can’t perform that action at this time.
0 commit comments