File tree 2 files changed +12
-9
lines changed
2 files changed +12
-9
lines changed Original file line number Diff line number Diff line change 7
7
use python:: Python ;
8
8
use std:: mem;
9
9
use std:: os:: raw:: c_void;
10
- use typeob:: { PyObjectAlloc , PyTypeInfo } ;
10
+ use typeob:: { pytype_drop , PyObjectAlloc , PyTypeInfo } ;
11
11
12
12
/// Implementing this trait for custom class adds free allocation list to class.
13
13
/// The performance improvement applies to types that are often created and deleted in a row,
85
85
86
86
#[ cfg( Py_3 ) ]
87
87
unsafe fn dealloc ( py : Python , obj : * mut ffi:: PyObject ) {
88
- Self :: drop ( py, obj) ;
88
+ pytype_drop :: < T > ( py, obj) ;
89
89
90
90
if ffi:: PyObject_CallFinalizerFromDealloc ( obj) < 0 {
91
91
return ;
@@ -114,7 +114,7 @@ where
114
114
115
115
#[ cfg( not( Py_3 ) ) ]
116
116
unsafe fn dealloc ( py : Python , obj : * mut ffi:: PyObject ) {
117
- Self :: drop ( py, obj) ;
117
+ pytype_drop :: < T > ( py, obj) ;
118
118
119
119
if let Some ( obj) = <T as PyObjectWithFreeList >:: get_free_list ( ) . insert ( obj) {
120
120
match ( * T :: type_object ( ) ) . tp_free {
Original file line number Diff line number Diff line change @@ -186,6 +186,14 @@ impl PyObjectWithToken for PyRawObject {
186
186
}
187
187
}
188
188
189
+ pub ( crate ) unsafe fn pytype_drop < T : PyTypeInfo > ( py : Python , obj : * mut ffi:: PyObject ) {
190
+ if T :: OFFSET != 0 {
191
+ let ptr = ( obj as * mut u8 ) . offset ( T :: OFFSET ) as * mut T ;
192
+ std:: ptr:: drop_in_place ( ptr) ;
193
+ pytype_drop :: < T :: BaseType > ( py, obj) ;
194
+ }
195
+ }
196
+
189
197
/// A Python object allocator that is usable as a base type for `#[pyclass]`
190
198
pub trait PyObjectAlloc < T > {
191
199
/// Allocates a new object (usually by calling ty->tp_alloc),
@@ -207,12 +215,7 @@ where
207
215
#[ allow( unconditional_recursion) ]
208
216
/// Calls the rust destructor for the object.
209
217
default unsafe fn drop ( py : Python , obj : * mut ffi:: PyObject ) {
210
- if T :: OFFSET != 0 {
211
- let ptr = ( obj as * mut u8 ) . offset ( T :: OFFSET ) as * mut T ;
212
- std:: ptr:: drop_in_place ( ptr) ;
213
-
214
- T :: BaseType :: drop ( py, obj) ;
215
- }
218
+ pytype_drop :: < T > ( py, obj) ;
216
219
}
217
220
218
221
default unsafe fn alloc ( _py : Python ) -> PyResult < * mut ffi:: PyObject > {
You can’t perform that action at this time.
0 commit comments