Skip to content

Drop the re-exports of PyMem_Raw* calls as those are not available using the limited API. #283

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 3 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/simple/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ name = "rust_ext"
crate-type = ["cdylib"]

[dependencies]
pyo3 = { version = "0.16", features = ["extension-module"] }
pyo3 = { version = "0.16", features = ["extension-module", "abi3-py37"] }
numpy = { path = "../.." }
13 changes: 6 additions & 7 deletions src/npyffi/array.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
//! Low-Level binding for [Array API](https://numpy.org/doc/stable/reference/c-api/array.html)
use libc::FILE;
//!
//! Note that NumPy's low-level allocation functions `PyArray_{malloc,realloc,free}` are not part of this module.
//! The reason is that they would be re-exports of the `PyMem_Raw{Malloc,Realloc,Free}` functions from PyO3,
//! but those are not unconditionally exported, i.e. they are not available when using the limited Python C-API.

use std::cell::Cell;
use std::os::raw::*;
use std::ptr::null;

use libc::FILE;
use pyo3::ffi::{self, PyObject, PyTypeObject};

use crate::npyffi::*;
Expand Down Expand Up @@ -394,12 +399,6 @@ pub unsafe fn PyArray_CheckExact(py: Python, op: *mut PyObject) -> c_int {
(ffi::Py_TYPE(op) == PY_ARRAY_API.get_type_object(py, NpyTypes::PyArray_Type)) as _
}

// these are under `#if NPY_USE_PYMEM == 1` which seems to be always defined as 1
pub use pyo3::ffi::{
PyMem_RawFree as PyArray_free, PyMem_RawMalloc as PyArray_malloc,
PyMem_RawRealloc as PyArray_realloc,
};

#[cfg(test)]
mod tests {
use super::PY_ARRAY_API;
Expand Down