15
15
#include "extobj.h"
16
16
17
17
// static variables are zero-filled by default, no need to explicitly do so
18
- NPY_VISIBILITY_HIDDEN npy_interned_str_struct npy_interned_str ;
19
- NPY_VISIBILITY_HIDDEN npy_static_pydata_struct npy_static_pydata ;
20
- NPY_VISIBILITY_HIDDEN npy_static_cdata_struct npy_static_cdata ;
21
-
22
- #define INTERN_STRING (struct_member , string ) \
23
- assert(npy_interned_str.struct_member == NULL); \
24
- npy_interned_str.struct_member = PyUnicode_InternFromString(string); \
25
- if (npy_interned_str.struct_member == NULL) { \
26
- return -1; \
27
- } \
18
+ NPY_VISIBILITY_HIDDEN const npy_interned_str_struct npy_interned_str ;
19
+ NPY_VISIBILITY_HIDDEN const npy_static_pydata_struct npy_static_pydata ;
20
+ NPY_VISIBILITY_HIDDEN const npy_static_cdata_struct npy_static_cdata ;
21
+
22
+ #define INTERN_STRING (struct_member , string ) \
23
+ assert(npy_interned_str.struct_member == NULL); \
24
+ ((npy_interned_str_struct *)&npy_interned_str)->struct_member = \
25
+ PyUnicode_InternFromString(string); \
26
+ if (npy_interned_str.struct_member == NULL) { \
27
+ return -1; \
28
+ } \
28
29
29
30
NPY_NO_EXPORT int
30
31
intern_strings (void )
@@ -100,80 +101,84 @@ initialize_static_globals(void)
100
101
* module for performance reasons
101
102
*/
102
103
104
+ // cast away const to initialize
105
+ npy_static_pydata_struct * npy_static_pydata_mut =
106
+ (npy_static_pydata_struct * )& npy_static_pydata ;
107
+
103
108
IMPORT_GLOBAL ("math" , "floor" ,
104
- npy_static_pydata . math_floor_func );
109
+ npy_static_pydata_mut -> math_floor_func );
105
110
106
111
IMPORT_GLOBAL ("math" , "ceil" ,
107
- npy_static_pydata . math_ceil_func );
112
+ npy_static_pydata_mut -> math_ceil_func );
108
113
109
114
IMPORT_GLOBAL ("math" , "trunc" ,
110
- npy_static_pydata . math_trunc_func );
115
+ npy_static_pydata_mut -> math_trunc_func );
111
116
112
117
IMPORT_GLOBAL ("math" , "gcd" ,
113
- npy_static_pydata . math_gcd_func );
118
+ npy_static_pydata_mut -> math_gcd_func );
114
119
115
120
IMPORT_GLOBAL ("numpy.exceptions" , "AxisError" ,
116
- npy_static_pydata . AxisError );
121
+ npy_static_pydata_mut -> AxisError );
117
122
118
123
IMPORT_GLOBAL ("numpy.exceptions" , "ComplexWarning" ,
119
- npy_static_pydata . ComplexWarning );
124
+ npy_static_pydata_mut -> ComplexWarning );
120
125
121
126
IMPORT_GLOBAL ("numpy.exceptions" , "DTypePromotionError" ,
122
- npy_static_pydata . DTypePromotionError );
127
+ npy_static_pydata_mut -> DTypePromotionError );
123
128
124
129
IMPORT_GLOBAL ("numpy.exceptions" , "TooHardError" ,
125
- npy_static_pydata . TooHardError );
130
+ npy_static_pydata_mut -> TooHardError );
126
131
127
132
IMPORT_GLOBAL ("numpy.exceptions" , "VisibleDeprecationWarning" ,
128
- npy_static_pydata . VisibleDeprecationWarning );
133
+ npy_static_pydata_mut -> VisibleDeprecationWarning );
129
134
130
135
IMPORT_GLOBAL ("numpy._globals" , "_CopyMode" ,
131
- npy_static_pydata . _CopyMode );
136
+ npy_static_pydata_mut -> _CopyMode );
132
137
133
138
IMPORT_GLOBAL ("numpy._globals" , "_NoValue" ,
134
- npy_static_pydata . _NoValue );
139
+ npy_static_pydata_mut -> _NoValue );
135
140
136
141
IMPORT_GLOBAL ("numpy._core._exceptions" , "_ArrayMemoryError" ,
137
- npy_static_pydata . _ArrayMemoryError );
142
+ npy_static_pydata_mut -> _ArrayMemoryError );
138
143
139
144
IMPORT_GLOBAL ("numpy._core._exceptions" , "_UFuncBinaryResolutionError" ,
140
- npy_static_pydata . _UFuncBinaryResolutionError );
145
+ npy_static_pydata_mut -> _UFuncBinaryResolutionError );
141
146
142
147
IMPORT_GLOBAL ("numpy._core._exceptions" , "_UFuncInputCastingError" ,
143
- npy_static_pydata . _UFuncInputCastingError );
148
+ npy_static_pydata_mut -> _UFuncInputCastingError );
144
149
145
150
IMPORT_GLOBAL ("numpy._core._exceptions" , "_UFuncNoLoopError" ,
146
- npy_static_pydata . _UFuncNoLoopError );
151
+ npy_static_pydata_mut -> _UFuncNoLoopError );
147
152
148
153
IMPORT_GLOBAL ("numpy._core._exceptions" , "_UFuncOutputCastingError" ,
149
- npy_static_pydata . _UFuncOutputCastingError );
154
+ npy_static_pydata_mut -> _UFuncOutputCastingError );
150
155
151
156
IMPORT_GLOBAL ("os" , "fspath" ,
152
- npy_static_pydata . os_fspath );
157
+ npy_static_pydata_mut -> os_fspath );
153
158
154
159
IMPORT_GLOBAL ("os" , "PathLike" ,
155
- npy_static_pydata . os_PathLike );
160
+ npy_static_pydata_mut -> os_PathLike );
156
161
157
162
// default_truediv_type_tup
158
163
PyArray_Descr * tmp = PyArray_DescrFromType (NPY_DOUBLE );
159
- npy_static_pydata . default_truediv_type_tup =
164
+ npy_static_pydata_mut -> default_truediv_type_tup =
160
165
PyTuple_Pack (3 , tmp , tmp , tmp );
161
166
Py_DECREF (tmp );
162
167
if (npy_static_pydata .default_truediv_type_tup == NULL ) {
163
168
return -1 ;
164
169
}
165
170
166
- npy_static_pydata . kwnames_is_copy = Py_BuildValue ("(s)" , "copy" );
171
+ npy_static_pydata_mut -> kwnames_is_copy = Py_BuildValue ("(s)" , "copy" );
167
172
if (npy_static_pydata .kwnames_is_copy == NULL ) {
168
173
return -1 ;
169
174
}
170
175
171
- npy_static_pydata . one_obj = PyLong_FromLong ((long ) 1 );
176
+ npy_static_pydata_mut -> one_obj = PyLong_FromLong ((long ) 1 );
172
177
if (npy_static_pydata .one_obj == NULL ) {
173
178
return -1 ;
174
179
}
175
180
176
- npy_static_pydata . zero_obj = PyLong_FromLong ((long ) 0 );
181
+ npy_static_pydata_mut -> zero_obj = PyLong_FromLong ((long ) 0 );
177
182
if (npy_static_pydata .zero_obj == NULL ) {
178
183
return -1 ;
179
184
}
@@ -189,6 +194,10 @@ initialize_static_globals(void)
189
194
* up this way for performance reasons.
190
195
*/
191
196
197
+ // cast away const to initialize
198
+ npy_static_cdata_struct * npy_static_cdata_mut =
199
+ (npy_static_cdata_struct * )& npy_static_cdata ;
200
+
192
201
PyObject * flags = PySys_GetObject ("flags" ); /* borrowed object */
193
202
if (flags == NULL ) {
194
203
PyErr_SetString (PyExc_AttributeError , "cannot get sys.flags" );
@@ -198,7 +207,7 @@ initialize_static_globals(void)
198
207
if (level == NULL ) {
199
208
return -1 ;
200
209
}
201
- npy_static_cdata . optimize = PyLong_AsLong (level );
210
+ npy_static_cdata_mut -> optimize = PyLong_AsLong (level );
202
211
Py_DECREF (level );
203
212
204
213
/*
@@ -214,7 +223,7 @@ initialize_static_globals(void)
214
223
npy_intp k ;
215
224
for (k = 0 ; k < 8 ; k ++ ) {
216
225
npy_uint8 v = (j & (1 << k )) == (1 << k );
217
- npy_static_cdata . unpack_lookup_big [j ].bytes [7 - k ] = v ;
226
+ npy_static_cdata_mut -> unpack_lookup_big [j ].bytes [7 - k ] = v ;
218
227
}
219
228
}
220
229
0 commit comments