Merge pull request #1046 from davidhewitt/py-type

Replace internal uses of (*o).ob_type with Py_TYPE(o)
This commit is contained in:
David Hewitt 2020-07-18 10:28:42 +01:00 committed by GitHub
commit 2a36863ebc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 8 deletions

View file

@ -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
}

View file

@ -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)

View file

@ -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()) }
}
}

View file

@ -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.