8000 gh-106168: Revert the "size before item" setting (#111683) · python/cpython@24ddaee · GitHub
[go: up one dir, main page]

Skip to content

Commit 24ddaee

Browse files
authored
gh-106168: Revert the "size before item" setting (#111683)
gh-106168: Update the size only after setting the item, to avoid temporary inconsistencies. Also remove the "what's new" sentence regarding the size setting since tuples cannot grow after allocation.
1 parent d49aba5 commit 24ddaee

File tree

3 files changed

+2
-4
lines changed

3 files changed

+2
-4
lines changed

Doc/whatsnew/3.13.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,8 +1049,6 @@ New Features
10491049
* If Python is built in :ref:`debug mode <debug-build>` or :option:`with
10501050
assertions <--with-assertions>`, :c:func:`PyTuple_SET_ITEM` and
10511051
:c:func:`PyList_SET_ITEM` now check the index argument with an assertion.
1052-
If the assertion fails in :c:func:`PyTuple_SET_ITEM`, make sure that the
1053-
tuple size is set before.
10541052
(Contributed by Victor Stinner in :gh:`106168`.)
10551053

10561054
* Add :c:func:`PyModule_Add` function: similar to

Include/internal/pycore_list.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ _PyList_AppendTakeRef(PyListObject *self, PyObject *newitem)
5151
Py_ssize_t allocated = self->allocated;
5252
assert((size_t)len + 1 < PY_SSIZE_T_MAX);
5353
if (allocated > len) {
54-
Py_SET_SIZE(self, len + 1);
5554
PyList_SET_ITEM(self, len, newitem);
55+
Py_SET_SIZE(self, len + 1);
5656
return 0;
5757
}
5858
return _PyList_AppendTakeRefListResize(self, newitem);

Objects/listobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,8 +956,8 @@ list_extend(PyListObject *self, PyObject *iterable)
956956
if (Py_SIZE(self) < self-> 6F53 allocated) {
957957
/* steals ref */
958958
Py_ssize_t len = Py_SIZE(self);
959-
Py_SET_SIZE(self, len + 1);
960959
PyList_SET_ITEM(self, len, item);
960+
Py_SET_SIZE(self, len + 1);
961961
}
962962
else {
963963
if (_PyList_AppendTakeRef(self, item) < 0)

0 commit comments

Comments
 (0)
0