Skip to content

Commit 74d9557

Browse files
authored
Merge pull request #252 from kngwyu/compile-hack
Temporary hack to compile with latest nightly
2 parents d598cf4 + 56b82c2 commit 74d9557

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/freelist.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use ffi;
77
use python::Python;
88
use std::mem;
99
use std::os::raw::c_void;
10-
use typeob::{PyObjectAlloc, PyTypeInfo};
10+
use typeob::{pytype_drop, PyObjectAlloc, PyTypeInfo};
1111

1212
/// Implementing this trait for custom class adds free allocation list to class.
1313
/// The performance improvement applies to types that are often created and deleted in a row,
@@ -85,7 +85,7 @@ where
8585

8686
#[cfg(Py_3)]
8787
unsafe fn dealloc(py: Python, obj: *mut ffi::PyObject) {
88-
Self::drop(py, obj);
88+
pytype_drop::<T>(py, obj);
8989

9090
if ffi::PyObject_CallFinalizerFromDealloc(obj) < 0 {
9191
return;
@@ -114,7 +114,7 @@ where
114114

115115
#[cfg(not(Py_3))]
116116
unsafe fn dealloc(py: Python, obj: *mut ffi::PyObject) {
117-
Self::drop(py, obj);
117+
pytype_drop::<T>(py, obj);
118118

119119
if let Some(obj) = <T as PyObjectWithFreeList>::get_free_list().insert(obj) {
120120
match (*T::type_object()).tp_free {

src/typeob.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,14 @@ impl PyObjectWithToken for PyRawObject {
186186
}
187187
}
188188

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+
189197
/// A Python object allocator that is usable as a base type for `#[pyclass]`
190198
pub trait PyObjectAlloc<T> {
191199
/// Allocates a new object (usually by calling ty->tp_alloc),
@@ -207,12 +215,7 @@ where
207215
#[allow(unconditional_recursion)]
208216
/// Calls the rust destructor for the object.
209217
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);
216219
}
217220

218221
default unsafe fn alloc(_py: Python) -> PyResult<*mut ffi::PyObject> {

0 commit comments

Comments
 (0)