diff options
author | Donghee Na <donghee.na@python.org> | 2024-02-14 17:00:50 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-14 17:00:50 (GMT) |
commit | a2d4281415e67c62f91363376db97eb66a9fb716 (patch) | |
tree | a70679c72f7c89af35614c6e1258c4507bd741a8 /Python | |
parent | 4b2d1786ccf913bc80ff571c32b196be1543ca54 (diff) | |
download | cpython-a2d4281415e67c62f91363376db97eb66a9fb716.zip cpython-a2d4281415e67c62f91363376db97eb66a9fb716.tar.gz cpython-a2d4281415e67c62f91363376db97eb66a9fb716.tar.bz2 |
gh-112087: Make __sizeof__ and listiter_{len, next} to be threadsafe (gh-114843)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/bytecodes.c | 8 | ||||
-rw-r--r-- | Python/executor_cases.c.h | 3 | ||||
-rw-r--r-- | Python/generated_cases.c.h | 5 |
3 files changed, 10 insertions, 6 deletions
diff --git a/Python/bytecodes.c b/Python/bytecodes.c index 96b97ca..28ade64 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)) { diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h index 58d2383..7a0e0e4 100644 --- a/Python/executor_cases.c.h +++ b/Python/executor_cases.c.h @@ -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; } diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h index a49223e..177bc32 100644 --- a/Python/generated_cases.c.h +++ b/Python/generated_cases.c.h @@ -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 */ |