summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorNeil Schemenauer <nas-github@arctrix.com>2023-01-12 18:03:50 (GMT)
committerGitHub <noreply@github.com>2023-01-12 18:03:50 (GMT)
commitc549fcccbbcf6cbf7db3da928a09e81e2c8bc7f3 (patch)
tree002234db1aaab2205ee02d8fed52460bc22596d9 /Objects
parent2161bbf243983c625e8f24cdf43b757f2a21463b (diff)
downloadcpython-c549fcccbbcf6cbf7db3da928a09e81e2c8bc7f3.zip
cpython-c549fcccbbcf6cbf7db3da928a09e81e2c8bc7f3.tar.gz
cpython-c549fcccbbcf6cbf7db3da928a09e81e2c8bc7f3.tar.bz2
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.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/typeobject.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index e4da5b2..59e0bf2 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -1289,8 +1289,13 @@ PyObject *
_PyType_AllocNoTrack(PyTypeObject *type, Py_ssize_t nitems)
{
PyObject *obj;
+ /* The +1 on nitems is needed for most types but not all. We could save a
+ * bit of space by allocating one less item in certain cases, depending on
+ * the type. However, given the extra complexity (e.g. an additional type
+ * flag to indicate when that is safe) it does not seem worth the memory
+ * savings. An example type that doesn't need the +1 is a subclass of
+ * tuple. See GH-100659 and GH-81381. */
const size_t size = _PyObject_VAR_SIZE(type, nitems+1);
- /* note that we need to add one, for the sentinel */
const size_t presize = _PyType_PreHeaderSize(type);
char *alloc = PyObject_Malloc(size + presize);