Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/libs/eclsig.c
4057 views
1
/*
2
* eclsig.c: included from ecl.pyx
3
*
4
* AUTHORS:
5
*
6
* - Jeroen Demeyer (2011-03-30): initial version for #10818
7
*
8
*/
9
10
11
#include <signal.h>
12
static struct sigaction ecl_sigint_handler;
13
static struct sigaction ecl_sigbus_handler;
14
static struct sigaction ecl_sigsegv_handler;
15
static struct sigaction sage_sigint_handler;
16
static struct sigaction sage_sigbus_handler;
17
static struct sigaction sage_sigsegv_handler;
18
19
inline void set_ecl_signal_handler()
20
{
21
sigaction(SIGINT, &ecl_sigint_handler, &sage_sigint_handler);
22
sigaction(SIGBUS, &ecl_sigbus_handler, &sage_sigbus_handler);
23
sigaction(SIGSEGV, &ecl_sigsegv_handler, &sage_sigsegv_handler);
24
}
25
26
inline void unset_ecl_signal_handler()
27
{
28
sigaction(SIGINT, &sage_sigint_handler, NULL);
29
sigaction(SIGBUS, &sage_sigbus_handler, NULL);
30
sigaction(SIGSEGV, &sage_sigsegv_handler, NULL);
31
}
32
33
/* This MUST be a macro because sig_on() must be in the same
34
* stack frame as ecl_sig_on(). */
35
#define ecl_sig_on() \
36
(sig_on() && (set_ecl_signal_handler() , 1))
37
38
inline void ecl_sig_off()
39
{
40
unset_ecl_signal_handler();
41
sig_off();
42
}
43
44
inline mpz_t* ecl_mpz_from_bignum(cl_object obj)
45
{
46
return obj->big.big_num;
47
}
48
49
cl_object ecl_bignum_from_mpz(mpz_t* num)
50
{
51
cl_object z = _ecl_big_register0();
52
mpz_set(ecl_mpz_from_bignum(z),num);
53
return _ecl_big_register_copy(z);
54
}
55
56