File tree Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Original file line number Diff line number Diff line change @@ -73,7 +73,7 @@ impl ModuleState {
7373 ///
7474 /// Calling this function multiple times on a single ModuleState is a noop,
7575 /// beyond the first
76- fn drop_impl ( & mut self ) {
76+ unsafe fn drop_impl ( & mut self ) {
7777 if let Some ( ptr) = self . inner . take ( ) . map ( |state| state. as_ptr ( ) ) {
7878 // SAFETY: This ptr is allocated via Box::new in Self::new, and is
7979 // non null
@@ -135,6 +135,8 @@ impl ModuleState {
135135 pub ( crate ) unsafe fn pymodule_free_state ( module : * mut ffi:: PyObject ) {
136136 unsafe {
137137 if let Some ( state) = Self :: pymodule_get_state ( module) {
138+ // SAFETY: this callback is called when python is freeing the
139+ // associated PyModule, so we should never be accessed again
138140 ( * state. as_ptr ( ) ) . drop_impl ( )
139141 }
140142 }
@@ -143,7 +145,8 @@ impl ModuleState {
143145
144146impl Drop for ModuleState {
145147 fn drop ( & mut self ) {
146- self . drop_impl ( ) ;
148+ // SAFETY: we're being dropped, so we'll never be accessed again
149+ unsafe { self . drop_impl ( ) } ;
147150 }
148151}
149152
You can’t perform that action at this time.
0 commit comments