diff --git a/src/ffi/objectabstract.rs b/src/ffi/objectabstract.rs index e180d3c3..289a2b7b 100644 --- a/src/ffi/objectabstract.rs +++ b/src/ffi/objectabstract.rs @@ -98,7 +98,7 @@ extern "C" { #[cfg(not(Py_LIMITED_API))] #[inline] pub unsafe fn PyObject_CheckBuffer(o: *mut PyObject) -> c_int { - let tp_as_buffer = (*(*o).ob_type).tp_as_buffer; + let tp_as_buffer = (*Py_TYPE(o)).tp_as_buffer; (!tp_as_buffer.is_null() && (*tp_as_buffer).bf_getbuffer.is_some()) as c_int } @@ -158,7 +158,7 @@ extern "C" { #[inline] #[cfg_attr(PyPy, link_name = "PyPyIter_Check")] pub unsafe fn PyIter_Check(o: *mut PyObject) -> c_int { - (match (*(*o).ob_type).tp_iternext { + (match (*Py_TYPE(o)).tp_iternext { Some(tp_iternext) => { tp_iternext as *const c_void != crate::ffi::object::_PyObject_NextNotImplemented as *const c_void @@ -217,7 +217,7 @@ extern "C" { #[inline] #[cfg_attr(PyPy, link_name = "PyPyIndex_Check")] pub unsafe fn PyIndex_Check(o: *mut PyObject) -> c_int { - let tp_as_number = (*(*o).ob_type).tp_as_number; + 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 } diff --git a/src/ffi/pyerrors.rs b/src/ffi/pyerrors.rs index 2467902f..f61233cf 100644 --- a/src/ffi/pyerrors.rs +++ b/src/ffi/pyerrors.rs @@ -69,13 +69,13 @@ pub unsafe fn PyExceptionClass_Check(x: *mut PyObject) -> c_int { #[inline] pub unsafe fn PyExceptionInstance_Check(x: *mut PyObject) -> c_int { - PyType_FastSubclass((*x).ob_type, Py_TPFLAGS_BASE_EXC_SUBCLASS) + PyType_FastSubclass(Py_TYPE(x), Py_TPFLAGS_BASE_EXC_SUBCLASS) } #[inline] #[cfg_attr(PyPy, link_name = "PyPyExceptionInstance_Class")] pub unsafe fn PyExceptionInstance_Class(x: *mut PyObject) -> *mut PyObject { - (*x).ob_type as *mut PyObject + Py_TYPE(x) as *mut PyObject } // ported from cpython exception.c (line 2096) diff --git a/src/type_object.rs b/src/type_object.rs index 3548ac0e..a1b43c0e 100644 --- a/src/type_object.rs +++ b/src/type_object.rs @@ -111,7 +111,7 @@ pub unsafe trait PyTypeInfo: Sized { /// Check if `*mut ffi::PyObject` is exact instance of this type fn is_exact_instance(object: &PyAny) -> bool { - unsafe { (*object.as_ptr()).ob_type == Self::type_object_raw(object.py()) } + unsafe { ffi::Py_TYPE(object.as_ptr()) == Self::type_object_raw(object.py()) } } } diff --git a/src/types/any.rs b/src/types/any.rs index 725ecce5..76ddf089 100644 --- a/src/types/any.rs +++ b/src/types/any.rs @@ -366,13 +366,13 @@ impl PyAny { /// Returns the Python type object for this object's type. pub fn get_type(&self) -> &PyType { - unsafe { PyType::from_type_ptr(self.py(), (*self.as_ptr()).ob_type) } + unsafe { PyType::from_type_ptr(self.py(), ffi::Py_TYPE(self.as_ptr())) } } /// Returns the Python type pointer for this object. #[inline] pub fn get_type_ptr(&self) -> *mut ffi::PyTypeObject { - unsafe { (*self.as_ptr()).ob_type } + unsafe { ffi::Py_TYPE(self.as_ptr()) } } /// Casts the PyObject to a concrete Python object type.