bpo-40826: Add _PyOS_InterruptOccurred(tstate) function by vstinner · Pull Request #20599 · python/cpython

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

vstinner

my_fgets() now calls _PyOS_InterruptOccurred(tstate) to check for
pending signals, rather calling PyOS_InterruptOccurred().

my_fgets() is called with the GIL released, whereas
PyOS_InterruptOccurred() must be called with the GIL held.

https://bugs.python.org/issue40826

my_fgets() now calls _PyOS_InterruptOccurred(tstate) to check for
pending signals, rather calling PyOS_InterruptOccurred().

my_fgets() is called with the GIL released, whereas
PyOS_InterruptOccurred() must be called with the GIL held.

@vstinner

@corona10

test_repl: use text=True and avoid SuppressCrashReport in
test_multiline_string_parsing().

@vstinner

Well, I added a test, but different than yours.

@vstinner

The test fails on Windows:

FAIL: test_close_stdin (test.test_repl.TestInteractiveInterpreter)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\a\cpython\cpython\lib\test\test_repl.py", line 103, in test_close_stdin
    self.assertEqual(process.returncode, 0)
AssertionError: 3221226505 != 0

@corona10

The test fails on Windows:

Yeah, I skipped the test on Windows.

@vstinner

Yeah, I skipped the test on Windows.

Well, 3221226505 exit code is STATUS_STACK_BUFFER_OVERRUN (0xC0000409): it's a crash.

It seems like fgets() crash when the file descriptor is closed.

On Windows, fgets(fp) does crash if fileno(fp) is closed.

@vstinner

@corona10: I fixed yet another bug, crash on Windows, in my PR. Would you mind to review the PR?

corona10

Copy link

Member

@corona10 corona10 left a comment

Nice! LGTM

The PR is very awesome that it solve also the Windows issue :)

@vstinner

vstinner added a commit that referenced this pull request

Jun 3, 2020
* bpo-40826: Fix GIL usage in PyOS_Readline() (GH-20579)

Fix GIL usage in PyOS_Readline(): lock the GIL to set an exception.

Pass tstate to my_fgets() and _PyOS_WindowsConsoleReadline(). Cleanup
these functions.

(cherry picked from commit c353764)

* bpo-40826: Add _PyOS_InterruptOccurred(tstate) function (GH-20599)

my_fgets() now calls _PyOS_InterruptOccurred(tstate) to check for
pending signals, rather calling PyOS_InterruptOccurred().

my_fgets() is called with the GIL released, whereas
PyOS_InterruptOccurred() must be called with the GIL held.

test_repl: use text=True and avoid SuppressCrashReport in
test_multiline_string_parsing().

Fix my_fgets() on Windows: fgets(fp) does crash if fileno(fp) is closed.

(cherry picked from commit fa7ab6a)

vstinner added a commit that referenced this pull request

Jun 3, 2020
* bpo-40826: Fix GIL usage in PyOS_Readline() (GH-20579)

Fix GIL usage in PyOS_Readline(): lock the GIL to set an exception.

Pass tstate to my_fgets() and _PyOS_WindowsConsoleReadline(). Cleanup
these functions.

(cherry picked from commit c353764)

* bpo-40826: Add _PyOS_InterruptOccurred(tstate) function (GH-20599)

my_fgets() now calls _PyOS_InterruptOccurred(tstate) to check for
pending signals, rather calling PyOS_InterruptOccurred().

my_fgets() is called with the GIL released, whereas
PyOS_InterruptOccurred() must be called with the GIL held.

test_repl: use text=True and avoid SuppressCrashReport in
test_multiline_string_parsing().

Fix my_fgets() on Windows: fgets(fp) does crash if fileno(fp) is closed.

(cherry picked from commit fa7ab6a)

arun-mani-j pushed a commit to arun-mani-j/cpython that referenced this pull request

Jul 21, 2020
my_fgets() now calls _PyOS_InterruptOccurred(tstate) to check for
pending signals, rather calling PyOS_InterruptOccurred().

my_fgets() is called with the GIL released, whereas
PyOS_InterruptOccurred() must be called with the GIL held.

test_repl: use text=True and avoid SuppressCrashReport in
test_multiline_string_parsing().

Fix my_fgets() on Windows: fgets(fp) does crash if fileno(fp) is closed.