Skip to content

gh-158893: Make os.strerror() thread-safe - #158927

Merged
vstinner merged 3 commits into
python:mainfrom
vstinner:strerror_r
Oct 6, 2026
Merged

vstinner merged 3 commits into
python:mainfrom
vstinner:strerror_r

Conversation

@vstinner

@vstinner vstinner commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

Make os.strerror() thread-safe: use the reentrant strerror_r() function if available.

  • The configure script now checks if strerror_r() is supported.
  • Add a stress test to test_free_threading.test_os (new module).
  • Add a comment on decode_current_locale() assertion which fails if the input string is mutated.
  • Add an assertion to _Py_DecodeLocale() to detect if the input string was mutated during the function call.

Make os.strerror() thread-safe: use the reentrant strerror_r()
function if available.

* The configure script now checks if strerror_r() is supported.
* Add a stress test to test_free_threading.test_os (new module).
* Add a comment on decode_current_locale() assertion which fails if
  the input string is mutated.
* Add an assertion to _Py_DecodeLocale() to detect if the input
  string was mutated during the function call.
@vstinner

vstinner commented Oct 6, 2026

Copy link
Copy Markdown
Member Author

The test depends on PR #158926. Without the second PR, the test is always skipped.

@vstinner

vstinner commented Oct 6, 2026

Copy link
Copy Markdown
Member Author

Oh. Build fails on Android. It seems like Android C library (bionic) uses the GNU API for strerror_r().

  ../../Modules/posixmodule.c:13953:9: error: incompatible pointer to integer conversion initializing 'int' with an expression of type 'char * _Nonnull' [-Wint-conversion]
   13953 |     int len = strerror_r(code, small_buffer, buflen);
         |         ^     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ../../Modules/posixmodule.c:13973:17: error: incompatible pointer to integer conversion assigning to 'int' from 'char * _Nonnull' [-Wint-conversion]
   13973 |             len = strerror_r(code, buffer, buflen);
         |                 ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@vstinner

vstinner commented Oct 6, 2026

Copy link
Copy Markdown
Member Author

I clicked on [Update branch] to retrieve the sysconfig change, to run the test on Free Threaded builds.

@vstinner

vstinner commented Oct 6, 2026

Copy link
Copy Markdown
Member Author

!buildbot FreeBSD15 NoGIL

@bedevere-bot

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @vstinner for commit 7d18e20 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F158927%2Fmerge

The command will test the builders whose names match following regular expression: FreeBSD15 NoGIL

The builders matched are:

  • AMD64 FreeBSD15 NoGIL PR

@vstinner

vstinner commented Oct 6, 2026

Copy link
Copy Markdown
Member Author

buildbot/AMD64 FreeBSD15 NoGIL PR

The build https://buildbot.python.org/#/builders/2369/builds/1 failed because of test_free_threading.test_capi which is unrelated to this change, and I wrote #158935 to fix this test.

The test passed successfully! 0:08:38 load avg: 4.04 mem: 453.2 MiB [345/559] test.test_free_threading.test_os passed.

I ran manually test_free_threading.test_os on the main branch on Free Threading on FreeBSD 15: the test crashed as expected. So the test covers well the modified code.

@vstinner
vstinner merged commit 6318730 into python:main Oct 6, 2026
56 of 57 checks passed
@vstinner
vstinner deleted the strerror_r branch October 6, 2026 21:02
@vstinner vstinner added needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Oct 6, 2026
@miss-islington-app

Copy link
Copy Markdown

Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Sorry, @vstinner, I could not cleanly backport this to 3.15 due to a conflict.

Please backport manually with cherry_picker, see the devguide for more information.

cherry_picker 6318730aeebdf7282fa9a18aca52af4e87c0c39d 3.15

@miss-islington-app

Copy link
Copy Markdown

Sorry, @vstinner, I could not cleanly backport this to 3.14 due to a conflict.

Please backport manually with cherry_picker, see the devguide for more information.

cherry_picker 6318730aeebdf7282fa9a18aca52af4e87c0c39d 3.14

@vstinner

vstinner commented Oct 6, 2026

Copy link
Copy Markdown
Member Author

I will backport the fix to 3.14 and 3.15 branches once the 3.15 branch will be unblocked (next week). Right now, there are too many backports to 3.15 in the queue.

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

Labels

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