From 7ddcf45ec5dabc43b1ad7b6a91d219bc9f8225c6 Mon Sep 17 00:00:00 2001 From: David Hewitt <1939362+davidhewitt@users.noreply.github.com> Date: Sun, 18 Oct 2020 18:36:31 +0100 Subject: [PATCH] Fix lifetime soundness in freelist --- pyo3-derive-backend/src/pyclass.rs | 2 +- src/freelist.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyo3-derive-backend/src/pyclass.rs b/pyo3-derive-backend/src/pyclass.rs index 558a6f6e..032935d5 100644 --- a/pyo3-derive-backend/src/pyclass.rs +++ b/pyo3-derive-backend/src/pyclass.rs @@ -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() { diff --git a/src/freelist.rs b/src/freelist.rs index 65331773..5b56c337 100644 --- a/src/freelist.rs +++ b/src/freelist.rs @@ -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 {