aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/Objects/listobject.c
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.com>2024-08-17 21:51:59 +0300
committershadchin <shadchin@yandex-team.com>2024-08-17 22:04:51 +0300
commitee9edbd8878888bafcd0eeb3b528f3ec4311560b (patch)
treed54d8138e50a446904f10a2092719be86af011b7 /contrib/tools/python3/Objects/listobject.c
parent72cbe4bad58add0912623ba51351ff1db8587249 (diff)
downloadydb-ee9edbd8878888bafcd0eeb3b528f3ec4311560b.tar.gz
Update Python 3 to 3.12.5
https://docs.python.org/release/3.12.5/whatsnew/changelog.html#python-3-12-5-final de86cdeacd3a8653b9ec36e87975886fafcf6dc2
Diffstat (limited to 'contrib/tools/python3/Objects/listobject.c')
-rw-r--r--contrib/tools/python3/Objects/listobject.c54
1 files changed, 41 insertions, 13 deletions
diff --git a/contrib/tools/python3/Objects/listobject.c b/contrib/tools/python3/Objects/listobject.c
index f59abe2e64..d017f34b94 100644
--- a/contrib/tools/python3/Objects/listobject.c
+++ b/contrib/tools/python3/Objects/listobject.c
@@ -2759,7 +2759,14 @@ list_richcompare(PyObject *v, PyObject *w, int op)
}
/* Compare the final item again using the proper operator */
- return PyObject_RichCompare(vl->ob_item[i], wl->ob_item[i], op);
+ PyObject *vitem = vl->ob_item[i];
+ PyObject *witem = wl->ob_item[i];
+ Py_INCREF(vitem);
+ Py_INCREF(witem);
+ PyObject *result = PyObject_RichCompare(vl->ob_item[i], wl->ob_item[i], op);
+ Py_DECREF(vitem);
+ Py_DECREF(witem);
+ return result;
}
/*[clinic input]
@@ -2928,6 +2935,23 @@ list_subscript(PyListObject* self, PyObject* item)
}
}
+static Py_ssize_t
+adjust_slice_indexes(PyListObject *lst,
+ Py_ssize_t *start, Py_ssize_t *stop,
+ Py_ssize_t step)
+{
+ Py_ssize_t slicelength = PySlice_AdjustIndices(Py_SIZE(lst), start, stop,
+ step);
+
+ /* Make sure s[5:2] = [..] inserts at the right place:
+ before 5, not before 2. */
+ if ((step < 0 && *start < *stop) ||
+ (step > 0 && *start > *stop))
+ *stop = *start;
+
+ return slicelength;
+}
+
static int
list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value)
{
@@ -2940,22 +2964,11 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value)
return list_ass_item(self, i, value);
}
else if (PySlice_Check(item)) {
- Py_ssize_t start, stop, step, slicelength;
+ Py_ssize_t start, stop, step;
if (PySlice_Unpack(item, &start, &stop, &step) < 0) {
return -1;
}
- slicelength = PySlice_AdjustIndices(Py_SIZE(self), &start, &stop,
- step);
-
- if (step == 1)
- return list_ass_slice(self, start, stop, value);
-
- /* Make sure s[5:2] = [..] inserts at the right place:
- before 5, not before 2. */
- if ((step < 0 && start < stop) ||
- (step > 0 && start > stop))
- stop = start;
if (value == NULL) {
/* delete slice */
@@ -2964,6 +2977,12 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value)
Py_ssize_t i;
int res;
+ Py_ssize_t slicelength = adjust_slice_indexes(self, &start, &stop,
+ step);
+
+ if (step == 1)
+ return list_ass_slice(self, start, stop, value);
+
if (slicelength <= 0)
return 0;
@@ -3039,6 +3058,15 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value)
if (!seq)
return -1;
+ Py_ssize_t slicelength = adjust_slice_indexes(self, &start, &stop,
+ step);
+
+ if (step == 1) {
+ int res = list_ass_slice(self, start, stop, seq);
+ Py_DECREF(seq);
+ return res;
+ }
+
if (PySequence_Fast_GET_SIZE(seq) != slicelength) {
PyErr_Format(PyExc_ValueError,
"attempt to assign sequence of "