Make check warning clean in limited API mode
This commit is contained in:
parent
2ec1c3b0b9
commit
870914da90
|
@ -8,9 +8,9 @@ use crate::type_object::{PyBorrowFlagLayout, PyLayout, PySizedLayout, PyTypeInfo
|
|||
use crate::types::PyAny;
|
||||
use crate::{ffi, IntoPy, PyErr, PyNativeType, PyObject, PyResult, Python};
|
||||
use std::cell::{Cell, UnsafeCell};
|
||||
use std::fmt;
|
||||
use std::mem::ManuallyDrop;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::{fmt, mem};
|
||||
|
||||
/// Base layout of PyCell.
|
||||
/// This is necessary for sharing BorrowFlag between parents and children.
|
||||
|
@ -170,20 +170,26 @@ pub struct PyCell<T: PyClass> {
|
|||
|
||||
impl<T: PyClass> PyCell<T> {
|
||||
/// Get the offset of the dictionary from the start of the struct in bytes.
|
||||
#[cfg(not(Py_LIMITED_API))]
|
||||
pub(crate) fn dict_offset() -> Option<usize> {
|
||||
if T::Dict::IS_DUMMY {
|
||||
None
|
||||
} else {
|
||||
Some(mem::size_of::<Self>() - mem::size_of::<T::Dict>() - mem::size_of::<T::WeakRef>())
|
||||
Some(
|
||||
std::mem::size_of::<Self>()
|
||||
- std::mem::size_of::<T::Dict>()
|
||||
- std::mem::size_of::<T::WeakRef>(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the offset of the weakref list from the start of the struct in bytes.
|
||||
#[cfg(not(Py_LIMITED_API))]
|
||||
pub(crate) fn weakref_offset() -> Option<usize> {
|
||||
if T::WeakRef::IS_DUMMY {
|
||||
None
|
||||
} else {
|
||||
Some(mem::size_of::<Self>() - mem::size_of::<T::WeakRef>())
|
||||
Some(std::mem::size_of::<Self>() - std::mem::size_of::<T::WeakRef>())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,6 +51,8 @@ pub(crate) unsafe fn default_new<T: PyTypeInfo>(
|
|||
}
|
||||
#[cfg(Py_LIMITED_API)]
|
||||
{
|
||||
// Silence unused parameter warning.
|
||||
let _ = py;
|
||||
unreachable!("Subclassing native types isn't support in limited API mode");
|
||||
}
|
||||
}
|
||||
|
@ -275,7 +277,7 @@ fn tp_init_additional<T: PyClass>(type_object: *mut ffi::PyTypeObject) {
|
|||
}
|
||||
|
||||
#[cfg(Py_LIMITED_API)]
|
||||
fn tp_init_additional<T: PyClass>(type_object: *mut ffi::PyTypeObject) {}
|
||||
fn tp_init_additional<T: PyClass>(_type_object: *mut ffi::PyTypeObject) {}
|
||||
|
||||
fn py_class_flags<T: PyClass + PyTypeInfo>() -> c_uint {
|
||||
let mut flags = if T::gc_methods().is_some() || T::FLAGS & type_flags::GC != 0 {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#[cfg(not(PyPy))]
|
||||
#[cfg(all(not(PyPy), not(Py_LIMITED_API)))]
|
||||
use crate::instance::PyNativeType;
|
||||
use crate::{ffi, AsPyPointer, PyAny, Python};
|
||||
#[cfg(not(PyPy))]
|
||||
#[cfg(all(not(PyPy), not(Py_LIMITED_API)))]
|
||||
use std::ops::*;
|
||||
use std::os::raw::c_double;
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ use crate::{
|
|||
exceptions, AsPyPointer, FromPyObject, IntoPy, IntoPyPointer, Py, PyAny, PyErr, PyNativeType,
|
||||
PyObject, PyResult, PyTryFrom, Python, ToPyObject,
|
||||
};
|
||||
use std::slice;
|
||||
|
||||
/// Represents a Python `tuple` object.
|
||||
///
|
||||
|
@ -87,7 +86,7 @@ impl PyTuple {
|
|||
// and because tuples are immutable.
|
||||
unsafe {
|
||||
let ptr = self.as_ptr() as *mut ffi::PyTupleObject;
|
||||
let slice = slice::from_raw_parts((*ptr).ob_item.as_ptr(), self.len());
|
||||
let slice = std::slice::from_raw_parts((*ptr).ob_item.as_ptr(), self.len());
|
||||
&*(slice as *const [*mut ffi::PyObject] as *const [&PyAny])
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue