diff options
author | Donghee Na <donghee.na@python.org> | 2024-02-15 02:00:50 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-15 02:00:50 +0900 |
commit | a2d4281415e67c62f91363376db97eb66a9fb716 (patch) | |
tree | a70679c72f7c89af35614c6e1258c4507bd741a8 /Python/bytecodes.c | |
parent | 4b2d1786ccf913bc80ff571c32b196be1543ca54 (diff) | |
download | cpython-a2d4281415e67c62f91363376db97eb66a9fb716.tar.gz cpython-a2d4281415e67c62f91363376db97eb66a9fb716.zip |
gh-112087: Make __sizeof__ and listiter_{len, next} to be threadsafe (gh-114843)
Diffstat (limited to 'Python/bytecodes.c')
-rw-r--r-- | Python/bytecodes.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/Python/bytecodes.c b/Python/bytecodes.c index 96b97ca4be6..28ade64e056 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -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)) { |