Skip to content

Commit d424fd8

Browse files
committed
add pygame patch
1 parent ddd19fb commit d424fd8

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
diff --git a/src_c/base.c b/src_c/base.c
2+
index e73eb001..6f1c479d 100644
3+
--- a/src_c/base.c
4+
+++ b/src_c/base.c
5+
@@ -25,6 +25,7 @@
6+
#include "pygame.h"
7+
8+
#include <signal.h>
9+
+#include <string.h>
10+
#include "doc/pygame_doc.h"
11+
#include "pgarrinter.h"
12+
#include "pgcompat.h"
13+
@@ -2022,18 +2023,27 @@ pg_install_parachute(void)
14+
{
15+
#ifdef HAVE_SIGNAL_H
16+
int i;
17+
- void (*ohandler)(int);
18+
+ struct sigaction act;
19+
20+
if (parachute_installed) {
21+
return;
22+
}
23+
parachute_installed = 1;
24+
25+
- /* Set a handler for any fatal signal not already handled */
26+
+ /* Set a handler for any fatal signal not already handled.
27+
+ Use sigaction to retrieve the current handler first, so
28+
+ we don't mess with signal handlers in multi-threaded
29+
+ runtimes without a GIL. This is still racy, but better
30+
+ than using the signal function. */
31+
for (i = 0; fatal_signals[i]; ++i) {
32+
- ohandler = (void (*)(int))signal(fatal_signals[i], pygame_parachute);
33+
- if (ohandler != SIG_DFL) {
34+
- signal(fatal_signals[i], ohandler);
35+
+ sigaction(fatal_signals[i], NULL, &act);
36+
+ if (act.sa_handler == SIG_DFL) {
37+
+ memset(&act, 0, sizeof(struct sigaction));
38+
+ sigemptyset(&act.sa_mask);
39+
+ sigaddset(&act.sa_mask, fatal_signals[i]);
40+
+ act.sa_handler = pygame_parachute;
41+
+ act.sa_flags = SA_RESTART;
42+
+ sigaction(fatal_signals[i], &act, NULL);
43+
}
44+
}
45+

0 commit comments

Comments
 (0)