Merge pull request #1248 from davidhewitt/freelist-lifetime

Fix lifetime soundness in freelist
This commit is contained in:
David Hewitt 2020-10-18 22:43:19 +01:00 committed by GitHub
commit ef50a10537
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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> {