Skip to content

Commit b842fd3

Browse files
committed
Use atomic read and write with should_auto_add_history
Fix the variable race problem TSAN-0025 in gh-153852
1 parent 7745710 commit b842fd3

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

Modules/readline.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ readline_set_auto_history_impl(PyObject *module,
841841
int _should_auto_add_history)
842842
/*[clinic end generated code: output=619c6968246fd82b input=3d413073a1a03355]*/
843843
{
844-
should_auto_add_history = _should_auto_add_history;
844+
FT_ATOMIC_STORE_INT_RELAXED(should_auto_add_history, _should_auto_add_history);
845845
Py_RETURN_NONE;
846846
}
847847

@@ -1590,7 +1590,7 @@ call_readline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt)
15901590

15911591
/* we have a valid line */
15921592
n = strlen(p);
1593-
if (should_auto_add_history && n > 0) {
1593+
if (FT_ATOMIC_LOAD_INT_RELAXED(should_auto_add_history) && n > 0) {
15941594
const char *line;
15951595
int length = _py_get_history_length_lock_held();
15961596
if (length > 0) {

0 commit comments

Comments
 (0)