8000 gh-123321: Make Parser/myreadline.c locking safe in free-threaded build by colesbury · Pull Request #123690 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-123321: Make Parser/myreadline.c locking safe in free-threaded build #123690

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 2 commits into from
Sep 6, 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
Restore removed Py_BEGIN_ALLOW_THREADS macro call.
The PyOS_ReadlineFunctionPointer and PyOS_StdioReadline expect to be
called with the GIL released.
  • Loading branch information
colesbury committed Sep 5, 2024
commit ebbdf97be79d9537482f644001cd11eac8cb3033
2 changes: 2 additions & 0 deletions Parser/myreadline.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ PyOS_Readline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt)
// GH-123321: We need to acquire the lock before setting
// _PyOS_ReadlineTState, otherwise the variable may be nullified by a
// different thread.
Py_BEGIN_ALLOW_THREADS
PyMutex_Lock(&_PyOS_ReadlineLock);
_Py_atomic_store_ptr_relaxed(&_PyOS_ReadlineTState, tstate);
if (PyOS_ReadlineFunctionPointer == NULL) {
Expand Down Expand Up @@ -415,6 +416,7 @@ PyOS_Readline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt)
// taking the GIL. Otherwise a deadlock or segfault may occur.
_Py_atomic_store_ptr_relaxed(&_PyOS_ReadlineTState, NULL);
PyMutex_Unlock(&_PyOS_ReadlineLock);
Py_END_ALLOW_THREADS

if (rv == NULL)
return NULL;
Expand Down
Loading
0