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

PyObjectAlloc no longer uses specialization and freelist is removed #264

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Removed
* `pyo3::freelist` removed.

## [0.5.0] - 2018-11-11

### Added
Expand All @@ -26,7 +29,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Changed
* Removes the types from the root module and the prelude. They now live in `pyo3::types` instead.
* All exceptions are consturcted with `py_err` instead of `new`, as they return `PyErr` and not `Self`.
* All exceptions are constructed with `py_err` instead of `new`, as they return `PyErr` and not `Self`.
* `as_mut` and friends take and `&mut self` instead of `&self`
* `ObjectProtocol::call` now takes an `Option<&PyDict>` for the kwargs instead of an `IntoPyDictPointer`.
* `IntoPyDictPointer` was replace by `IntoPyDict` which doesn't convert `PyDict` itself anymore and returns a `PyDict` instead of `*mut PyObject`.
Expand Down
30 changes: 0 additions & 30 deletions pyo3-derive-backend/src/py_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,32 +115,6 @@ fn impl_class(
None
};

let extra = {
if let Some(freelist) = params.get("freelist") {
Some(quote! {
impl ::pyo3::freelist::PyObjectWithFreeList for #cls {
#[inline]
fn get_free_list() -> &'static mut ::pyo3::freelist::FreeList<*mut ::pyo3::ffi::PyObject> {
static mut FREELIST: *mut ::pyo3::freelist::FreeList<*mut ::pyo3::ffi::PyObject> = 0 as *mut _;
unsafe {
if FREELIST.is_null() {
FREELIST = Box::into_raw(Box::new(
::pyo3::freelist::FreeList::with_capacity(#freelist)));

<#cls as ::pyo3::typeob::PyTypeCreate>::init_type();
}
&mut *FREELIST
}
}
}

#extra
})
} else {
extra
}
};

let extra = if !descriptors.is_empty() {
let ty = syn::parse_str(&cls.to_string()).expect("no name");
let desc_impls = impl_descriptors(&ty, descriptors);
Expand Down Expand Up @@ -396,10 +370,6 @@ fn parse_attribute(
};

match key.as_str() {
"freelist" => {
// TODO: check if int literal
params.insert("freelist", *ass.right.clone());
}
"name" => match *ass.right {
syn::Expr::Path(ref exp) if exp.path.segments.len() == 1 => {
params.insert("name", exp.clone().into());
Expand Down
139 changes: 0 additions & 139 deletions src/freelist.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ mod conversion;
#[doc(hidden)]
pub mod derive_utils;
mod err;
pub mod freelist;
mod instance;
mod noargs;
mod object;
Expand Down
4 changes: 2 additions & 2 deletions src/typeob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ where
pytype_drop::<T>(py, obj);
}

default unsafe fn alloc(_py: Python) -> PyResult<*mut ffi::PyObject> {
unsafe fn alloc(_py: Python) -> PyResult<*mut ffi::PyObject> {
// TODO: remove this
<T as PyTypeCreate>::init_type();

Expand All @@ -230,7 +230,7 @@ where
Ok(obj)
}

default unsafe fn dealloc(py: Python, obj: *mut ffi::PyObject) {
unsafe fn dealloc(py: Python, obj: *mut ffi::PyObject) {
Self::drop(py, obj);

#[cfg(Py_3)]
Expand Down
30 changes: 0 additions & 30 deletions tests/test_gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,6 @@ use std::sync::Arc;
#[macro_use]
mod common;

#[pyclass(freelist = 2)]
struct ClassWithFreelist {
token: PyToken,
}

#[test]
fn class_with_freelist() {
let ptr;
{
let gil = Python::acquire_gil();
let py = gil.python();

let inst = Py::new(py, |t| ClassWithFreelist { token: t }).unwrap();
let _inst2 = Py::new(py, |t| ClassWithFreelist { token: t }).unwrap();
ptr = inst.as_ptr();
drop(inst);
}

{
let gil = Python::acquire_gil();
let py = gil.python();

let inst3 = Py::new(py, |t| ClassWithFreelist { token: t }).unwrap();
assert_eq!(ptr, inst3.as_ptr());

let inst4 = Py::new(py, |t| ClassWithFreelist { token: t }).unwrap();
assert_ne!(ptr, inst4.as_ptr())
}
}

struct TestDropCall {
drop_called: Arc<AtomicBool>,
}
Expand Down