@@ -62,6 +62,37 @@ static int PARI_SIGINT_block = 0;
62
62
static int PARI_SIGINT_pending = 0 ;
63
63
#define paricfg_version NULL
64
64
#endif
65
+
66
+ // Custom signal handling of other packages.
67
+ #define MAX_N_CUSTOM_HANDLERS 16
68
+
69
+ static int (* custom_signal_is_blocked_pts [MAX_N_CUSTOM_HANDLERS ])();
70
+ static void (* custom_signal_unblock_pts [MAX_N_CUSTOM_HANDLERS ])();
71
+ static void (* custom_set_pending_signal_pts [MAX_N_CUSTOM_HANDLERS ])(int );
72
+ static int n_custom_handlers = 0 ;
73
+
74
+ int custom_signal_is_blocked (){
75
+ // Check if a custom block is set.
76
+ for (int i = 0 ; i < n_custom_handlers ; i ++ ){
77
+ if (custom_signal_is_blocked_pts [i ]())
78
+ return 1 ;
79
+ }
80
+ return 0 ;
81
+ }
82
+
83
+ void custom_signal_unblock (){
84
+ // Unset all custom blocks.
85
+ for (int i = 0 ; i < n_custom_handlers ; i ++ )
86
+ custom_signal_unblock_pts [i ]();
87
+ }
88
+
89
+
90
+ void custom_set_pending_signal (int sig ){
91
+ // Set a pending signal to custom handlers.
92
+ for (int i = 0 ; i < n_custom_handlers ; i ++ )
93
+ custom_set_pending_signal_pts [i ](sig );
94
+ }
95
+
65
96
#if HAVE_WINDOWS_H
66
97
/* We must include <windows.h> after <pari.h>
67
98
* See https://github.com/sagemath/cysignals/issues/107 */
@@ -214,7 +245,7 @@ static void cysigs_interrupt_handler(int sig)
214
245
215
246
if (cysigs .sig_on_count > 0 )
216
247
{
217
- if (!cysigs .block_sigint && !PARI_SIGINT_block )
248
+ if (!cysigs .block_sigint && !PARI_SIGINT_block && ! custom_signal_is_blocked () )
218
249
{
219
250
/* Raise an exception so Python can see it */
220
251
do_raise_exception (sig );
@@ -238,6 +269,7 @@ static void cysigs_interrupt_handler(int sig)
238
269
{
239
270
cysigs .interrupt_received = sig ;
240
271
PARI_SIGINT_pending = sig ;
272
+ custom_set_pending_signal (sig );
241
273
}
242
274
}
243
275
@@ -400,6 +432,7 @@ static void _sig_on_interrupt_received(void)
400
432
cysigs .sig_on_count = 0 ;
401
433
cysigs .interrupt_received = 0 ;
402
434
PARI_SIGINT_pending = 0 ;
435
+ custom_signal_unblock ();
403
436
404
437
#if HAVE_SIGPROCMASK
405
438
sigprocmask (SIG_SETMASK , & oldset , NULL );
@@ -412,9 +445,11 @@ static void _sig_on_recover(void)
412
445
{
413
446
cysigs .block_sigint = 0 ;
414
447
PARI_SIGINT_block = 0 ;
448
+ custom_signal_unblock ();
415
449
cysigs .sig_on_count = 0 ;
416
450
cysigs .interrupt_received = 0 ;
417
451
PARI_SIGINT_pending = 0 ;
452
+ custom_set_pending_signal (0 );
418
453
419
454
#if HAVE_SIGPROCMASK
420
455
/* Reset signal mask */
0 commit comments