summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorscoder <stefan_ml@behnel.de>2023-11-03 11:02:39 (GMT)
committerGitHub <noreply@github.com>2023-11-03 11:02:39 (GMT)
commit24ddaee5ca112063b460e72d31b3da551a02bf0a (patch)
tree24407ff8b7373cba709e1656900d3f53b5be2d24
parentd49aba5a7a3c695213810a9f82715809c6332df2 (diff)
downloadcpython-24ddaee5ca112063b460e72d31b3da551a02bf0a.zip
cpython-24ddaee5ca112063b460e72d31b3da551a02bf0a.tar.gz
cpython-24ddaee5ca112063b460e72d31b3da551a02bf0a.tar.bz2
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.
-rw-r--r--Doc/whatsnew/3.13.rst2
-rw-r--r--Include/internal/pycore_list.h2
-rw-r--r--Objects/listobject.c2
3 files changed, 2 insertions, 4 deletions
diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst
index aa693c6..f2c1441 100644
--- a/Doc/whatsnew/3.13.rst
+++ b/Doc/whatsnew/3.13.rst
@@ -1049,8 +1049,6 @@ New Features
* If Python is built in :ref:`debug mode <debug-build>` or :option:`with
assertions <--with-assertions>`, :c:func:`PyTuple_SET_ITEM` and
:c:func:`PyList_SET_ITEM` now check the index argument with an assertion.
- If the assertion fails in :c:func:`PyTuple_SET_ITEM`, make sure that the
- tuple size is set before.
(Contributed by Victor Stinner in :gh:`106168`.)
* Add :c:func:`PyModule_Add` function: similar to
diff --git a/Include/internal/pycore_list.h b/Include/internal/pycore_list.h
index 056be2c..55d67b3 100644
--- a/Include/internal/pycore_list.h
+++ b/Include/internal/pycore_list.h
@@ -51,8 +51,8 @@ _PyList_AppendTakeRef(PyListObject *self, PyObject *newitem)
Py_ssize_t allocated = self->allocated;
assert((size_t)len + 1 < PY_SSIZE_T_MAX);
if (allocated > len) {
- Py_SET_SIZE(self, len + 1);
PyList_SET_ITEM(self, len, newitem);
+ Py_SET_SIZE(self, len + 1);
return 0;
}
return _PyList_AppendTakeRefListResize(self, newitem);
diff --git a/Objects/listobject.c b/Objects/listobject.c
index ad1840b..af006ef 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -956,8 +956,8 @@ list_extend(PyListObject *self, PyObject *iterable)
if (Py_SIZE(self) < self->allocated) {
/* steals ref */
Py_ssize_t len = Py_SIZE(self);
- Py_SET_SIZE(self, len + 1);
PyList_SET_ITEM(self, len, item);
+ Py_SET_SIZE(self, len + 1);
}
else {
if (_PyList_AppendTakeRef(self, item) < 0)