Skip to content

Commit 3fcc529

Browse files
committed
Use pointer to have PyArray_Type in global scope
to avoid copy
1 parent 2628624 commit 3fcc529

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ num-complex = "0.1"
1515
ndarray = "0.10"
1616

1717
[dependencies.pyo3]
18-
git = "https://github.com/PyO3/pyo3.git"
19-
rev = "c22bec6124ab68f47a7f28550931e3060f89071b"
18+
git = "https://github.com/PyO3/pyo3"
19+
rev = "4169b0317826dc62eafcdd0faab7d009f6808c06"

src/array.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use super::*;
1212

1313
/// Untyped safe interface for NumPy ndarray.
1414
pub struct PyArray(PyObject);
15-
pyobject_native_type!(PyArray, npyffi::PyArray_Type_Global, npyffi::PyArray_Check);
15+
pyobject_native_type!(PyArray, *npyffi::PyArray_Type_Ptr, npyffi::PyArray_Check);
1616

1717
impl PyArray {
1818
pub fn as_array_ptr(&self) -> *mut npyffi::PyArrayObject {

src/npyffi/array.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub struct PyArrayModule<'py> {
2626
}
2727

2828
#[allow(non_upper_case_globals)]
29-
pub static mut PyArray_Type_Global: PyTypeObject = ffi::PyTypeObject_INIT;
29+
pub static mut PyArray_Type_Ptr: *mut PyTypeObject = null_mut();
3030

3131
impl<'py> Deref for PyArrayModule<'py> {
3232
type Target = PyModule;
@@ -55,7 +55,7 @@ impl<'py> PyArrayModule<'py> {
5555
};
5656
let mod_ = PyArrayModule { numpy, api };
5757
unsafe {
58-
PyArray_Type_Global = *mod_.get_type_object(ArrayType::PyArray_Type);
58+
PyArray_Type_Ptr = mod_.get_type_object(ArrayType::PyArray_Type);
5959
}
6060
Ok(mod_)
6161
}
@@ -378,12 +378,10 @@ impl_array_type!(
378378

379379
#[allow(non_snake_case)]
380380
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)
381+
ffi::PyObject_TypeCheck(op, PyArray_Type_Ptr)
383382
}
384383

385384
#[allow(non_snake_case)]
386385
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
386+
(ffi::Py_TYPE(op) == PyArray_Type_Ptr) as c_int
389387
}

0 commit comments

Comments
 (0)