Skip to content

Commit

Permalink
Merge pull request #1368 from dalcde/osraw
Browse files Browse the repository at this point in the history
Prefer to use std::os::raw type definitions
  • Loading branch information
kngwyu committed Jan 7, 2021
2 parents 4d24213 + 4562de7 commit 423b7bf
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 23 deletions.
2 changes: 1 addition & 1 deletion pyo3-macros-backend/src/pymethod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ pub(crate) fn impl_wrap_setter(
#[allow(unused_mut)]
unsafe extern "C" fn __wrap(
_slf: *mut pyo3::ffi::PyObject,
_value: *mut pyo3::ffi::PyObject, _: *mut std::os::raw::c_void) -> pyo3::libc::c_int
_value: *mut pyo3::ffi::PyObject, _: *mut std::os::raw::c_void) -> std::os::raw::c_int
{
const _LOCATION: &'static str = concat!(stringify!(#cls),".",stringify!(#python_name),"()");
pyo3::callback_body_without_convert!(_py, {
Expand Down
16 changes: 11 additions & 5 deletions src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,15 +300,21 @@ impl<T: Element> PyBuffer<T> {
#[inline]
pub fn is_c_contiguous(&self) -> bool {
unsafe {
ffi::PyBuffer_IsContiguous(&*self.0 as *const ffi::Py_buffer, b'C' as libc::c_char) != 0
ffi::PyBuffer_IsContiguous(
&*self.0 as *const ffi::Py_buffer,
b'C' as std::os::raw::c_char,
) != 0
}
}

/// Gets whether the buffer is contiguous in Fortran-style order (first index varies fastest when visiting items in order of memory address).
#[inline]
pub fn is_fortran_contiguous(&self) -> bool {
unsafe {
ffi::PyBuffer_IsContiguous(&*self.0 as *const ffi::Py_buffer, b'F' as libc::c_char) != 0
ffi::PyBuffer_IsContiguous(
&*self.0 as *const ffi::Py_buffer,
b'F' as std::os::raw::c_char,
) != 0
}
}

Expand Down Expand Up @@ -441,7 +447,7 @@ impl<T: Element> PyBuffer<T> {
target.as_ptr() as *mut raw::c_void,
&*self.0 as *const ffi::Py_buffer as *mut ffi::Py_buffer,
self.0.len,
fort as libc::c_char,
fort as std::os::raw::c_char,
),
)
}
Expand Down Expand Up @@ -475,7 +481,7 @@ impl<T: Element> PyBuffer<T> {
vec.as_mut_ptr() as *mut raw::c_void,
&*self.0 as *const ffi::Py_buffer as *mut ffi::Py_buffer,
self.0.len,
fort as libc::c_char,
fort as std::os::raw::c_char,
),
)?;
// set vector length to mark the now-initialized space as usable
Expand Down Expand Up @@ -528,7 +534,7 @@ impl<T: Element> PyBuffer<T> {
&*self.0 as *const ffi::Py_buffer as *mut ffi::Py_buffer,
source.as_ptr() as *mut raw::c_void,
self.0.len,
fort as libc::c_char,
fort as std::os::raw::c_char,
),
)
}
Expand Down
10 changes: 5 additions & 5 deletions src/callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl PyCallbackOutput for *mut ffi::PyObject {
const ERR_VALUE: Self = std::ptr::null_mut();
}

impl PyCallbackOutput for libc::c_int {
impl PyCallbackOutput for std::os::raw::c_int {
const ERR_VALUE: Self = -1;
}

Expand Down Expand Up @@ -62,14 +62,14 @@ impl IntoPyCallbackOutput<Self> for *mut ffi::PyObject {
}
}

