os.dup2() raises wrong OSError for negative fds #102179
Copy link
Copy link
Closed
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
>>> os.dup2(-1, 0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: [Errno 0] Error
The bug is caused by the old manual sign check that at some point lost the part that set errno:
Lines 9832 to 9834 in c3a1783
| if (fd < 0 || fd2 < 0) { | |
| posix_error(); | |
| return -1; |
I'm going to submit a PR with the fix.
Linked PRs
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Activity
pythongh-102179: Fix os.dup2() error reporting for negative fds
pythongh-102179: Fix os.dup2() error reporting for negative fds
izbyshev commentedon Mar 4, 2023
It turned out that on wasm32-emscripten
dup2()for negative fds is currently broken. I could reproduce that with the C equivalent of the failed test case and the latest emsdk:Apparently, in Emscripten there is ongoing work on WASMFS which fixed this particular issue, and comments in this PR additionally confirm that
dup2()is broken in the current default FS implementation.Indeed, compiling with
-sWASMFSmakes the test work as expected:Given the current state of Emscripten, I don't think we should care that
os.dup2()will start to behave differently after removing the manual fd check in CPython. I propose to simply skip the failed test case on Emscripten.gh-102179: Fix `os.dup2` error reporting for negative fds (#102180)
pythongh-102179: Fix `os.dup2` error reporting for negative fds (pyth…
pythongh-102179: Fix `os.dup2` error reporting for negative fds (pyth…
gh-102179: Fix `os.dup2` error reporting for negative fds (GH-102180)
[3.10] gh-102179: Fix `os.dup2` error reporting for negative fds (GH-…
pythongh-102179: Fix `os.dup2` error reporting for negative fds (pyth…
Merge branch 'main' into nodeaddict
Merge branch 'main' into inlinecomp2