@@ -165,15 +165,15 @@ impl<T: PyNativeType + PyTypeInfo> PyObjectRecursiveOperations
165
165
// the 'most derived class' of `obj`. i.e. the result of calling `type(obj)`.
166
166
let actual_type = unsafe { PyType :: from_borrowed_type_ptr ( py, ffi:: Py_TYPE ( obj) ) } ;
167
167
168
- if type_ptr == std:: ptr:: addr_of_mut!( ffi:: PyBaseObject_Type ) {
168
+ if std :: ptr :: eq ( type_ptr, std:: ptr:: addr_of_mut!( ffi:: PyBaseObject_Type ) ) {
169
169
// the `PyBaseObject_Type` destructor (tp_dealloc) just calls tp_free so we can do this directly
170
170
let tp_free = actual_type
171
171
. get_slot ( TP_FREE )
172
172
. expect ( "base type should have tp_free" ) ;
173
173
return unsafe { tp_free ( obj. cast ( ) ) } ;
174
174
}
175
175
176
- if type_ptr == std:: ptr:: addr_of_mut!( ffi:: PyType_Type ) {
176
+ if std :: ptr :: eq ( type_ptr, std:: ptr:: addr_of_mut!( ffi:: PyType_Type ) ) {
177
177
let tp_dealloc = unsafe {
178
178
PyType :: from_borrowed_type_ptr ( py, type_ptr)
179
179
. get_slot ( TP_DEALLOC )
@@ -189,23 +189,21 @@ impl<T: PyNativeType + PyTypeInfo> PyObjectRecursiveOperations
189
189
190
190
// More complex native types (e.g. `extends=PyDict`) require calling the base's dealloc.
191
191
#[ cfg( not( Py_LIMITED_API ) ) ]
192
- {
192
+ unsafe {
193
193
// FIXME: should this be using actual_type.tp_dealloc?
194
- if let Some ( dealloc) = unsafe { ( * type_ptr) . tp_dealloc } {
194
+ if let Some ( dealloc) = ( * type_ptr) . tp_dealloc {
195
195
// Before CPython 3.11 BaseException_dealloc would use Py_GC_UNTRACK which
196
196
// assumes the exception is currently GC tracked, so we have to re-track
197
197
// before calling the dealloc so that it can safely call Py_GC_UNTRACK.
198
198
#[ cfg( not( any( Py_3_11 , PyPy ) ) ) ]
199
199
if ffi:: PyType_FastSubclass ( type_ptr, ffi:: Py_TPFLAGS_BASE_EXC_SUBCLASS ) == 1 {
200
200
ffi:: PyObject_GC_Track ( obj. cast ( ) ) ;
201
201
}
202
- unsafe { dealloc ( obj) } ;
202
+ dealloc ( obj) ;
203
203
} else {
204
- unsafe {
205
- ( * actual_type. as_type_ptr ( ) )
206
- . tp_free
207
- . expect ( "type missing tp_free" ) ( obj. cast ( ) )
208
- } ;
204
+ ( * actual_type. as_type_ptr ( ) )
205
+ . tp_free
206
+ . expect ( "type missing tp_free" ) ( obj. cast ( ) ) ;
209
207
}
210
208
}
211
209
@@ -286,7 +284,9 @@ pub(crate) mod static_layout {
286
284
287
285
impl < T : PyClassImpl > PyStaticClassLayout < T > {
288
286
/// A layout is valid if `ob_base` does not have the type [InvalidStaticLayout].
289
- pub const IS_VALID : bool = offset_of ! ( Self , contents) > 0 ;
287
+ pub fn is_valid ( ) -> bool {
288
+ offset_of ! ( Self , contents) > 0
289
+ }
290
290
}
291
291
292
292
unsafe impl < T : PyClassImpl > PyLayout < T > for PyStaticClassLayout < T > { }
@@ -302,7 +302,7 @@ pub(crate) mod static_layout {
302
302
unsafe impl < T , U > PyLayout < T > for PyStaticNativeLayout < U > where U : PySizedLayout < T > { }
303
303
304
304
/// a struct for use with opaque native types to indicate that they
305
- /// cannot be used as part of a static layout (see `PyStaticLayout::IS_VALID `).
305
+ /// cannot be used as part of a static layout (see `PyStaticLayout::is_valid `).
306
306
#[ repr( C ) ]
307
307
pub struct InvalidStaticLayout ;
308
308
@@ -374,7 +374,7 @@ impl PyObjectLayout {
374
374
} else {
375
375
let obj: * mut static_layout:: PyStaticClassLayout < T > = obj. cast ( ) ;
376
376
debug_assert ! (
377
- static_layout:: PyStaticClassLayout :: <T >:: IS_VALID ,
377
+ static_layout:: PyStaticClassLayout :: <T >:: is_valid ( ) ,
378
378
"invalid static layout found"
379
379
) ;
380
380
unsafe { addr_of_mut ! ( ( * obj) . contents) }
0 commit comments