mirror of
https://github.com/python/cpython.git
synced 2025-08-27 12:16:04 +00:00
gh-112087: Make __sizeof__ and listiter_{len, next} to be threadsafe (gh-114843)
This commit is contained in:
parent
4b2d1786cc
commit
a2d4281415
7 changed files with 80 additions and 69 deletions
|
@ -2606,11 +2606,14 @@ dummy_func(
|
|||
assert(Py_TYPE(iter) == &PyListIter_Type);
|
||||
STAT_INC(FOR_ITER, hit);
|
||||
PyListObject *seq = it->it_seq;
|
||||
if (seq == NULL || it->it_index >= PyList_GET_SIZE(seq)) {
|
||||
if ((size_t)it->it_index >= (size_t)PyList_GET_SIZE(seq)) {
|
||||
it->it_index = -1;
|
||||
#ifndef Py_GIL_DISABLED
|
||||
if (seq != NULL) {
|
||||
it->it_seq = NULL;
|
||||
Py_DECREF(seq);
|
||||
}
|
||||
#endif
|
||||
Py_DECREF(iter);
|
||||
STACK_SHRINK(1);
|
||||
/* Jump forward oparg, then skip following END_FOR and POP_TOP instructions */
|
||||
|
@ -2624,8 +2627,7 @@ dummy_func(
|
|||
_PyListIterObject *it = (_PyListIterObject *)iter;
|
||||
assert(Py_TYPE(iter) == &PyListIter_Type);
|
||||
PyListObject *seq = it->it_seq;
|
||||
DEOPT_IF(seq == NULL);
|
||||
DEOPT_IF(it->it_index >= PyList_GET_SIZE(seq));
|
||||
DEOPT_IF((size_t)it->it_index >= (size_t)PyList_GET_SIZE(seq));
|
||||
}
|
||||
|
||||
op(_ITER_NEXT_LIST, (iter -- iter, next)) {
|
||||
|
|
3
Python/executor_cases.c.h
generated
3
Python/executor_cases.c.h
generated
|
@ -2201,8 +2201,7 @@
|
|||
_PyListIterObject *it = (_PyListIterObject *)iter;
|
||||
assert(Py_TYPE(iter) == &PyListIter_Type);
|
||||
PyListObject *seq = it->it_seq;
|
||||
if (seq == NULL) goto deoptimize;
|
||||
if (it->it_index >= PyList_GET_SIZE(seq)) goto deoptimize;
|
||||
if ((size_t)it->it_index >= (size_t)PyList_GET_SIZE(seq)) goto deoptimize;
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
5
Python/generated_cases.c.h
generated
5
Python/generated_cases.c.h
generated
|
@ -2541,11 +2541,14 @@
|
|||
assert(Py_TYPE(iter) == &PyListIter_Type);
|
||||
STAT_INC(FOR_ITER, hit);
|
||||
PyListObject *seq = it->it_seq;
|
||||
if (seq == NULL || it->it_index >= PyList_GET_SIZE(seq)) {
|
||||
if ((size_t)it->it_index >= (size_t)PyList_GET_SIZE(seq)) {
|
||||
it->it_index = -1;
|
||||
#ifndef Py_GIL_DISABLED
|
||||
if (seq != NULL) {
|
||||
it->it_seq = NULL;
|
||||
Py_DECREF(seq);
|
||||
}
|
||||
#endif
|
||||
Py_DECREF(iter);
|
||||
STACK_SHRINK(1);
|
||||
/* Jump forward oparg, then skip following END_FOR and POP_TOP instructions */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue