Anonymous View
Skip to content

gh-151218: Replace sys.flags in PyConfig_Set()#151402

Open
vstinner wants to merge 4 commits into
python:mainfrom
vstinner:replace_sys_flags
Open

gh-151218: Replace sys.flags in PyConfig_Set()#151402
vstinner wants to merge 4 commits into
python:mainfrom
vstinner:replace_sys_flags

Conversation

@vstinner

@vstinner vstinner commented Jun 12, 2026

Copy link
Copy Markdown
Member

PyConfig_Set() and sys.set_int_max_str_digits() now replace sys.flags, instead of modifying sys.flags in-place.

Modifying sys.flags in-place can lead to data races when multiple threads are reading or writing sys.flags in parallel.

Use _Py_atomic functions to get and set max_str_digits members.

PyConfig_Set() and sys.set_int_max_str_digits() now replace
sys.flags, instead of modifying sys.flags in-place.

Modifying sys.flags in-place can lead to data races when multiple
threads are reading or writing sys.flags in parallel.

Use _Py_atomic functions to get and set max_str_digits members.
@vstinner

Copy link
Copy Markdown
Member Author

I built Python with ./configure --with-pydebug --disable-gil --with-thread-sanitizer CC=clang LD=clang and I ran the reproducer: TSan doesn't report data races anymore.

If we agree that this change is the right approach, I will add a non-regression test.

@skirpichev skirpichev self-requested a review June 12, 2026 13:44

@skirpichev skirpichev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it's a correct approach.

@vstinner

Copy link
Copy Markdown
Member Author

I added a thread test to test_free_threading.test_sys which is run by ./python -m test --tsan.

I also added some simple tests on get_int_max_str_digits() / set_int_max_str_digits() (in test_sys).

@vstinner

Copy link
Copy Markdown
Member Author

@picnixz @gpshead: Would you mind to review this fix?

@vstinner vstinner added needs backport to 3.15 pre-release feature fixes, bugs and security fixes needs backport to 3.14 bugs and security fixes labels Jun 15, 2026
@vstinner

Copy link
Copy Markdown
Member Author

Python 3.13 is not affected: sys.set_int_max_str_digits() only sets tstate->interp->long_state.max_str_digits, it doesn't update sys.flags. And PyConfig_Set() was only added to Python 3.14.

I modified sys.set_int_max_str_digits() in Python 3.14 when I implemented PEP 741 (PyConfig_Set()).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants