Merge pull request #252 from kngwyu/compile-hack

Temporary hack to compile with latest nightly
This commit is contained in:
konstin 2018-10-29 17:27:31 +01:00 committed by GitHub
commit 74d9557784
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 9 deletions

View File

@ -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::<T>(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::<T>(py, obj);
if let Some(obj) = <T as PyObjectWithFreeList>::get_free_list().insert(obj) {
match (*T::type_object()).tp_free {

View File

@ -186,6 +186,14 @@ impl PyObjectWithToken for PyRawObject {
}
}
pub(crate) unsafe fn pytype_drop<T: PyTypeInfo>(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::<T::BaseType>(py, obj);
}
}
/// A Python object allocator that is usable as a base type for `#[pyclass]`
pub trait PyObjectAlloc<T> {
/// 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::<T>(py, obj);
}
default unsafe fn alloc(_py: Python) -> PyResult<*mut ffi::PyObject> {