Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions newsfragments/5977.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use `Py_IS_TYPE` on abi3 & python 3.15+
2 changes: 1 addition & 1 deletion pyo3-ffi/src/boolobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::ffi::{c_int, c_long};

#[inline]
pub unsafe fn PyBool_Check(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == &raw mut PyBool_Type) as c_int
Py_IS_TYPE(op, &raw mut PyBool_Type)
}

extern_libpython! {
Expand Down
2 changes: 1 addition & 1 deletion pyo3-ffi/src/bytearrayobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub unsafe fn PyByteArray_Check(op: *mut PyObject) -> c_int {

#[inline]
pub unsafe fn PyByteArray_CheckExact(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == &raw mut PyByteArray_Type) as c_int
Py_IS_TYPE(op, &raw mut PyByteArray_Type)
}

extern_libpython! {
Expand Down
2 changes: 1 addition & 1 deletion pyo3-ffi/src/bytesobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub unsafe fn PyBytes_Check(op: *mut PyObject) -> c_int {

#[inline]
pub unsafe fn PyBytes_CheckExact(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == &raw mut PyBytes_Type) as c_int
Py_IS_TYPE(op, &raw mut PyBytes_Type)
}

extern_libpython! {
Expand Down
9 changes: 5 additions & 4 deletions pyo3-ffi/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::object::{PyObject, PyTypeObject, Py_TYPE};
use crate::object::{PyObject, PyTypeObject};
use crate::Py_IS_TYPE;
use std::ffi::{c_char, c_int};

extern_libpython! {
Expand All @@ -12,17 +13,17 @@ extern_libpython! {

#[inline]
pub unsafe fn PyContext_CheckExact(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == &raw mut PyContext_Type) as c_int
Py_IS_TYPE(op, &raw mut PyContext_Type)
}

#[inline]
pub unsafe fn PyContextVar_CheckExact(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == &raw mut PyContextVar_Type) as c_int
Py_IS_TYPE(op, &raw mut PyContextVar_Type)
}

#[inline]
pub unsafe fn PyContextToken_CheckExact(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == &raw mut PyContextToken_Type) as c_int
Py_IS_TYPE(op, &raw mut PyContextToken_Type)
}

extern_libpython! {
Expand Down
2 changes: 1 addition & 1 deletion pyo3-ffi/src/cpython/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ extern_libpython! {
#[inline]
#[cfg(not(PyPy))]
pub unsafe fn PyCode_Check(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == &raw mut PyCode_Type) as c_int
Py_IS_TYPE(op, &raw mut PyCode_Type)
}

extern_libpython! {
Expand Down
4 changes: 2 additions & 2 deletions pyo3-ffi/src/cpython/funcobject.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::PyObject;
use crate::{PyObject, Py_IS_TYPE};
use std::ffi::c_int;

#[cfg(all(not(any(PyPy, GraalPy)), not(Py_3_10)))]
Expand Down Expand Up @@ -65,7 +65,7 @@ extern_libpython! {

#[inline]
pub unsafe fn PyFunction_Check(op: *mut PyObject) -> c_int {
(crate::Py_TYPE(op) == &raw mut PyFunction_Type) as c_int
Py_IS_TYPE(op, &raw mut PyFunction_Type)
}

extern_libpython! {
Expand Down
2 changes: 1 addition & 1 deletion pyo3-ffi/src/cpython/genobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub unsafe fn PyGen_Check(op: *mut PyObject) -> c_int {

#[inline]
pub unsafe fn PyGen_CheckExact(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == &raw mut PyGen_Type) as c_int
Py_IS_TYPE(op, &raw mut PyGen_Type)
}

extern_libpython! {
Expand Down
2 changes: 1 addition & 1 deletion pyo3-ffi/src/cpython/methodobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extern_libpython! {

#[inline]
pub unsafe fn PyCMethod_CheckExact(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == &raw mut PyCMethod_Type) as c_int
Py_IS_TYPE(op, &raw mut PyCMethod_Type)
}

#[inline]
Expand Down
6 changes: 3 additions & 3 deletions pyo3-ffi/src/cpython/pyframe.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[cfg(any(Py_3_11, all(Py_3_9, not(PyPy))))]
use crate::PyFrameObject;
use crate::{PyObject, PyTypeObject, Py_TYPE};
use crate::{PyObject, PyTypeObject, Py_IS_TYPE};
#[cfg(Py_3_12)]
use std::ffi::c_char;
use std::ffi::c_int;
Expand Down Expand Up @@ -32,13 +32,13 @@ extern_libpython! {

#[inline]
pub unsafe fn PyFrame_Check(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == &raw mut PyFrame_Type) as c_int
Py_IS_TYPE(op, &raw mut PyFrame_Type)
}

#[cfg(Py_3_13)]
#[inline]
pub unsafe fn PyFrameLocalsProxy_Check(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == &raw mut PyFrameLocalsProxy_Type) as c_int
Py_IS_TYPE(op, &raw mut PyFrameLocalsProxy_Type)
}

extern_libpython! {
Expand Down
12 changes: 6 additions & 6 deletions pyo3-ffi/src/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use crate::PyCapsule_Import;
#[cfg(GraalPy)]
use crate::{PyLong_AsLong, PyLong_Check, PyObject_GetAttrString, Py_DecRef};
use crate::{PyObject, PyObject_TypeCheck, PyTypeObject, Py_None, Py_TYPE};
use crate::{PyObject, PyObject_TypeCheck, PyTypeObject, Py_IS_TYPE, Py_None};
use std::ffi::c_char;
use std::ffi::c_int;
use std::ptr;
Expand Down Expand Up @@ -651,7 +651,7 @@ pub unsafe fn PyDate_Check(op: *mut PyObject) -> c_int {
#[inline]
/// Check if `op`'s type is exactly `PyDateTimeAPI.DateType`.
pub unsafe fn PyDate_CheckExact(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == (*PyDateTimeAPI()).DateType) as c_int
Py_IS_TYPE(op, (*PyDateTimeAPI()).DateType)
}

#[inline]
Expand All @@ -663,7 +663,7 @@ pub unsafe fn PyDateTime_Check(op: *mut PyObject) -> c_int {
#[inline]
/// Check if `op`'s type is exactly `PyDateTimeAPI.DateTimeType`.
pub unsafe fn PyDateTime_CheckExact(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == (*PyDateTimeAPI()).DateTimeType) as c_int
Py_IS_TYPE(op, (*PyDateTimeAPI()).DateTimeType)
}

#[inline]
Expand All @@ -675,7 +675,7 @@ pub unsafe fn PyTime_Check(op: *mut PyObject) -> c_int {
#[inline]
/// Check if `op`'s type is exactly `PyDateTimeAPI.TimeType`.
pub unsafe fn PyTime_CheckExact(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == (*PyDateTimeAPI()).TimeType) as c_int
Py_IS_TYPE(op, (*PyDateTimeAPI()).TimeType)
}

#[inline]
Expand All @@ -687,7 +687,7 @@ pub unsafe fn PyDelta_Check(op: *mut PyObject) -> c_int {
#[inline]
/// Check if `op`'s type is exactly `PyDateTimeAPI.DeltaType`.
pub unsafe fn PyDelta_CheckExact(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == (*PyDateTimeAPI()).DeltaType) as c_int
Py_IS_TYPE(op, (*PyDateTimeAPI()).DeltaType)
}

#[inline]
Expand All @@ -699,7 +699,7 @@ pub unsafe fn PyTZInfo_Check(op: *mut PyObject) -> c_int {
#[inline]
/// Check if `op`'s type is exactly `PyDateTimeAPI.TZInfoType`.
pub unsafe fn PyTZInfo_CheckExact(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == (*PyDateTimeAPI()).TZInfoType) as c_int
Py_IS_TYPE(op, (*PyDateTimeAPI()).TZInfoType)
}

pub unsafe fn PyDate_FromDate(year: c_int, month: c_int, day: c_int) -> *mut PyObject {
Expand Down
2 changes: 1 addition & 1 deletion pyo3-ffi/src/dictobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub unsafe fn PyDict_Check(op: *mut PyObject) -> c_int {

#[inline]
pub unsafe fn PyDict_CheckExact(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == &raw mut PyDict_Type) as c_int
Py_IS_TYPE(op, &raw mut PyDict_Type)
}

extern_libpython! {
Expand Down
2 changes: 1 addition & 1 deletion pyo3-ffi/src/floatobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub unsafe fn PyFloat_Check(op: *mut PyObject) -> c_int {

#[inline]
pub unsafe fn PyFloat_CheckExact(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == &raw mut PyFloat_Type) as c_int
Py_IS_TYPE(op, &raw mut PyFloat_Type)
}

// skipped Py_RETURN_NAN
Expand Down
4 changes: 2 additions & 2 deletions pyo3-ffi/src/iterobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extern_libpython! {

#[inline]
pub unsafe fn PySeqIter_Check(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == &raw mut PySeqIter_Type) as c_int
Py_IS_TYPE(op, &raw mut PySeqIter_Type)
}

extern_libpython! {
Expand All @@ -18,7 +18,7 @@ extern_libpython! {

#[inline]
pub unsafe fn PyCallIter_Check(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == &raw mut PyCallIter_Type) as c_int
Py_IS_TYPE(op, &raw mut PyCallIter_Type)
}

extern_libpython! {
Expand Down
2 changes: 1 addition & 1 deletion pyo3-ffi/src/listobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub unsafe fn PyList_Check(op: *mut PyObject) -> c_int {

#[inline]
pub unsafe fn PyList_CheckExact(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == &raw mut PyList_Type) as c_int
Py_IS_TYPE(op, &raw mut PyList_Type)
}

extern_libpython! {
Expand Down
2 changes: 1 addition & 1 deletion pyo3-ffi/src/longobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub unsafe fn PyLong_Check(op: *mut PyObject) -> c_int {

#[inline]
pub unsafe fn PyLong_CheckExact(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == &raw mut PyLong_Type) as c_int
Py_IS_TYPE(op, &raw mut PyLong_Type)
}

extern_libpython! {
Expand Down
2 changes: 1 addition & 1 deletion pyo3-ffi/src/memoryobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extern_libpython! {

#[inline]
pub unsafe fn PyMemoryView_Check(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == &raw mut PyMemoryView_Type) as c_int
Py_IS_TYPE(op, &raw mut PyMemoryView_Type)
}

// skipped non-limited PyMemoryView_GET_BUFFER
Expand Down
7 changes: 4 additions & 3 deletions pyo3-ffi/src/methodobject.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::object::{PyObject, PyTypeObject, Py_TYPE};
use crate::object::{PyObject, PyTypeObject};
#[cfg(Py_3_9)]
use crate::PyObject_TypeCheck;
use crate::Py_IS_TYPE;
use std::ffi::{c_char, c_int, c_void};
use std::{mem, ptr};

Expand All @@ -23,7 +24,7 @@ extern_libpython! {
#[cfg(Py_3_9)]
#[inline]
pub unsafe fn PyCFunction_CheckExact(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == &raw mut PyCFunction_Type) as c_int
Py_IS_TYPE(op, &raw mut PyCFunction_Type)
}

#[cfg(Py_3_9)]
Expand All @@ -35,7 +36,7 @@ pub unsafe fn PyCFunction_Check(op: *mut PyObject) -> c_int {
#[cfg(not(Py_3_9))]
#[inline]
pub unsafe fn PyCFunction_Check(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == &raw mut PyCFunction_Type) as c_int
Py_IS_TYPE(op, &raw mut PyCFunction_Type)
}

pub type PyCFunction =
Expand Down
2 changes: 1 addition & 1 deletion pyo3-ffi/src/moduleobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub unsafe fn PyModule_Check(op: *mut PyObject) -> c_int {

#[inline]
pub unsafe fn PyModule_CheckExact(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == &raw mut PyModule_Type) as c_int
Py_IS_TYPE(op, &raw mut PyModule_Type)
}

extern_libpython! {
Expand Down
6 changes: 6 additions & 0 deletions pyo3-ffi/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,13 @@ pub unsafe fn Py_SIZE(ob: *mut PyObject) -> Py_ssize_t {
_Py_SIZE(ob)
}

#[cfg(all(Py_LIMITED_API, Py_3_15))]
extern_libpython! {
pub fn Py_IS_TYPE(ob: *mut PyObject, tp: *mut PyTypeObject) -> c_int;
}

#[inline]
#[cfg(not(all(Py_LIMITED_API, Py_3_15)))]
pub unsafe fn Py_IS_TYPE(ob: *mut PyObject, tp: *mut PyTypeObject) -> c_int {
(Py_TYPE(ob) == tp) as c_int
}
Expand Down
2 changes: 1 addition & 1 deletion pyo3-ffi/src/rangeobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ extern_libpython! {

#[inline]
pub unsafe fn PyRange_Check(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == &raw mut PyRange_Type) as c_int
Py_IS_TYPE(op, &raw mut PyRange_Type)
}
2 changes: 1 addition & 1 deletion pyo3-ffi/src/sliceobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ extern_libpython! {

#[inline]
pub unsafe fn PySlice_Check(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == &raw mut PySlice_Type) as c_int
Py_IS_TYPE(op, &raw mut PySlice_Type)
}

extern_libpython! {
Expand Down
2 changes: 1 addition & 1 deletion pyo3-ffi/src/traceback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ extern_libpython! {
#[inline]
#[cfg(not(PyPy))]
pub unsafe fn PyTraceBack_Check(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == &raw mut PyTraceBack_Type) as c_int
Py_IS_TYPE(op, &raw mut PyTraceBack_Type)
}
2 changes: 1 addition & 1 deletion pyo3-ffi/src/tupleobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub unsafe fn PyTuple_Check(op: *mut PyObject) -> c_int {

#[inline]
pub unsafe fn PyTuple_CheckExact(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == &raw mut PyTuple_Type) as c_int
Py_IS_TYPE(op, &raw mut PyTuple_Type)
}

extern_libpython! {
Expand Down
2 changes: 1 addition & 1 deletion pyo3-ffi/src/unicodeobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub unsafe fn PyUnicode_Check(op: *mut PyObject) -> c_int {
#[inline]
#[cfg(not(PyPy))]
pub unsafe fn PyUnicode_CheckExact(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == &raw mut PyUnicode_Type) as c_int
Py_IS_TYPE(op, &raw mut PyUnicode_Type)
}

pub const Py_UNICODE_REPLACEMENT_CHARACTER: Py_UCS4 = 0xFFFD;
Expand Down
6 changes: 3 additions & 3 deletions pyo3-ffi/src/weakrefobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ pub unsafe fn PyWeakref_CheckRef(op: *mut PyObject) -> c_int {
#[inline]
#[cfg(not(PyPy))]
pub unsafe fn PyWeakref_CheckRefExact(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == &raw mut _PyWeakref_RefType) as c_int
Py_IS_TYPE(op, &raw mut _PyWeakref_RefType)
}

#[inline]
#[cfg(not(PyPy))]
pub unsafe fn PyWeakref_CheckProxy(op: *mut PyObject) -> c_int {
((Py_TYPE(op) == &raw mut _PyWeakref_ProxyType)
|| (Py_TYPE(op) == &raw mut _PyWeakref_CallableProxyType)) as c_int
(Py_IS_TYPE(op, &raw mut _PyWeakref_ProxyType) > 0
|| Py_IS_TYPE(op, &raw mut _PyWeakref_CallableProxyType) > 0) as c_int
}

#[inline]
Expand Down
Loading