pypy: fix warnings

This commit is contained in:
David Hewitt 2020-12-18 23:42:17 +00:00
parent 3d6356223e
commit dd479052e2
11 changed files with 97 additions and 23 deletions

View File

@ -12,10 +12,14 @@ extern "C" {
static mut _Py_TrueStruct: PyLongObject;
#[cfg_attr(PyPy, link_name = "PyPyBool_FromLong")]
pub fn PyBool_FromLong(arg1: c_long) -> *mut PyObject;
#[cfg(PyPy)]
#[link_name = "PyPyBool_Check"]
pub fn PyBool_Check(op: *mut PyObject) -> c_int;
}
#[inline]
#[cfg_attr(PyPy, link_name = "PyPyBool_Check")]
#[cfg(not(PyPy))]
pub unsafe fn PyBool_Check(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == &mut PyBool_Type) as c_int
}

View File

@ -133,16 +133,24 @@ extern "C" {
names: *mut PyObject,
lnotab: *mut PyObject,
) -> *mut PyObject;
#[cfg(PyPy)]
#[link_name = "PyPyCode_Check"]
pub fn PyCode_Check(op: *mut PyObject) -> c_int;
#[cfg(PyPy)]
#[link_name = "PyPyCode_GetNumFree"]
pub fn PyCode_GetNumFree(op: *mut PyCodeObject) -> Py_ssize_t;
}
#[inline]
#[cfg_attr(PyPy, link_name = "PyPyCode_Check")]
#[cfg(not(PyPy))]
pub unsafe fn PyCode_Check(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == &mut PyCode_Type) as c_int
}
#[inline]
#[cfg_attr(PyPy, link_name = "PyPyCode_GetNumFree")]
#[cfg(not(PyPy))]
pub unsafe fn PyCode_GetNumFree(op: *mut PyCodeObject) -> Py_ssize_t {
crate::ffi::tupleobject::PyTuple_GET_SIZE((*op).co_freevars)
}

View File

@ -11,7 +11,6 @@
//! Support for `PyDateTime_CAPI` is limited as of PyPy 7.0.0.
//! `DateTime_FromTimestamp` and `Date_FromTimestamp` are currently not supported.
use crate::ffi::Py_hash_t;
use crate::ffi::{PyObject, PyTypeObject};
use crate::ffi::{PyObject_TypeCheck, Py_TYPE};
use crate::once_cell::GILOnceCell;
@ -19,7 +18,10 @@ use crate::Python;
use std::ops::Deref;
use std::os::raw::{c_char, c_int, c_uchar};
#[cfg(not(PyPy))]
use {crate::ffi::PyCapsule_Import, std::ffi::CString};
use {
crate::ffi::{PyCapsule_Import, Py_hash_t},
std::ffi::CString,
};
#[repr(C)]
#[derive(Debug, Copy, Clone)]

View File

@ -72,7 +72,7 @@ extern "C" {
module: *mut PyObject,
) -> *mut PyObject;
#[cfg_attr(PyPy, link_name = "PyPyCFunction_NewEx")]
#[cfg_attr(PyPy, link_name = "PyPyCFunction_New")]
pub fn PyCFunction_New(ml: *mut PyMethodDef, slf: *mut PyObject) -> *mut PyObject;
}

View File

