Skip to content

Commit c549fcc

Browse files
authored
GH-81381: Add longer comment _PyType_AllocNoTrack() (GH-100954)
The details on the "nitems+1" expression is a bit subtle so add a longer comment about it.
1 parent 2161bbf commit c549fcc

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Objects/typeobject.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1289,8 +1289,13 @@ PyObject *
12891289
_PyType_AllocNoTrack(PyTypeObject *type, Py_ssize_t nitems)
12901290
{
12911291
PyObject *obj;
1292+
/* The +1 on nitems is needed for most types but not all. We could save a
1293+
* bit of space by allocating one less item in certain cases, depending on
1294+
* the type. However, given the extra complexity (e.g. an additional type
1295+
* flag to indicate when that is safe) it does not seem worth the memory
1296+
* savings. An example type that doesn't need the +1 is a subclass of
1297+
* tuple. See GH-100659 and GH-81381. */
12921298
const size_t size = _PyObject_VAR_SIZE(type, nitems+1);
1293-
/* note that we need to add one, for the sentinel */
12941299

12951300
const size_t presize = _PyType_PreHeaderSize(type);
12961301
char *alloc = PyObject_Malloc(size + presize);

0 commit comments

Comments
 (0)