Skip to content

Commit 208d664

Browse files
yoneymeta-codesync[bot]
authored andcommitted
Fix iterator invalidation when reopting functions
Summary: Advance the iterator before `reoptFunc()` erase the current function from the set, avoiding invalid iteration. https://github.com/greg7mdp/parallel-hashmap?tab=readme-ov-file#iterator-invalidation-for-hash-containers Reviewed By: alexmalyshev Differential Revision: D97437765 fbshipit-source-id: a7cf22e082a7e798d997bd75dc5d2aa961592c12
1 parent ba1657f commit 208d664

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

cinderx/Jit/pyjit.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,12 @@ bool enable_jit_impl() {
13751375
}
13761376

13771377
size_t count = 0;
1378-
for (BorrowedRef<PyFunctionObject> func : jitCtx()->deoptedFuncs()) {
1378+
auto& funcs = jitCtx()->deoptedFuncs();
1379+
for (auto it = funcs.begin(); it != funcs.end();) {
1380+
BorrowedRef<PyFunctionObject> func = *it;
1381+
// Advance before reoptFunc() which erases func from funcs,
1382+
// invalidating the iterator pointing to it.
1383+
++it;
13791384
reoptFunc(func);
13801385
count++;
13811386
}

0 commit comments

Comments
 (0)