@ -3,10 +3,15 @@ use crate::ffi::pyport::Py_ssize_t;
use std::os::raw::{c_char, c_int};
use std::ptr;
extern "C" {
#[cfg(PyPy)]
#[link_name = "PyPyObject_DelAttrString"]
pub fn PyObject_DelAttrString(o: *mut PyObject, attr_name: *const c_char) -> c_int;
}
#[inline]
#[cfg_attr(PyPy, link_name = "PyPyObject_DelAttrString")]
#[cfg(not(PyPy))]
pub unsafe fn PyObject_DelAttrString(o: *mut PyObject, attr_name: *const c_char) -> c_int {
#[cfg_attr(PyPy, link_name = "PyPyObject_SetAttr")]
PyObject_SetAttrString(o, attr_name, ptr::null_mut())
}
@ -129,11 +134,14 @@ extern "C" {
pub fn PyNumber_Xor(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject;
#[cfg_attr(PyPy, link_name = "PyPyNumber_Or")]
pub fn PyNumber_Or(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject;
#[cfg(PyPy)]
#[link_name = "PyPyIndex_Check"]
pub fn PyIndex_Check(o: *mut PyObject) -> c_int;
}
#[cfg(not(Py_LIMITED_API))]
#[cfg(not(any(Py_LIMITED_API, PyPy)))]
#[inline]
#[cfg_attr(PyPy, link_name = "PyPyIndex_Check")]
pub unsafe fn PyIndex_Check(o: *mut PyObject) -> c_int {
let tp_as_number = (*Py_TYPE(o)).tp_as_number;
(!tp_as_number.is_null() && (*tp_as_number).nb_index.is_some()) as c_int
@ -184,10 +192,14 @@ extern "C" {
pub fn PySequence_Check(o: *mut PyObject) -> c_int;
#[cfg_attr(PyPy, link_name = "PyPySequence_Size")]
pub fn PySequence_Size(o: *mut PyObject) -> Py_ssize_t;
#[cfg(PyPy)]
#[link_name = "PyPySequence_Length"]
pub fn PySequence_Length(o: *mut PyObject) -> Py_ssize_t;
}
#[inline]
#[cfg_attr(PyPy, link_name = "PyPySequence_Length")]
#[cfg(not(PyPy))]
pub unsafe fn PySequence_Length(o: *mut PyObject) -> Py_ssize_t {
PySequence_Size(o)
}
@ -242,10 +254,14 @@ extern "C" {
pub fn PyMapping_Check(o: *mut PyObject) -> c_int;
#[cfg_attr(PyPy, link_name = "PyPyMapping_Size")]
pub fn PyMapping_Size(o: *mut PyObject) -> Py_ssize_t;
#[cfg(PyPy)]
#[link_name = "PyPyMapping_Length"]
pub fn PyMapping_Length(o: *mut PyObject) -> Py_ssize_t;
}
#[inline]
#[cfg_attr(PyPy, link_name = "PyPyMapping_Length")]
#[cfg(not(PyPy))]
pub unsafe fn PyMapping_Length(o: *mut PyObject) -> Py_ssize_t {
PyMapping_Size(o)
}

View File

@ -128,6 +128,10 @@ extern "C" {
pub fn PyException_GetContext(arg1: *mut PyObject) -> *mut PyObject;
#[cfg_attr(PyPy, link_name = "PyPyException_SetContext")]
pub fn PyException_SetContext(arg1: *mut PyObject, arg2: *mut PyObject);
#[cfg(PyPy)]
#[link_name = "PyPyExceptionInstance_Class"]
pub fn PyExceptionInstance_Class(x: *mut PyObject) -> *mut PyObject;
}
#[inline]
@ -143,7 +147,7 @@ pub unsafe fn PyExceptionInstance_Check(x: *mut PyObject) -> c_int {
}
#[inline]
#[cfg_attr(PyPy, link_name = "PyPyExceptionInstance_Class")]
#[cfg(not(PyPy))]
pub unsafe fn PyExceptionInstance_Class(x: *mut PyObject) -> *mut PyObject {
Py_TYPE(x) as *mut PyObject
}

View File

@ -9,6 +9,18 @@ extern "C" {
#[cfg_attr(PyPy, link_name = "PyPyFrozenSet_Type")]
pub static mut PyFrozenSet_Type: PyTypeObject;
pub static mut PySetIter_Type: PyTypeObject;
#[cfg(PyPy)]
#[link_name = "PyPyFrozenSet_CheckExact"]
pub fn PyFrozenSet_CheckExact(ob: *mut PyObject) -> c_int;
#[cfg(PyPy)]
#[link_name = "PyPyAnySet_CheckExact"]
pub fn PyAnySet_CheckExact(ob: *mut PyObject) -> c_int;
#[cfg(PyPy)]
#[link_name = "PyPySet_Check"]
pub fn PySet_Check(ob: *mut PyObject) -> c_int;
}
pub const PySet_MINSIZE: usize = 8;
@ -35,13 +47,13 @@ pub struct PySetObject {
}
#[inline]
#[cfg_attr(PyPy, link_name = "PyPyFrozenSet_CheckExact")]
#[cfg(not(PyPy))]
pub unsafe fn PyFrozenSet_CheckExact(ob: *mut PyObject) -> c_int {
(Py_TYPE(ob) == &mut PyFrozenSet_Type) as c_int
}
#[inline]
#[cfg_attr(PyPy, link_name = "PyPyAnySet_CheckExact")]
#[cfg(not(PyPy))]
pub unsafe fn PyAnySet_CheckExact(ob: *mut PyObject) -> c_int {
(Py_TYPE(ob) == &mut PySet_Type || Py_TYPE(ob) == &mut PyFrozenSet_Type) as c_int
}
@ -54,7 +66,7 @@ pub unsafe fn PyAnySet_Check(ob: *mut PyObject) -> c_int {
}
#[inline]
#[cfg_attr(PyPy, link_name = "PyPySet_Check")]
#[cfg(not(PyPy))]
pub unsafe fn PySet_Check(ob: *mut PyObject) -> c_int {
(Py_TYPE(ob) == &mut PySet_Type || PyType_IsSubtype(Py_TYPE(ob), &mut PySet_Type) != 0) as c_int
}

View File

@ -17,10 +17,14 @@ extern "C" {
#[cfg_attr(PyPy, link_name = "PyPySlice_Type")]
pub static mut PySlice_Type: PyTypeObject;
pub static mut PyEllipsis_Type: PyTypeObject;
#[cfg(PyPy)]
#[link_name = "PyPySlice_Check"]
pub fn PySlice_Check(op: *mut PyObject) -> c_int;
}
#[inline]
#[cfg_attr(PyPy, link_name = "PyPySlice_Check")]
#[cfg(not(PyPy))]
pub unsafe fn PySlice_Check(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == &mut PySlice_Type) as c_int
}

View File

@ -12,10 +12,14 @@ extern "C" {
extern "C" {
#[cfg_attr(PyPy, link_name = "PyPyTraceBack_Type")]
pub static mut PyTraceBack_Type: PyTypeObject;
#[cfg(PyPy)]
#[link_name = "PyPyTraceBack_Check"]
pub fn PyTraceBack_Check(op: *mut PyObject) -> c_int;
}
#[inline]
#[cfg_attr(PyPy, link_name = "PyPyTraceBack_Check")]
#[cfg(not(PyPy))]
pub unsafe fn PyTraceBack_Check(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == &mut PyTraceBack_Type) as c_int
}

View File

@ -15,16 +15,24 @@ extern "C" {
#[cfg_attr(PyPy, link_name = "PyPyUnicode_Type")]
pub static mut PyUnicode_Type: PyTypeObject;
pub static mut PyUnicodeIter_Type: PyTypeObject;
#[cfg(PyPy)]
#[link_name = "PyPyUnicode_Check"]
pub fn PyUnicode_Check(op: *mut PyObject) -> c_int;
#[cfg(PyPy)]
#[link_name = "PyPyUnicode_CheckExact"]
pub fn PyUnicode_CheckExact(op: *mut PyObject) -> c_int;
}
#[inline]
#[cfg_attr(PyPy, link_name = "PyPyUnicode_Check")]
#[cfg(not(PyPy))]
pub unsafe fn PyUnicode_Check(op: *mut PyObject) -> c_int {
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_UNICODE_SUBCLASS)
}
#[inline]
#[cfg_attr(PyPy, link_name = "PyPyUnicode_CheckExact")]
#[cfg(not(PyPy))]
pub unsafe fn PyUnicode_CheckExact(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == &mut PyUnicode_Type) as c_int
}

