Expose some APIs for rust-numpy

This commit is contained in:
kngwyu 2020-06-22 23:49:33 +09:00
parent 4c04268bdb
commit 2caf5b1c10
3 changed files with 15 additions and 5 deletions

View file

@ -372,7 +372,8 @@ extern "C" fn finalize() {
/// Ensure the GIL is held, useful in implementation of APIs like PyErr::new where it's
/// inconvenient to force the user to acquire the GIL.
pub(crate) fn ensure_gil() -> EnsureGIL {
#[doc(hidden)]
pub fn ensure_gil() -> EnsureGIL {
if gil_is_acquired() {
EnsureGIL(None)
} else {
@ -381,7 +382,8 @@ pub(crate) fn ensure_gil() -> EnsureGIL {
}
/// Struct used internally which avoids acquiring the GIL where it's not necessary.
pub(crate) struct EnsureGIL(Option<GILGuard>);
#[doc(hidden)]
pub struct EnsureGIL(Option<GILGuard>);
impl EnsureGIL {
/// Get the GIL token.

View file

@ -195,6 +195,12 @@ mod python;
pub mod type_object;
pub mod types;
/// Internal utilities exposed for rust-numpy
#[doc(hidden)]
pub mod internal_utils {
pub use crate::gil::{ensure_gil, EnsureGIL};
}
/// The proc macros, which are also part of the prelude.
#[cfg(feature = "macros")]
pub mod proc_macro {

View file

@ -114,8 +114,9 @@ impl<T: PyClass> PyClassInitializer<T> {
PyClassInitializer::new(subclass_value, self)
}
// Create a new PyCell and initialize it.
pub(crate) fn create_cell(self, py: Python) -> PyResult<*mut PyCell<T>>
/// Create a new PyCell and initialize it.
#[doc(hidden)]
pub fn create_cell(self, py: Python) -> PyResult<*mut PyCell<T>>
where
T: PyClass,
T::BaseLayout: PyBorrowFlagLayout<T::BaseType>,
@ -127,7 +128,8 @@ impl<T: PyClass> PyClassInitializer<T> {
/// Called by our `tp_new` generated by the `#[new]` attribute.
///
/// # Safety
/// `cls` must be a subclass of T.
/// `subtype` must be a subclass of T.
#[doc(hidden)]
pub unsafe fn create_cell_from_subtype(
self,
py: Python,