impl IntoPyCallbackOutput<libc::c_int> for () {
fn convert(self, _: Python) -> PyResult<libc::c_int> {
impl IntoPyCallbackOutput<std::os::raw::c_int> for () {
fn convert(self, _: Python) -> PyResult<std::os::raw::c_int> {
Ok(0)
}
}

impl IntoPyCallbackOutput<libc::c_int> for bool {
fn convert(self, _: Python) -> PyResult<libc::c_int> {
impl IntoPyCallbackOutput<std::os::raw::c_int> for bool {
fn convert(self, _: Python) -> PyResult<std::os::raw::c_int> {
Ok(self as c_int)
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/class/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ macro_rules! py_func_set {
slf: *mut $crate::ffi::PyObject,
name: *mut $crate::ffi::PyObject,
value: *mut $crate::ffi::PyObject,
) -> libc::c_int
) -> std::os::raw::c_int
where
T: for<'p> $trait_name<'p>,
{
Expand Down Expand Up @@ -260,7 +260,7 @@ macro_rules! py_func_del {
slf: *mut $crate::ffi::PyObject,
name: *mut $crate::ffi::PyObject,
value: *mut $crate::ffi::PyObject,
) -> libc::c_int
) -> std::os::raw::c_int
where
T: for<'p> $trait_name<'p>,
{
Expand Down Expand Up @@ -288,7 +288,7 @@ macro_rules! py_func_set_del {
slf: *mut $crate::ffi::PyObject,
name: *mut $crate::ffi::PyObject,
value: *mut $crate::ffi::PyObject,
) -> libc::c_int
) -> std::os::raw::c_int
where
T: for<'p> $trait1<'p> + for<'p> $trait2<'p>,
{
Expand Down
2 changes: 1 addition & 1 deletion src/class/methods.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) 2017-present PyO3 Project and Contributors

use crate::{ffi, PyObject, Python};
use libc::c_int;
use std::ffi::CStr;
use std::fmt;
use std::os::raw::c_int;

/// `PyMethodDefType` represents different types of Python callable objects.
/// It is used by the `#[pymethods]` and `#[pyproto]` annotations.
Expand Down
2 changes: 1 addition & 1 deletion src/err/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ use crate::{
AsPyPointer, FromPyPointer, IntoPy, Py, PyAny, PyNativeType, PyObject, Python,
ToBorrowedObject, ToPyObject,
};
use libc::c_int;
use std::borrow::Cow;
use std::cell::UnsafeCell;
use std::ffi::CString;
use std::os::raw::c_char;
use std::os::raw::c_int;
use std::ptr::NonNull;

mod err_state;
Expand Down
2 changes: 1 addition & 1 deletion src/ffi/cpython/abstract_.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::ffi::{PyObject, Py_buffer, Py_ssize_t};
use libc::{c_char, c_int, c_void};
use std::os::raw::{c_char, c_int, c_void};

#[cfg(all(Py_3_8, not(PyPy)))]
use crate::ffi::{
Expand Down
3 changes: 2 additions & 1 deletion src/ffi/initconfig.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* --- PyStatus ----------------------------------------------- */

use crate::ffi::Py_ssize_t;
use libc::{c_char, c_int, c_ulong, wchar_t};
use libc::wchar_t;
use std::os::raw::{c_char, c_int, c_ulong};

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum _PyStatus_TYPE {
Expand Down
4 changes: 0 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,6 @@ pub use {
unindent, // Re-exported for py_run
};

// Re-exported for the `__wrap` functions
#[doc(hidden)]
pub use libc;

// The CPython stable ABI does not include PyBuffer.
#[cfg(not(Py_LIMITED_API))]
pub mod buffer;
Expand Down
2 changes: 1 addition & 1 deletion src/types/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use crate::exceptions::PyTypeError;
use crate::type_object::PyTypeObject;
use crate::types::{PyDict, PyIterator, PyList, PyString, PyTuple, PyType};
use crate::{err, ffi, Py, PyNativeType, PyObject};
use libc::c_int;
use std::cell::UnsafeCell;
use std::cmp::Ordering;
use std::os::raw::c_int;

/// A Python object with GIL lifetime
///
Expand Down

0 comments on commit 423b7bf

Please sign in to comment.