From 56b82c2f7dc42eaa480133183875fceaf853d278 Mon Sep 17 00:00:00 2001 From: kngwyu Date: Sun, 28 Oct 2018 18:16:44 +0900 Subject: [PATCH] Temporary hack to compile with latest nightly --- src/freelist.rs | 6 +++--- src/typeob.rs | 15 +++++++++------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/freelist.rs b/src/freelist.rs index 722a7723..4d2b7561 100644 --- a/src/freelist.rs +++ b/src/freelist.rs @@ -7,7 +7,7 @@ use ffi; use python::Python; use std::mem; use std::os::raw::c_void; -use typeob::{PyObjectAlloc, PyTypeInfo}; +use typeob::{pytype_drop, PyObjectAlloc, PyTypeInfo}; /// Implementing this trait for custom class adds free allocation list to class. /// The performance improvement applies to types that are often created and deleted in a row, @@ -85,7 +85,7 @@ where #[cfg(Py_3)] unsafe fn dealloc(py: Python, obj: *mut ffi::PyObject) { - Self::drop(py, obj); + pytype_drop::(py, obj); if ffi::PyObject_CallFinalizerFromDealloc(obj) < 0 { return; @@ -114,7 +114,7 @@ where #[cfg(not(Py_3))] unsafe fn dealloc(py: Python, obj: *mut ffi::PyObject) { - Self::drop(py, obj); + pytype_drop::(py, obj); if let Some(obj) = ::get_free_list().insert(obj) { match (*T::type_object()).tp_free { diff --git a/src/typeob.rs b/src/typeob.rs index 8b42fbc9..d85ffdb2 100644 --- a/src/typeob.rs +++ b/src/typeob.rs @@ -186,6 +186,14 @@ impl PyObjectWithToken for PyRawObject { } } +pub(crate) unsafe fn pytype_drop(py: Python, obj: *mut ffi::PyObject) { + if T::OFFSET != 0 { + let ptr = (obj as *mut u8).offset(T::OFFSET) as *mut T; + std::ptr::drop_in_place(ptr); + pytype_drop::(py, obj); + } +} + /// A Python object allocator that is usable as a base type for `#[pyclass]` pub trait PyObjectAlloc { /// Allocates a new object (usually by calling ty->tp_alloc), @@ -207,12 +215,7 @@ where #[allow(unconditional_recursion)] /// Calls the rust destructor for the object. default unsafe fn drop(py: Python, obj: *mut ffi::PyObject) { - if T::OFFSET != 0 { - let ptr = (obj as *mut u8).offset(T::OFFSET) as *mut T; - std::ptr::drop_in_place(ptr); - - T::BaseType::drop(py, obj); - } + pytype_drop::(py, obj); } default unsafe fn alloc(_py: Python) -> PyResult<*mut ffi::PyObject> {