Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5ab399b

Browse files
authored
Merge pull request #27956 from QuLogic/macos-setsig
Use PyOS_setsig in macos backend
2 parents 42472ef + 9c85514 commit 5ab399b

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/_macosx.m

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
static bool stdin_received = false;
4545
static bool stdin_sigint = false;
4646
// Global variable to store the original SIGINT handler
47-
static struct sigaction originalSigintAction = {0};
47+
static PyOS_sighandler_t originalSigintAction = NULL;
4848

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

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

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

9592
// Restore the original SIGINT handler upon exiting the function
96-
sigaction(SIGINT, &originalSigintAction, NULL);
93+
PyOS_setsig(SIGINT, originalSigintAction);
9794
return 1;
9895
}
9996
}

0 commit comments

Comments
 (0)