Skip to content

Commit d36b2b3

Browse files
committed
Cleanup
* list_new_prealloc() sets ob_size and allocated before ob_item * Add comment to list_get_size()
1 parent ba04abb commit d36b2b3

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

‎Modules/_testcapi/list.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ static PyObject *
1111
list_get_size(PyObject *Py_UNUSED(module), PyObject *obj)
1212
{
1313
NULLABLE(obj);
14-
RETURN_SIZE(PyList_GET_SIZE(obj));
14+
RETURN_SIZE(PyList_GET_SIZE(obj)); // crash if not list or NULL
1515
}
1616

1717

‎Objects/listobject.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,9 @@ list_new_prealloc(Py_ssize_t size)
320320
}
321321
}
322322

323+
Py_SET_SIZE(op, 0);
324+
op->allocated = size;
325+
323326
if (size == 0) {
324327
op->ob_item = NULL;
325328
}
@@ -340,8 +343,6 @@ list_new_prealloc(Py_ssize_t size)
340343
}
341344
#endif
342345
}
343-
Py_SET_SIZE(op, 0);
344-
op->allocated = size;
345346

346347
return (PyObject *) op;
347348
}

0 commit comments

Comments
 (0)