From 4be582993913acdef83c5be1d23f5bf3db0aa5bb Mon Sep 17 00:00:00 2001 From: xxyzz Date: Thu, 23 Jul 2026 16:45:13 +0800 Subject: [PATCH] gh-154539: Use atomic read and write with `should_auto_add_history` Fix the variable race problem TSAN-0025 in gh-153852 --- Modules/readline.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/readline.c b/Modules/readline.c index fc79a5866dfd38..c887b159798215 100644 --- a/Modules/readline.c +++ b/Modules/readline.c @@ -841,7 +841,7 @@ readline_set_auto_history_impl(PyObject *module, int _should_auto_add_history) /*[clinic end generated code: output=619c6968246fd82b input=3d413073a1a03355]*/ { - should_auto_add_history = _should_auto_add_history; + FT_ATOMIC_STORE_INT_RELAXED(should_auto_add_history, _should_auto_add_history); Py_RETURN_NONE; } @@ -1590,7 +1590,7 @@ call_readline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt) /* we have a valid line */ n = strlen(p); - if (should_auto_add_history && n > 0) { + if (FT_ATOMIC_LOAD_INT_RELAXED(should_auto_add_history) && n > 0) { const char *line; int length = _py_get_history_length_lock_held(); if (length > 0) {