diff --git a/src/buffer.rs b/src/buffer.rs index 672ab32ca6b..07f6321aecd 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -1,5 +1,4 @@ #![cfg(not(Py_LIMITED_API))] -#![cfg_attr(docsrs, doc(cfg(not(Py_LIMITED_API))))] // Copyright (c) 2017 Daniel Grunwald // // Permission is hereby granted, free of charge, to any person obtaining a copy of this diff --git a/src/class/mod.rs b/src/class/mod.rs index 29315a82e26..4b7543aaccc 100644 --- a/src/class/mod.rs +++ b/src/class/mod.rs @@ -7,7 +7,6 @@ mod macros; pub mod basic; #[cfg(not(Py_LIMITED_API))] -#[cfg_attr(docsrs, doc(cfg(not(Py_LIMITED_API))))] pub mod buffer; pub mod context; pub mod descr; @@ -24,7 +23,6 @@ pub mod sequence; pub use self::basic::PyObjectProtocol; #[cfg(not(Py_LIMITED_API))] -#[cfg_attr(docsrs, doc(cfg(not(Py_LIMITED_API))))] pub use self::buffer::PyBufferProtocol; pub use self::context::PyContextProtocol; pub use self::descr::PyDescrProtocol; diff --git a/src/conversions/eyre.rs b/src/conversions/eyre.rs index 445045f7c40..172f18c5903 100644 --- a/src/conversions/eyre.rs +++ b/src/conversions/eyre.rs @@ -1,5 +1,5 @@ #![cfg(feature = "eyre")] -#![cfg_attr(docsrs, doc(cfg(feature = "eyre")))] + //! A conversion from [eyre]’s [`Report`] type to [`PyErr`]. //! //! Use of an error handling library like [eyre] is common in application code and when you just diff --git a/src/conversions/hashbrown.rs b/src/conversions/hashbrown.rs index 3dd65fbe737..31b8b1420eb 100644 --- a/src/conversions/hashbrown.rs +++ b/src/conversions/hashbrown.rs @@ -1,5 +1,4 @@ #![cfg(feature = "hashbrown")] -#![cfg_attr(docsrs, doc(cfg(feature = "hashbrown")))] //! Conversions to and from [hashbrown](https://docs.rs/hashbrown/)’s //! `HashMap` and `HashSet`. diff --git a/src/conversions/indexmap.rs b/src/conversions/indexmap.rs index 9ffac69a14a..c7e20e4c411 100644 --- a/src/conversions/indexmap.rs +++ b/src/conversions/indexmap.rs @@ -1,5 +1,4 @@ #![cfg(feature = "indexmap")] -#![cfg_attr(docsrs, doc(cfg(feature = "indexmap")))] //! Conversions to and from [indexmap](https://docs.rs/indexmap/)’s //! `IndexMap`. diff --git a/src/conversions/num_bigint.rs b/src/conversions/num_bigint.rs index 3882ebb0034..d5932b6b2bb 100644 --- a/src/conversions/num_bigint.rs +++ b/src/conversions/num_bigint.rs @@ -3,11 +3,6 @@ // based on Daniel Grunwald's https://github.com/dgrunwald/rust-cpython #![cfg(all(feature = "num-bigint", not(any(Py_LIMITED_API, PyPy))))] -#![cfg_attr( - docsrs, - doc(cfg(all(feature = "num-bigint", not(any(Py_LIMITED_API, PyPy))))) -)] - //! Conversions to and from [num-bigint](https://docs.rs/num-bigint)’s [`BigInt`] and [`BigUint`] types. //! //! This is useful for converting Python integers when they may not fit in Rust's built-in integer types. @@ -85,6 +80,7 @@ unsafe fn extract(ob: &PyLong, buffer: &mut [c_uchar], is_signed: c_int) -> PyRe macro_rules! bigint_conversion { ($rust_ty: ty, $is_signed: expr, $to_bytes: path, $from_bytes: path) => { + #[cfg_attr(docsrs, doc(cfg(feature = "num-bigint")))] impl ToPyObject for $rust_ty { fn to_object(&self, py: Python) -> PyObject { unsafe { @@ -99,11 +95,15 @@ macro_rules! bigint_conversion { } } } + + #[cfg_attr(docsrs, doc(cfg(feature = "num-bigint")))] impl IntoPy for $rust_ty { fn into_py(self, py: Python) -> PyObject { self.to_object(py) } } + + #[cfg_attr(docsrs, doc(cfg(feature = "num-bigint")))] impl<'source> FromPyObject<'source> for $rust_ty { fn extract(ob: &'source PyAny) -> PyResult<$rust_ty> { let py = ob.py(); diff --git a/src/conversions/num_complex.rs b/src/conversions/num_complex.rs index af822e0959c..d5fd5e15618 100644 --- a/src/conversions/num_complex.rs +++ b/src/conversions/num_complex.rs @@ -1,5 +1,5 @@ #![cfg(feature = "num-complex")] -#![cfg_attr(docsrs, doc(cfg(feature = "num-complex")))] + //! Conversions to and from [num-complex](https://docs.rs/num-complex)’ //! [`Complex`]`<`[`f32`]`>` and [`Complex`]`<`[`f64`]`>`. //! @@ -117,12 +117,15 @@ impl PyComplex { macro_rules! complex_conversion { ($float: ty) => { + #[cfg_attr(docsrs, doc(cfg(feature = "num-complex")))] impl ToPyObject for Complex<$float> { #[inline] fn to_object(&self, py: Python) -> PyObject { crate::IntoPy::::into_py(self.to_owned(), py) } } + + #[cfg_attr(docsrs, doc(cfg(feature = "num-complex")))] impl crate::IntoPy for Complex<$float> { fn into_py(self, py: Python) -> PyObject { unsafe { @@ -132,10 +135,12 @@ macro_rules! complex_conversion { } } } - #[cfg(not(any(Py_LIMITED_API, PyPy)))] + + #[cfg_attr(docsrs, doc(cfg(feature = "num-complex")))] #[allow(clippy::float_cmp)] // The comparison is for an error value impl<'source> FromPyObject<'source> for Complex<$float> { fn extract(obj: &'source PyAny) -> PyResult> { + #[cfg(not(any(Py_LIMITED_API, PyPy)))] unsafe { let val = ffi::PyComplex_AsCComplex(obj.as_ptr()); if val.real == -1.0 && PyErr::occurred(obj.py()) { @@ -144,12 +149,8 @@ macro_rules! complex_conversion { Ok(Complex::new(val.real as $float, val.imag as $float)) } } - } - } - #[cfg(any(Py_LIMITED_API, PyPy))] - #[allow(clippy::float_cmp)] // The comparison is for an error value - impl<'source> FromPyObject<'source> for Complex<$float> { - fn extract(obj: &'source PyAny) -> PyResult> { + + #[cfg(any(Py_LIMITED_API, PyPy))] unsafe { let ptr = obj.as_ptr(); let real = ffi::PyComplex_RealAsDouble(ptr); diff --git a/src/conversions/serde.rs b/src/conversions/serde.rs index e6571e2f4ea..b9dbed07f79 100644 --- a/src/conversions/serde.rs +++ b/src/conversions/serde.rs @@ -1,4 +1,3 @@ -#![cfg_attr(docsrs, doc(cfg(feature = "serde")))] #![cfg(feature = "serde")] //! Enables (de)serialization of [`Py`]`` objects via [serde](https://docs.rs/serde). diff --git a/src/exceptions.rs b/src/exceptions.rs index 71c051c5c20..3a55f0003de 100644 --- a/src/exceptions.rs +++ b/src/exceptions.rs @@ -225,6 +225,22 @@ macro_rules! impl_native_exception ( ) ); +#[cfg(windows)] +macro_rules! impl_windows_native_exception ( + ($name:ident, $exc_name:ident, $doc:expr, $layout:path) => ( + #[cfg(windows)] + #[doc = $doc] + #[allow(clippy::upper_case_acronyms)] + pub struct $name($crate::PyAny); + + $crate::impl_exception_boilerplate!($name); + $crate::pyobject_native_type!($name, $layout, *($crate::ffi::$exc_name as *mut $crate::ffi::PyTypeObject)); + ); + ($name:ident, $exc_name:ident, $doc:expr) => ( + impl_windows_native_exception!($name, $exc_name, $doc, $crate::ffi::PyBaseExceptionObject); + ) +); + macro_rules! native_doc( ($name: literal, $alt: literal) => ( concat!( @@ -516,8 +532,9 @@ impl_native_exception!( native_doc!("EnvironmentError") ); impl_native_exception!(PyIOError, PyExc_IOError, native_doc!("IOError")); + #[cfg(windows)] -impl_native_exception!( +impl_windows_native_exception!( PyWindowsError, PyExc_WindowsError, native_doc!("WindowsError") diff --git a/src/ffi/abstract_.rs b/src/ffi/abstract_.rs index b223dee27ea..3fa035b3b1c 100644 --- a/src/ffi/abstract_.rs +++ b/src/ffi/abstract_.rs @@ -113,7 +113,6 @@ extern "C" { #[cfg_attr(PyPy, link_name = "PyPyIter_Next")] pub fn PyIter_Next(arg1: *mut PyObject) -> *mut PyObject; #[cfg(all(not(PyPy), Py_3_10))] - #[cfg_attr(docsrs, doc(cfg(all(not(PyPy), Py_3_10))))] pub fn PyIter_Send(iter: *mut PyObject, arg: *mut PyObject, presult: *mut *mut PyObject); #[cfg_attr(PyPy, link_name = "PyPyNumber_Check")] diff --git a/src/ffi/cpython/pystate.rs b/src/ffi/cpython/pystate.rs index b132cc4e05f..3f545450486 100644 --- a/src/ffi/cpython/pystate.rs +++ b/src/ffi/cpython/pystate.rs @@ -43,17 +43,14 @@ extern "C" { // skipped _PyThread_CurrentExceptions #[cfg(not(PyPy))] - #[cfg_attr(docsrs, doc(cfg(not(PyPy))))] pub fn PyInterpreterState_Main() -> *mut PyInterpreterState; #[cfg_attr(PyPy, link_name = "PyPyInterpreterState_Head")] pub fn PyInterpreterState_Head() -> *mut PyInterpreterState; #[cfg_attr(PyPy, link_name = "PyPyInterpreterState_Next")] pub fn PyInterpreterState_Next(interp: *mut PyInterpreterState) -> *mut PyInterpreterState; #[cfg(not(PyPy))] - #[cfg_attr(docsrs, doc(cfg(not(PyPy))))] pub fn PyInterpreterState_ThreadHead(interp: *mut PyInterpreterState) -> *mut PyThreadState; #[cfg(not(PyPy))] - #[cfg_attr(docsrs, doc(cfg(not(PyPy))))] pub fn PyThreadState_Next(tstate: *mut PyThreadState) -> *mut PyThreadState; #[cfg(py_sys_config = "WITH_THREAD")] @@ -62,7 +59,6 @@ extern "C" { } #[cfg(Py_3_9)] -#[cfg_attr(docsrs, doc(cfg(Py_3_9)))] pub type _PyFrameEvalFunction = extern "C" fn( *mut crate::ffi::PyThreadState, *mut crate::ffi::PyFrameObject, @@ -72,13 +68,11 @@ pub type _PyFrameEvalFunction = extern "C" fn( #[cfg(Py_3_9)] extern "C" { /// Get the frame evaluation function. - #[cfg_attr(docsrs, doc(cfg(Py_3_9)))] pub fn _PyInterpreterState_GetEvalFrameFunc( interp: *mut PyInterpreterState, ) -> _PyFrameEvalFunction; ///Set the frame evaluation function. - #[cfg_attr(docsrs, doc(cfg(Py_3_9)))] pub fn _PyInterpreterState_SetEvalFrameFunc( interp: *mut PyInterpreterState, eval_frame: _PyFrameEvalFunction, diff --git a/src/ffi/cpython/unicodeobject.rs b/src/ffi/cpython/unicodeobject.rs index 03400859219..f357d91d9f5 100644 --- a/src/ffi/cpython/unicodeobject.rs +++ b/src/ffi/cpython/unicodeobject.rs @@ -52,7 +52,7 @@ pub struct PyASCIIObject { /// /// In addition, they are disabled on big-endian architectures to restrict this to most "common" /// platforms, which are at least tested on CI and appear to be sound. -#[cfg(not(target_endian = "big"))] +#[cfg(target_endian = "little")] impl PyASCIIObject { #[inline] pub unsafe fn interned(&self) -> c_uint { @@ -117,7 +117,7 @@ pub const SSTATE_INTERNED_MORTAL: c_uint = 1; pub const SSTATE_INTERNED_IMMORTAL: c_uint = 2; #[inline] -#[cfg(not(target_endian = "big"))] +#[cfg(target_endian = "little")] pub unsafe fn PyUnicode_IS_ASCII(op: *mut PyObject) -> c_uint { debug_assert!(crate::ffi::PyUnicode_Check(op) != 0); debug_assert!(PyUnicode_IS_READY(op) != 0); @@ -126,13 +126,13 @@ pub unsafe fn PyUnicode_IS_ASCII(op: *mut PyObject) -> c_uint { } #[inline] -#[cfg(not(target_endian = "big"))] +#[cfg(target_endian = "little")] pub unsafe fn PyUnicode_IS_COMPACT(op: *mut PyObject) -> c_uint { (*(op as *mut PyASCIIObject)).compact() } #[inline] -#[cfg(not(target_endian = "big"))] +#[cfg(target_endian = "little")] pub unsafe fn PyUnicode_IS_COMPACT_ASCII(op: *mut PyObject) -> c_uint { if (*(op as *mut PyASCIIObject)).ascii() != 0 && PyUnicode_IS_COMPACT(op) != 0 { 1 @@ -150,25 +150,25 @@ pub const PyUnicode_2BYTE_KIND: c_uint = 2; pub const PyUnicode_4BYTE_KIND: c_uint = 4; #[inline] -#[cfg(not(target_endian = "big"))] +#[cfg(target_endian = "little")] pub unsafe fn PyUnicode_1BYTE_DATA(op: *mut PyObject) -> *mut Py_UCS1 { PyUnicode_DATA(op) as *mut Py_UCS1 } #[inline] -#[cfg(not(target_endian = "big"))] +#[cfg(target_endian = "little")] pub unsafe fn PyUnicode_2BYTE_DATA(op: *mut PyObject) -> *mut Py_UCS2 { PyUnicode_DATA(op) as *mut Py_UCS2 } #[inline] -#[cfg(not(target_endian = "big"))] +#[cfg(target_endian = "little")] pub unsafe fn PyUnicode_4BYTE_DATA(op: *mut PyObject) -> *mut Py_UCS4 { PyUnicode_DATA(op) as *mut Py_UCS4 } #[inline] -#[cfg(not(target_endian = "big"))] +#[cfg(target_endian = "little")] pub unsafe fn PyUnicode_KIND(op: *mut PyObject) -> c_uint { debug_assert!(crate::ffi::PyUnicode_Check(op) != 0); debug_assert!(PyUnicode_IS_READY(op) != 0); @@ -177,7 +177,7 @@ pub unsafe fn PyUnicode_KIND(op: *mut PyObject) -> c_uint { } #[inline] -#[cfg(not(target_endian = "big"))] +#[cfg(target_endian = "little")] pub unsafe fn _PyUnicode_COMPACT_DATA(op: *mut PyObject) -> *mut c_void { if PyUnicode_IS_ASCII(op) != 0 { (op as *mut PyASCIIObject).offset(1) as *mut c_void @@ -187,7 +187,7 @@ pub unsafe fn _PyUnicode_COMPACT_DATA(op: *mut PyObject) -> *mut c_void { } #[inline] -#[cfg(not(target_endian = "big"))] +#[cfg(target_endian = "little")] pub unsafe fn _PyUnicode_NONCOMPACT_DATA(op: *mut PyObject) -> *mut c_void { debug_assert!(!(*(op as *mut PyUnicodeObject)).data.any.is_null()); @@ -195,7 +195,7 @@ pub unsafe fn _PyUnicode_NONCOMPACT_DATA(op: *mut PyObject) -> *mut c_void { } #[inline] -#[cfg(not(target_endian = "big"))] +#[cfg(target_endian = "little")] pub unsafe fn PyUnicode_DATA(op: *mut PyObject) -> *mut c_void { debug_assert!(crate::ffi::PyUnicode_Check(op) != 0); @@ -211,7 +211,7 @@ pub unsafe fn PyUnicode_DATA(op: *mut PyObject) -> *mut c_void { // skipped PyUnicode_READ_CHAR #[inline] -#[cfg(not(target_endian = "big"))] +#[cfg(target_endian = "little")] pub unsafe fn PyUnicode_GET_LENGTH(op: *mut PyObject) -> Py_ssize_t { debug_assert!(crate::ffi::PyUnicode_Check(op) != 0); debug_assert!(PyUnicode_IS_READY(op) != 0); @@ -220,7 +220,7 @@ pub unsafe fn PyUnicode_GET_LENGTH(op: *mut PyObject) -> Py_ssize_t { } #[inline] -#[cfg(not(target_endian = "big"))] +#[cfg(target_endian = "little")] pub unsafe fn PyUnicode_IS_READY(op: *mut PyObject) -> c_uint { (*(op as *mut PyASCIIObject)).ready() } @@ -228,7 +228,7 @@ pub unsafe fn PyUnicode_IS_READY(op: *mut PyObject) -> c_uint { #[cfg(not(Py_3_12))] #[cfg_attr(Py_3_10, deprecated(note = "Python 3.10"))] #[inline] -#[cfg(not(target_endian = "big"))] +#[cfg(target_endian = "little")] pub unsafe fn PyUnicode_READY(op: *mut PyObject) -> c_int { debug_assert!(crate::ffi::PyUnicode_Check(op) != 0); @@ -252,7 +252,6 @@ extern "C" { // skipped _PyUnicode_Copy #[cfg(not(PyPy))] - #[cfg_attr(docsrs, doc(cfg(not(PyPy))))] pub fn PyUnicode_CopyCharacters( to: *mut PyObject, to_start: Py_ssize_t, @@ -264,7 +263,6 @@ extern "C" { // skipped _PyUnicode_FastCopyCharacters #[cfg(not(PyPy))] - #[cfg_attr(docsrs, doc(cfg(not(PyPy))))] pub fn PyUnicode_Fill( unicode: *mut PyObject, start: Py_ssize_t, @@ -489,7 +487,7 @@ extern "C" { // skipped _PyUnicode_ScanIdentifier #[cfg(test)] -#[cfg(not(target_endian = "big"))] +#[cfg(target_endian = "little")] mod tests { use super::*; use crate::types::PyString; diff --git a/src/ffi/modsupport.rs b/src/ffi/modsupport.rs index 7362c2885ad..30cba10e639 100644 --- a/src/ffi/modsupport.rs +++ b/src/ffi/modsupport.rs @@ -54,7 +54,6 @@ extern "C" { // skipped non-limited _PyArg_Fini #[cfg(Py_3_10)] - #[cfg_attr(docsrs, doc(cfg(Py_3_10)))] pub fn PyModule_AddObjectRef( module: *mut PyObject, name: *const c_char, diff --git a/src/ffi/object.rs b/src/ffi/object.rs index cd9a96af516..05898a06d77 100644 --- a/src/ffi/object.rs +++ b/src/ffi/object.rs @@ -14,36 +14,13 @@ pub use crate::ffi::cpython::object::PyTypeObject; // _PyObject_HEAD_EXTRA: conditionally defined in PyObject_HEAD_INIT // _PyObject_EXTRA_INIT: conditionally defined in PyObject_HEAD_INIT -#[cfg(py_sys_config = "Py_TRACE_REFS")] -#[cfg(not(PyPy))] -pub const PyObject_HEAD_INIT: PyObject = PyObject { - _ob_next: std::ptr::null_mut(), - _ob_prev: std::ptr::null_mut(), - ob_refcnt: 1, - ob_type: std::ptr::null_mut(), -}; - -#[cfg(not(py_sys_config = "Py_TRACE_REFS"))] -#[cfg(not(PyPy))] -pub const PyObject_HEAD_INIT: PyObject = PyObject { - ob_refcnt: 1, - ob_type: std::ptr::null_mut(), -}; - -#[cfg(py_sys_config = "Py_TRACE_REFS")] -#[cfg(PyPy)] pub const PyObject_HEAD_INIT: PyObject = PyObject { + #[cfg(py_sys_config = "Py_TRACE_REFS")] _ob_next: std::ptr::null_mut(), + #[cfg(py_sys_config = "Py_TRACE_REFS")] _ob_prev: std::ptr::null_mut(), ob_refcnt: 1, - ob_pypy_link: 0, - ob_type: std::ptr::null_mut(), -}; - -#[cfg(not(py_sys_config = "Py_TRACE_REFS"))] -#[cfg(PyPy)] -pub const PyObject_HEAD_INIT: PyObject = PyObject { - ob_refcnt: 1, + #[cfg(PyPy)] ob_pypy_link: 0, ob_type: std::ptr::null_mut(), }; @@ -53,21 +30,13 @@ pub const PyObject_HEAD_INIT: PyObject = PyObject { #[repr(C)] #[derive(Copy, Clone, Debug)] -#[cfg(not(PyPy))] pub struct PyObject { #[cfg(py_sys_config = "Py_TRACE_REFS")] - _ob_next: *mut PyObject, + pub _ob_next: *mut PyObject, #[cfg(py_sys_config = "Py_TRACE_REFS")] - _ob_prev: *mut PyObject, - pub ob_refcnt: Py_ssize_t, - pub ob_type: *mut PyTypeObject, -} - -#[repr(C)] -#[derive(Debug, Copy, Clone)] -#[cfg(PyPy)] -pub struct PyObject { + pub _ob_prev: *mut PyObject, pub ob_refcnt: Py_ssize_t, + #[cfg(PyPy)] pub ob_pypy_link: Py_ssize_t, pub ob_type: *mut PyTypeObject, } @@ -353,11 +322,9 @@ extern "C" { pub const Py_PRINT_RAW: c_int = 1; // No string quotes etc. #[cfg(Py_3_10)] -#[cfg_attr(docsrs, doc(cfg(Py_3_10)))] pub const Py_TPFLAGS_DISALLOW_INSTANTIATION: c_ulong = 1 << 7; #[cfg(Py_3_10)] -#[cfg_attr(docsrs, doc(cfg(Py_3_10)))] pub const Py_TPFLAGS_IMMUTABLETYPE: c_ulong = 1 << 8; /// Set if the type object is dynamically allocated @@ -468,10 +435,8 @@ extern "C" { pub fn Py_DecRef(o: *mut PyObject); #[cfg(Py_3_10)] - #[cfg_attr(docsrs, doc(cfg(Py_3_10)))] pub fn Py_NewRef(obj: *mut PyObject) -> *mut PyObject; #[cfg(Py_3_10)] - #[cfg_attr(docsrs, doc(cfg(Py_3_10)))] pub fn Py_XNewRef(obj: *mut PyObject) -> *mut PyObject; } diff --git a/src/ffi/objimpl.rs b/src/ffi/objimpl.rs index 3891b902b22..59d00e2b145 100644 --- a/src/ffi/objimpl.rs +++ b/src/ffi/objimpl.rs @@ -30,11 +30,12 @@ extern "C" { pub fn PyGC_Collect() -> Py_ssize_t; #[cfg(Py_3_10)] - #[cfg_attr(docsrs, doc(cfg(Py_3_10)))] pub fn PyGC_Enable() -> c_int; - #[cfg_attr(docsrs, doc(cfg(Py_3_10)))] + + #[cfg(Py_3_10)] pub fn PyGC_Disable() -> c_int; - #[cfg_attr(docsrs, doc(cfg(Py_3_10)))] + + #[cfg(Py_3_10)] pub fn PyGC_IsEnabled() -> c_int; } diff --git a/src/ffi/pyerrors.rs b/src/ffi/pyerrors.rs index af0c109cd39..462d983d07c 100644 --- a/src/ffi/pyerrors.rs +++ b/src/ffi/pyerrors.rs @@ -375,7 +375,6 @@ extern "C" { #[cfg_attr(PyPy, link_name = "PyPyErr_SetInterrupt")] pub fn PyErr_SetInterrupt(); #[cfg(Py_3_10)] - #[cfg_attr(docsrs, doc(cfg(Py_3_10)))] pub fn PyErr_SetInterruptEx(signum: c_int); pub fn PyErr_SyntaxLocation(filename: *const c_char, lineno: c_int); pub fn PyErr_SyntaxLocationEx(filename: *const c_char, lineno: c_int, col_offset: c_int); diff --git a/src/ffi/pystate.rs b/src/ffi/pystate.rs index e2f0d9c6a78..a00af79d8c4 100644 --- a/src/ffi/pystate.rs +++ b/src/ffi/pystate.rs @@ -13,37 +13,28 @@ opaque_struct!(PyInterpreterState); extern "C" { #[cfg(not(PyPy))] - #[cfg_attr(docsrs, doc(cfg(not(PyPy))))] pub fn PyInterpreterState_New() -> *mut PyInterpreterState; #[cfg(not(PyPy))] - #[cfg_attr(docsrs, doc(cfg(not(PyPy))))] pub fn PyInterpreterState_Clear(arg1: *mut PyInterpreterState); #[cfg(not(PyPy))] - #[cfg_attr(docsrs, doc(cfg(not(PyPy))))] pub fn PyInterpreterState_Delete(arg1: *mut PyInterpreterState); #[cfg(all(Py_3_9, not(PyPy)))] - #[cfg_attr(docsrs, doc(cfg(all(Py_3_9, not(PyPy)))))] pub fn PyInterpreterState_Get() -> *mut PyInterpreterState; #[cfg(all(Py_3_8, not(PyPy)))] - #[cfg_attr(docsrs, doc(cfg(all(Py_3_8, not(PyPy)))))] pub fn PyInterpreterState_GetDict(arg1: *mut PyInterpreterState) -> *mut PyObject; #[cfg(all(Py_3_7, not(PyPy)))] - #[cfg_attr(docsrs, doc(cfg(all(Py_3_7, not(PyPy)))))] pub fn PyInterpreterState_GetID(arg1: *mut PyInterpreterState) -> i64; #[cfg(not(PyPy))] - #[cfg_attr(docsrs, doc(cfg(not(PyPy))))] pub fn PyState_AddModule(arg1: *mut PyObject, arg2: *mut PyModuleDef) -> c_int; #[cfg(not(PyPy))] - #[cfg_attr(docsrs, doc(cfg(not(PyPy))))] pub fn PyState_RemoveModule(arg1: *mut PyModuleDef) -> c_int; #[cfg(not(PyPy))] - #[cfg_attr(docsrs, doc(cfg(not(PyPy))))] pub fn PyState_FindModule(arg1: *mut PyModuleDef) -> *mut PyObject; #[cfg_attr(PyPy, link_name = "PyPyThreadState_New")] @@ -68,7 +59,6 @@ extern "C" { #[cfg_attr(PyPy, link_name = "PyPyThreadState_GetDict")] pub fn PyThreadState_GetDict() -> *mut PyObject; #[cfg(not(PyPy))] - #[cfg_attr(docsrs, doc(cfg(not(PyPy))))] pub fn PyThreadState_SetAsyncExc(arg1: c_long, arg2: *mut PyObject) -> c_int; } @@ -89,6 +79,5 @@ extern "C" { #[cfg_attr(PyPy, link_name = "PyPyGILState_Release")] pub fn PyGILState_Release(arg1: PyGILState_STATE); #[cfg(not(PyPy))] - #[cfg_attr(docsrs, doc(cfg(not(PyPy))))] pub fn PyGILState_GetThisThreadState() -> *mut PyThreadState; } diff --git a/src/ffi/setobject.rs b/src/ffi/setobject.rs index 70d1adb9dd3..7471c5fe8ad 100644 --- a/src/ffi/setobject.rs +++ b/src/ffi/setobject.rs @@ -119,7 +119,6 @@ pub unsafe fn PyAnySet_Check(ob: *mut PyObject) -> c_int { #[inline] #[cfg(Py_3_10)] -#[cfg_attr(docsrs, doc(cfg(Py_3_10)))] pub unsafe fn PySet_CheckExact(op: *mut PyObject) -> c_int { crate::ffi::Py_IS_TYPE(op, &mut PySet_Type) } diff --git a/src/ffi/structseq.rs b/src/ffi/structseq.rs index b164ea2aca3..d0d45c795ef 100644 --- a/src/ffi/structseq.rs +++ b/src/ffi/structseq.rs @@ -34,7 +34,6 @@ extern "C" { ) -> c_int; #[cfg(not(PyPy))] - #[cfg_attr(docsrs, doc(cfg(not(PyPy))))] pub fn PyStructSequence_NewType(desc: *mut PyStructSequence_Desc) -> *mut PyTypeObject; #[cfg_attr(PyPy, link_name = "PyPyStructSequence_New")] pub fn PyStructSequence_New(_type: *mut PyTypeObject) -> *mut PyObject; @@ -57,10 +56,8 @@ pub unsafe fn PyStructSequence_GET_ITEM(op: *mut PyObject, i: Py_ssize_t) -> *mu extern "C" { #[cfg(not(PyPy))] - #[cfg_attr(docsrs, doc(cfg(not(PyPy))))] pub fn PyStructSequence_SetItem(arg1: *mut PyObject, arg2: Py_ssize_t, arg3: *mut PyObject); #[cfg(not(PyPy))] - #[cfg_attr(docsrs, doc(cfg(not(PyPy))))] pub fn PyStructSequence_GetItem(arg1: *mut PyObject, arg2: Py_ssize_t) -> *mut PyObject; } diff --git a/src/ffi/unicodeobject.rs b/src/ffi/unicodeobject.rs index cbe3bf96f4a..61a60f8c101 100644 --- a/src/ffi/unicodeobject.rs +++ b/src/ffi/unicodeobject.rs @@ -166,11 +166,9 @@ extern "C" { #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUTF8String")] pub fn PyUnicode_AsUTF8String(unicode: *mut PyObject) -> *mut PyObject; #[cfg(any(Py_3_10, all(Py_3_7, not(Py_LIMITED_API))))] - #[cfg_attr(docsrs, doc(cfg(any(Py_3_10, not(Py_LIMITED_API)))))] #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUTF8AndSize")] pub fn PyUnicode_AsUTF8AndSize(unicode: *mut PyObject, size: *mut Py_ssize_t) -> *const c_char; #[cfg(not(any(Py_3_7, Py_LIMITED_API)))] - #[cfg_attr(docsrs, doc(cfg(any(Py_3_10, not(Py_LIMITED_API)))))] #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUTF8AndSize")] pub fn PyUnicode_AsUTF8AndSize(unicode: *mut PyObject, size: *mut Py_ssize_t) -> *mut c_char; #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeUTF32")] diff --git a/src/gil.rs b/src/gil.rs index 4727eac815a..01c5d0bf1b2 100644 --- a/src/gil.rs +++ b/src/gil.rs @@ -69,7 +69,6 @@ pub(crate) fn gil_is_acquired() -> bool { /// # } /// ``` #[cfg(not(PyPy))] -#[cfg_attr(docsrs, doc(cfg(not(PyPy))))] #[allow(clippy::collapsible_if)] // for if cfg! pub fn prepare_freethreaded_python() { // Protect against race conditions when Python is not yet initialized and multiple threads @@ -135,7 +134,6 @@ pub fn prepare_freethreaded_python() { /// # } /// ``` #[cfg(not(PyPy))] -#[cfg_attr(docsrs, doc(cfg(not(PyPy))))] #[allow(clippy::collapsible_if)] // for if cfg! pub unsafe fn with_embedded_python_interpreter(f: F) -> R where diff --git a/src/lib.rs b/src/lib.rs index 83a3ebbbe27..2d0ca39ba70 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -289,7 +289,6 @@ pub use crate::conversion::{ }; pub use crate::err::{PyDowncastError, PyErr, PyErrArguments, PyResult}; #[cfg(not(PyPy))] -#[cfg_attr(docsrs, doc(cfg(not(PyPy))))] pub use crate::gil::{prepare_freethreaded_python, with_embedded_python_interpreter}; pub use crate::gil::{GILGuard, GILPool}; pub use crate::instance::{Py, PyNativeType, PyObject}; @@ -355,7 +354,6 @@ pub mod proc_macro { pub use pyo3_macros::{pyclass, pyfunction, pymethods, pymodule, pyproto}; } -#[cfg_attr(docsrs, doc(cfg(feature = "macros")))] #[cfg(feature = "macros")] pub use pyo3_macros::{pyclass, pyfunction, pymethods, pymodule, pyproto, FromPyObject}; diff --git a/src/marshal.rs b/src/marshal.rs index 95786f9d5a5..1f089dfbd39 100644 --- a/src/marshal.rs +++ b/src/marshal.rs @@ -1,5 +1,5 @@ #![cfg(not(Py_LIMITED_API))] -#![cfg_attr(docsrs, doc(cfg(not(Py_LIMITED_API))))] + //! Support for the Python `marshal` format. use crate::ffi; diff --git a/src/prelude.rs b/src/prelude.rs index 7fd0cee87b4..a5c265c6fc8 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -22,6 +22,5 @@ pub use crate::python::Python; pub use crate::types::{PyAny, PyModule}; pub use crate::wrap_pyfunction; -#[cfg_attr(docsrs, doc(cfg(feature = "macros")))] #[cfg(feature = "macros")] pub use pyo3_macros::{pyclass, pyfunction, pymethods, pymodule, pyproto, FromPyObject}; diff --git a/src/types/complex.rs b/src/types/complex.rs index a294bfc71a8..5cd93373a58 100644 --- a/src/types/complex.rs +++ b/src/types/complex.rs @@ -37,7 +37,6 @@ impl PyComplex { } #[cfg(not(any(Py_LIMITED_API, PyPy)))] -#[cfg_attr(docsrs, doc(cfg(not(any(Py_LIMITED_API, PyPy)))))] mod not_limited_impls { use super::*; use std::ops::{Add, Div, Mul, Neg, Sub}; diff --git a/src/types/dict.rs b/src/types/dict.rs index bd3d4a711ce..cf7dbbaf0bf 100644 --- a/src/types/dict.rs +++ b/src/types/dict.rs @@ -39,7 +39,6 @@ impl PyDict { /// Returns an error on invalid input. In the case of key collisions, /// this keeps the last entry seen. #[cfg(not(PyPy))] - #[cfg_attr(docsrs, doc(cfg(not(PyPy))))] pub fn from_sequence(py: Python, seq: PyObject) -> PyResult<&PyDict> { unsafe { let dict = py.from_owned_ptr::(ffi::PyDict_New()); diff --git a/src/types/iterator.rs b/src/types/iterator.rs index 869c1be2cdc..6ba447745e9 100644 --- a/src/types/iterator.rs +++ b/src/types/iterator.rs @@ -71,7 +71,6 @@ impl<'p> Iterator for &'p PyIterator { // PyIter_Check does not exist in the limited API until 3.8 #[cfg(any(not(Py_LIMITED_API), Py_3_8))] -#[cfg_attr(docsrs, doc(cfg(any(not(Py_LIMITED_API), Py_3_8))))] impl<'v> PyTryFrom<'v> for PyIterator { fn try_from>(value: V) -> Result<&'v PyIterator, PyDowncastError<'v>> { let value = value.into(); diff --git a/src/types/list.rs b/src/types/list.rs index 8d3fca5406c..30c596ce916 100644 --- a/src/types/list.rs +++ b/src/types/list.rs @@ -98,7 +98,6 @@ impl PyList { /// /// Caller must verify that the index is within the bounds of the list. #[cfg(not(any(Py_LIMITED_API, PyPy)))] - #[cfg_attr(docsrs, doc(cfg(not(any(Py_LIMITED_API, PyPy)))))] pub unsafe fn get_item_unchecked(&self, index: usize) -> &PyAny { let item = ffi::PyList_GET_ITEM(self.as_ptr(), index as Py_ssize_t); // PyList_GET_ITEM return borrowed ptr; must make owned for safety (see #890). diff --git a/src/types/mod.rs b/src/types/mod.rs index 817cc175562..db09044a7c4 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -8,7 +8,6 @@ pub use self::bytearray::PyByteArray; pub use self::bytes::PyBytes; pub use self::complex::PyComplex; #[cfg(not(Py_LIMITED_API))] -#[cfg_attr(docsrs, doc(cfg(not(Py_LIMITED_API))))] pub use self::datetime::{ PyDate, PyDateAccess, PyDateTime, PyDelta, PyDeltaAccess, PyTime, PyTimeAccess, PyTzInfo, }; @@ -24,7 +23,7 @@ pub use self::num::PyLong as PyInt; pub use self::sequence::PySequence; pub use self::set::{PyFrozenSet, PySet}; pub use self::slice::{PySlice, PySliceIndices}; -#[cfg(not(any(Py_LIMITED_API, target_endian = "big")))] +#[cfg(all(not(Py_LIMITED_API), target_endian = "little"))] pub use self::string::PyStringData; pub use self::string::{PyString, PyString as PyUnicode}; pub use self::tuple::PyTuple; @@ -225,7 +224,6 @@ mod bytearray; mod bytes; mod complex; #[cfg(not(Py_LIMITED_API))] -#[cfg_attr(docsrs, doc(cfg(not(Py_LIMITED_API))))] mod datetime; mod dict; mod floatob; diff --git a/src/types/module.rs b/src/types/module.rs index ba3b3138c85..0121ae16ac1 100644 --- a/src/types/module.rs +++ b/src/types/module.rs @@ -176,7 +176,6 @@ impl PyModule { /// /// May fail if the module does not have a `__file__` attribute. #[cfg(not(all(windows, PyPy)))] - #[cfg_attr(docsrs, doc(cfg(not(all(windows, PyPy)))))] pub fn filename(&self) -> PyResult<&str> { use crate::types::PyString; unsafe { diff --git a/src/types/sequence.rs b/src/types/sequence.rs index c41ec3c8eab..1a1e1500b15 100644 --- a/src/types/sequence.rs +++ b/src/types/sequence.rs @@ -183,7 +183,6 @@ impl PySequence { /// number of keys for which `self[key] == value`. #[inline] #[cfg(not(PyPy))] - #[cfg_attr(docsrs, doc(cfg(not(PyPy))))] pub fn count(&self, value: V) -> PyResult where V: ToBorrowedObject, diff --git a/src/types/string.rs b/src/types/string.rs index c934e6f623c..0648eedc041 100644 --- a/src/types/string.rs +++ b/src/types/string.rs @@ -1,6 +1,6 @@ // Copyright (c) 2017-present PyO3 Project and Contributors -#[cfg(not(any(Py_LIMITED_API, target_endian = "big")))] +#[cfg(all(not(Py_LIMITED_API), target_endian = "little"))] use crate::exceptions::PyUnicodeDecodeError; use crate::types::PyBytes; use crate::{ @@ -15,8 +15,7 @@ use std::str; /// /// Python internally stores strings in various representations. This enumeration /// represents those variations. -#[cfg(not(any(Py_LIMITED_API, target_endian = "big")))] -#[cfg_attr(docsrs, doc(cfg(not(any(Py_LIMITED_API, target_endian = "big")))))] +#[cfg(all(not(Py_LIMITED_API), target_endian = "little"))] #[derive(Clone, Copy, Debug, PartialEq)] pub enum PyStringData<'a> { /// UCS1 representation. @@ -29,7 +28,7 @@ pub enum PyStringData<'a> { Ucs4(&'a [u32]), } -#[cfg(not(any(Py_LIMITED_API, target_endian = "big")))] +#[cfg(all(not(Py_LIMITED_API), target_endian = "little"))] impl<'a> PyStringData<'a> { /// Obtain the raw bytes backing this instance as a [u8] slice. pub fn as_bytes(&self) -> &[u8] { @@ -224,8 +223,7 @@ impl PyString { /// expected on the targets where you plan to distribute your software. /// /// For example, it is known not to work on big-endian platforms. - #[cfg(not(any(Py_LIMITED_API, target_endian = "big")))] - #[cfg_attr(docsrs, doc(cfg(not(any(Py_LIMITED_API, target_endian = "big")))))] + #[cfg(all(not(Py_LIMITED_API), target_endian = "little"))] pub unsafe fn data(&self) -> PyResult> { let ptr = self.as_ptr(); @@ -365,11 +363,11 @@ impl FromPyObject<'_> for char { #[cfg(test)] mod tests { use super::*; - #[cfg(not(any(Py_LIMITED_API, target_endian = "big")))] + #[cfg(all(not(Py_LIMITED_API), target_endian = "little"))] use crate::type_object::PyTypeObject; use crate::Python; use crate::{FromPyObject, PyObject, PyTryFrom, ToPyObject}; - #[cfg(not(any(Py_LIMITED_API, target_endian = "big")))] + #[cfg(all(not(Py_LIMITED_API), target_endian = "little"))] use std::borrow::Cow; #[test] @@ -475,7 +473,7 @@ mod tests { } #[test] - #[cfg(not(any(Py_LIMITED_API, target_endian = "big")))] + #[cfg(all(not(Py_LIMITED_API), target_endian = "little"))] fn test_string_data_ucs1() { Python::with_gil(|py| { let s = PyString::new(py, "hello, world"); @@ -488,7 +486,7 @@ mod tests { } #[test] - #[cfg(not(any(Py_LIMITED_API, target_endian = "big")))] + #[cfg(all(not(Py_LIMITED_API), target_endian = "little"))] fn test_string_data_ucs1_invalid() { Python::with_gil(|py| { // 0xfe is not allowed in UTF-8. @@ -514,7 +512,7 @@ mod tests { } #[test] - #[cfg(not(any(Py_LIMITED_API, target_endian = "big")))] + #[cfg(all(not(Py_LIMITED_API), target_endian = "little"))] fn test_string_data_ucs2() { Python::with_gil(|py| { let s = py.eval("'foo\\ud800'", None, None).unwrap(); @@ -530,7 +528,7 @@ mod tests { } #[test] - #[cfg(not(any(Py_LIMITED_API, target_endian = "big")))] + #[cfg(all(not(Py_LIMITED_API), target_endian = "little"))] fn test_string_data_ucs2_invalid() { Python::with_gil(|py| { // U+FF22 (valid) & U+d800 (never valid) @@ -556,7 +554,7 @@ mod tests { } #[test] - #[cfg(not(any(Py_LIMITED_API, target_endian = "big")))] + #[cfg(all(not(Py_LIMITED_API), target_endian = "little"))] fn test_string_data_ucs4() { Python::with_gil(|py| { let s = "哈哈🐈"; @@ -569,7 +567,7 @@ mod tests { } #[test] - #[cfg(not(any(Py_LIMITED_API, target_endian = "big")))] + #[cfg(all(not(Py_LIMITED_API), target_endian = "little"))] fn test_string_data_ucs4_invalid() { Python::with_gil(|py| { // U+20000 (valid) & U+d800 (never valid) diff --git a/src/types/tuple.rs b/src/types/tuple.rs index b33a3398629..fe9bd6fb202 100644 --- a/src/types/tuple.rs +++ b/src/types/tuple.rs @@ -134,7 +134,6 @@ impl PyTuple { /// /// Caller must verify that the index is within the bounds of the tuple. #[cfg(not(any(Py_LIMITED_API, PyPy)))] - #[cfg_attr(docsrs, doc(cfg(not(any(Py_LIMITED_API, PyPy)))))] pub unsafe fn get_item_unchecked(&self, index: usize) -> &PyAny { let item = ffi::PyTuple_GET_ITEM(self.as_ptr(), index as Py_ssize_t); self.py().from_borrowed_ptr(item) @@ -142,7 +141,6 @@ impl PyTuple { /// Returns `self` as a slice of objects. #[cfg(not(Py_LIMITED_API))] - #[cfg_attr(docsrs, doc(cfg(not(Py_LIMITED_API))))] pub fn as_slice(&self) -> &[&PyAny] { // This is safe because &PyAny has the same memory layout as *mut ffi::PyObject, // and because tuples are immutable.