|
18 | 18 | #include "common.h" |
19 | 19 |
|
20 | 20 |
|
21 | | -/* |
22 | | - * The global ContextVar to store the extobject. It is exposed to Python |
23 | | - * as `_extobj_contextvar`. |
24 | | - */ |
25 | | -static PyObject *default_extobj_capsule = NULL; |
26 | | -NPY_NO_EXPORT PyObject *npy_extobj_contextvar = NULL; |
27 | | - |
28 | | - |
29 | 21 | #define UFUNC_ERR_IGNORE 0 |
30 | 22 | #define UFUNC_ERR_WARN 1 |
31 | 23 | #define UFUNC_ERR_RAISE 2 |
@@ -130,7 +122,8 @@ fetch_curr_extobj_state(npy_extobj *extobj) |
130 | 122 | { |
131 | 123 | PyObject *capsule; |
132 | 124 | if (PyContextVar_Get( |
133 | | - npy_extobj_contextvar, default_extobj_capsule, &capsule) < 0) { |
| 125 | + npy_ma_global_data->npy_extobj_contextvar, |
| 126 | + npy_ma_global_data->default_extobj_capsule, &capsule) < 0) { |
134 | 127 | return -1; |
135 | 128 | } |
136 | 129 | npy_extobj *obj = PyCapsule_GetPointer(capsule, "numpy.ufunc.extobj"); |
@@ -164,15 +157,15 @@ init_extobj(void) |
164 | 157 | } |
165 | 158 | } |
166 | 159 |
|
167 | | - default_extobj_capsule = make_extobj_capsule( |
| 160 | + npy_ma_global_data->default_extobj_capsule = make_extobj_capsule( |
168 | 161 | NPY_BUFSIZE, UFUNC_ERR_DEFAULT, Py_None); |
169 | | - if (default_extobj_capsule == NULL) { |
| 162 | + if (npy_ma_global_data->default_extobj_capsule == NULL) { |
170 | 163 | return -1; |
171 | 164 | } |
172 | | - npy_extobj_contextvar = PyContextVar_New( |
173 | | - "numpy.ufunc.extobj", default_extobj_capsule); |
174 | | - if (npy_extobj_contextvar == NULL) { |
175 | | - Py_CLEAR(default_extobj_capsule); |
| 165 | + npy_ma_global_data->npy_extobj_contextvar = PyContextVar_New( |
| 166 | + "numpy.ufunc.extobj", npy_ma_global_data->default_extobj_capsule); |
| 167 | + if (npy_ma_global_data->npy_extobj_contextvar == NULL) { |
| 168 | + Py_CLEAR(npy_ma_global_data->default_extobj_capsule); |
176 | 169 | return -1; |
177 | 170 | } |
178 | 171 | return 0; |
@@ -213,7 +206,7 @@ errmodeconverter(PyObject *obj, int *mode) |
213 | 206 | /* |
214 | 207 | * This function is currently exposed as `umath._seterrobj()`, it is private |
215 | 208 | * and returns a capsule representing the errstate. This capsule is then |
216 | | - * assigned to the `npy_extobj_contextvar` in Python. |
| 209 | + * assigned to the `_extobj_contextvar` in Python. |
217 | 210 | */ |
218 | 211 | NPY_NO_EXPORT PyObject * |
219 | 212 | extobj_make_extobj(PyObject *NPY_UNUSED(mod), |
|
0 commit comments