View File

@ -7,22 +7,34 @@ extern "C" {
static mut _PyWeakref_RefType: PyTypeObject;
static mut _PyWeakref_ProxyType: PyTypeObject;
static mut _PyWeakref_CallableProxyType: PyTypeObject;
#[cfg(PyPy)]
#[link_name = "PyPyWeakref_CheckRef"]
pub fn PyWeakref_CheckRef(op: *mut PyObject) -> c_int;
#[cfg(PyPy)]
#[link_name = "PyPyWeakref_CheckRefExact"]
pub fn PyWeakref_CheckRefExact(op: *mut PyObject) -> c_int;
#[cfg(PyPy)]
#[link_name = "PyPyWeakref_CheckProxy"]
pub fn PyWeakref_CheckProxy(op: *mut PyObject) -> c_int;
}
#[inline]
#[cfg_attr(PyPy, link_name = "PyPyWeakref_CheckRef")]
#[cfg(not(PyPy))]
pub unsafe fn PyWeakref_CheckRef(op: *mut PyObject) -> c_int {
PyObject_TypeCheck(op, &mut _PyWeakref_RefType)
}
#[inline]
#[cfg_attr(PyPy, link_name = "PyPyWeakref_CheckRefExact")]
#[cfg(not(PyPy))]
pub unsafe fn PyWeakref_CheckRefExact(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == &mut _PyWeakref_RefType) as c_int
}
#[inline]
#[cfg_attr(PyPy, link_name = "PyPyWeakref_CheckProxy")]
#[cfg(not(PyPy))]
pub unsafe fn PyWeakref_CheckProxy(op: *mut PyObject) -> c_int {
((Py_TYPE(op) == &mut _PyWeakref_ProxyType)
|| (Py_TYPE(op) == &mut _PyWeakref_CallableProxyType)) as c_int