@@ -25,6 +25,9 @@ pub struct PyArrayModule<'py> {
25
25
api : * const * const c_void ,
26
26
}
27
27
28
+ #[ allow( non_upper_case_globals) ]
29
+ pub static mut PyArray_Type_Global : PyTypeObject = ffi:: PyTypeObject_INIT ;
30
+
28
31
impl < ' py > Deref for PyArrayModule < ' py > {
29
32
type Target = PyModule ;
30
33
fn deref ( & self ) -> & Self :: Target {
@@ -50,10 +53,11 @@ impl<'py> PyArrayModule<'py> {
50
53
let api = unsafe {
51
54
ffi:: PyCapsule_GetPointer ( c_api. as_ptr ( ) , null_mut ( ) ) as * const * const c_void
52
55
} ;
53
- Ok ( Self {
54
- numpy : numpy,
55
- api : api,
56
- } )
56
+ let mod_ = PyArrayModule { numpy, api } ;
57
+ unsafe {
58
+ PyArray_Type_Global = * mod_. get_type_object ( ArrayType :: PyArray_Type ) ;
59
+ }
60
+ Ok ( mod_)
57
61
}
58
62
59
63
pyarray_api ! [ 0 ; PyArray_GetNDArrayCVersion ( ) -> c_uint] ;
@@ -373,11 +377,13 @@ impl_array_type!(
373
377
) ;
374
378
375
379
#[ allow( non_snake_case) ]
376
- pub unsafe fn PyArray_Check ( np : & PyArrayModule , op : * mut PyObject ) -> c_int {
377
- ffi:: PyObject_TypeCheck ( op, np. get_type_object ( ArrayType :: PyArray_Type ) )
380
+ pub unsafe fn PyArray_Check ( op : * mut PyObject ) -> c_int {
381
+ let typeobj_ptr: * mut PyTypeObject = & mut PyArray_Type_Global ;
382
+ ffi:: PyObject_TypeCheck ( op, typeobj_ptr)
378
383
}
379
384
380
385
#[ allow( non_snake_case) ]
381
- pub unsafe fn PyArray_CheckExact ( np : & PyArrayModule , op : * mut PyObject ) -> c_int {
382
- ( ffi:: Py_TYPE ( op) == np. get_type_object ( ArrayType :: PyArray_Type ) ) as c_int
386
+ pub unsafe fn PyArray_CheckExact ( op : * mut PyObject ) -> c_int {
387
+ let typeobj_ptr: * mut _ = & mut PyArray_Type_Global ;
388
+ ( ffi:: Py_TYPE ( op) == typeobj_ptr) as c_int
383
389
}
0 commit comments