Skip to content

[3.15] gh-158893: Make os.strerror() thread-safe - #159120

Merged
vstinner merged 3 commits into
python:3.15from
vstinner:strerror15
Oct 10, 2026
Merged

vstinner merged 3 commits into
python:3.15from
vstinner:strerror15

Conversation

@vstinner

@vstinner vstinner commented Oct 10, 2026 •

Copy link
Copy Markdown
Member

…on#158926)

Add parse_config_h() tests to test_sysconfig.

(cherry picked from commit 978a8be)
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.
Add a new internal _Py_strerror() function to Python/fileutils.c. It
uses strerror_r() if available, or use strerror() otherwise.

Replace all strerror(code) calls with _Py_strerror(code).

(cherry picked from commit 15dd735)
@vstinner

Copy link
Copy Markdown
Member Author

!buildbot FreeBSD

@bedevere-bot

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @vstinner for commit 710c455 🤖

Results will be shown at:

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

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

The builders matched are:

  • AMD64 FreeBSD15 NoGIL PR
  • AMD64 FreeBSD16 Non-Debug PR
  • AMD64 FreeBSD14 PR
  • AMD64 FreeBSD15 PR
  • AMD64 FreeBSD Refleaks PR
  • AMD64 FreeBSD16 PR

@vstinner

Copy link
Copy Markdown
Member Author

Good, the test suite passed on 4 FreeBSD buildbots. There are unrelated failure on the two other FreeBSD buildbots.

buildbot/AMD64 FreeBSD Refleaks PR

Unrelated failure:

1 test altered the execution environment (env changed):
    test.test_asyncio.test_events:
        unraisable exception (ResourceWarning)

buildbot/AMD64 FreeBSD15 NoGIL PR

0:07:03 load avg: 9.71 [324/559/2] test.test_free_threading.test_capi failed (uncaught exception) -- running (1): test.test_multiprocessing_forkserver.test_manager (31.6 sec)
...
ModuleNotFoundError: Standard library module '_ctypes' was not found

Ah, that's an unrelated failure. I will backport my fix from main.

@vstinner
vstinner merged commit c774d15 into python:3.15 Oct 10, 2026
64 of 66 checks passed
@vstinner
vstinner deleted the strerror15 branch October 10, 2026 20:08
@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.14 due to a conflict.

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

cherry_picker c774d1526f32057c3a34e0ff0a217a1acc8bf43a 3.14

vstinner added a commit to vstinner/cpython that referenced this pull request Oct 10, 2026
* pythongh-157695: Parse also _Py_HAVE_xxx variables in sysconfig (python#158926)

Add parse_config_h() tests to test_sysconfig.

(cherry picked from commit 978a8be)

* pythongh-158893: Make os.strerror() thread-safe (python#158927)

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.

* pythongh-158893: Add internal _Py_strerror() function (python#158982)

Add a new internal _Py_strerror() function to Python/fileutils.c. It
uses strerror_r() if available, or use strerror() otherwise.

Replace all strerror(code) calls with _Py_strerror(code).

(cherry picked from commit 15dd735)
(cherry picked from commit c774d15)
@bedevere-app

bedevere-app Bot commented Oct 10, 2026

Copy link
Copy Markdown

GH-159145 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants