Skip to content

Use PyOS_setsig in macos backend #27956

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

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/_macosx.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
static bool stdin_received = false;
static bool stdin_sigint = false;
// Global variable to store the original SIGINT handler
static struct sigaction originalSigintAction = {0};
static PyOS_sighandler_t originalSigintAction = NULL;

// Signal handler for SIGINT, only sets a flag to exit the run loop
static void handleSigint(int signal) {
Expand All @@ -57,10 +57,7 @@ static int wait_for_stdin() {
stdin_sigint = false;

// Set up a SIGINT handler to interrupt the event loop if ctrl+c comes in too
struct sigaction customAction = {0};
customAction.sa_handler = handleSigint;
// Set the new handler and store the old one
sigaction(SIGINT, &customAction, &originalSigintAction);
originalSigintAction = PyOS_setsig(SIGINT, handleSigint);

// Create an NSFileHandle for standard input
NSFileHandle *stdinHandle = [NSFileHandle fileHandleWithStandardInput];
Expand Down Expand Up @@ -93,7 +90,7 @@ static int wait_for_stdin() {
[[NSNotificationCenter defaultCenter] removeObserver: stdinHandle];

// Restore the original SIGINT handler upon exiting the function
sigaction(SIGINT, &originalSigintAction, NULL);
PyOS_setsig(SIGINT, originalSigintAction);
return 1;
}
}
Expand Down