Fix some cfg's and banners
This commit is contained in:
parent
bfb33da168
commit
dd0bf8118d
|
@ -80,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 {
|
||||
|
@ -94,11 +95,15 @@ macro_rules! bigint_conversion {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "num-bigint")))]
|
||||
impl IntoPy<PyObject> 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();
|
||||
|
|
|
@ -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::<PyObject>::into_py(self.to_owned(), py)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "num-complex")))]
|
||||
impl crate::IntoPy<PyObject> 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<Complex<$float>> {
|
||||
#[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<Complex<$float>> {
|
||||
|
||||
#[cfg(any(Py_LIMITED_API, PyPy))]
|
||||
unsafe {
|
||||
let ptr = obj.as_ptr();
|
||||
let real = ffi::PyComplex_RealAsDouble(ptr);
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
@ -487,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;
|
||||
|
|
|
@ -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 {
|
||||
#[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_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 {
|
||||
_ob_next: std::ptr::null_mut(),
|
||||
_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,
|
||||
}
|
||||
|
|
|
@ -32,8 +32,10 @@ extern "C" {
|
|||
#[cfg(Py_3_10)]
|
||||
pub fn PyGC_Enable() -> c_int;
|
||||
|
||||
#[cfg(Py_3_10)]
|
||||
pub fn PyGC_Disable() -> c_int;
|
||||
|
||||
#[cfg(Py_3_10)]
|
||||
pub fn PyGC_IsEnabled() -> c_int;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,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;
|
||||
|
|
|
@ -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,7 +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(all(not(Py_LIMITED_API), target_endian = "little"))]
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub enum PyStringData<'a> {
|
||||
/// UCS1 representation.
|
||||
|
@ -28,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] {
|
||||
|
@ -223,7 +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(all(not(Py_LIMITED_API), target_endian = "little"))]
|
||||
pub unsafe fn data(&self) -> PyResult<PyStringData<'_>> {
|
||||
let ptr = self.as_ptr();
|
||||
|
||||
|
@ -363,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]
|
||||
|
@ -473,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");
|
||||
|
@ -486,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.
|
||||
|
@ -512,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();
|
||||
|
@ -528,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)
|
||||
|
@ -554,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 = "哈哈🐈";
|
||||
|
@ -567,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)
|
||||
|
|
Loading…
Reference in a new issue