summarylogtreecommitdiffstats
path: root/sagemath-python3.10.patch
blob: d05c8c56fbe70a0951b08fa2ac12849e9ba09759 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
diff --git a/src/sage/cpython/atexit.pyx b/src/sage/cpython/atexit.pyx
index 5b0c6d1..3ba391b 100644
--- a/src/sage/cpython/atexit.pyx
+++ b/src/sage/cpython/atexit.pyx
@@ -144,43 +144,63 @@ cdef class restore_atexit:
 
 from cpython.ref cimport PyObject
 
-# Internal structures defined in the CPython source in
-# Modules/atexitmodule.c and subject to (but unlikely to) change.  Watch
-# https://bugs.python.org/issue32082 for a request to (eventually)
-# re-expose more of the atexit module's internals to Python
-ctypedef struct atexit_callback:
-    PyObject* func
-    PyObject* args
-    PyObject* kwargs
-
-
-ctypedef struct atexitmodule_state:
-    atexit_callback** atexit_callbacks
-    int ncallbacks
-    int callback_len
-
-
-cdef extern from "Python.h":
-    void* PyModule_GetState(object module)
-
+# Implement "_atexit_callbacks()" for each supported python version
+cdef extern from *:
+    """
+    #if PY_VERSION_HEX >= 0x030a0000
+    /********** Python 3.10 **********/
+    #define Py_BUILD_CORE
+    #undef _PyGC_FINALIZED
+    #include "internal/pycore_interp.h"
+    #include "internal/pycore_pystate.h"
+    static atexit_callback ** _atexit_callbacks(PyObject *self) {
+        PyInterpreterState *interp = _PyInterpreterState_GET();
+        struct atexit_state state = interp->atexit;
+        return state.callbacks;
+    }
+    #else
+    /********** Python < 3.10 **********/
+    /* Internal structures defined in the CPython source in
+     * Modules/atexitmodule.c and subject to (but unlikely to) change.  Watch
+     * https://bugs.python.org/issue32082 for a request to (eventually)
+     * re-expose more of the atexit module's internals to Python
+     * typedef struct
+     */
+    typedef struct {
+        PyObject *func;
+        PyObject *args;
+        PyObject *kwargs;
+    } atexit_callback;
+    typedef struct {
+        atexit_callback **atexit_callbacks;
+        int ncallbacks;
+        int callback_len;
+    } atexitmodule_state;
+    static atexit_callback ** _atexit_callbacks(PyObject *self) {
+        atexitmodule_state *state = PyModule_GetState(self);
+        return state->atexit_callbacks;
+    }
+    #endif
+    """
+    ctypedef struct atexit_callback:
+        PyObject* func
+        PyObject* args
+        PyObject* kwargs
+    atexit_callback** _atexit_callbacks(object module)
 
 def _get_exithandlers():
     """Return list of exit handlers registered with the atexit module."""
-    cdef atexitmodule_state* state
+    cdef atexit_callback ** callbacks
     cdef atexit_callback callback
     cdef list exithandlers
     cdef int idx
     cdef object kwargs
 
-    state = <atexitmodule_state*>PyModule_GetState(atexit)
-
-    if not state:
-        raise RuntimeError("atexit module state missing or corrupt")
-
     exithandlers = []
+    callbacks = _atexit_callbacks(atexit)
 
-    for idx in range(state.ncallbacks):
-        callback = state.atexit_callbacks[idx][0]
+    for idx in range(atexit._ncallbacks()):
+        callback = callbacks[idx][0]
         if callback.kwargs:
             kwargs = <object>callback.kwargs
         else:
@@ -207,4 +227,5 @@ def _set_exithandlers(exithandlers):
 
 def _clear_exithandlers():
     """Clear the atexit module of all registered exit handlers."""
+
     atexit._clear()
diff --git a/src/sage_docbuild/utils.py b/src/sage_docbuild/utils.py
index 956d703f..3e4793e 100644
--- a/src/sage_docbuild/utils.py
+++ b/src/sage_docbuild/utils.py
@@ -79,7 +79,7 @@ def build_many(target, args, processes=None):
         ....:         # Task 4 is a poison pill
         ....:         1 / 0
         ....:     else:
-        ....:         time.sleep(0.5)
+        ....:         time.sleep(float(0.5))
         ....:         print('Processed task %s' % N)
         ....:
 
@@ -104,7 +104,7 @@ def build_many(target, args, processes=None):
         ....:         # Task 4 is a poison pill
         ....:         os.kill(os.getpid(), signal.SIGKILL)
         ....:     else:
-        ....:         time.sleep(0.5)
+        ....:         time.sleep(float(0.5))
         ....:         print('Processed task %s' % N)
         ....:
         sage: build_many(target, range(8), processes=8)
diff --git a/src/setup.cfg.m4 b/src/setup.cfg.m4
index 5c866c8..d2012aa 100644
--- a/src/setup.cfg.m4
+++ b/src/setup.cfg.m4
@@ -26,7 +26,7 @@ classifiers =
     Topic :: Scientific/Engineering :: Mathematics
 
 [options]
-python_requires = >=3.7, <3.10
+python_requires = >=3.7, <3.11
 install_requires =
     sage_conf
     esyscmd(`sage-get-system-packages install-requires \