Skip to content

Commit 712626b

Browse files
committed
Bring the PyArray_* allocation functions back conditionally based on the enabled PyO3 features.
1 parent 990c392 commit 712626b

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ num-traits = "0.2"
2121
ndarray = ">= 0.13, < 0.16"
2222
pyo3 = { version = "0.16", default-features = false }
2323

24+
[build-dependencies]
25+
pyo3-build-config = "0.16"
26+
2427
[dev-dependencies]
2528
pyo3 = { version = "0.16", features = ["auto-initialize"] }
2629

build.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
use pyo3_build_config::use_pyo3_cfgs;
2+
3+
fn main() {
4+
use_pyo3_cfgs();
5+
}

src/npyffi/array.rs

+7
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,13 @@ pub unsafe fn PyArray_CheckExact(py: Python, op: *mut PyObject) -> c_int {
394394
(ffi::Py_TYPE(op) == PY_ARRAY_API.get_type_object(py, NpyTypes::PyArray_Type)) as _
395395
}
396396

397+
// these are under `#if NPY_USE_PYMEM == 1` which seems to be always defined as 1
398+
#[cfg(not(Py_LIMITED_API))]
399+
pub use pyo3::ffi::{
400+
PyMem_RawFree as PyArray_free, PyMem_RawMalloc as PyArray_malloc,
401+
PyMem_RawRealloc as PyArray_realloc,
402+
};
403+
397404
#[cfg(test)]
398405
mod tests {
399406
use super::PY_ARRAY_API;

0 commit comments

Comments
 (0)