File tree Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ static int
80
80
list_preallocate_exact (PyListObject * self , Py_ssize_t size )
81
81
{
82
82
PyObject * * items ;
83
- size_t allocated , num_allocated_bytes ;
83
+ size_t allocated ;
84
84
85
85
allocated = (size_t )size ;
86
86
if (allocated > (size_t )PY_SSIZE_T_MAX / sizeof (PyObject * )) {
@@ -91,8 +91,7 @@ list_preallocate_exact(PyListObject *self, Py_ssize_t size)
91
91
if (size == 0 ) {
92
92
allocated = 0 ;
93
93
}
94
- num_allocated_bytes = allocated * sizeof (PyObject * );
95
- items = (PyObject * * )PyMem_Malloc (num_allocated_bytes );
94
+ items = (PyObject * * )PyMem_New (PyObject * , allocated );
96
95
if (items == NULL ) {
97
96
PyErr_NoMemory ();
98
97
return -1 ;
@@ -2675,10 +2674,14 @@ list___init___impl(PyListObject *self, PyObject *iterable)
2675
2674
(void )_list_clear (self );
2676
2675
}
2677
2676
if (iterable != NULL ) {
2678
- if (_PyObject_HasLen (iterable )) {
2679
- Py_ssize_t iter_len = PyObject_Length (iterable );
2677
+ if (_PyObject_HasLen (iterable ) && self -> ob_item == NULL ) {
2678
+ Py_ssize_t iter_len = PyObject_Size (iterable );
2680
2679
if (iter_len == -1 ) {
2681
- PyErr_Clear ();
2680
+ if (PyErr_ExceptionMatches (PyExc_Exception )) {
2681
+ PyErr_Clear ();
2682
+ } else {
2683
+ return -1 ;
2684
+ }
2682
2685
}
2683
2686
if (iter_len > 0 && list_preallocate_exact (self , iter_len )) {
2684
2687
return -1 ;
You can’t perform that action at this time.
0 commit comments