Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/c_lib/src/stdsage.c
4034 views
1
/**
2
* @file stdsage.c
3
*
4
* Some global C stuff that gets imported into pyrex modules.
5
*
6
*/
7
8
/******************************************************************************
9
* Copyright (C) 2006 William Stein <[email protected]>
10
* 2006 David Harvey <[email protected]>
11
* 2006 Martin Albrecht <[email protected]>
12
* 2011 Jeroen Demeyer <[email protected]>
13
*
14
* Distributed under the terms of the GNU General Public License (GPL)
15
* as published by the Free Software Foundation; either version 2 of
16
* the License, or (at your option) any later version.
17
* http://www.gnu.org/licenses/
18
****************************************************************************/
19
20
21
#include "stdsage.h"
22
#include "interrupt.h"
23
24
PyObject* global_empty_tuple;
25
26
void init_global_empty_tuple(void) {
27
_CALLED_ONLY_ONCE;
28
29
global_empty_tuple = PyTuple_New(0);
30
}
31
32
33
/*
34
This function gets called whenever NTL calls Error().
35
s is the error message generated by NTL.
36
We just copy the error message into a global buffer, and then abort() to run
37
the usual interrupt machinery.
38
*/
39
void global_NTL_error_callback(const char* s, void* context)
40
{
41
set_sage_signal_handler_message(s);
42
abort();
43
}
44
45
46
/* This is called once during Sage startup. On some platforms like
47
* Cygwin, this is also called from init_csage_module(). */
48
void init_csage() {
49
init_global_empty_tuple();
50
init_memory_functions();
51
setup_sage_signal_handler();
52
setup_NTL_error_callback(global_NTL_error_callback, NULL);
53
}
54
55
/* This is called once for every single module that links in stdsage */
56
void init_csage_module() {
57
#if defined(__CYGWIN32__)
58
init_csage();
59
#endif
60
}
61
62