Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporary hack to compile with latest nightly #252

Merged
merged 1 commit into from
Oct 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/freelist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
15 changes: 9 additions & 6 deletions src/typeob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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> {
Expand Down