8000 gh-120317: Lock around global state in the tokenize module by lysnikolaou · Pull Request #120318 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-120317: Lock around global state in the tokenize module #120318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jul 16, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Guard atomic store behind Py_GIL_DISABLED
  • Loading branch information
lysnikolaou committed Jun 10, 2024
commit c1093be27ba1631b4c2c0e94ea560584ac02434a
10 changes: 10 additions & 0 deletions Python/Python-tokenize.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,13 @@ tokenizeriter_next(tokenizeriterobject *it)
}
if (it->done || type == ERRORTOKEN) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need to protect the read? Otherwise we may get weird partial reads no?

PyErr_SetString(PyExc_StopIteration, "EOF");

#ifdef Py_GIL_DISABLED
_Py_atomic_store_int(&it->done, 1);
#else
it->done = 1;
#endif

goto exit;
}
PyObject *str = NULL;
Expand Down Expand Up @@ -332,7 +338,11 @@ tokenizeriter_next(tokenizeriterobject *it)
exit:
_PyToken_Free(&token);
if (type == ENDMARKER) {
#ifdef Py_GIL_DISABLED
_Py_atomic_store_int(&it->done, 1);
#else
it->done = 1;
#endif
}
return result;
}
Expand Down
0