https://github.com/python/cpython/commit/386d9d071cee2168bee135bc15897a27377d0999
commit: 386d9d071cee2168bee135bc15897a27377d0999
branch: main
author: Cody Maloney <[email protected]>
committer: corona10 <[email protected]>
date: 2026-10-30T05:32:10+09:00
summary:

gh-160858: Use the list freelist in list() (gh-160859)

files:
M Objects/listobject.c

diff --git a/Objects/listobject.c b/Objects/listobject.c
index a01f40d57181da..4384a850780b7f 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -3600,7 +3600,7 @@ static int
 list___init___impl(PyListObject *self, PyObject *iterable)
 /*[clinic end generated code: output=0f3c21379d01de48 input=b3f3fe7206af8f6b]*/
 {
-    /* Verify list invariants established by PyType_GenericAlloc() */
+    /* Verify list invariants */
     assert(0 <= Py_SIZE(self));
     assert(Py_SIZE(self) <= self->allocated || self->allocated == -1);
     assert(self->ob_item != NULL ||
@@ -3632,7 +3632,10 @@ list_vectorcall(PyObject *type, PyObject * const*args,
         return NULL;
     }
 
-    PyObject *list = PyType_GenericAlloc(_PyType_CAST(type), 0);
+    /* use PyList_New() to make exact lists from the freelist. */
+    PyObject *list = (type == (PyObject *)&PyList_Type
+                      ? PyList_New(0)
+                      : PyType_GenericAlloc(_PyType_CAST(type), 0));
     if (list == NULL) {
         return NULL;
     }

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to