Skip to content

Commit e1e5385

Browse files
committed
Some minor copy-editing of the FFI module.
1 parent 8599efc commit e1e5385

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

src/npyffi/array.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,14 +328,15 @@ impl PyArrayAPI {
328328
impl_api![303; PyArray_SetWritebackIfCopyBase(arr: *mut PyArrayObject, base: *mut PyArrayObject) -> c_int];
329329
}
330330

331-
// Define type objects that belongs to Numpy API
331+
// Define type objects associated with the NumPy API
332332
macro_rules! impl_array_type {
333333
($(($offset:expr, $tname:ident)),*) => {
334-
/// All type objects of numpy API.
334+
/// All type objects exported by the NumPy API.
335335
#[allow(non_camel_case_types)]
336336
pub enum NpyTypes { $($tname),* }
337+
337338
impl PyArrayAPI {
338-
/// Get the pointer of the type object that `self` refers.
339+
/// Get a pointer of the type object assocaited with `ty`.
339340
pub unsafe fn get_type_object(&self, py: Python, ty: NpyTypes) -> *mut PyTypeObject {
340341
match ty {
341342
$( NpyTypes::$tname => *(self.get(py, $offset)) as _ ),*
@@ -401,11 +402,11 @@ pub unsafe fn PyArray_CheckExact(py: Python, op: *mut PyObject) -> c_int {
401402

402403
#[cfg(test)]
403404
mod tests {
404-
use super::PY_ARRAY_API;
405+
use super::*;
405406

406407
#[test]
407408
fn call_api() {
408-
pyo3::Python::with_gil(|py| unsafe {
409+
Python::with_gil(|py| unsafe {
409410
assert_eq!(
410411
PY_ARRAY_API.PyArray_MultiplyIntList(py, [1, 2, 3].as_mut_ptr(), 3),
411412
6

src/npyffi/mod.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,24 @@ fn get_numpy_api(_py: Python, module: &str, capsule: &str) -> *const *const c_vo
1818
let module = CString::new(module).unwrap();
1919
let capsule = CString::new(capsule).unwrap();
2020
unsafe {
21-
let numpy = ffi::PyImport_ImportModule(module.as_ptr());
22-
assert!(!numpy.is_null(), "Failed to import numpy module");
23-
let capsule = ffi::PyObject_GetAttrString(numpy as _, capsule.as_ptr());
24-
assert!(!capsule.is_null(), "Failed to get numpy capsule API");
21+
let module = ffi::PyImport_ImportModule(module.as_ptr());
22+
assert!(!module.is_null(), "Failed to import NumPy module");
23+
let capsule = ffi::PyObject_GetAttrString(module as _, capsule.as_ptr());
24+
assert!(!capsule.is_null(), "Failed to get NumPy API capsule");
2525
ffi::PyCapsule_GetPointer(capsule, null_mut()) as _
2626
}
2727
}
2828

29-
// Define Array&UFunc APIs
29+
// Implements wrappers for NumPy's Array and UFunc API
3030
macro_rules! impl_api {
31-
[$offset: expr; $fname: ident ( $($arg: ident : $t: ty),* ) $( -> $ret: ty )* ] => {
31+
[$offset: expr; $fname: ident ( $($arg: ident : $t: ty),* $(,)?) $( -> $ret: ty )* ] => {
3232
#[allow(non_snake_case)]
3333
pub unsafe fn $fname(&self, py: Python, $($arg : $t), *) $( -> $ret )* {
3434
let fptr = self.get(py, $offset)
3535
as *const extern fn ($($arg : $t), *) $( -> $ret )*;
3636
(*fptr)($($arg), *)
3737
}
3838
};
39-
// To allow fn a(b: type,) -> ret
40-
[$offset: expr; $fname: ident ( $($arg: ident : $t:ty,)* ) $( -> $ret: ty )* ] => {
41-
impl_api![$offset; $fname( $($arg: $t),*) $( -> $ret )*];
42-
}
4339
}
4440

4541
pub mod array;

src/npyffi/ufunc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const MOD_NAME: &str = "numpy.core.umath";
1212
const CAPSULE_NAME: &str = "_UFUNC_API";
1313

1414
/// A global variable which stores a ['capsule'](https://docs.python.org/3/c-api/capsule.html)
15-
/// pointer to [Numpy UFunc API](https://numpy.org/doc/stable/reference/c-api/array.html).
15+
/// pointer to [Numpy UFunc API](https://numpy.org/doc/stable/reference/c-api/ufunc.html).
1616
pub static PY_UFUNC_API: PyUFuncAPI = PyUFuncAPI::new();
1717

1818
pub struct PyUFuncAPI {

0 commit comments

Comments
 (0)