Fix lifetime soundness in freelist

This commit is contained in:
David Hewitt 2020-10-18 18:36:31 +01:00
parent 95ed5bb0b2
commit 7ddcf45ec5
2 changed files with 2 additions and 2 deletions

View File

@ -267,7 +267,7 @@ fn impl_class(
quote! {
impl pyo3::freelist::PyClassWithFreeList for #cls {
#[inline]
fn get_free_list(_py: pyo3::Python) -> &'static mut pyo3::freelist::FreeList<*mut pyo3::ffi::PyObject> {
fn get_free_list(_py: pyo3::Python) -> &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() {

View File

@ -12,7 +12,7 @@ use std::os::raw::c_void;
/// The performance improvement applies to types that are often created and deleted in a row,
/// so that they can benefit from a freelist.
pub trait PyClassWithFreeList {
fn get_free_list(py: Python) -> &'static mut FreeList<*mut ffi::PyObject>;
fn get_free_list(py: Python) -> &mut FreeList<*mut ffi::PyObject>;
}
pub enum Slot<T> {